Search in sources :

Example 11 with Authorization

use of com.agiletec.aps.system.services.authorization.Authorization in project entando-core by entando.

the class TestContentAuthorization method addUserForTest.

private void addUserForTest(String username, String password) throws Throwable {
    MockUser user = new MockUser();
    user.setUsername(username);
    user.setPassword(password);
    user.setDisabled(false);
    Authorization auth = new Authorization(this._groupManager.getGroup(Group.FREE_GROUP_NAME), this._roleManager.getRole("editor"));
    user.addAuthorization(auth);
    this._userManager.removeUser(user);
    UserDetails extractedUser = _userManager.getUser(username);
    assertNull(extractedUser);
    this._userManager.addUser(user);
    this._authorizationManager.addUserAuthorization(username, auth);
}
Also used : Authorization(com.agiletec.aps.system.services.authorization.Authorization) UserDetails(com.agiletec.aps.system.services.user.UserDetails) MockUser(com.agiletec.aps.system.services.user.MockUser)

Example 12 with Authorization

use of com.agiletec.aps.system.services.authorization.Authorization in project entando-core by entando.

the class BaseContentListHelper method getAllowedGroupCodes.

public static Collection<String> getAllowedGroupCodes(UserDetails user) {
    Set<String> codes = new HashSet<String>();
    codes.add(Group.FREE_GROUP_NAME);
    List<Authorization> auths = (null != user) ? user.getAuthorizations() : null;
    if (null != auths) {
        for (Authorization auth : auths) {
            if (null != auth && null != auth.getGroup()) {
                codes.add(auth.getGroup().getName());
            }
        }
    }
    return codes;
}
Also used : Authorization(com.agiletec.aps.system.services.authorization.Authorization) HashSet(java.util.HashSet)

Example 13 with Authorization

use of com.agiletec.aps.system.services.authorization.Authorization in project entando-core by entando.

the class BaseContentDispenser method getRenderizationInfoCacheKey.

public static String getRenderizationInfoCacheKey(String contentId, long modelId, String langCode, RequestContext reqCtx) {
    UserDetails currentUser = (null != reqCtx) ? (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER) : null;
    StringBuffer key = new StringBuffer();
    key.append(contentId).append("_").append(modelId).append("_").append(langCode).append("_RENDER_INFO_CacheKey");
    if (null != currentUser && !currentUser.getUsername().equals(SystemConstants.GUEST_USER_NAME)) {
        List<String> codes = new ArrayList<String>();
        if (null != currentUser.getAuthorizations()) {
            for (int i = 0; i < currentUser.getAuthorizations().size(); i++) {
                Authorization auth = currentUser.getAuthorizations().get(i);
                if (null != auth && null != auth.getGroup()) {
                    String code = auth.getGroup().getAuthority() + "_";
                    if (null != auth.getRole()) {
                        code += auth.getRole().getAuthority();
                    } else {
                        code += "null";
                    }
                    codes.add(code);
                }
            }
        }
        if (!codes.isEmpty()) {
            key.append("_AUTHS:");
            appendAuthCodes(codes, key);
        }
    }
    return key.toString();
}
Also used : Authorization(com.agiletec.aps.system.services.authorization.Authorization) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList)

Aggregations

Authorization (com.agiletec.aps.system.services.authorization.Authorization)13 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 Group (com.agiletec.aps.system.services.group.Group)2 Role (com.agiletec.aps.system.services.role.Role)2 MockUser (com.agiletec.aps.system.services.user.MockUser)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2