Skip to content

Commit

Permalink
RANGER-5061: checkstyle compliance updates - security-admin org.apach…
Browse files Browse the repository at this point in the history
…e.ranger.service
  • Loading branch information
pradeepagrawal8184 committed Jan 8, 2025
1 parent 23cb503 commit ccc0ddf
Show file tree
Hide file tree
Showing 79 changed files with 8,926 additions and 10,075 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
* under the License.
*/

package org.apache.ranger.service;

import java.util.ArrayList;
import java.util.List;
package org.apache.ranger.service;

import org.apache.ranger.common.RangerConstants;
import org.apache.ranger.common.SearchCriteria;
Expand All @@ -34,157 +31,114 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Scope("singleton")
public class AuthSessionService extends
AbstractBaseResourceService<XXAuthSession, VXAuthSession> {

public static final String NAME = "AuthSession";

public static final List<SortField> AUTH_SESSION_SORT_FLDS = new ArrayList<SortField>();
static {
AUTH_SESSION_SORT_FLDS.add(new SortField("id", "obj.id"));
AUTH_SESSION_SORT_FLDS.add(new SortField("authTime", "obj.authTime",
true, SortField.SORT_ORDER.DESC));
}

public static List<SearchField> AUTH_SESSION_SEARCH_FLDS = new ArrayList<SearchField>();
static {
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createLong("id", "obj.id"));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("loginId",
"obj.loginId", SearchField.SEARCH_TYPE.PARTIAL,
StringUtil.VALIDATION_LOGINID));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createLong("userId",
"obj.userId"));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createEnum("authStatus",
"obj.authStatus", "statusList", XXAuthSession.AuthStatus_MAX));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createEnum("authType",
"obj.authType", "Authentication Type",
XXAuthSession.AuthType_MAX));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createEnum("deviceType",
"obj.deviceType", "Device Type", RangerConstants.DeviceType_MAX));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("requestIP",
"obj.requestIP", SearchField.SEARCH_TYPE.PARTIAL,
StringUtil.VALIDATION_IP_ADDRESS));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString(
"requestUserAgent", "obj.requestUserAgent",
SearchField.SEARCH_TYPE.PARTIAL, null));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("firstName",
"obj.user.firstName", SearchField.DATA_TYPE.STRING,
SearchField.SEARCH_TYPE.PARTIAL));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("lastName",
"obj.user.lastName", SearchField.DATA_TYPE.STRING,
SearchField.SEARCH_TYPE.PARTIAL));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("requestIP",
"obj.requestIP", SearchField.SEARCH_TYPE.PARTIAL,
StringUtil.VALIDATION_IP_ADDRESS));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("startDate", "obj.createTime",
SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.GREATER_EQUAL_THAN));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("endDate", "obj.createTime",
SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.LESS_EQUAL_THAN));
}

@Override
protected String getResourceName() {
return NAME;
}

/*
* (non-Javadoc)
*/
@Override
protected XXAuthSession createEntityObject() {
return new XXAuthSession();
}

/*
* (non-Javadoc)
*/
@Override
protected VXAuthSession createViewObject() {
return new VXAuthSession();
}

/*
* (non-Javadoc)
*/
@Override
protected void validateForCreate(VXAuthSession vXAuthSession) {
logger.error("This method is not required and shouldn't be called.",
new Throwable().fillInStackTrace());
}

/*
* (non-Javadoc)
*/
@Override
protected void validateForUpdate(VXAuthSession vXAuthSession,
XXAuthSession mObj) {
logger.error("This method is not required and shouldn't be called.",
new Throwable().fillInStackTrace());
}

/*
* (non-Javadoc)
*/
@Override
protected XXAuthSession mapViewToEntityBean(VXAuthSession vXAuthSession,
XXAuthSession t, int OPERATION_CONTEXT) {
logger.error("This method is not required and shouldn't be called.",
new Throwable().fillInStackTrace());
return null;
}

/*
* (non-Javadoc)
*/
@Override
protected VXAuthSession mapEntityToViewBean(VXAuthSession viewObj,
XXAuthSession resource) {
viewObj.setLoginId(resource.getLoginId());
viewObj.setAuthTime(resource.getAuthTime());
viewObj.setAuthStatus(resource.getAuthStatus());
viewObj.setAuthType(resource.getAuthType());
viewObj.setDeviceType(resource.getDeviceType());
viewObj.setId(resource.getId());
viewObj.setRequestIP(resource.getRequestIP());

viewObj.setRequestUserAgent(resource.getRequestUserAgent());

if (resource.getUserId() != null) {
viewObj.setUserId(resource.getUserId());

XXPortalUser gjUser = daoManager.getXXPortalUser().getById(resource.getUserId());
if (gjUser != null) {
viewObj.setEmailAddress(gjUser.getEmailAddress());
viewObj.setFamilyScreenName(gjUser.getLastName());
viewObj.setFirstName(gjUser.getFirstName());
viewObj.setLastName(gjUser.getLastName());
viewObj.setPublicScreenName(gjUser.getPublicScreenName());
}
}

return viewObj;
}

/**
* @param searchCriteria
* @return
*/
public VXAuthSessionList search(SearchCriteria searchCriteria) {
VXAuthSessionList returnList = new VXAuthSessionList();
List<VXAuthSession> viewList = new ArrayList<VXAuthSession>();

List<XXAuthSession> resultList = searchResources(searchCriteria,
AUTH_SESSION_SEARCH_FLDS, AUTH_SESSION_SORT_FLDS, returnList);

// Iterate over the result list and create the return list
for (XXAuthSession gjObj : resultList) {
VXAuthSession viewObj = populateViewBean(gjObj);
viewList.add(viewObj);
}

returnList.setVXAuthSessions(viewList);
return returnList;
}
public class AuthSessionService extends AbstractBaseResourceService<XXAuthSession, VXAuthSession> {
public static final String NAME = "AuthSession";

public static final List<SortField> AUTH_SESSION_SORT_FLDS = new ArrayList<>();
public static final List<SearchField> AUTH_SESSION_SEARCH_FLDS = new ArrayList<>();

/**
* @param searchCriteria
* @return
*/
public VXAuthSessionList search(SearchCriteria searchCriteria) {
VXAuthSessionList returnList = new VXAuthSessionList();
List<VXAuthSession> viewList = new ArrayList<>();

List<XXAuthSession> resultList = searchResources(searchCriteria, AUTH_SESSION_SEARCH_FLDS, AUTH_SESSION_SORT_FLDS, returnList);

// Iterate over the result list and create the return list
for (XXAuthSession gjObj : resultList) {
VXAuthSession viewObj = populateViewBean(gjObj);
viewList.add(viewObj);
}

returnList.setVXAuthSessions(viewList);
return returnList;
}

@Override
protected void validateForCreate(VXAuthSession vXAuthSession) {
logger.error("This method is not required and shouldn't be called.", new Throwable().fillInStackTrace());
}

@Override
protected void validateForUpdate(VXAuthSession vXAuthSession, XXAuthSession mObj) {
logger.error("This method is not required and shouldn't be called.", new Throwable().fillInStackTrace());
}

@Override
protected XXAuthSession mapViewToEntityBean(VXAuthSession vXAuthSession, XXAuthSession t, int operationContext) {
logger.error("This method is not required and shouldn't be called.", new Throwable().fillInStackTrace());
return null;
}

@Override
protected VXAuthSession mapEntityToViewBean(VXAuthSession viewObj, XXAuthSession resource) {
viewObj.setLoginId(resource.getLoginId());
viewObj.setAuthTime(resource.getAuthTime());
viewObj.setAuthStatus(resource.getAuthStatus());
viewObj.setAuthType(resource.getAuthType());
viewObj.setDeviceType(resource.getDeviceType());
viewObj.setId(resource.getId());
viewObj.setRequestIP(resource.getRequestIP());

viewObj.setRequestUserAgent(resource.getRequestUserAgent());

if (resource.getUserId() != null) {
viewObj.setUserId(resource.getUserId());

XXPortalUser gjUser = daoManager.getXXPortalUser().getById(resource.getUserId());
if (gjUser != null) {
viewObj.setEmailAddress(gjUser.getEmailAddress());
viewObj.setFamilyScreenName(gjUser.getLastName());
viewObj.setFirstName(gjUser.getFirstName());
viewObj.setLastName(gjUser.getLastName());
viewObj.setPublicScreenName(gjUser.getPublicScreenName());
}
}

return viewObj;
}

@Override
protected String getResourceName() {
return NAME;
}

@Override
protected XXAuthSession createEntityObject() {
return new XXAuthSession();
}

@Override
protected VXAuthSession createViewObject() {
return new VXAuthSession();
}

static {
AUTH_SESSION_SORT_FLDS.add(new SortField("id", "obj.id"));
AUTH_SESSION_SORT_FLDS.add(new SortField("authTime", "obj.authTime", true, SortField.SORT_ORDER.DESC));
}

static {
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createLong("id", "obj.id"));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("loginId", "obj.loginId", SearchField.SEARCH_TYPE.PARTIAL, StringUtil.VALIDATION_LOGINID));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createLong("userId", "obj.userId"));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createEnum("authStatus", "obj.authStatus", "statusList", XXAuthSession.AuthStatus_MAX));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createEnum("authType", "obj.authType", "Authentication Type", XXAuthSession.AuthType_MAX));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createEnum("deviceType", "obj.deviceType", "Device Type", RangerConstants.DeviceType_MAX));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("requestIP", "obj.requestIP", SearchField.SEARCH_TYPE.PARTIAL, StringUtil.VALIDATION_IP_ADDRESS));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("requestUserAgent", "obj.requestUserAgent", SearchField.SEARCH_TYPE.PARTIAL, null));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("firstName", "obj.user.firstName", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("lastName", "obj.user.lastName", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));
AUTH_SESSION_SEARCH_FLDS.add(SearchField.createString("requestIP", "obj.requestIP", SearchField.SEARCH_TYPE.PARTIAL, StringUtil.VALIDATION_IP_ADDRESS));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("startDate", "obj.createTime", SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.GREATER_EQUAL_THAN));
AUTH_SESSION_SEARCH_FLDS.add(new SearchField("endDate", "obj.createTime", SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.LESS_EQUAL_THAN));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@
* under the License.
*/

package org.apache.ranger.service;
package org.apache.ranger.service;

import org.apache.ranger.view.VXDataObject;

public abstract class PublicAPIServiceBase<VXA extends VXDataObject, VX extends VXDataObject> {
protected VX mapBaseAttributesToPublicObject(VXA vXAObj, VX vPublicObj) {
vPublicObj.setId(vXAObj.getId());
vPublicObj.setCreateDate(vXAObj.getCreateDate());
vPublicObj.setUpdateDate(vXAObj.getUpdateDate());
vPublicObj.setOwner(vXAObj.getOwner());
vPublicObj.setUpdatedBy(vXAObj.getUpdatedBy());
return vPublicObj;
}

protected VX mapBaseAttributesToPublicObject(VXA vXAObj, VX vPublicObj) {
vPublicObj.setId(vXAObj.getId());
vPublicObj.setCreateDate(vXAObj.getCreateDate());
vPublicObj.setUpdateDate(vXAObj.getUpdateDate());
vPublicObj.setOwner(vXAObj.getOwner());
vPublicObj.setUpdatedBy(vXAObj.getUpdatedBy());
return vPublicObj;
}

protected VXA mapBaseAttributesToXAObject(VX vPublicObj, VXA vXAObj) {
vXAObj.setId(vPublicObj.getId());
vXAObj.setCreateDate(vPublicObj.getCreateDate());
vXAObj.setUpdateDate(vPublicObj.getUpdateDate());
vXAObj.setOwner(vPublicObj.getOwner());
vXAObj.setUpdatedBy(vPublicObj.getUpdatedBy());

return vXAObj;
}
protected VXA mapBaseAttributesToXAObject(VX vPublicObj, VXA vXAObj) {
vXAObj.setId(vPublicObj.getId());
vXAObj.setCreateDate(vPublicObj.getCreateDate());
vXAObj.setUpdateDate(vPublicObj.getUpdateDate());
vXAObj.setOwner(vPublicObj.getOwner());
vXAObj.setUpdatedBy(vPublicObj.getUpdatedBy());

return vXAObj;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@

@Component
public class RangerAuditFields<T extends XXDBBase> {
public <T extends XXDBBase, PARENT extends XXDBBase> T populateAuditFields(T xObj, PARENT parentObj) {
xObj.setCreateTime(parentObj.getCreateTime());
xObj.setUpdateTime(parentObj.getUpdateTime());
xObj.setAddedByUserId(parentObj.getAddedByUserId());
xObj.setUpdatedByUserId(parentObj.getUpdatedByUserId());
return xObj;
}

public <T extends XXDBBase, PARENT extends XXDBBase> T populateAuditFields(T xObj, PARENT parentObj) {
xObj.setCreateTime(parentObj.getCreateTime());
xObj.setUpdateTime(parentObj.getUpdateTime());
xObj.setAddedByUserId(parentObj.getAddedByUserId());
xObj.setUpdatedByUserId(parentObj.getUpdatedByUserId());
return xObj;
}

public <T extends XXDBBase> T populateAuditFieldsForCreate(T xObj) {
xObj.setCreateTime(DateUtil.getUTCDate());
xObj.setUpdateTime(DateUtil.getUTCDate());
xObj.setAddedByUserId(ContextUtil.getCurrentUserId());
xObj.setUpdatedByUserId(ContextUtil.getCurrentUserId());
return xObj;
}

public <T extends XXDBBase> T populateAuditFieldsForCreate(T xObj) {
xObj.setCreateTime(DateUtil.getUTCDate());
xObj.setUpdateTime(DateUtil.getUTCDate());
xObj.setAddedByUserId(ContextUtil.getCurrentUserId());
xObj.setUpdatedByUserId(ContextUtil.getCurrentUserId());
return xObj;
}
}
Loading

0 comments on commit ccc0ddf

Please sign in to comment.