use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class AbstractPreAuthFederationFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String principal = getPrimaryPrincipal(httpRequest);
if (principal != null) {
if (PreAuthService.validate(httpRequest, filterConfig, validators)) {
Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal(principal));
addGroupPrincipals(httpRequest, subject.getPrincipals());
// KM: Audit Fix
auditService.getContext().setUsername(principal);
String sourceUri = (String) request.getAttribute(AbstractGatewayFilter.SOURCE_REQUEST_CONTEXT_URL_ATTRIBUTE_NAME);
auditor.audit(Action.AUTHENTICATION, sourceUri, ResourceType.URI, ActionOutcome.SUCCESS);
doAs(httpRequest, response, chain, subject);
} else {
// TODO: log preauthenticated SSO validation failure
((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, "SSO Validation Failure.");
}
} else {
((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, "Missing Required Header for PreAuth SSO Federation");
}
}
use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class HadoopAuthPostFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String principal = httpRequest.getRemoteUser();
if (principal != null) {
Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal(principal));
log.hadoopAuthAssertedPrincipal(principal);
// KM: Audit Fix
auditService.getContext().setUsername(principal);
String sourceUri = (String) request.getAttribute(AbstractGatewayFilter.SOURCE_REQUEST_CONTEXT_URL_ATTRIBUTE_NAME);
auditor.audit(Action.AUTHENTICATION, sourceUri, ResourceType.URI, ActionOutcome.SUCCESS);
doAs(httpRequest, response, chain, subject);
} else {
((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, "User not authenticated");
}
}
Aggregations