use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class BasicAuthenticationHandler method handleError.
@Override
public HandlerResult handleError(ServletRequest servletRequest, ServletResponse servletResponse, SecurityFilterChain chain) {
doAuthPrompt((HttpServletResponse) servletResponse);
HandlerResult result = new HandlerResultImpl(HandlerResult.Status.REDIRECTED, null);
result.setSource(SOURCE);
LOGGER.debug("In error handler for basic auth - prompted for auth credentials.");
return result;
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class BasicAuthenticationHandlerTest method testGetNormalizedTokenResolveWithoutCredentials.
/**
* This test case handles the scenario in which the credentials should be obtained (i.e. resolve
* flag is set) - both requests without and with the credentials are tested.
*/
@Test
public void testGetNormalizedTokenResolveWithoutCredentials() throws IOException {
BasicAuthenticationHandler handler = new BasicAuthenticationHandler();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SecurityFilterChain chain = mock(SecurityFilterChain.class);
HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
assertNotNull(result);
assertEquals(HandlerResult.Status.REDIRECTED, result.getStatus());
// confirm that the proper responses were sent through the HttpResponse
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
Mockito.verify(response).setContentLength(0);
Mockito.verify(response).flushBuffer();
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class OAuthHandler method getNormalizedToken.
@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, SecurityFilterChain chain, boolean resolve) throws AuthenticationFailureException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (httpRequest.getMethod().equals("HEAD")) {
return processHeadRequest(httpResponse);
}
JEESessionStore sessionStore = new JEESessionStore();
JEEContext jeeContext = new JEEContext(httpRequest, httpResponse, sessionStore);
// time to try and pull credentials off of the request
LOGGER.debug("Doing OAuth authentication and authorization for path {}.", httpRequest.getContextPath());
OidcCredentials credentials;
StringBuffer requestUrlBuffer = httpRequest.getRequestURL();
requestUrlBuffer.append(httpRequest.getQueryString() == null ? "" : "?" + httpRequest.getQueryString());
String ipAddress = httpRequest.getRemoteAddr();
boolean isMachine = userAgentIsNotBrowser(httpRequest);
// machine to machine, check for Client Credentials Flow credentials
if (isMachine) {
try {
credentials = getCredentialsFromRequest(jeeContext);
} catch (IllegalArgumentException e) {
LOGGER.error("Problem with the OAuth Handler's OAuthHandlerConfiguration. " + "Check the OAuth Handler Configuration in the admin console.", e);
return noActionResult;
} catch (OAuthCredentialsException e) {
LOGGER.error("Problem extracting credentials from machine to machine request. " + "See OAuth2's \"Client Credential Flow\" for more information.", e);
return noActionResult;
}
} else {
LOGGER.info("The OAuth Handler does not handle user agent requests. Continuing to other handlers.");
return noActionResult;
}
// if the request has credentials, process it
if (credentials.getCode() != null || credentials.getAccessToken() != null || credentials.getIdToken() != null) {
LOGGER.info("Oidc credentials found/retrieved. Saving to session and continuing filter chain.");
OidcAuthenticationToken token = new OidcAuthenticationToken(credentials, jeeContext, ipAddress);
HandlerResult handlerResult = new HandlerResultImpl(Status.COMPLETED, token);
handlerResult.setSource(SOURCE);
return handlerResult;
} else {
LOGGER.info("No credentials found on user-agent request. " + "This handler does not support the acquisition of user agent credentials. Continuing to other handlers.");
return noActionResult;
}
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class HandlerResultTest method testHandlerResultConstructor.
/**
* This test ensures that when the constructor is called, the data members are properly
* initialized.
*/
@Test
public void testHandlerResultConstructor() {
HandlerResult result = new HandlerResultImpl();
assertEquals(HandlerResult.Status.NO_ACTION, result.getStatus());
BaseAuthenticationToken token = new BaseAuthenticationToken("x", "y", "127.0.0.1");
result = new HandlerResultImpl(HandlerResult.Status.COMPLETED, token);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
assertEquals(result.getToken(), token);
}
Aggregations