Spring Security remove RoleVoter prefix

spring, spring-security

Solution

Spring security `RoleVoter`needs a prefix in order to distinguish the granted authorities that are roles, see this answer for further details.

If you want to change this, you can always provide your own custom `AccessDecisionManager and configure it with a custom`RoleVoter`.

This is an example of such a custom access decision manager:

public class MyAccessDecisionManager  extends AffirmativeBased {


    public MyAccessDecisionManager() {
        super();
        List<AccessDecisionVoter> decisionVoters = new ArrayList<AccessDecisionVoter>();
        RoleVoter roleVoter = new MyCustomRoleVoter();
        decisionVoters.add(roleVoter);
        AuthenticatedVoter authenticatedVoter = new AuthenticatedVoter();
        decisionVoters.add(authenticatedVoter);
        setDecisionVoters(decisionVoters);

    }

And for using it in place of the default access decision manager:

<bean id="myAccessDecisionManager" class="full.package.name.MyAccessDecisionManager" />

<security:http access-decision-manager-ref="myAccessDecisionManager">
    ...
</security:http>

Problem

In the project I am working we authenticate based on role ids rather than role description and this mapping is stored in the database. My question is, How do I remove Spring Security's RoleVoter prefix to implement the design as above?

Original source

Related problems