首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@PicketLink注释类未在identity.login()中使用

@PicketLink注释类未在identity.login()中使用
EN

Stack Overflow用户
提问于 2016-02-12 18:56:09
回答 1查看 283关注 0票数 7

我正在尝试使用@PicketLinked类来扩展BaseAuthenticator。

我的设置是wildfly 9.0.2上的一个ear项目。

我在我的jboss-deployment-structure.xml中使用了它

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>  
<jboss-deployment-structure>  
<deployment>  
     <dependencies>  
          <!-- This will enable PicketLink Authentication/Authorization and IDM dependencies to your deployment. -->
        <module name="org.picketlink.core.api" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.core" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm.api" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm" meta-inf="import" annotations="true"/>    
        <module name="org.picketlink.common" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm.schema" meta-inf="import" annotations="true"/>
    </dependencies>  
</deployment> 
<sub-deployment name="prestiz-web.war">
    <dependencies>  
          <!-- This will enable PicketLink Authentication/Authorization and IDM dependencies to your deployment. -->
        <module name="org.picketlink.core.api" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.core" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm.api" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm" meta-inf="import" annotations="true"/>    
        <module name="org.picketlink.common" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm.schema" meta-inf="import" annotations="true"/>
    </dependencies> 
</sub-deployment>
<sub-deployment name="prestiz-ejb.jar">
    <dependencies>  
          <!-- This will enable PicketLink Authentication/Authorization and IDM dependencies to your deployment. -->
        <module name="org.picketlink.core.api" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.core" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm.api" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm" meta-inf="import" annotations="true"/>    
        <module name="org.picketlink.common" meta-inf="import" annotations="true"/>
        <module name="org.picketlink.idm.schema" meta-inf="import" annotations="true"/>
    </dependencies> 
</sub-deployment>
</jboss-deployment-structure>

我的BaseAuthenticator类在我的ejb.jar中声明如下

代码语言:javascript
复制
@RequestScoped
@PicketLink
public class PicketlinkAuthenticator extends BaseAuthenticator

我的LoginController配置如下:

代码语言:javascript
复制
@Path("/login")
public class LoginController {
    @Inject
    private Identity identity;

    @Inject
    private DefaultLoginCredentials credentials;

    @GET
    @Path("/dologin/{username}/{password}")
    @Produces(MediaType.TEXT_PLAIN)
    @Transactional(TxType.REQUIRED)
    public String doLogin(@PathParam("username") String username, @PathParam("password") String password){
        credentials.setUserId(username);
        credentials.setPassword(password);
        AuthenticationResult authResult=identity.login();
        if(authResult.equals(AuthenticationResult.SUCCESS)){
            return "success";
        }else{
            return "failed";
        }
    }

在调用identity.login()之后,我在日志中看到了以下内容:

代码语言:javascript
复制
11:49:09,630 INFO  [org.picketlink.idm] (default task-2) PLIDM001000:  Bootstrapping PicketLink IDM Partition Manager
11:49:09,667 INFO  [org.picketlink.idm.identity.store] (default task-2) PLIDM001001: Initializing Identity Store [class org.picketlink.idm.file.internal.FileIdentityStore]
11:49:09,679 WARN  [org.picketlink.idm.identity.store.file] (default task-2) PLIDM001101: Working directory [C:\Users\bgadeyne\AppData\Local\Temp\pl-idm] is marked to be always created. All your existing data will be lost.
11:49:09,688 INFO  [org.picketlink.idm.identity.store.file] (default task-2) PLIDM001100: Using working directory [C:\Users\bgadeyne\AppData\Local\Temp\pl-idm].

我的身份验证器的身份验证方法也有一些日志记录,但没有显示。

这里我漏掉了什么?

EN

回答 1

Stack Overflow用户

发布于 2017-03-20 19:36:31

解决方案是您需要一个AuthenticatorSelector,它将选择您的验证器。这允许您拥有多个验证器:

代码语言:javascript
复制
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import lombok.Setter;
import org.picketlink.annotations.PicketLink;
import org.picketlink.authentication.Authenticator;
import org.picketlink.authentication.internal.IdmAuthenticator;



@RequestScoped
@Named
public class AuthenticatorSelector {
    @Inject private Instance<SingleSignOnAuthenticator> ssoAuthenticator;
    @Inject private Instance<IdmAuthenticator> idmAuthenticator;
    @Inject private Instance<TokenAuthenticator> tokenAuthenticator;

    @Setter private boolean singleSignOn = false; 
    @Setter private boolean tokenAuth = false; 

    public boolean getSingleSignOn() {return singleSignOn;}

    @Produces
    @PicketLink
    public Authenticator selectAuthenticator() {
        if (singleSignOn) {
            return ssoAuthenticator.get();
        } else if (tokenAuth) {
            return tokenAuthenticator.get();
        } else {
            return idmAuthenticator.get();
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35360818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档