Search in sources :

Example 1 with Authorization

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

the class BaseDataListHelper 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 (int i = 0; i < auths.size(); i++) {
            Authorization auth = auths.get(i);
            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 2 with Authorization

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

the class MockUser method addAuthorization.

public void addAuthorization(Group group, Role role) {
    if (null == group)
        return;
    Authorization auth = new Authorization(group, role);
    super.addAuthorization(auth);
}
Also used : Authorization(com.agiletec.aps.system.services.authorization.Authorization)

Example 3 with Authorization

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

the class TestAuthenticationProviderManager method addUserForTest.

private void addUserForTest(String username, String password) throws Throwable {
    MockUser user = new MockUser();
    user.setUsername(username);
    user.setPassword(password);
    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)

Example 4 with Authorization

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

the class UserAuthorizationAction method addAuthorization.

public String addAuthorization() {
    try {
        if (!this.checkAuthorizationSessionBean()) {
            return "userList";
        }
        String groupName = this.getGroupName();
        String roleName = this.getRoleName();
        Group group = this.getGroupManager().getGroup(groupName);
        Role role = this.getRoleManager().getRole(roleName);
        if (!StringUtils.isEmpty(groupName) && null == group) {
            this.addFieldError("groupName", this.getText("error.userAuthorization.invalidGroup", new String[] { groupName }));
        }
        if (!StringUtils.isEmpty(roleName) && null == role) {
            this.addFieldError("roleName", this.getText("error.userAuthorization.invalidRole", new String[] { groupName }));
        }
        if (null == group && null == role) {
            this.addFieldError("groupName", this.getText("error.userAuthorization.invalidGroupAndRole"));
            this.addFieldError("roleName", this.getText("error.userAuthorization.invalidGroupAndRole"));
        }
        if (this.hasFieldErrors()) {
            return INPUT;
        }
        Authorization authorization = new Authorization(group, role);
        boolean result = this.getUserAuthsFormBean().addAuthorization(authorization);
        if (!result) {
            this.addActionError(this.getText("error.userAuthorization.alreadyExists", new String[] { groupName, roleName }));
            return INPUT;
        }
    } catch (Throwable t) {
        _logger.error("error adding user authorization", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Authorization(com.agiletec.aps.system.services.authorization.Authorization) Group(com.agiletec.aps.system.services.group.Group)

Example 5 with Authorization

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

the class AbstractUser method addAuthorizations.

@Override
public void addAuthorizations(List<Authorization> auths) {
    for (int i = 0; i < auths.size(); i++) {
        Authorization auth = auths.get(i);
        this.addAuthorization(auth);
    }
}
Also used : Authorization(com.agiletec.aps.system.services.authorization.Authorization)

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