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);
}
}
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();
}
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();
}
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());
}
}
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;
}
Aggregations