37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
|
package +zoccolo+.web.authentication.authority;
|
||
|
|
||
|
import java.util.Collection;
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.springframework.security.core.GrantedAuthority;
|
||
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||
|
|
||
|
import +tabposition+.+tabella+;
|
||
|
|
||
|
/**
|
||
|
* A utility class used for creating the {@link GrantedAuthority}'s given a {@link +tabella+}. In a real solution
|
||
|
* this would be looked up in the existing system, but for simplicity our original system had no notion of authorities.
|
||
|
*
|
||
|
* @author Rob Winch
|
||
|
*
|
||
|
*/
|
||
|
public final class UserAuthorityUtils {
|
||
|
|
||
|
private static final List<GrantedAuthority> ADMIN_ROLES = AuthorityUtils.createAuthorityList("ROLE_ADMIN",
|
||
|
"ROLE_USER");
|
||
|
private static final List<GrantedAuthority> USER_ROLES = AuthorityUtils.createAuthorityList("ROLE_USER");
|
||
|
|
||
|
private UserAuthorityUtils() {
|
||
|
|
||
|
}
|
||
|
|
||
|
public static Collection<? extends GrantedAuthority> createAuthorities(+tabella+ user) {
|
||
|
String username = user.getChiave();
|
||
|
// NON CANCELLARE
|
||
|
if (username.startsWith("admin")) {
|
||
|
return ADMIN_ROLES;
|
||
|
}
|
||
|
return USER_ROLES;
|
||
|
}
|
||
|
}
|