use of org.apache.nifi.web.api.entity.UsersEntity in project nifi by apache.
the class TenantsResource method getUsers.
/**
* Retrieves all the of users in this NiFi.
*
* @return A UsersEntity.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("users")
@ApiOperation(value = "Gets all users", notes = NON_GUARANTEED_ENDPOINT, response = UsersEntity.class, authorizations = { @Authorization(value = "Read - /tenants") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getUsers() {
// ensure we're running with a configurable authorizer
if (!AuthorizerCapabilityDetection.isManagedAuthorizer(authorizer)) {
throw new IllegalStateException(AccessPolicyDAO.MSG_NON_MANAGED_AUTHORIZER);
}
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable tenants = lookup.getTenant();
tenants.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
});
// get all the users
final Set<UserEntity> users = serviceFacade.getUsers();
// create the response entity
final UsersEntity entity = new UsersEntity();
entity.setGenerated(new Date());
entity.setUsers(populateRemainingUserEntitiesContent(users));
// generate the response
return generateOkResponse(entity).build();
}
use of org.apache.nifi.web.api.entity.UsersEntity in project nifi by apache.
the class UsersEndpointMerger method merge.
@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
if (!canHandle(uri, method)) {
throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
}
final UsersEntity responseEntity = clientResponse.getClientResponse().readEntity(UsersEntity.class);
final Collection<UserEntity> userEntities = responseEntity.getUsers();
final Map<String, Map<NodeIdentifier, UserEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final UsersEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(UsersEntity.class);
final Collection<UserEntity> nodeUserEntities = nodeResponseEntity.getUsers();
// only retain users that all nodes agree on
userEntities.retainAll(nodeUserEntities);
for (final UserEntity nodeUserEntity : nodeUserEntities) {
final NodeIdentifier nodeId = nodeResponse.getNodeId();
Map<NodeIdentifier, UserEntity> innerMap = entityMap.get(nodeId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeUserEntity.getId(), innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeUserEntity);
}
}
UsersEntityMerger.mergeUsers(userEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
Aggregations