Picketlink - 如何实现同时接受使用用户名或电子邮件的身份验证

时间:2016-06-04 06:26:59

标签: java security picketlink

人。 我需要实现身份验证方法,在表单登录时接受用户名或电子邮件。

我怀疑是PasswordCredentialHandler及其AbstractCredentialHandler抽象类的实现。

有没有人经历过这个?

1 个答案:

答案 0 :(得分:0)

更新1

根据UsernamePasswordCredential创建基于PasswordCredentialHandler类和Credential的处理程序。在商店配置中添加新的处理程序:

@Produces 
IdentityConfiguration produceIdentityManagementConfiguration() {
    IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();

    builder
        .named("default")
        .stores()
        .jpa().addCredentialHandler(EmailPasswordCredentialHandler.class)
        .supportAllFeatures().supportType(UserAccount.class);

    return builder.build();

使用多个身份验证器支持或自定义身份验证器。

在身份验证中添加逻辑以识别用户键入的用户名或电子邮件,然后实例化正确的凭据。

<强> ORIGINAL

请参阅此官方示例(来自picketlink网站):

@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();
        }
   }
 }

您可以在selectAutheticator方法中实现逻辑以选择每个电子邮件或用户ID的登录,然后@Produces@Picketlink注释提供框架您的自定义身份验证器(电子邮件登录)或idm身份验证器(普通userId登录)