-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1452 from gentics/dev-gpu-311-permissions-endpoints
Dev gpu 311 permissions endpoints
- Loading branch information
Showing
48 changed files
with
3,227 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
core/src/main/java/com/gentics/mesh/core/endpoint/RolePermissionHandlingEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.gentics.mesh.core.endpoint; | ||
|
||
import static com.gentics.mesh.core.rest.MeshEvent.ROLE_PERMISSIONS_CHANGED; | ||
import static com.gentics.mesh.http.HttpConstants.APPLICATION_JSON; | ||
import static io.netty.handler.codec.http.HttpResponseStatus.OK; | ||
import static io.vertx.core.http.HttpMethod.DELETE; | ||
import static io.vertx.core.http.HttpMethod.GET; | ||
import static io.vertx.core.http.HttpMethod.POST; | ||
|
||
import com.gentics.mesh.auth.MeshAuthChainImpl; | ||
import com.gentics.mesh.context.InternalActionContext; | ||
import com.gentics.mesh.core.endpoint.handler.AbstractCrudHandler; | ||
import com.gentics.mesh.rest.InternalEndpointRoute; | ||
import com.gentics.mesh.router.route.AbstractInternalEndpoint; | ||
|
||
/** | ||
* Abstract endpoint implementation with methods that add routes for getting/granting/revoking role permissions | ||
*/ | ||
public abstract class RolePermissionHandlingEndpoint extends AbstractInternalEndpoint { | ||
|
||
protected RolePermissionHandlingEndpoint(String basePath, MeshAuthChainImpl chain) { | ||
super(basePath, chain); | ||
} | ||
|
||
/** | ||
* Add role permission handler | ||
* @param uuidParameterName name of the uuid parameter (e.g. "groupUuid") | ||
* @param uuidParameterExample example of the uuid parameter | ||
* @param typeDescription description of the object type (e.g. "group") | ||
* @param crudHandler crud handler | ||
* @param includePublishPermissions true to include the publish permissions into the example | ||
*/ | ||
protected void addRolePermissionHandler(String uuidParameterName, String uuidParameterExample, String typeDescription, | ||
AbstractCrudHandler<?, ?> crudHandler, boolean includePublishPermissions) { | ||
String path = "/:" + uuidParameterName + "/rolePermissions"; | ||
InternalEndpointRoute readPermissionsEndpoint = createRoute(); | ||
readPermissionsEndpoint.path(path); | ||
readPermissionsEndpoint.addUriParameter(uuidParameterName, "Uuid of the " + typeDescription, uuidParameterExample); | ||
readPermissionsEndpoint.method(GET); | ||
readPermissionsEndpoint.description("Get the permissions on the " + typeDescription + " for all roles."); | ||
readPermissionsEndpoint.produces(APPLICATION_JSON); | ||
readPermissionsEndpoint.exampleResponse(OK, roleExamples.getObjectPermissionResponse(includePublishPermissions), "Loaded permissions."); | ||
readPermissionsEndpoint.blockingHandler(rc -> { | ||
InternalActionContext ac = wrap(rc); | ||
String uuid = rc.request().getParam(uuidParameterName); | ||
crudHandler.handleReadPermissions(ac, uuid); | ||
}, false); | ||
|
||
InternalEndpointRoute grantPermissionsEndpoint = createRoute(); | ||
grantPermissionsEndpoint.path(path); | ||
grantPermissionsEndpoint.addUriParameter(uuidParameterName, "Uuid of the " + typeDescription, uuidParameterExample); | ||
grantPermissionsEndpoint.method(POST); | ||
grantPermissionsEndpoint.description("Grant permissions on the " + typeDescription + " to multiple roles."); | ||
grantPermissionsEndpoint.consumes(APPLICATION_JSON); | ||
grantPermissionsEndpoint.produces(APPLICATION_JSON); | ||
grantPermissionsEndpoint.exampleRequest(roleExamples.getObjectPermissionGrantRequest(includePublishPermissions)); | ||
grantPermissionsEndpoint.exampleResponse(OK, roleExamples.getObjectPermissionResponse(includePublishPermissions), "Updated permissions."); | ||
grantPermissionsEndpoint.events(ROLE_PERMISSIONS_CHANGED); | ||
grantPermissionsEndpoint.blockingHandler(rc -> { | ||
InternalActionContext ac = wrap(rc); | ||
String uuid = rc.request().getParam(uuidParameterName); | ||
crudHandler.handleGrantPermissions(ac, uuid); | ||
}); | ||
|
||
InternalEndpointRoute revokePermissionsEndpoint = createRoute(); | ||
revokePermissionsEndpoint.path(path); | ||
revokePermissionsEndpoint.addUriParameter(uuidParameterName, "Uuid of the " + typeDescription, uuidParameterExample); | ||
revokePermissionsEndpoint.method(DELETE); | ||
revokePermissionsEndpoint.description("Revoke permissions on the " + typeDescription + " from multiple roles."); | ||
revokePermissionsEndpoint.consumes(APPLICATION_JSON); | ||
revokePermissionsEndpoint.produces(APPLICATION_JSON); | ||
revokePermissionsEndpoint.exampleRequest(roleExamples.getObjectPermissionRevokeRequest(includePublishPermissions)); | ||
revokePermissionsEndpoint.exampleResponse(OK, roleExamples.getObjectPermissionResponse(includePublishPermissions), "Updated permissions."); | ||
revokePermissionsEndpoint.events(ROLE_PERMISSIONS_CHANGED); | ||
revokePermissionsEndpoint.blockingHandler(rc -> { | ||
InternalActionContext ac = wrap(rc); | ||
String uuid = rc.request().getParam(uuidParameterName); | ||
crudHandler.handleRevokePermissions(ac, uuid); | ||
}); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
core/src/main/java/com/gentics/mesh/core/endpoint/RolePermissionHandlingProjectEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.gentics.mesh.core.endpoint; | ||
|
||
import static com.gentics.mesh.core.rest.MeshEvent.ROLE_PERMISSIONS_CHANGED; | ||
import static com.gentics.mesh.http.HttpConstants.APPLICATION_JSON; | ||
import static io.netty.handler.codec.http.HttpResponseStatus.OK; | ||
import static io.vertx.core.http.HttpMethod.DELETE; | ||
import static io.vertx.core.http.HttpMethod.GET; | ||
import static io.vertx.core.http.HttpMethod.POST; | ||
|
||
import com.gentics.mesh.auth.MeshAuthChainImpl; | ||
import com.gentics.mesh.cli.BootstrapInitializer; | ||
import com.gentics.mesh.context.InternalActionContext; | ||
import com.gentics.mesh.core.endpoint.handler.AbstractCrudHandler; | ||
import com.gentics.mesh.rest.InternalEndpointRoute; | ||
import com.gentics.mesh.router.route.AbstractProjectEndpoint; | ||
|
||
/** | ||
* Abstract endpoint implementation with methods that add routes for getting/granting/revoking role permissions | ||
*/ | ||
public abstract class RolePermissionHandlingProjectEndpoint extends AbstractProjectEndpoint { | ||
|
||
protected RolePermissionHandlingProjectEndpoint(String basePath, MeshAuthChainImpl chain, | ||
BootstrapInitializer boot) { | ||
super(basePath, chain, boot); | ||
} | ||
|
||
/** | ||
* Add role permission handler | ||
* @param uuidParameterName name of the uuid parameter (e.g. "groupUuid") | ||
* @param uuidParameterExample example of the uuid parameter | ||
* @param typeDescription description of the object type (e.g. "group") | ||
* @param crudHandler crud handler | ||
* @param includePublishPermissions true to include the publish permissions into the example | ||
*/ | ||
protected void addRolePermissionHandler(String uuidParameterName, String uuidParameterExample, String typeDescription, | ||
AbstractCrudHandler<?, ?> crudHandler, boolean includePublishPermissions) { | ||
String path = "/:" + uuidParameterName + "/rolePermissions"; | ||
InternalEndpointRoute readPermissionsEndpoint = createRoute(); | ||
readPermissionsEndpoint.path(path); | ||
readPermissionsEndpoint.addUriParameter(uuidParameterName, "Uuid of the " + typeDescription, uuidParameterExample); | ||
readPermissionsEndpoint.method(GET); | ||
readPermissionsEndpoint.description("Get the permissions on the " + typeDescription + " for all roles."); | ||
readPermissionsEndpoint.produces(APPLICATION_JSON); | ||
readPermissionsEndpoint.exampleResponse(OK, roleExamples.getObjectPermissionResponse(includePublishPermissions), "Loaded permissions."); | ||
readPermissionsEndpoint.blockingHandler(rc -> { | ||
InternalActionContext ac = wrap(rc); | ||
String uuid = rc.request().getParam(uuidParameterName); | ||
crudHandler.handleReadPermissions(ac, uuid); | ||
}, false); | ||
|
||
InternalEndpointRoute grantPermissionsEndpoint = createRoute(); | ||
grantPermissionsEndpoint.path(path); | ||
grantPermissionsEndpoint.addUriParameter(uuidParameterName, "Uuid of the " + typeDescription, uuidParameterExample); | ||
grantPermissionsEndpoint.method(POST); | ||
grantPermissionsEndpoint.description("Grant permissions on the " + typeDescription + " to multiple roles."); | ||
grantPermissionsEndpoint.consumes(APPLICATION_JSON); | ||
grantPermissionsEndpoint.produces(APPLICATION_JSON); | ||
grantPermissionsEndpoint.exampleRequest(roleExamples.getObjectPermissionGrantRequest(includePublishPermissions)); | ||
grantPermissionsEndpoint.exampleResponse(OK, roleExamples.getObjectPermissionResponse(includePublishPermissions), "Updated permissions."); | ||
grantPermissionsEndpoint.events(ROLE_PERMISSIONS_CHANGED); | ||
grantPermissionsEndpoint.blockingHandler(rc -> { | ||
InternalActionContext ac = wrap(rc); | ||
String uuid = rc.request().getParam(uuidParameterName); | ||
crudHandler.handleGrantPermissions(ac, uuid); | ||
}); | ||
|
||
InternalEndpointRoute revokePermissionsEndpoint = createRoute(); | ||
revokePermissionsEndpoint.path(path); | ||
revokePermissionsEndpoint.addUriParameter(uuidParameterName, "Uuid of the " + typeDescription, uuidParameterExample); | ||
revokePermissionsEndpoint.method(DELETE); | ||
revokePermissionsEndpoint.description("Revoke permissions on the " + typeDescription + " from multiple roles."); | ||
revokePermissionsEndpoint.consumes(APPLICATION_JSON); | ||
revokePermissionsEndpoint.produces(APPLICATION_JSON); | ||
revokePermissionsEndpoint.exampleRequest(roleExamples.getObjectPermissionRevokeRequest(includePublishPermissions)); | ||
revokePermissionsEndpoint.exampleResponse(OK, roleExamples.getObjectPermissionResponse(includePublishPermissions), "Updated permissions."); | ||
revokePermissionsEndpoint.events(ROLE_PERMISSIONS_CHANGED); | ||
revokePermissionsEndpoint.blockingHandler(rc -> { | ||
InternalActionContext ac = wrap(rc); | ||
String uuid = rc.request().getParam(uuidParameterName); | ||
crudHandler.handleRevokePermissions(ac, uuid); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.