use of org.apache.ranger.common.UserSessionBase in project ranger by apache.
the class XUserMgr method createXUserPermission.
// User permission
public VXUserPermission createXUserPermission(VXUserPermission vXUserPermission) {
vXUserPermission = xUserPermissionService.createResource(vXUserPermission);
Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForPortalUserId(vXUserPermission.getUserId());
if (!CollectionUtils.isEmpty(userSessions)) {
for (UserSessionBase userSession : userSessions) {
logger.info("Assigning permission to user who's found logged in into system, so updating permission in session of that user: [" + vXUserPermission.getUserName() + "]");
sessionMgr.resetUserModulePermission(userSession);
}
}
return vXUserPermission;
}
use of org.apache.ranger.common.UserSessionBase in project ranger by apache.
the class XUserMgr method updateXGroupPermission.
public VXGroupPermission updateXGroupPermission(VXGroupPermission vXGroupPermission) {
vXGroupPermission = xGroupPermissionService.updateResource(vXGroupPermission);
List<XXGroupUser> grpUsers = daoManager.getXXGroupUser().findByGroupId(vXGroupPermission.getGroupId());
for (XXGroupUser xGrpUser : grpUsers) {
Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForXUserId(xGrpUser.getUserId());
if (!CollectionUtils.isEmpty(userSessions)) {
for (UserSessionBase userSession : userSessions) {
logger.info("Assigning permission to group whose one of the user found logged in into system, so updating permission in session of that user");
sessionMgr.resetUserModulePermission(userSession);
}
}
}
return vXGroupPermission;
}
use of org.apache.ranger.common.UserSessionBase in project ranger by apache.
the class XUserMgr method deleteXGroupPermission.
public void deleteXGroupPermission(Long id, boolean force) {
XXGroupPermission xGrpPerm = daoManager.getXXGroupPermission().getById(id);
if (xGrpPerm == null) {
throw restErrorUtil.createRESTException("No GroupPermission object with ID: [" + id + "found.", MessageEnums.DATA_NOT_FOUND);
}
xGroupPermissionService.deleteResource(id);
List<XXGroupUser> grpUsers = daoManager.getXXGroupUser().findByGroupId(xGrpPerm.getGroupId());
for (XXGroupUser xGrpUser : grpUsers) {
Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForXUserId(xGrpUser.getUserId());
if (!CollectionUtils.isEmpty(userSessions)) {
for (UserSessionBase userSession : userSessions) {
logger.info("deleting permission of the group whose one of the user found logged in into system, so updating permission in session of that user");
sessionMgr.resetUserModulePermission(userSession);
}
}
}
}
use of org.apache.ranger.common.UserSessionBase in project ranger by apache.
the class XUserMgr method modifyUserActiveStatus.
public void modifyUserActiveStatus(HashMap<Long, Integer> statusMap) {
checkAdminAccess();
UserSessionBase session = ContextUtil.getCurrentUserSession();
String currentUser = null;
if (session != null) {
currentUser = session.getLoginId();
if (currentUser == null || currentUser.trim().isEmpty()) {
currentUser = null;
}
}
if (currentUser == null) {
return;
}
Set<Map.Entry<Long, Integer>> entries = statusMap.entrySet();
for (Map.Entry<Long, Integer> entry : entries) {
if (entry != null && entry.getKey() != null && entry.getValue() != null) {
XXUser xUser = daoManager.getXXUser().getById(entry.getKey());
if (xUser != null) {
VXPortalUser vXPortalUser = userMgr.getUserProfileByLoginId(xUser.getName());
if (vXPortalUser != null) {
if (vXPortalUser.getLoginId() != null && !vXPortalUser.getLoginId().equalsIgnoreCase(currentUser)) {
vXPortalUser.setStatus(entry.getValue());
userMgr.updateUser(vXPortalUser);
}
}
}
}
}
}
use of org.apache.ranger.common.UserSessionBase in project ranger by apache.
the class XUserMgr method checkAdminAccess.
public void checkAdminAccess() {
UserSessionBase session = ContextUtil.getCurrentUserSession();
if (session != null) {
if (!session.isUserAdmin()) {
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
vXResponse.setMsgDesc("Operation" + " denied. LoggedInUser=" + (session != null ? session.getXXPortalUser().getId() : "Not Logged In") + " ,isn't permitted to perform the action.");
throw restErrorUtil.generateRESTException(vXResponse);
}
} else {
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
vXResponse.setMsgDesc("Bad Credentials");
throw restErrorUtil.generateRESTException(vXResponse);
}
}
Aggregations