Search in sources :

Example 1 with CacheRoleImpl

use of org.infinispan.security.impl.CacheRoleImpl in project infinispan by infinispan.

the class SecurityResource method createRole.

private CompletionStage<RestResponse> createRole(RestRequest request) {
    NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
    if (rolePermissionMapper == null) {
        return completedFuture(new NettyRestResponse.Builder().status(CONFLICT).entity(Log.REST.rolePermissionMapperNotMutable()).build());
    }
    String name = request.variables().get("role");
    List<String> perms = request.parameters().get("permission");
    if (perms == null) {
        return completedFuture(builder.status(HttpResponseStatus.BAD_REQUEST).build());
    }
    Set<AuthorizationPermission> permissions = perms.stream().map(p -> AuthorizationPermission.valueOf(p.toUpperCase())).collect(Collectors.toSet());
    Role role = new CacheRoleImpl(name, true, permissions);
    return rolePermissionMapper.addRole(role).thenCompose(ignore -> aclCacheFlush(request));
}
Also used : PUT(org.infinispan.rest.framework.Method.PUT) ResourceHandler(org.infinispan.rest.framework.ResourceHandler) MutablePrincipalRoleMapper(org.infinispan.security.MutablePrincipalRoleMapper) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) GET(org.infinispan.rest.framework.Method.GET) Role(org.infinispan.security.Role) CompletableFuture(java.util.concurrent.CompletableFuture) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) POST(org.infinispan.rest.framework.Method.POST) CONFLICT(io.netty.handler.codec.http.HttpResponseStatus.CONFLICT) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) NO_CONTENT(io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT) RestCacheManager(org.infinispan.rest.cachemanager.RestCacheManager) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) DELETE(org.infinispan.rest.framework.Method.DELETE) GlobalSecurityManager(org.infinispan.security.GlobalSecurityManager) Map(java.util.Map) Log(org.infinispan.rest.logging.Log) RestRequest(org.infinispan.rest.framework.RestRequest) SubjectACL(org.infinispan.security.impl.SubjectACL) Invocations(org.infinispan.rest.framework.impl.Invocations) NettyRestResponse(org.infinispan.rest.NettyRestResponse) AuthorizationPermission(org.infinispan.security.AuthorizationPermission) GlobalAuthorizationConfiguration(org.infinispan.configuration.global.GlobalAuthorizationConfiguration) Collection(java.util.Collection) Set(java.util.Set) InvocationHelper(org.infinispan.rest.InvocationHelper) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Json(org.infinispan.commons.dataconversion.internal.Json) Collectors(java.util.stream.Collectors) MutableRolePermissionMapper(org.infinispan.security.MutableRolePermissionMapper) Subject(javax.security.auth.Subject) ResourceUtil.asJsonResponseFuture(org.infinispan.rest.resources.ResourceUtil.asJsonResponseFuture) List(java.util.List) PrincipalRoleMapper(org.infinispan.security.PrincipalRoleMapper) CompletionStage(java.util.concurrent.CompletionStage) Authorizer(org.infinispan.security.impl.Authorizer) Configuration(org.infinispan.configuration.cache.Configuration) AuditContext(org.infinispan.security.AuditContext) RestResponse(org.infinispan.rest.framework.RestResponse) CacheRoleImpl(org.infinispan.security.impl.CacheRoleImpl) RolePermissionMapper(org.infinispan.security.RolePermissionMapper) Role(org.infinispan.security.Role) AuthorizationPermission(org.infinispan.security.AuthorizationPermission) CacheRoleImpl(org.infinispan.security.impl.CacheRoleImpl) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 BAD_REQUEST (io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST)1 CONFLICT (io.netty.handler.codec.http.HttpResponseStatus.CONFLICT)1 NO_CONTENT (io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Collectors (java.util.stream.Collectors)1 Subject (javax.security.auth.Subject)1 Json (org.infinispan.commons.dataconversion.internal.Json)1 Configuration (org.infinispan.configuration.cache.Configuration)1 GlobalAuthorizationConfiguration (org.infinispan.configuration.global.GlobalAuthorizationConfiguration)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 InvocationHelper (org.infinispan.rest.InvocationHelper)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1