I realize most of the posts here talk about extending the DaoAuthenticationProvider, but since I am getting my authorization roles from LDAP, can't I just extend the LdapAuthenticationProvider? This way I can just swap out the authentication mechanism from LDAP to Siteminder depending the environment and use the nifty declarative approach the LdapAuthenticationProvider affords.
However, I have attempted to use Acegi 1.0 Siteminder plug-in together with my extended LdapAuthenticationProvider, but no luck. Any suggestions?
Code:
<bean id="authenticationProcessingFilter" class="com.xxx.xxx.common.security.SiteminderAuthenticationProcessingFilter">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="authenticationFailureUrl"><value>/accessDenied.jsp</value></property>
<property name="defaultTargetUrl"><value>/jsp/Hello.jsp</value></property>
<property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
<property name="siteminderUsernameHeaderKey"><value>SM_USER</value></property>
<property name="siteminderPasswordHeaderKey"><value>SM_USER</value></property>
</bean>
...
<bean id="ldapAuthProvider"
class="com.xxx.xxx.common.security.SiteminderLdapAuthenticationProvider">
<constructor-arg>
<bean
class="org.acegisecurity.providers.ldap.authenticator.BindAuthenticator">
<constructor-arg>
<ref local="initialDirContextFactory"/>
</constructor-arg>
<property name="userDnPatterns">
<list>
<value>uid={0},ou=people</value>
</list>
</property>
</bean>
</constructor-arg>
<constructor-arg>
<bean
class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator">
<constructor-arg>
<ref local="initialDirContextFactory"/>
</constructor-arg>
<constructor-arg>
<value>ou=dl</value>
</constructor-arg>
<property name="groupRoleAttribute">
<value>cn</value>
</property>
</bean>
</constructor-arg>
</bean>
Here's my simple code for the provider for userID/password equality as per the docs, since Siteminder already does authentication (just need LDAP for querying roles for authorization):
Code:
public class SiteminderLdapAuthenticationProvider extends
LdapAuthenticationProvider {
public SiteminderLdapAuthenticationProvider(LdapAuthenticator arg0,
LdapAuthoritiesPopulator arg1) {
super(arg0, arg1);
}
protected final void additionalAuthenticationChecks(
final UserDetails userDetails,
final UsernamePasswordAuthenticationToken authentication)
throws AuthenticationException {
// Since siteminder does authentication, simply check that
// the userid and password credentials match form siteminder.
if (!userDetails.getUsername().equalsIgnoreCase(
(String) authentication.getCredentials())) {
throw new AuthenticationServiceException(
"UserName and Password do not match.");
}
}
}
Thanks in advance,