Search in sources :

Example 1 with PermitAll

use of javax.annotation.security.PermitAll in project jeeshop by remibantos.

the class Catalogs method findCategories.

@GET
@Path("/{catalogId}/categories")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public List<Category> findCategories(@PathParam("catalogId") @NotNull Long catalogId, @QueryParam("locale") String locale) {
    Catalog catalog = entityManager.find(Catalog.class, catalogId);
    checkNotNull(catalog);
    List<Category> rootCategories = catalog.getRootCategories();
    if (rootCategories.isEmpty()) {
        return new ArrayList<>();
    }
    if (isAdminUser(sessionContext)) {
        return rootCategories;
    } else {
        return catalogItemFinder.findVisibleCatalogItems(category, rootCategories, locale);
    }
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) ArrayList(java.util.ArrayList) Catalog(org.rembx.jeeshop.catalog.model.Catalog) PermitAll(javax.annotation.security.PermitAll)

Example 2 with PermitAll

use of javax.annotation.security.PermitAll in project iaf by ibissource.

the class Init method getAllResources.

@GET
@PermitAll
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllResources(@QueryParam("allowedRoles") boolean displayAllowedRoles) {
    List<Object> JSONresources = new ArrayList<Object>();
    Map<String, Object> HALresources = new HashMap<String, Object>();
    Map<String, Object> resources = new HashMap<String, Object>(1);
    ResourceMethodRegistry registry = (ResourceMethodRegistry) dispatcher.getRegistry();
    StringBuffer requestPath = httpServletRequest.getRequestURL();
    if (requestPath.substring(requestPath.length() - 1).equals("/"))
        requestPath.setLength(requestPath.length() - 1);
    for (Map.Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
        for (ResourceInvoker invoker : entry.getValue()) {
            Method method = invoker.getMethod();
            String relation = null;
            if (method.getDeclaringClass() == getClass()) {
                continue;
            }
            if (method.getDeclaringClass().getName().endsWith("ShowMonitors") && !AppConstants.getInstance().getBoolean("monitoring.enabled", false)) {
                continue;
            }
            Map<String, Object> resource = new HashMap<String, Object>(4);
            if (method.isAnnotationPresent(GET.class))
                resource.put("type", "GET");
            else if (method.isAnnotationPresent(POST.class))
                resource.put("type", "POST");
            else if (method.isAnnotationPresent(PUT.class))
                resource.put("type", "PUT");
            else if (method.isAnnotationPresent(DELETE.class))
                resource.put("type", "DELETE");
            Path path = method.getAnnotation(Path.class);
            if (path != null) {
                String p = path.value();
                if (!p.startsWith("/"))
                    p = "/" + p;
                resource.put("href", requestPath + p);
            }
            RolesAllowed rolesAllowed = method.getAnnotation(RolesAllowed.class);
            if (rolesAllowed != null && displayAllowedRoles) {
                resource.put("allowed", rolesAllowed.value());
            }
            if ((HATEOASImplementation.equalsIgnoreCase("hal"))) {
                if (method.isAnnotationPresent(Relation.class))
                    relation = method.getAnnotation(Relation.class).value();
                if (relation != null) {
                    if (HALresources.containsKey(relation)) {
                        Object prevRelation = HALresources.get(relation);
                        List<Object> tmpList = null;
                        if (prevRelation instanceof List)
                            tmpList = (List) prevRelation;
                        else {
                            tmpList = new ArrayList<Object>();
                            tmpList.add(prevRelation);
                        }
                        tmpList.add(resource);
                        HALresources.put(relation, tmpList);
                    } else
                        HALresources.put(relation, resource);
                }
            } else {
                if (method.isAnnotationPresent(Relation.class))
                    resource.put("rel", method.getAnnotation(Relation.class).value());
                JSONresources.add(resource);
            }
        }
    }
    if ((HATEOASImplementation.equalsIgnoreCase("hal")))
        resources.put(ResourceKey, HALresources);
    else
        resources.put(ResourceKey, JSONresources);
    return Response.status(Response.Status.CREATED).entity(resources).build();
}
Also used : Path(javax.ws.rs.Path) HashMap(java.util.HashMap) POST(javax.ws.rs.POST) ArrayList(java.util.ArrayList) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) Method(java.lang.reflect.Method) ResourceInvoker(org.jboss.resteasy.core.ResourceInvoker) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 3 with PermitAll

use of javax.annotation.security.PermitAll in project iaf by ibissource.

the class ServerStatistics method getServerInformation.

@GET
@PermitAll
@Path("/server/info")
@Produces(MediaType.APPLICATION_JSON)
public Response getServerInformation() throws ApiException {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    List<Object> configurations = new ArrayList<Object>();
    initBase(servletConfig);
    for (Configuration configuration : ibisManager.getConfigurations()) {
        Map<String, Object> cfg = new HashMap<String, Object>();
        cfg.put("name", configuration.getName());
        cfg.put("version", configuration.getVersion());
        cfg.put("type", configuration.getClassLoaderType());
        ClassLoader classLoader = configuration.getClassLoader().getParent();
        if (classLoader instanceof DatabaseClassLoader) {
            cfg.put("filename", ((DatabaseClassLoader) classLoader).getFileName());
            cfg.put("created", ((DatabaseClassLoader) classLoader).getCreationDate());
            cfg.put("user", ((DatabaseClassLoader) classLoader).getUser());
        }
        configurations.add(cfg);
    }
    returnMap.put("configurations", configurations);
    returnMap.put("version", ibisContext.getFrameworkVersion());
    returnMap.put("name", ibisContext.getApplicationName());
    returnMap.put("applicationServer", servletConfig.getServletContext().getServerInfo());
    returnMap.put("javaVersion", System.getProperty("java.runtime.name") + " (" + System.getProperty("java.runtime.version") + ")");
    Map<String, Object> fileSystem = new HashMap<String, Object>(2);
    fileSystem.put("totalSpace", Misc.getFileSystemTotalSpace());
    fileSystem.put("freeSpace", Misc.getFileSystemFreeSpace());
    returnMap.put("fileSystem", fileSystem);
    returnMap.put("processMetrics", ProcessMetrics.toMap());
    Date date = new Date();
    returnMap.put("serverTime", date.getTime());
    returnMap.put("machineName", Misc.getHostname());
    returnMap.put("uptime", ibisContext.getUptimeDate());
    return Response.status(Response.Status.CREATED).entity(returnMap).build();
}
Also used : DatabaseClassLoader(nl.nn.adapterframework.configuration.classloaders.DatabaseClassLoader) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) DatabaseClassLoader(nl.nn.adapterframework.configuration.classloaders.DatabaseClassLoader) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 4 with PermitAll

use of javax.annotation.security.PermitAll in project traccar by traccar.

the class SessionResource method add.

@PermitAll
@POST
public User add(@FormParam("email") String email, @FormParam("password") String password) throws SQLException {
    User user = Context.getPermissionsManager().login(email, password);
    if (user != null) {
        request.getSession().setAttribute(USER_ID_KEY, user.getId());
        LogAction.login(user.getId());
        return user;
    } else {
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
    }
}
Also used : User(org.traccar.model.User) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 5 with PermitAll

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

the class MPJWTSecurityAnnotationsInterceptorsFeature method processSecurityAnnotations.

private boolean processSecurityAnnotations(final Class clazz, final Method method) {
    final List<Class<? extends Annotation>[]> classSecurityAnnotations = hasClassLevelAnnotations(clazz, RolesAllowed.class, PermitAll.class, DenyAll.class);
    final List<Class<? extends Annotation>[]> methodSecurityAnnotations = hasMethodLevelAnnotations(method, RolesAllowed.class, PermitAll.class, DenyAll.class);
    if (classSecurityAnnotations.isEmpty() && methodSecurityAnnotations.isEmpty()) {
        // nothing to do
        return false;
    }
    /*
         * Process annotations at the class level
         */
    if (classSecurityAnnotations.size() > 1) {
        throw new IllegalStateException(clazz.getName() + " has more than one security annotation (RolesAllowed, PermitAll, DenyAll).");
    }
    if (methodSecurityAnnotations.size() > 1) {
        throw new IllegalStateException(method.toString() + " has more than one security annotation (RolesAllowed, PermitAll, DenyAll).");
    }
    if (methodSecurityAnnotations.isEmpty()) {
        // no need to deal with class level annotations if the method has some
        final RolesAllowed classRolesAllowed = (RolesAllowed) clazz.getAnnotation(RolesAllowed.class);
        final PermitAll classPermitAll = (PermitAll) clazz.getAnnotation(PermitAll.class);
        final DenyAll classDenyAll = (DenyAll) clazz.getAnnotation(DenyAll.class);
        if (classRolesAllowed != null) {
            Set<String> roles = new HashSet<>();
            final Set<String> previous = rolesAllowed.putIfAbsent(method, roles);
            if (previous != null) {
                roles = previous;
            }
            roles.addAll(Arrays.asList(classRolesAllowed.value()));
        }
        if (classPermitAll != null) {
            permitAll.add(method);
        }
        if (classDenyAll != null) {
            denyAll.add(method);
        }
    }
    final RolesAllowed mthdRolesAllowed = method.getAnnotation(RolesAllowed.class);
    final PermitAll mthdPermitAll = method.getAnnotation(PermitAll.class);
    final DenyAll mthdDenyAll = method.getAnnotation(DenyAll.class);
    if (mthdRolesAllowed != null) {
        Set<String> roles = new HashSet<>();
        final Set<String> previous = rolesAllowed.putIfAbsent(method, roles);
        if (previous != null) {
            roles = previous;
        }
        roles.addAll(Arrays.asList(mthdRolesAllowed.value()));
    }
    if (mthdPermitAll != null) {
        permitAll.add(method);
    }
    if (mthdDenyAll != null) {
        denyAll.add(method);
    }
    return true;
}
Also used : RolesAllowed(javax.annotation.security.RolesAllowed) DenyAll(javax.annotation.security.DenyAll) PermitAll(javax.annotation.security.PermitAll) 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