use of ddf.security.service.SecurityServiceException in project ddf by codice.
the class IdpEndpointTest method testFailedLogin.
@Test
public void testFailedLogin() throws SecurityServiceException {
String samlRequest = authNRequestGet;
HttpServletRequest request = mock(HttpServletRequest.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
Response response = idpEndpoint.processLogin(samlRequest, relayState, Idp.GUEST, signatureAlgorithm, signature, SamlProtocol.REDIRECT_BINDING, request);
assertThat(response.getStatus(), is(401));
}
use of ddf.security.service.SecurityServiceException in project ddf by codice.
the class IdpEndpointTest method testLoginForceAuthnCookie.
@Test
public void testLoginForceAuthnCookie() throws SecurityServiceException, WSSecurityException, IOException {
String samlRequest = RestSecurity.deflateAndBase64Encode(authNRequestGetForce);
HttpServletRequest request = mock(HttpServletRequest.class);
Cookie cookie = mock(Cookie.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
idpEndpoint.setStrictSignature(false);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
when(cookie.getName()).thenReturn(IdpEndpoint.COOKIE);
when(cookie.getValue()).thenReturn("1");
Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request);
assertThat(response.getEntity().toString(), containsString("<title>Login</title>"));
}
use of ddf.security.service.SecurityServiceException in project ddf by codice.
the class IdpEndpointTest method testPassiveLoginPkiFail.
@Test
public void testPassiveLoginPkiFail() throws SecurityServiceException, WSSecurityException, CertificateEncodingException, IOException {
String samlRequest = authNRequestPassivePkiGet;
HttpServletRequest request = mock(HttpServletRequest.class);
X509Certificate x509Certificate = mock(X509Certificate.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
idpEndpoint.setStrictSignature(false);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
//dummy cert
when((X509Certificate[]) request.getAttribute(requestCertificateAttributeName)).thenReturn(new X509Certificate[] { x509Certificate });
when(x509Certificate.getEncoded()).thenReturn(new byte[48]);
Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request);
String responseStr = StringUtils.substringBetween(response.getEntity().toString(), "SAMLResponse=", "&RelayState");
responseStr = URLDecoder.decode(responseStr, "UTF-8");
responseStr = RestSecurity.inflateBase64(responseStr);
//the only cookie that should exist is the "1" cookie so "2" should send us to the login webapp
assertThat(responseStr, containsString("status:AuthnFailed"));
}
use of ddf.security.service.SecurityServiceException in project ddf by codice.
the class AuthenticationEndpoint method login.
@POST
public Response login(@Context HttpServletRequest request, @FormParam("username") String username, @FormParam("password") String password, @FormParam("prevurl") String prevurl) throws SecurityServiceException {
// Make sure we're using HTTPS
if (!request.isSecure()) {
throw new IllegalArgumentException("Authentication request must use TLS.");
}
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
// Get the realm from the previous url
String realm = BaseAuthenticationToken.DEFAULT_REALM;
ContextPolicy policy = contextPolicyManager.getContextPolicy(prevurl);
if (policy != null) {
realm = policy.getRealm();
}
// Create an authentication token
UPAuthenticationToken authenticationToken = new UPAuthenticationToken(username, password, realm);
// Authenticate
Subject subject = securityManager.getSubject(authenticationToken);
if (subject == null) {
throw new SecurityServiceException("Authentication failed");
}
for (Object principal : subject.getPrincipals()) {
if (principal instanceof SecurityAssertion) {
SecurityToken securityToken = ((SecurityAssertion) principal).getSecurityToken();
if (securityToken == null) {
LOGGER.debug("Cannot add null security token to session");
continue;
}
// Create a session and add the security token
session = sessionFactory.getOrCreateSession(request);
SecurityTokenHolder holder = (SecurityTokenHolder) session.getAttribute(SecurityConstants.SAML_ASSERTION);
holder.addSecurityToken(realm, securityToken);
}
}
// Redirect to the previous url
URI redirect = uriInfo.getBaseUriBuilder().replacePath(prevurl).build();
return Response.seeOther(redirect).build();
}
use of ddf.security.service.SecurityServiceException in project ddf by codice.
the class WfsSource method getCapabilities.
private WFSCapabilitiesType getCapabilities() throws SecurityServiceException {
WFSCapabilitiesType capabilities = null;
Wfs wfs = factory.getClient();
try {
capabilities = wfs.getCapabilities(new GetCapabilitiesRequest());
} catch (WfsException wfse) {
LOGGER.info(WFS_ERROR_MESSAGE + " Received HTTP code '{}' from server for source with id='{}'", wfse.getHttpStatus(), getId());
LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
} catch (WebApplicationException wae) {
LOGGER.debug(handleWebApplicationException(wae), wae);
} catch (Exception e) {
handleClientException(e);
}
return capabilities;
}
Aggregations