Search in sources :

Example 11 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class XUserMgr method checkAccess.

public void checkAccess(String loginID) {
    UserSessionBase session = ContextUtil.getCurrentUserSession();
    if (session != null) {
        if (!session.isUserAdmin() && !session.isKeyAdmin() && !session.getLoginId().equalsIgnoreCase(loginID)) {
            throw restErrorUtil.create403RESTException("Operation" + " denied. LoggedInUser=" + (session != null ? session.getXXPortalUser().getId() : "Not Logged In") + " ,isn't permitted to perform the action.");
        }
    } else {
        VXResponse vXResponse = new VXResponse();
        vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
        vXResponse.setMsgDesc("Bad Credentials");
        throw restErrorUtil.generateRESTException(vXResponse);
    }
}
Also used : UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 12 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class XUserMgr method deleteXUserPermission.

public void deleteXUserPermission(Long id, boolean force) {
    XXUserPermission xUserPermission = daoManager.getXXUserPermission().getById(id);
    if (xUserPermission == null) {
        throw restErrorUtil.createRESTException("No UserPermission found to delete, ID: " + id, MessageEnums.DATA_NOT_FOUND);
    }
    xUserPermissionService.deleteResource(id);
    Set<UserSessionBase> userSessions = sessionMgr.getActiveUserSessionsForPortalUserId(xUserPermission.getUserId());
    if (!CollectionUtils.isEmpty(userSessions)) {
        for (UserSessionBase userSession : userSessions) {
            logger.info("deleting permission of user who's found logged in into system, so updating permission in session of that user");
            sessionMgr.resetUserModulePermission(userSession);
        }
    }
}
Also used : XXUserPermission(org.apache.ranger.entity.XXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 13 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerPolicyService method setup.

public void setup() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(true);
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 14 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerPolicyServiceBase method setup.

public void setup() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(true);
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 15 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerServiceDefService method setup.

public void setup() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(true);
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Aggregations

UserSessionBase (org.apache.ranger.common.UserSessionBase)69 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)24 XXPortalUser (org.apache.ranger.entity.XXPortalUser)11 VXString (org.apache.ranger.view.VXString)11 XXUser (org.apache.ranger.entity.XXUser)8 ArrayList (java.util.ArrayList)6 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)6 XXService (org.apache.ranger.entity.XXService)5 VXResponse (org.apache.ranger.view.VXResponse)4 Test (org.junit.Test)4 Authentication (org.springframework.security.core.Authentication)4 HashSet (java.util.HashSet)3 HttpSession (javax.servlet.http.HttpSession)3 XXGroupUser (org.apache.ranger.entity.XXGroupUser)3 XXResource (org.apache.ranger.entity.XXResource)3 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2