Java源码示例:org.apache.shiro.authc.pam.UnsupportedTokenException

示例1
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (!(token instanceof UsernamePasswordToken)) {
        throw new UnsupportedTokenException(String.format("Token of type %s  is not supported. A %s is required.",
                token.getClass().getName(), UsernamePasswordToken.class.getName()));
    }

    UsernamePasswordToken t = (UsernamePasswordToken) token;
    LOGGER.info("doGetAuthenticationInfo for {}", ((UsernamePasswordToken) token).getUsername());

    GitlabPrincipal authenticatedPrincipal;
    try {
        authenticatedPrincipal = gitlabClient.authz(t.getUsername(), t.getPassword());
        LOGGER.info("Successfully authenticated {}",t.getUsername());
    } catch (GitlabAuthenticationException e) {
        LOGGER.warn("Failed authentication", e);
        return null;
    }

    return createSimpleAuthInfo(authenticatedPrincipal, t);
}
 
示例2
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	if (!(token instanceof UsernamePasswordToken)) {
		throw new UnsupportedTokenException(String.format("Token of type %s  is not supported. A %s is required.",
				token.getClass().getName(), UsernamePasswordToken.class.getName()));
	}

	UsernamePasswordToken t = (UsernamePasswordToken) token;
	LOGGER.info("doGetAuthenticationInfo for {}", ((UsernamePasswordToken) token).getUsername());
	GithubPrincipal authenticatedPrincipal;
	try {
		authenticatedPrincipal = githubClient.authz(t.getUsername(), t.getPassword());
		LOGGER.info("Successfully authenticated {}",t.getUsername());
	} catch (GithubAuthenticationException e) {
		LOGGER.warn("Failed authentication", e);
		return null;
	}

	return createSimpleAuthInfo(authenticatedPrincipal, t);
}
 
示例3
@Override
public void login(Object credentials) throws AuthenticationException {
   if(!(credentials instanceof AuthenticationToken)) {
      throw new UnsupportedTokenException("Invalid authentication token");
   }
   
   subject.login((AuthenticationToken) credentials);
}