org.apache.shiro.authc.pam.AuthenticationStrategy Java Examples

The following examples show how to use org.apache.shiro.authc.pam.AuthenticationStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IamAutoConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Bean
public ExceptionModularRealmAuthenticator exceptionModularRealmAuthenticator(AuthenticationStrategy authenticationStrategy) {
	ExceptionModularRealmAuthenticator authenticator = new ExceptionModularRealmAuthenticator();
	authenticator.setAuthenticationStrategy(authenticationStrategy);
	List<Realm> realms = actx.getBeansOfType(AbstractAuthorizingRealm.class).values().stream().collect(toList());
	authenticator.setRealms(realms);
	return authenticator;
}
 
Example #2
Source File: ExceptionModularRealmAuthenticator.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
protected AuthenticationInfo doMultiRealmAuthentication(Collection<Realm> realms, AuthenticationToken token) {
	AuthenticationStrategy strategy = getAuthenticationStrategy();
	AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);
	if (log.isTraceEnabled()) {
		log.trace("Iterating through {} realms for PAM authentication", realms.size());
	}

	for (Realm realm : realms) {
		aggregate = strategy.beforeAttempt(realm, token, aggregate);
		if (realm.supports(token)) {
			if (log.isTraceEnabled()) {
				log.trace("Attempting to authenticate token [{}] using realm [{}]", token, realm);
			}

			AuthenticationInfo info = null;
			Throwable t = null;
			try {
				info = realm.getAuthenticationInfo(token);
			} catch (Throwable throwable) {
				t = throwable;
				throw new AuthenticationException(t);
			} finally {
				aggregate = strategy.afterAttempt(realm, token, info, aggregate, t);
			}
		} else if (log.isDebugEnabled()) {
			log.debug("Realm [{}] does not support token {}.  Skipping realm.", realm, token);
		}
	}

	return strategy.afterAllAttempts(token, aggregate);
}
 
Example #3
Source File: SecurityGuiceConfigurer.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
public void configure(Binder binder) {
    // Subject
    SecurityConfig.SubjectConfig subjectConfig = securityConfig.subject();
    Optional.ofNullable(subjectConfig.getContext()).ifPresent(c -> binder.bind(SubjectContext.class).to(c));
    Optional.ofNullable(subjectConfig.getFactory()).ifPresent(f -> binder.bind(SubjectFactory.class).to(f));
    Class<? extends SubjectDAO> subjectDao = subjectConfig.getDao();
    binder.bind(SubjectDAO.class).to(subjectDao != null ? subjectDao : DefaultSubjectDAO.class);

    // Authentication
    SecurityConfig.AuthenticationConfig authenticationConfig = securityConfig.authentication();
    binder.bind(Authenticator.class).to(authenticationConfig.getAuthenticator());
    binder.bind(AuthenticationStrategy.class).to(authenticationConfig.getStrategy());
    binder.bind(CredentialsMatcher.class).to(authenticationConfig.getCredentialsMatcher());

    // Cache configuration
    SecurityConfig.CacheConfig cacheConfig = securityConfig.cache();
    binder.bind(CacheManager.class).to(cacheConfig.getManager());

    // Sessions
    SecurityConfig.SessionConfig sessionConfig = securityConfig.sessions();
    binder.bind(SessionStorageEvaluator.class).to(sessionConfig.getStorageEvaluator());
    Optional.ofNullable(sessionConfig.getValidationScheduler())
            .ifPresent(s -> binder.bind(SessionValidationScheduler.class).to(s));
    binder.bindConstant()
            .annotatedWith(Names.named("shiro.sessionValidationInterval"))
            .to(sessionConfig.getValidationInterval() * 1000);
    binder.bindConstant()
            .annotatedWith(Names.named("shiro.globalSessionTimeout"))
            .to(sessionConfig.getTimeout() * 1000);
}
 
Example #4
Source File: SecurityConfig.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
public Class<? extends AuthenticationStrategy> getStrategy() {
    return strategy;
}
 
Example #5
Source File: SecurityConfig.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
public AuthenticationConfig setStrategy(
        Class<? extends AuthenticationStrategy> strategy) {
    this.strategy = strategy;
    return this;
}
 
Example #6
Source File: EnhanceModularRealmAuthenticator.java    From Shiro-Action with MIT License 3 votes vote down vote up
/**
 * 抛出 realm 中第一个遇到的异常
 */
@Override
protected AuthenticationInfo doMultiRealmAuthentication(Collection<Realm> realms, AuthenticationToken token) {

    AuthenticationStrategy strategy = getAuthenticationStrategy();

    AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);

    if (log.isTraceEnabled()) {
        log.trace("Iterating through {} realms for PAM authentication", realms.size());
    }

    for (Realm realm : realms) {

        aggregate = strategy.beforeAttempt(realm, token, aggregate);

        if (realm.supports(token)) {

            log.trace("Attempting to authenticate token [{}] using realm [{}]", token, realm);

            AuthenticationInfo info;
            // 有异常从此处抛出
            info = realm.getAuthenticationInfo(token);

            aggregate = strategy.afterAttempt(realm, token, info, aggregate, null);

        } else {
            log.debug("Realm [{}] does not support token {}.  Skipping realm.", realm, token);
        }
    }

    aggregate = strategy.afterAllAttempts(token, aggregate);

    return aggregate;
}