Search in sources :

Example 6 with NiFiUser

use of org.apache.nifi.registry.security.authorization.user.NiFiUser in project nifi-registry by apache.

the class AuthorizationService method getPermissionsForResource.

public Permissions getPermissionsForResource(Authorizable authorizableResource) {
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    final Permissions permissions = new Permissions();
    permissions.setCanRead(authorizableResource.isAuthorized(authorizer, RequestAction.READ, user));
    permissions.setCanWrite(authorizableResource.isAuthorized(authorizer, RequestAction.WRITE, user));
    permissions.setCanDelete(authorizableResource.isAuthorized(authorizer, RequestAction.DELETE, user));
    return permissions;
}
Also used : NiFiUser(org.apache.nifi.registry.security.authorization.user.NiFiUser) Permissions(org.apache.nifi.registry.authorization.Permissions) ResourcePermissions(org.apache.nifi.registry.authorization.ResourcePermissions)

Example 7 with NiFiUser

use of org.apache.nifi.registry.security.authorization.user.NiFiUser in project nifi-registry by apache.

the class AuthorizationService method getCurrentUser.

// ---------------------- Permissions methods ---------------------------------------
public CurrentUser getCurrentUser() {
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final CurrentUser currentUser = new CurrentUser();
    currentUser.setIdentity(user.getIdentity());
    currentUser.setAnonymous(user.isAnonymous());
    currentUser.setResourcePermissions(getTopLevelPermissions());
    return currentUser;
}
Also used : NiFiUser(org.apache.nifi.registry.security.authorization.user.NiFiUser) CurrentUser(org.apache.nifi.registry.authorization.CurrentUser)

Example 8 with NiFiUser

use of org.apache.nifi.registry.security.authorization.user.NiFiUser in project nifi-registry by apache.

the class AccessResource method getAccessStatus.

/**
 * Gets the current client's identity and authorized permissions.
 *
 * @param httpServletRequest the servlet request
 * @return An object describing the current client identity, as determined by the server, and it's permissions.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Returns the current client's authenticated identity and permissions to top-level resources", response = CurrentUser.class, authorizations = { @Authorization(value = "Authorization") })
@ApiResponses({ @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409 + " The NiFi Registry might be running unsecured.") })
public Response getAccessStatus(@Context HttpServletRequest httpServletRequest) {
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user == null) {
        // Not expected to happen unless the nifi registry server has been seriously misconfigured.
        throw new WebApplicationException(new Throwable("Unable to access details for current user."));
    }
    final CurrentUser currentUser = authorizationService.getCurrentUser();
    return generateOkResponse(currentUser).build();
}
Also used : NiFiUser(org.apache.nifi.registry.security.authorization.user.NiFiUser) WebApplicationException(javax.ws.rs.WebApplicationException) CurrentUser(org.apache.nifi.registry.authorization.CurrentUser) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NiFiUser (org.apache.nifi.registry.security.authorization.user.NiFiUser)8 Permissions (org.apache.nifi.registry.authorization.Permissions)3 ResourcePermissions (org.apache.nifi.registry.authorization.ResourcePermissions)3 CurrentUser (org.apache.nifi.registry.authorization.CurrentUser)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Status (javax.ws.rs.core.Response.Status)1 AuthenticationRequest (org.apache.nifi.registry.security.authentication.AuthenticationRequest)1 AccessDeniedException (org.apache.nifi.registry.security.authorization.exception.AccessDeniedException)1 NiFiUserDetails (org.apache.nifi.registry.security.authorization.user.NiFiUserDetails)1 StandardNiFiUser (org.apache.nifi.registry.security.authorization.user.StandardNiFiUser)1 AuthenticationSuccessToken (org.apache.nifi.registry.web.security.authentication.AuthenticationSuccessToken)1 UntrustedProxyException (org.apache.nifi.registry.web.security.authentication.exception.UntrustedProxyException)1