Java Code Examples for org.apache.nifi.authorization.user.NiFiUser#isAnonymous()
The following examples show how to use
org.apache.nifi.authorization.user.NiFiUser#isAnonymous() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessDeniedExceptionMapper.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public Response toResponse(AccessDeniedException exception) { // get the current user NiFiUser user = NiFiUserUtils.getNiFiUser(); // if the user was authenticated - forbidden, otherwise unauthorized... the user may be null if the // AccessDeniedException was thrown from a /access endpoint that isn't subject to the security // filter chain. for instance, one that performs kerberos negotiation final Response.Status status; if (user == null || user.isAnonymous()) { status = Status.UNAUTHORIZED; } else { status = Status.FORBIDDEN; } final String identity; if (user == null) { identity = "<no user found>"; } else { identity = user.getIdentity(); } logger.info(String.format("%s does not have permission to access the requested resource. %s Returning %s response.", identity, exception.getMessage(), status)); if (logger.isDebugEnabled()) { logger.debug(StringUtils.EMPTY, exception); } return Response.status(status) .entity(String.format("%s Contact the system administrator.", exception.getMessage())) .type("text/plain") .build(); }
Example 2
Source File: AccessDeniedExceptionMapper.java From nifi with Apache License 2.0 | 5 votes |
@Override public Response toResponse(AccessDeniedException exception) { // get the current user NiFiUser user = NiFiUserUtils.getNiFiUser(); // if the user was authenticated - forbidden, otherwise unauthorized... the user may be null if the // AccessDeniedException was thrown from a /access endpoint that isn't subject to the security // filter chain. for instance, one that performs kerberos negotiation final Response.Status status; if (user == null || user.isAnonymous()) { status = Status.UNAUTHORIZED; } else { status = Status.FORBIDDEN; } final String identity; if (user == null) { identity = "<no user found>"; } else { identity = user.toString(); } logger.info(String.format("%s does not have permission to access the requested resource. %s Returning %s response.", identity, exception.getMessage(), status)); if (logger.isDebugEnabled()) { logger.debug(StringUtils.EMPTY, exception); } return Response.status(status) .entity(String.format("%s Contact the system administrator.", exception.getMessage())) .type("text/plain") .build(); }
Example 3
Source File: RegistryUtil.java From nifi with Apache License 2.0 | 4 votes |
private String getIdentity(final NiFiUser user) { return (user == null || user.isAnonymous()) ? null : user.getIdentity(); }
Example 4
Source File: RestBasedFlowRegistry.java From nifi with Apache License 2.0 | 4 votes |
private String getIdentity(final NiFiUser user) { return (user == null || user.isAnonymous()) ? null : user.getIdentity(); }