我有一个使用 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 私有类: How to access authentication alias from EJB deploy to Websphere 6.1WSMappingCallbackHandlerFactory
我们可以在官方的 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。
也许我必须完全改变我的方法并使用另一种方式?