java - AS7/Picketbox 4 中 SecurityAssociation 的替代方案

标签 java jboss seam kerberos

我在 Seam 2 应用程序中有以下类,它与 SPNEGO 结合使用来进行 Kerberos 身份验证。在 AS7 Final(使用 Pickbox 4.0.0.CR1)中,SecurityAssociation 类已被删除。我应该使用哪个类或函数来代替 SecurityAssociation.getPrincipal()SecurityAssociation.getSubject()

package com.redhat.topicindex.security;


import java.lang.reflect.Field;


import javax.faces.context.FacesContext;


import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.core.Events;
import org.jboss.seam.security.Identity;
import org.jboss.security.SecurityAssociation;


@SuppressWarnings("serial")
@Name("org.jboss.seam.security.identity")
@Scope(ScopeType.SESSION)
@Install(precedence = Install.DEPLOYMENT)
@BypassInterceptors
@Startup
public class CustomIdentity extends Identity {


          private static final String SUBJECT = "subject";
          private static final String PRINCIPAL = "principal";
          private static final String LOGGED_IN = "loggedIn";


          @Override
          public String login() {

                    if(isLoggedIn()) return LOGGED_IN;

                    try {
                              getCredentials().setUsername(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
                              getCredentials().setPassword("");

                              Field field = Identity.class.getDeclaredField(PRINCIPAL);
                              field.setAccessible(true);
                              field.set(this, SecurityAssociation.getPrincipal()); 

                              field = Identity.class.getDeclaredField(SUBJECT);
                              field.setAccessible(true);
                              field.set(this, SecurityAssociation.getSubject());

                              if (Events.exists()) Events.instance().raiseEvent(EVENT_LOGIN_SUCCESSFUL);

                              return LOGGED_IN;
                    } catch (Exception e) {
                              e.printStackTrace();
                              return null;
                    }

          }
}

最佳答案

此问题已在 http://community.jboss.org/thread/170545 中得到解答:

SecurityContext sc = SecurityContextAssociation.getCurrentContext();
sc.getUti().getSubject()  
(...)

此补丁对于最新(现在为 2015 年 3 月)的 PickectBox 版本 (4.0.21.Beta1) 似乎不再有效。等效代码如下所示:

SecurityContextAssociation.getSubject();

关于java - AS7/Picketbox 4 中 SecurityAssociation 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6975805/

相关文章:

jboss - 使用 Fiddler 为 JBoss (ESB) 调试设置代理

java - 如何为 JAX-WS WebService 调用设置超时

java - 使用 JSF 的 Seam 与使用 GWT 的 Seam

ubuntu - 在 Ubuntu 上安装 JDK 时遇到问题

Java Scanner 类给出 java.util.NoSuchElementException

java - Arquillian 测试的回滚事务 - 获取 NullPointerException

java - jdbc4.MySQL语法错误异常: error in your SQL syntax; check the manual MySQL server version for the right syntax to use near ') )' at line 1

java - 使用 java nio 路径时未安装 JBoss wildfly 8.x Provider "vfs"

html - 如何重写 URL

java - 无法使用 javascript 提交()接缝表单