Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package rights; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.GrantedAuthorityImpl; /** * * @author Rice Pavel */ public class AuthorityWrapper implements Authentication { private final Authentication auth; private final String[] additionalRoles; public AuthorityWrapper(Authentication auth, String[] additionalRoles) { this.auth = auth; this.additionalRoles = additionalRoles; } public Collection<? extends GrantedAuthority> getAuthorities() { Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); List<GrantedAuthority> newList = new ArrayList(); for (GrantedAuthority ga : authorities) { newList.add(ga); } for (String roleName : additionalRoles) { newList.add(new GrantedAuthorityImpl(roleName)); } return newList; } public Object getCredentials() { return auth.getCredentials(); } public Object getDetails() { return auth.getDetails(); } @Override public Object getPrincipal() { return auth.getPrincipal(); } @Override public boolean isAuthenticated() { return auth.isAuthenticated(); } @Override public void setAuthenticated(boolean bln) throws IllegalArgumentException { auth.setAuthenticated(bln); } @Override public String getName() { return auth.getName(); } }