alternative to GrantedAuthorityImpl() class

Tags: , , ,



I want an alternative to GrantedAuthorityImpl() class. I want this in spring security implementation. GrantedAuthorityImpl() class is deprecated. Hence I want an alternative solution to it. My code :

public Collection<GrantedAuthority> getAuthorities(Integer access) {
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);
    
    if (access.compareTo(1) == 0) {
        authList.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
    }
    else{
        authList.add(new GrantedAuthorityImpl("ROLE_USER"));
    }
    return authList;
}

Answer

The class GrantedAuthorityImpl has been deprecated – you can use SimpleGrantedAuthority instead:

public Collection<GrantedAuthority> getAuthorities(Integer access) {
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);

    if (access.compareTo(1) == 0) {
        authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
    }
    else{
        authList.add(new SimpleGrantedAuthority("ROLE_USER"));
    }
    return authList;
}


Source: stackoverflow