use of ddf.security.samlp.SimpleSign in project ddf by codice.
the class LogoutRequestServiceTest method setup.
@Before
public void setup() throws ParserConfigurationException, SAXException, IOException {
simpleSign = mock(SimpleSign.class);
idpMetadata = mock(IdpMetadata.class);
relayStates = mock(RelayStates.class);
sessionFactory = mock(SessionFactory.class);
request = mock(HttpServletRequest.class);
logoutMessage = mock(LogoutMessage.class);
encryptionService = mock(EncryptionService.class);
session = mock(HttpSession.class);
securityTokenHolder = mock(SecurityTokenHolder.class);
Element issuedAssertion = readSamlAssertion().getDocumentElement();
String assertionId = issuedAssertion.getAttributeNodeNS(null, "ID").getNodeValue();
SecurityToken token = new SecurityToken(assertionId, issuedAssertion, null);
when(securityTokenHolder.getSecurityToken("idp")).thenReturn(token);
logoutRequestService = new MockLogoutRequestService(simpleSign, idpMetadata, relayStates);
logoutRequestService.setEncryptionService(encryptionService);
logoutRequestService.setLogOutPageTimeOut(LOGOUT_PAGE_TIMEOUT);
logoutRequestService.setLogoutMessage(logoutMessage);
logoutRequestService.setRequest(request);
logoutRequestService.setSessionFactory(sessionFactory);
logoutRequestService.init();
when(sessionFactory.getOrCreateSession(request)).thenReturn(session);
when(session.getAttribute(eq(SecurityConstants.SAML_ASSERTION))).thenReturn(securityTokenHolder);
when(request.getRequestURL()).thenReturn(new StringBuffer("www.url.com/url"));
when(idpMetadata.getSigningCertificate()).thenReturn("signingCertificate");
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.REDIRECT_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(redirectLogoutUrl);
System.setProperty("security.audit.roles", "none");
}
use of ddf.security.samlp.SimpleSign in project ddf by codice.
the class IdpHandlerTest method setUp.
@Before
public void setUp() throws Exception {
encryptionService = mock(EncryptionService.class);
systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
simpleSign = new SimpleSign(systemCrypto);
idpMetadata = new IdpMetadata();
relayStates = (RelayStates<String>) mock(RelayStates.class);
when(relayStates.encode(anyString())).thenReturn(RELAY_STATE_VAL);
when(relayStates.decode(RELAY_STATE_VAL)).thenReturn(LOCATION);
httpRequest = mock(HttpServletRequest.class);
when(httpRequest.getRequestURL()).thenReturn(new StringBuffer("https://localhost:8993"));
when(httpRequest.getMethod()).thenReturn("GET");
httpResponse = mock(HttpServletResponse.class);
idpHandler = new IdpHandler(simpleSign, idpMetadata, relayStates);
StringWriter writer = new StringWriter();
InputStream inputStream = this.getClass().getResourceAsStream("/IDPmetadata.xml");
IOUtils.copy(inputStream, writer, "UTF-8");
metadata = writer.toString();
idpMetadata.setMetadata(metadata);
}
use of ddf.security.samlp.SimpleSign in project ddf by codice.
the class AssertionConsumerServiceTest method setUp.
@Before
public void setUp() throws Exception {
encryptionService = mock(EncryptionService.class);
systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
simpleSign = new SimpleSign(systemCrypto);
relayStates = (RelayStates<String>) mock(RelayStates.class);
when(relayStates.encode("fubar")).thenReturn(RELAY_STATE_VAL);
when(relayStates.decode(RELAY_STATE_VAL)).thenReturn(LOCATION);
loginFilter = mock(javax.servlet.Filter.class);
sessionFactory = mock(SessionFactory.class);
httpRequest = mock(HttpServletRequest.class);
when(httpRequest.getRequestURL()).thenReturn(new StringBuffer("fubar"));
when(httpRequest.isSecure()).thenReturn(true);
idpMetadata = new IdpMetadata();
assertionConsumerService = new AssertionConsumerService(simpleSign, idpMetadata, systemCrypto, relayStates);
assertionConsumerService.setRequest(httpRequest);
assertionConsumerService.setLoginFilter(loginFilter);
assertionConsumerService.setSessionFactory(sessionFactory);
cannedResponse = Resources.toString(Resources.getResource(getClass(), "/SAMLResponse.xml"), Charsets.UTF_8);
String metadata = Resources.toString(Resources.getResource(getClass(), "/IDPmetadata.xml"), Charsets.UTF_8);
deflatedSamlResponse = Resources.toString(Resources.getResource(getClass(), "/DeflatedSAMLResponse.txt"), Charsets.UTF_8);
idpMetadata.setMetadata(metadata);
}
use of ddf.security.samlp.SimpleSign in project ddf by codice.
the class IdpEndpoint method getSamlRedirectResponse.
private Response getSamlRedirectResponse(XMLObject samlResponse, String targetUrl, String relayState, SamlProtocol.Type samlType) throws IOException, SimpleSign.SignatureException, WSSecurityException {
LOGGER.debug("Signing SAML response for redirect.");
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
String encodedResponse = URLEncoder.encode(RestSecurity.deflateAndBase64Encode(DOM2Writer.nodeToString(OpenSAMLUtil.toDom(samlResponse, doc, false))), "UTF-8");
String requestToSign = String.format("%s=%s&RelayState=%s", samlType.getKey(), encodedResponse, relayState);
UriBuilder uriBuilder = UriBuilder.fromUri(targetUrl);
uriBuilder.queryParam(samlType.getKey(), encodedResponse);
uriBuilder.queryParam(SSOConstants.RELAY_STATE, relayState == null ? "" : relayState);
new SimpleSign(systemCrypto).signUriString(requestToSign, uriBuilder);
LOGGER.debug("Signing successful.");
return Response.ok(HtmlResponseTemplate.getRedirectPage(uriBuilder.build().toString())).build();
}
Aggregations