Search in sources :

Example 1 with SimpleRole

use of org.apache.shiro.authz.SimpleRole in project shiro by apache.

the class TextConfigurationRealm method processRoleDefinitions.

protected void processRoleDefinitions(Map<String, String> roleDefs) {
    if (roleDefs == null || roleDefs.isEmpty()) {
        return;
    }
    for (String rolename : roleDefs.keySet()) {
        String value = roleDefs.get(rolename);
        SimpleRole role = getRole(rolename);
        if (role == null) {
            role = new SimpleRole(rolename);
            add(role);
        }
        Set<Permission> permissions = PermissionUtils.resolveDelimitedPermissions(value, getPermissionResolver());
        role.setPermissions(permissions);
    }
}
Also used : SimpleRole(org.apache.shiro.authz.SimpleRole) Permission(org.apache.shiro.authz.Permission)

Example 2 with SimpleRole

use of org.apache.shiro.authz.SimpleRole in project neo4j by neo4j.

the class PredefinedRolesBuilder method staticBuildRoles.

private static Map<String, SimpleRole> staticBuildRoles() {
    Map<String, SimpleRole> roles = new ConcurrentHashMap<>(4);
    SimpleRole admin = new SimpleRole(ADMIN);
    admin.add(FULL);
    roles.put(ADMIN, admin);
    SimpleRole architect = new SimpleRole(ARCHITECT);
    architect.add(SCHEMA);
    architect.add(WRITE);
    architect.add(TOKEN);
    roles.put(ARCHITECT, architect);
    SimpleRole publisher = new SimpleRole(PUBLISHER);
    publisher.add(WRITE);
    roles.put(PUBLISHER, publisher);
    SimpleRole reader = new SimpleRole(READER);
    reader.add(READ);
    roles.put(READER, reader);
    return roles;
}
Also used : SimpleRole(org.apache.shiro.authz.SimpleRole) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with SimpleRole

use of org.apache.shiro.authz.SimpleRole in project shiro by apache.

the class TextConfigurationRealm method processUserDefinitions.

protected void processUserDefinitions(Map<String, String> userDefs) {
    if (userDefs == null || userDefs.isEmpty()) {
        return;
    }
    for (String username : userDefs.keySet()) {
        String value = userDefs.get(username);
        String[] passwordAndRolesArray = StringUtils.split(value);
        String password = passwordAndRolesArray[0];
        SimpleAccount account = getUser(username);
        if (account == null) {
            account = new SimpleAccount(username, password, getName());
            add(account);
        }
        account.setCredentials(password);
        if (passwordAndRolesArray.length > 1) {
            for (int i = 1; i < passwordAndRolesArray.length; i++) {
                String rolename = passwordAndRolesArray[i];
                account.addRole(rolename);
                SimpleRole role = getRole(rolename);
                if (role != null) {
                    account.addObjectPermissions(role.getPermissions());
                }
            }
        } else {
            account.setRoles(null);
        }
    }
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) SimpleRole(org.apache.shiro.authz.SimpleRole)

Aggregations

SimpleRole (org.apache.shiro.authz.SimpleRole)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SimpleAccount (org.apache.shiro.authc.SimpleAccount)1 Permission (org.apache.shiro.authz.Permission)1