Controle de Permissão com VRaptor - QCon SP 2011
- 2. public enum Perfil {
MEMBRO, MODERADOR, ADMINISTRADOR
}
public class Usuario {
private Long id;
private String nome;
private Perfil perfil;
}
- 9. accepts()
{ true | false }
intercept()
{ next | redirect | error }
- 11. public void intercept(
InterceptorStack stack, ResourceMethod method, Object resource) {
Permission methodPermission =
method.getMethod().getAnnotation(Permission.class);
Permission controllerPermission =
method.getResource().getType().getAnnotation(Permission.class);
// ...
}
- 12. private boolean hasAccess(Permission permission) {
if (permission == null) return true;
Collection<Perfil> perfis = Arrays.asList(permission.value());
return perfis.contains(userSession.getUser().getPerfil());
}
- 15. Obrigado! (:
WASHINGTON BOTELHO
@wbotelhos | wbotelhos.com.br