Code example for AnnotatedElement

Methods: getAnnotation, isAnnotationPresent

0
    public static ModelSecurity scan(AnnotatedElement elem) {
        if (denyAllClass == null || permitAllClass == null || rolesAllowedClass == null) {
            return null; 
        } 
 
        boolean denyAll = elem.isAnnotationPresent(denyAllClass);
        boolean permitAll = elem.isAnnotationPresent(permitAllClass);
        RolesAllowed rolesAllowed = elem.getAnnotation(rolesAllowedClass);
 
        if (denyAll || permitAll || rolesAllowed != null) {
            String[] roles = (rolesAllowed != null) ? rolesAllowed.value() : null;
            return new ModelSecurity(denyAll, permitAll, roles);
        } else { 
            return null; 
        } 
    } 
 
    private static Class<DenyAll> denyAllClass;
    private static Class<PermitAll> permitAllClass;
    private static Class<RolesAllowed> rolesAllowedClass;