Search in sources :

Example 21 with SimpleAuthenticationInfo

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");
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection)

Example 22 with SimpleAuthenticationInfo

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;
}
Also used : User(com.luoxiao.model.User) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo)

Example 23 with SimpleAuthenticationInfo

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());
}
Also used : HashRequest(org.apache.shiro.crypto.hash.HashRequest) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) Hash(org.apache.shiro.crypto.hash.Hash)

Example 24 with SimpleAuthenticationInfo

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());
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) PAM(org.jvnet.libpam.PAM) PAMException(org.jvnet.libpam.PAMException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 25 with SimpleAuthenticationInfo

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;
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) Sha256Hash(org.apache.shiro.crypto.hash.Sha256Hash) SimpleHash(org.apache.shiro.crypto.hash.SimpleHash) Sha256Hash(org.apache.shiro.crypto.hash.Sha256Hash) Hash(org.apache.shiro.crypto.hash.Hash) SimpleHash(org.apache.shiro.crypto.hash.SimpleHash) Shiro1CryptFormat(org.apache.shiro.crypto.hash.format.Shiro1CryptFormat)

Aggregations

SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)39 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)15 AuthenticationException (org.apache.shiro.authc.AuthenticationException)12 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)9 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)5 AccountException (org.apache.shiro.authc.AccountException)4 Hash (org.apache.shiro.crypto.hash.Hash)4 Test (org.junit.Test)4 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)3 LockedAccountException (org.apache.shiro.authc.LockedAccountException)3 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)3 HashRequest (org.apache.shiro.crypto.hash.HashRequest)3 PAM (org.jvnet.libpam.PAM)3 PAMException (org.jvnet.libpam.PAMException)3 UnixUser (org.jvnet.libpam.UnixUser)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)2 ByteSource (org.apache.shiro.util.ByteSource)2 UserDO (cn.dubidubi.model.base.UserDO)1 TbUser (cn.exrick.manager.pojo.TbUser)1 PmphUser (com.bc.pmpheep.back.po.PmphUser)1