微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 在identity.login()中不使用@PicketLink注释类

我正在尝试使用扩展BaseAuthenticator的@PicketLinked类.

我的设置是一个关于野生动物9.0.2.Final的耳朵项目.

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

<?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中声明为以下内容

@RequestScoped
@PicketLink
public class PicketlinkAuthenticator extends BaseAuthenticator

我的LoginController配置如下:

@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()之后,我在日志中看到了这一点:

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].

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

在这里错过了什么?

解决方法

解决方案是您需要AuthenticatorSelector来选择您的身份验证器.这允许您拥有多个身份验证器:
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();
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


应用场景 C端用户提交工单、工单创建完成之后、会发布一条工单创建完成的消息事件(异步消息)、MQ消费者收到消息之后、会通知各处理器处理该消息、各处理器处理完后都会发布一条将该工单写入搜索引擎的消息、最终该工单出现在搜索引擎、被工单处理人检索和处理。 事故异常体现 1、异常体现 从工单的流转记录发现、
线程类,设置有一个公共资源 package cn.org.chris.concurrent; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /** * @Descrip
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量
Java 9中JShell中的不同启动脚本是什么?
使用Java的位填充错误检测技术
java中string是什么
如何使用Java中的JSON-lib API将Map转换为JSON对象?