Description
examples:
#1:
//...
@Named
@Admin
public class MyBean implements Serializable
{
//...
}
//...
@Stereotype
@Secured(RoleAccessDecisionVoter.class)
public @interface Admin
{
}
@ApplicationScoped
public class RoleAccessDecisionVoter implements AccessDecisionVoter
{
private static final long serialVersionUID = -8007511215776345835L;
@Inject
private AccessDecisionVoterContext voterContext;
public Set<SecurityViolation> checkPermission(InvocationContext invocationContext)
{ Admin admin = voterContext.getMetaDataFor(Admin.class.getName(), Admin.class); //... }}
#2:
//...
@Named
@HasRole("admin")
public class MyBean implements Serializable
{
//...
}
//...
@Stereotype
@Secured(RoleAccessDecisionVoter.class)
public @interface HasRole
{
String value();
}
@ApplicationScoped
public class RoleAccessDecisionVoter implements AccessDecisionVoter
{
private static final long serialVersionUID = -8007511215776345835L;
@Inject
private AccessDecisionVoterContext voterContext;
public Set<SecurityViolation> checkPermission(InvocationContext invocationContext)
{ HasRole hasRole = voterContext.getMetaDataFor(HasRole.class.getName(), HasRole.class); String roleName = hasRole.value(); //... }}