The basic steps are:
Use a custom authentication provider
<bean id="myAuthenticationProvider" class="myProviderImplementation" scope="singleton">
...
</bean>
Make your custom provider return a custom UserDetails
implementation. This UserDetailsImpl
will have a getAuthorities()
like this:
public Collection<GrantedAuthority> getAuthorities() {
List<GrantedAuthority> permissions = new ArrayList<GrantedAuthority>();
for (GrantedAuthority role: roles) {
permissions.addAll(getPermissionsIncludedInRole(role));
}
return permissions;
}
Of course from here you could apply a lot of optimizations/customizations for your specific requirements.