Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.archiva.redback.authentication.users;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 
 import java.util.Map;

org.apache.archiva.redback.authentication.Authenticator implementation that uses a wrapped org.apache.archiva.redback.users.UserManager to authenticate.

Author(s):
Rahul Thakur
 
 @Service"authenticator#user-manager" )
     implements Authenticator
 {
     private Logger log = LoggerFactory.getLoggerUserManagerAuthenticator.class );
 
     @Inject
     @Named( value = "userManager#jdo" )
     private UserManager userManager;
 
     @Inject
 
     public String getId()
     {
         return "UserManagerAuthenticator";
     }

    
 
     {
         boolean authenticationSuccess = false;
         String username = null;
         Exception resultException = null;
         Map<StringStringauthnResultExceptionsMap = new HashMap<StringString>();
 
         try
         {
             .debug"Authenticate: {}"source );
             User user = .findUsersource.getPrincipal() );
             username = user.getUsername();
 
             if ( user.isLocked() )
             {
                 throw new AccountLockedException"Account " + source.getPrincipal() + " is locked."user );
             }
 
             if ( user.isPasswordChangeRequired() && source.isEnforcePasswordChange() )
             {
                 throw new MustChangePasswordException"Password expired."user );
            }
            PasswordEncoder encoder = .getPasswordEncoder();
            .debug"PasswordEncoder: {}"encoder.getClass().getName() );
            boolean isPasswordValid = encoder.isPasswordValiduser.getEncodedPassword(), source.getPassword() );
            if ( isPasswordValid )
            {
                .debug"User {} provided a valid password"source.getPrincipal() );
                try
                {
                    .extensionPasswordExpirationuser );
                }
                catch ( MustChangePasswordException e )
                {
                    user.setPasswordChangeRequiredtrue );
                    throw e;
                }
                authenticationSuccess = true;
                //REDBACK-151 do not make unnessesary updates to the user object
                if ( user.getCountFailedLoginAttempts() > 0 )
                {
                    user.setCountFailedLoginAttempts( 0 );
                    .updateUseruser );
                }
                return new AuthenticationResulttruesource.getPrincipal(), null );
            }
            else
            {
                .warn"Password is Invalid for user " + source.getPrincipal() + "." );
                authnResultExceptionsMap.put.,
                                              "Password is Invalid for user " + source.getPrincipal() + "." );
                try
                {
                    .extensionExcessiveLoginAttemptsuser );
                }
                finally
                {
                    .updateUseruser );
                }
                return new AuthenticationResultfalsesource.getPrincipal(), nullauthnResultExceptionsMap );
            }
        }
        catch ( UserNotFoundException e )
        {
            .warn"Login for user " + source.getPrincipal() + " failed. user not found." );
            resultException = e;
            authnResultExceptionsMap.put.,
                                          "Login for user \" + source.getPrincipal() + \" failed. user not found." );
        }
        return new AuthenticationResultauthenticationSuccessusernameresultExceptionauthnResultExceptionsMap );
    }

    
Returns the wrapped org.apache.archiva.redback.users.UserManager used by this org.apache.archiva.redback.authentication.Authenticator implementation for authentication.

Returns:
the userManager
    public UserManager getUserManager()
    {
        return ;
    }

    
Sets a org.apache.archiva.redback.users.UserManager to be used by this org.apache.archiva.redback.authentication.Authenticator implementation for authentication.

Parameters:
userManager the userManager to set
    public void setUserManagerUserManager userManager )
    {
        this. = userManager;
    }
    public boolean supportsDataSourceAuthenticationDataSource source )
    {
        return ( source instanceof PasswordBasedAuthenticationDataSource );
    }
    {
        return ;
    }
    public void setSecurityPolicyUserSecurityPolicy securityPolicy )
    {
        this. = securityPolicy;
    }
New to GrepCode? Check out our FAQ X