public static Pair < Boolean , Optional < Map < String , Object > > > authenticate ( final String username , final String password , final List < RadiusServer > servers , final boolean failoverOnAuthenticationFailure , final boolean failoverOnException , final Optional state ) throws Exception { for ( val radiusServer : servers ) { LOGGER . debug ( "Attempting to authenticate [{}] at [{}]" , username , radiusServer ) ; try { val response = radiusServer . authenticate ( username , password , state ) ; if ( response != null ) { val attributes = new HashMap < String , Object > ( ) ; response . getAttributes ( ) . forEach ( attribute -> attributes . put ( attribute . getAttributeName ( ) , attribute . getValue ( ) ) ) ; return Pair . of ( Boolean . TRUE , Optional . of ( attributes ) ) ; } if ( ! failoverOnAuthenticationFailure ) { throw new FailedLoginException ( "Radius authentication failed for user " + username ) ; } LOGGER . debug ( "failoverOnAuthenticationFailure enabled -- trying next server" ) ; } catch ( final Exception e ) { if ( ! failoverOnException ) { throw e ; } LOGGER . warn ( "failoverOnException enabled -- trying next server." , e ) ; } } return Pair . of ( Boolean . FALSE , Optional . empty ( ) ) ; }
Authenticate pair .