Search in sources :

Example 36 with PermitAll

use of javax.annotation.security.PermitAll in project aries by apache.

the class AuthorizationInterceptor method preCall.

public Object preCall(ComponentMetadata cm, Method m, Object... parameters) throws Throwable {
    Annotation ann = new SecurityAnotationParser().getEffectiveAnnotation(beanClass, m);
    if (ann instanceof PermitAll) {
        return null;
    }
    // Also applies for @DenyAll
    String[] rolesAr = new String[] {};
    if (ann instanceof RolesAllowed) {
        rolesAr = ((RolesAllowed) ann).value();
    }
    Set<String> roles = new HashSet<String>(Arrays.asList(rolesAr));
    AccessControlContext acc = AccessController.getContext();
    Subject subject = Subject.getSubject(acc);
    if (subject == null) {
        throw new AccessControlException("Method call " + m.getDeclaringClass() + "." + m.getName() + " denied. No JAAS login present");
    }
    Set<Principal> principals = subject.getPrincipals();
    for (Principal principal : principals) {
        if (roles.contains(principal.getName())) {
            LOGGER.debug("Granting access to Method: {} for {}.", m, principal);
            return null;
        }
    }
    String msg = String.format("Method call %s.%s denied. Roles allowed are %s. Your principals are %s.", m.getDeclaringClass(), m.getName(), roles, getNames(principals));
    throw new AccessControlException(msg);
}
Also used : AccessControlException(java.security.AccessControlException) Annotation(java.lang.annotation.Annotation) Subject(javax.security.auth.Subject) RolesAllowed(javax.annotation.security.RolesAllowed) AccessControlContext(java.security.AccessControlContext) PermitAll(javax.annotation.security.PermitAll) Principal(java.security.Principal) HashSet(java.util.HashSet)

Aggregations

PermitAll (javax.annotation.security.PermitAll)36 ArrayList (java.util.ArrayList)8 User (org.traccar.model.User)8 POST (javax.ws.rs.POST)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 HashMap (java.util.HashMap)5 RolesAllowed (javax.annotation.security.RolesAllowed)5 DataTable (io.irontest.models.DataTable)4 UserDefinedProperty (io.irontest.models.UserDefinedProperty)4 Date (java.util.Date)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Catalog (org.rembx.jeeshop.catalog.model.Catalog)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Testcase (io.irontest.models.Testcase)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 JsonView (com.fasterxml.jackson.annotation.JsonView)2 Environment (io.irontest.models.Environment)2