Search in sources :

Example 1 with WebserviceAuthorizationException

use of com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException in project streamline by hortonworks.

the class SecurityUtil method checkRole.

public static void checkRole(StreamlineAuthorizer authorizer, SecurityContext securityContext, String... roles) {
    Principal principal = securityContext.getUserPrincipal();
    AuthenticationContext authenticationCtx = SecurityUtil.getAuthenticationContext(principal);
    for (String role : roles) {
        if (!authorizer.hasRole(authenticationCtx, role)) {
            throw new WebserviceAuthorizationException("Principal: " + principal + " does not have role: " + role);
        }
    }
}
Also used : WebserviceAuthorizationException(com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException) Principal(java.security.Principal)

Example 2 with WebserviceAuthorizationException

use of com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException in project streamline by hortonworks.

the class SecurityUtil method checkPermissions.

public static void checkPermissions(StreamlineAuthorizer authorizer, SecurityContext securityContext, String targetEntityNamespace, Long targetEntityId, Permission first, Permission... rest) {
    Principal principal = securityContext.getUserPrincipal();
    EnumSet<Permission> permissions = EnumSet.of(first, rest);
    if (!doCheckPermissions(authorizer, principal, targetEntityNamespace, targetEntityId, permissions)) {
        throw new WebserviceAuthorizationException("Principal: " + principal + " does not have permissions: " + permissions + " on namespace: " + targetEntityNamespace + " id: " + targetEntityId);
    }
}
Also used : WebserviceAuthorizationException(com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException) Principal(java.security.Principal)

Example 3 with WebserviceAuthorizationException

use of com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException in project streamline by hortonworks.

the class StreamlineKerberosRequestFilter method filter.

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    Principal principal = httpRequest.getUserPrincipal();
    String scheme = requestContext.getUriInfo().getRequestUri().getScheme();
    LOG.debug("Method: {}, AuthType: {}, RemoteUser: {}, UserPrincipal: {}, Scheme: {}", httpRequest.getMethod(), httpRequest.getAuthType(), httpRequest.getRemoteUser(), principal, scheme);
    if (principal == null || !httpRequest.getAuthType().equalsIgnoreCase(KERBEROS_AUTH)) {
        throw new WebserviceAuthorizationException("Not authorized");
    }
    SecurityContext securityContext = new StreamlineSecurityContext(principal, scheme, KERBEROS_AUTH);
    LOG.debug("SecurityContext {}", securityContext);
    requestContext.setSecurityContext(securityContext);
}
Also used : WebserviceAuthorizationException(com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException) SecurityContext(javax.ws.rs.core.SecurityContext) Principal(java.security.Principal)

Example 4 with WebserviceAuthorizationException

use of com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException in project streamline by hortonworks.

the class StreamlineBasicAuthorizationRequestFilter method filter.

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    Map.Entry<String, String> auth = getAuth(requestContext.getHeaders().getFirst("Authorization"));
    if (auth == null) {
        throw new WebserviceAuthorizationException("Not authorized");
    }
    StreamlinePrincipal user = new StreamlinePrincipal(auth.getKey());
    LOG.debug("StreamlinePrincipal: {}", user);
    String scheme = requestContext.getUriInfo().getRequestUri().getScheme();
    requestContext.setSecurityContext(new StreamlineSecurityContext(user, scheme));
}
Also used : WebserviceAuthorizationException(com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException) StreamlinePrincipal(com.hortonworks.streamline.streams.security.StreamlinePrincipal) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Aggregations

WebserviceAuthorizationException (com.hortonworks.streamline.common.exception.service.exception.request.WebserviceAuthorizationException)4 Principal (java.security.Principal)3 StreamlinePrincipal (com.hortonworks.streamline.streams.security.StreamlinePrincipal)1 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 SecurityContext (javax.ws.rs.core.SecurityContext)1