【发布时间】:2012-12-11 22:05:02
【问题描述】:
我有一个使用 LDAP 身份验证的 Java EE Web 应用程序。我使用 Spring 安全性通过以下代码连接到我的 LDAP:
<bean id="ldapContextSource" class="com.myapp.security.authentication.MySecurityContextSource">
<constructor-arg index="0" value="${ldap.url}" />
<constructor-arg index="1" ref="userConnexion" />
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="ldapAuthProvider" />
</security:authentication-manager>
<bean id="userConnexion" class="com.myapp.util.security.WebsphereCredentials">
<constructor-arg value="${ldap.authJndiAlias}" />
</bean>
<bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<constructor-arg>
<bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="ldapContextSource" />
<property name="userSearch" ref="userSearch" />
</bean>
</constructor-arg>
<constructor-arg>
<bean class="com.myapp.security.authentication.MyAuthoritiesPopulator" >
<property name="userService" ref="userService" />
</bean>
</constructor-arg>
<property name="userDetailsContextMapper" ref="myUserDetailsContextMapper"/>
<property name="hideUserNotFoundExceptions" value="false" />
</bean>
实际上,我的 bean WebsphereCredentials 使用 WebSphere 私有类 WSMappingCallbackHandlerFactory,如在此响应中:How to access authentication alias from EJB deployed to Websphere 6.1
我们可以在websphere官方文档中看到:http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Frsec_pluginj2c.html
但我不想要它,因为:
- 我认为我的应用程序可以访问我的 WebSphere 实例中的所有 JAAS 登录(不确定)。
- 这个类在巨大的 IBM 客户端库 com.ibm.ws.admin.client-7.0.0.jar (42 Mo) 中定义 => 编译速度较慢,在我的企业关系中不存在
- 它不是便携式的,不是标准的
关于信息,我将WebsphereCredentials 构造函数定义为:
Map<String, String> map = new HashMap<String, String>();
map.put(Constants.MAPPING_ALIAS, this.jndiAlias);
Subject subject;
try {
CallbackHandler callbackHandler = WSMappingCallbackHandlerFactory.getInstance().getCallbackHandler(map, null);
LoginContext lc = new LoginContext("DefaultPrincipalMapping", callbackHandler);
lc.login();
subject = lc.getSubject();
} catch (NotImplementedException e) {
throw new EfritTechnicalException(EfritTechnicalExceptionEnum.LOGIN_CREDENTIAL_PROBLEM, e);
} catch (LoginException e) {
throw new EfritTechnicalException(EfritTechnicalExceptionEnum.LOGIN_CREDENTIAL_PROBLEM, e);
}
PasswordCredential cred = (PasswordCredential) subject.getPrivateCredentials().toArray()[0];
this.user = cred.getUserName();
this.password = String.valueOf(cred.getPassword());
有没有办法只使用 Spring 安全性并删除此依赖项?
我不知道如何组合http://static.springsource.org/spring-security/site/docs/3.1.x/reference/jaas.html 和http://static.springsource.org/spring-security/site/docs/3.1.x/reference/ldap.html。
也许我必须完全改变我的方法并使用另一种方式?
【问题讨论】:
-
>HUGE IBM 客户端库 com.ibm.ws.admin.client-7.0.0.jar (42 Mo) => 编译速度较慢 - 虽然我知道需要避免使用如此大的 jar,但通常有它们不会减慢编译速度。 Java 不会重新编译 jar。它们已链接,但未编译。
-
是的,你是对的。我把它写得很快……我这么说是因为当我完成编译时,我复制了我的 jars 以进行部署。但是这个 jars 是由应用程序服务器提供的,我已经在 maven pom 文件中将它标记为提供。 ;o)
标签: authentication spring-security ldap websphere jaas