我有一个使用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>
其实,我的豆WebsphereCredentials
使用的WebSphere私有类WSMappingCallbackHandlerFactory
在这样的响应: 如何从EJB访问认证别名部署到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
但我不希望它因为:
- 我想我的应用程序可以访问所有JAAS登录我的WebSphere实例(不知道)。
- 这个类在巨大的IBM客户端库com.ibm.ws.admin.client-7.0.0.jar(42沫)=>汇编较慢,而不是在我的企业关系本定义
- 这不便于携带,不规范
有关信息,我定义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());
有没有办法使用只是春天的安全和消除这种依赖的方法吗?
我不知道如何结合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 。
也许我必须完全改变我的做法,用另一种方式?