Search in sources :

Example 11 with SimpleAccount

use of org.apache.shiro.authc.SimpleAccount 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)

Example 12 with SimpleAccount

use of org.apache.shiro.authc.SimpleAccount in project zeppelin by apache.

the class KerberosRealm method doGetAuthenticationInfo.

/**
 * This is called when Kerberos authentication is done and a {@link KerberosToken} has
 * been acquired.
 * This function returns a Shiro {@link SimpleAccount} based on the {@link KerberosToken}
 * provided. Null otherwise.
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken authenticationToken) throws org.apache.shiro.authc.AuthenticationException {
    if (null != authenticationToken) {
        KerberosToken kerberosToken = (KerberosToken) authenticationToken;
        SimpleAccount account = new SimpleAccount(kerberosToken.getPrincipal(), kerberosToken.getCredentials(), kerberosToken.getClass().getName());
        account.addRole(mapGroupPrincipals((String) kerberosToken.getPrincipal()));
        return account;
    }
    return null;
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount)

Example 13 with SimpleAccount

use of org.apache.shiro.authc.SimpleAccount in project zeppelin by apache.

the class KnoxJwtRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
    JWTAuthenticationToken upToken = (JWTAuthenticationToken) token;
    if (validateToken(upToken.getToken())) {
        try {
            SimpleAccount account = new SimpleAccount(getName(upToken), upToken.getToken(), getName());
            account.addRole(mapGroupPrincipals(getName(upToken)));
            return account;
        } catch (ParseException e) {
            LOGGER.error("ParseException in doGetAuthenticationInfo", e);
        }
    }
    return null;
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) ParseException(java.text.ParseException)

Example 14 with SimpleAccount

use of org.apache.shiro.authc.SimpleAccount in project graylog2-server by Graylog2.

the class RootAccountRealm method addRootAccount.

private void addRootAccount(String username, String password) {
    LOG.debug("Adding root account named {}, having all permissions", username);
    add(new SimpleAccount(username, password, getName(), CollectionUtils.asSet("root"), CollectionUtils.<Permission>asSet(new AllPermission())));
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) Permission(org.apache.shiro.authz.Permission) AllPermission(org.apache.shiro.authz.permission.AllPermission) AllPermission(org.apache.shiro.authz.permission.AllPermission)

Example 15 with SimpleAccount

use of org.apache.shiro.authc.SimpleAccount in project graylog2-server by Graylog2.

the class RootAccountRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    final AuthenticationInfo authenticationInfo = super.doGetAuthenticationInfo(token);
    // After successful authentication, exchange the principals to unique admin userId
    if (authenticationInfo instanceof SimpleAccount) {
        SimpleAccount account = (SimpleAccount) authenticationInfo;
        account.setPrincipals(new SimplePrincipalCollection(UserImpl.LocalAdminUser.LOCAL_ADMIN_ID, NAME));
        return account;
    }
    return null;
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo)

Aggregations

SimpleAccount (org.apache.shiro.authc.SimpleAccount)18 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)5 Settings (com.artezio.arttime.config.Settings)4 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)3 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 User (org.graylog2.plugin.database.users.User)3 Project (com.artezio.arttime.datamodel.Project)2 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)2 ValidationException (org.graylog2.plugin.database.ValidationException)2 User (io.nutz.demo.simple.bean.User)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapConnectionConfig (org.apache.directory.ldap.client.api.LdapConnectionConfig)1 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1