javasecuritypicketlink

Picketlink -How can i implement an authenticating that accept use username or email at same time


people. I need implement authenticating method that accept username or email in form login.

I suspect that is the implementation PasswordCredentialHandler and its AbstractCredentialHandler abstract class.

Has anyone ever experienced this?


Solution

  • UPDATE 1

    Create a handler based on class PasswordCredentialHandler and Credential based on UsernamePasswordCredential. Add new Handler in store configuration:

    @Produces 
    IdentityConfiguration produceIdentityManagementConfiguration() {
        IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();
    
        builder
            .named("default")
            .stores()
            .jpa().addCredentialHandler(EmailPasswordCredentialHandler.class)
            .supportAllFeatures().supportType(UserAccount.class);
    
        return builder.build();
    

    Use a Multiple Authenticator Support or a Custom Authenticator.

    In Authentication add logic to identify if user typed username or email, then instantiates a correct Credentials.

    ORIGINAL

    See this official example (from picketlink site):

    @RequestScoped
    @Named
    public class AuthenticatorSelector {
    
       @Inject Instance<CustomAuthenticator> customAuthenticator;
       @Inject Instance<IdmAuthenticator> idmAuthenticator;
    
       private String authenticator;
    
       public String getAuthenticator() {
    
          return authenticator;
        }
    
       public void setAuthenticator(String authenticator) {
          this.authenticator = authenticator;
       }
    
       @Produces
       @PicketLink
       public Authenticator selectAuthenticator() {
           if ("custom".equals(authenticator)) {
               return customAuthenticator.get();
            } else {
               return idmAuthenticator.get();
            }
       }
     }
    

    You can implement your logic to choose login per email or userid in selectAutheticator method and then @Produces and @Picketlink annotation provides to framework your custom authenticator (email login) or idm authenticator (ordinary userId login).