use of org.apache.shiro.authc.SimpleAuthenticationInfo in project perry by ca-cwds.
the class AbstractRealm method getAuthenticationInfo.
private AuthenticationInfo getAuthenticationInfo(PerryAccount perryAccount, String token) {
List<Object> principals = new ArrayList<>();
principals.add(perryAccount.getUser());
principals.add(perryAccount);
principals.add(token);
PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, getName());
return new SimpleAuthenticationInfo(principalCollection, "N/A");
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project ssm_shiro_blog by Mandelo.
the class MyRealm method doGetAuthenticationInfo.
/**
* 用于验证身份
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String username = (String) token.getPrincipal();
User user = userExtendDao.selectByUsername(username);
if (null != user) {
AuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), "xx");
return info;
}
return null;
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project knox by apache.
the class KnoxLdapRealm method createAuthenticationInfo.
@Override
protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, Object ldapPrincipal, Object ldapCredentials, LdapContext ldapContext) throws NamingException {
HashRequest.Builder builder = new HashRequest.Builder();
Hash credentialsHash = hashService.computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
return new SimpleAuthenticationInfo(token.getPrincipal(), credentialsHash.toHex(), credentialsHash.getSalt(), getName());
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project knox by apache.
the class KnoxPamRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
UnixUser user = null;
try {
user = (new PAM(this.getService())).authenticate(upToken.getUsername(), new String(upToken.getPassword()));
} catch (PAMException e) {
handleAuthFailure(token, e.getMessage(), e);
}
HashRequest.Builder builder = new HashRequest.Builder();
Hash credentialsHash = hashService.computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
/* Coverity Scan CID 1361684 */
if (credentialsHash == null) {
handleAuthFailure(token, "Failed to compute hash", null);
}
return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(), getName());
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project ANNIS by korpling.
the class ANNISUserRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
Validate.isInstanceOf(String.class, token.getPrincipal());
String userName = (String) token.getPrincipal();
if (userName.equals(anonymousUser)) {
// for anonymous users the user name equals the Password, so hash the user name
Sha256Hash hash = new Sha256Hash(userName);
return new SimpleAuthenticationInfo(userName, hash.getBytes(), ANNISUserRealm.class.getName());
}
User user = confManager.getUser(userName);
if (user != null) {
String passwordHash = user.getPasswordHash();
if (passwordHash != null) {
if (passwordHash.startsWith("$")) {
Shiro1CryptFormat fmt = new Shiro1CryptFormat();
Hash hashCredentials = fmt.parse(passwordHash);
if (hashCredentials instanceof SimpleHash) {
SimpleHash simpleHash = (SimpleHash) hashCredentials;
Validate.isTrue(simpleHash.getIterations() == 1, "Hash iteration count must be 1 for every password hash!");
// actually set the information from the user file
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(userName, simpleHash.getBytes(), ANNISUserRealm.class.getName());
info.setCredentialsSalt(new SerializableByteSource(simpleHash.getSalt()));
return info;
}
} else {
// fallback unsalted hex hash
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(), passwordHash, ANNISUserRealm.class.getName());
return info;
}
}
}
return null;
}
Aggregations