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);
}
}
}
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;
}
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;
}
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())));
}
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;
}
Aggregations