Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2007-2012 Sonatype, Inc. All rights reserved. This program is licensed to you under the Apache License Version 2.0, and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the Apache License Version 2.0 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
package org.sonatype.security.authentication;
This Authenticator will only try to authenticate with each realm. The first successful AuthenticationInfo found will be returned and other realms will not be queried.

This makes for the performance short comings when using the org.apache.shiro.authc.pam.ModularRealmAuthenticator and FirstSuccessfulAuthenticationStrategy where all the realms will be queried, but only the first success is returned.

Author(s):
Brian Demers
See also:
org.apache.shiro.authc.pam.ModularRealmAuthenticator
FirstSuccessfulAuthenticationStrategy
    private static final Logger log = LoggerFactory.getLoggerFirstSuccessfulModularRealmAuthenticator.class );
    @Override
    {
        .trace"Iterating through [" + realms.size() + "] realms for PAM authentication" );
        for ( Realm realm : realms )
        {
            // check if the realm supports this token
            if ( realm.supportstoken ) )
            {
                if ( .isTraceEnabled() )
                {
                    .trace"Attempting to authenticate token [" + token + "] " + "using realm of type [" + realm
                        + "]" );
                }
                try
                {
                    // try to login
                    AuthenticationInfo info = realm.getAuthenticationInfotoken );
                    // just make sure are ducks are in a row
                    // return the first successful login.
                    if ( info != null )
                    {
                        return info;
                    }
                    else
                    {
                        .warn"Realm [" + realm + "] returned null when authenticating token " + "[" + token + "]" );
                    }
                }
                catch ( Throwable t )
                {
                    if ( .isTraceEnabled() )
                    {
                        String msg =
                            "Realm [" + realm + "] threw an exception during a multi-realm authentication attempt:";
                        .tracemsgt );
                    }
                }
            }
            else
            {
                if ( .isTraceEnabled() )
                {
                    .trace"Realm of type [" + realm + "] does not support token " + "[" + token
                        + "].  Skipping realm." );
                }
            }
        }
        throw new org.apache.shiro.authc.AuthenticationException"Authentication token of type [" + token.getClass()
            + "] " + "could not be authenticated by any configured realms.  Please ensure that at least one realm can "
            + "authenticate these tokens." );
    }
New to GrepCode? Check out our FAQ X