@Override public void onAuthenticationFailure( HttpServerExchange exchange, Session session, AuthenticationMechanism currentAuthMechanism ) { if ( currentAuthMechanism != null && !currentAuthMechanism.sendAuthenticationChallenge( exchange, session ) ) throw new IllegalStateException( "Cannot send authentication challenge" ); } }
@Override public void onAuthenticationSuccess( HttpServerExchange exchange, Session session, AuthenticationMechanism currentAuthMechanism ) { if ( currentAuthMechanism != null && !currentAuthMechanism.sendAuthenticationSuccess( exchange, session ) ) throw new IllegalStateException( "Cannot send 'authentication success'" ); } }
Collection<AuthenticationMechanism> getConfigurableMechanisms( AuthenticationRuleMatcher ruleMatcher ){ final Set<AuthenticationMechanism> configurable = new HashSet<>(); ruleMatcher.rules().forEach( r -> configurable.addAll( r.mechanisms() ) ); final ArrayList<AuthenticationMechanism> configurableSorted = new ArrayList<>(configurable); configurableSorted.sort((o1, o2) -> Integer.compare(o2.priority(), o1.priority())); return configurableSorted; }
void configureAllAuthenticationMechanismsUsedOnTheApplication(AuthenticationRuleMatcher ruleMatcher) { final Collection<AuthenticationMechanism> configurable = getConfigurableMechanisms(ruleMatcher); configurable.forEach( m -> m.configure( securityConfiguration, authenticationEndpoints) ); }
private Account performAuthentication() { final Iterator<AuthenticationMechanism> iterator = rule.mechanisms().iterator(); Account account = getCurrentSession().getAuthenticatedAccount(); while ( account == null && iterator.hasNext() ) { currentAuthMechanism = iterator.next(); account = currentAuthMechanism.authenticate( exchange, rule.identityManagers(), getCurrentSession() ); } return account; }