I was able to do this, so for anyone interested my code is below. I created an AuthenticationProvider that takes a list of roles to automatically grant, which are passed in via a property.
I'd appreciate any comments about if this is the right way to go about this.
Code:
package com.cyc.acegisecurity.providers.fixed;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
import net.sf.acegisecurity.providers.AuthenticationProvider;
import net.sf.acegisecurity.providers.smb.NtlmAuthenticationToken;
public class FixedAuthenticationProvider implements AuthenticationProvider
{
private GrantedAuthority[] grantedAuthorities;
public void setGrantedAuthorities(List newGrantedAuthorities)
{
// convert the granted authorities list passed in to a GrantedAuthorities[]
ArrayList grantedArr = new ArrayList();
Iterator it = newGrantedAuthorities.iterator();
while(it.hasNext())
grantedArr.add(new GrantedAuthorityImpl((String)it.next()));
grantedAuthorities = (GrantedAuthority[])grantedArr.toArray(new GrantedAuthority[]{});
}
public Authentication authenticate(Authentication authentication)
{
NtlmAuthenticationToken token = (NtlmAuthenticationToken) authentication;
token.setAuthenticated(true);
token.setAuthorities(grantedAuthorities);
return token;
}
public boolean supports(Class authentication)
{
return NtlmAuthenticationToken.class.isAssignableFrom( authentication );
}
}
Code:
<!-- Authentication via NTLM -->
<bean id="smbAuthenticationProvider"
class="net.sf.acegisecurity.providers.smb.SmbNtlmAuthenticationProvider">
<property name="authorizationProvider">
<ref bean="authorizationProvider"/>
</property>
</bean>
<bean id="authorizationProvider"
class="com.cyc.acegisecurity.providers.fixed.FixedAuthenticationProvider">
<property name="grantedAuthorities">
<list>
<value>ROLE_USER</value>
</list>
</property>
</bean>