extensions/net.sf.basedb.otp/trunk/src/net/sf/basedb/otp/OtpAuthenticationManagerFactory.java

Code
Comments
Other
Rev Date Author Line
4847 13 Jun 18 nicklas 1 package net.sf.basedb.otp;
4847 13 Jun 18 nicklas 2
4847 13 Jun 18 nicklas 3
4847 13 Jun 18 nicklas 4 import net.sf.basedb.core.AuthenticationContext;
4847 13 Jun 18 nicklas 5 import net.sf.basedb.core.authentication.AuthenticationManager;
4851 14 Jun 18 nicklas 6 import net.sf.basedb.core.authentication.LoginRequest;
4847 13 Jun 18 nicklas 7 import net.sf.basedb.util.extensions.ActionFactory;
4847 13 Jun 18 nicklas 8 import net.sf.basedb.util.extensions.InvokationContext;
4847 13 Jun 18 nicklas 9
4847 13 Jun 18 nicklas 10 /**
4847 13 Jun 18 nicklas 11   Action factory for the OTP authentication.
4847 13 Jun 18 nicklas 12   Returns an {@link OtpAuthenticationManager} action.
4847 13 Jun 18 nicklas 13   
4847 13 Jun 18 nicklas 14    @author nicklas
4847 13 Jun 18 nicklas 15    @since 1.0
4847 13 Jun 18 nicklas 16 */
4847 13 Jun 18 nicklas 17 public class OtpAuthenticationManagerFactory
4847 13 Jun 18 nicklas 18   implements ActionFactory<AuthenticationManager>
4847 13 Jun 18 nicklas 19 {
4847 13 Jun 18 nicklas 20   
4847 13 Jun 18 nicklas 21   public OtpAuthenticationManagerFactory()
5183 06 Dec 18 nicklas 22   {}
4847 13 Jun 18 nicklas 23
4847 13 Jun 18 nicklas 24   /**
4847 13 Jun 18 nicklas 25     Checks if the OTP extension has been properly configured and
4847 13 Jun 18 nicklas 26     if the currently used client application has been disabled for
4847 13 Jun 18 nicklas 27     use with OTP.
4847 13 Jun 18 nicklas 28     @return TRUE if OTP is enabled, FALSE otherwise
4847 13 Jun 18 nicklas 29   */
4847 13 Jun 18 nicklas 30   @Override
4847 13 Jun 18 nicklas 31   public boolean prepareContext(InvokationContext<? super AuthenticationManager> context)
4847 13 Jun 18 nicklas 32   {
4848 13 Jun 18 nicklas 33     String clientId = context.getClientContext().getSessionControl().getExternalClientId();
5183 06 Dec 18 nicklas 34     return Otp.getConfig(true) != null && !Otp.isOtpDisabledForClient(clientId);
4847 13 Jun 18 nicklas 35   }
4847 13 Jun 18 nicklas 36
4847 13 Jun 18 nicklas 37   /**
4847 13 Jun 18 nicklas 38     @return A single {@link OtpAuthenticationManager} instance
4847 13 Jun 18 nicklas 39   */
4847 13 Jun 18 nicklas 40   @Override
4847 13 Jun 18 nicklas 41   public AuthenticationManager[] getActions(InvokationContext<? super AuthenticationManager> context)
4847 13 Jun 18 nicklas 42   {
4847 13 Jun 18 nicklas 43     AuthenticationContext authContext = (AuthenticationContext)context.getClientContext();
4851 14 Jun 18 nicklas 44     LoginRequest request = authContext.getLoginRequest();
5153 28 Nov 18 nicklas 45     String mode = request.getAttribute("login-form");
4851 14 Jun 18 nicklas 46     return new AuthenticationManager[] { Otp.SETUP_MODE.equals(mode) ? 
4851 14 Jun 18 nicklas 47         new SetupOtpAuthenticationManager(authContext) :
4851 14 Jun 18 nicklas 48         new OtpAuthenticationManager(authContext) 
4851 14 Jun 18 nicklas 49       };
4847 13 Jun 18 nicklas 50   }
4847 13 Jun 18 nicklas 51
4847 13 Jun 18 nicklas 52   
4847 13 Jun 18 nicklas 53 }