use of org.opensaml.saml.saml2.core.Issuer in project ddf by codice.
the class SamlProtocol method createResponse.
public static Response createResponse(Issuer issuer, Status status, String requestId, Element samlAssertion) throws WSSecurityException {
Response response = responseSAMLObjectBuilder.buildObject();
response.setIssuer(issuer);
response.setStatus(status);
response.setID("_" + UUID.randomUUID().toString());
response.setIssueInstant(new DateTime());
response.setInResponseTo(requestId);
response.setVersion(SAMLVersion.VERSION_20);
if (samlAssertion != null) {
SamlAssertionWrapper samlAssertionWrapper = new SamlAssertionWrapper(samlAssertion);
response.getAssertions().add(samlAssertionWrapper.getSaml2());
}
return response;
}
use of org.opensaml.saml.saml2.core.Issuer in project ddf by codice.
the class SamlProtocol method createIssuer.
public static Issuer createIssuer(String issuerValue) {
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(issuerValue);
return issuer;
}
use of org.opensaml.saml.saml2.core.Issuer in project ddf by codice.
the class LogoutRequestServiceTest method testPostLogoutRequestResponse.
@Test
public void testPostLogoutRequestResponse() throws Exception {
String encodedSamlResponse = "encodedSamlRequest";
String issuerStr = "issuer";
Issuer issuer = mock(Issuer.class);
LogoutResponse logoutResponse = mock(LogoutResponse.class);
logoutResponse.setIssuer(issuer);
LogoutWrapper<LogoutResponse> responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse);
when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(responseLogoutWrapper);
logoutRequestService.setLogoutMessage(logoutMessage);
when(logoutResponse.getIssuer()).thenReturn(issuer);
when(logoutResponse.getIssueInstant()).thenReturn(new DateTime());
when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20);
when(logoutResponse.getID()).thenReturn("id");
when(issuer.getValue()).thenReturn(issuerStr);
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
Response response = logoutRequestService.postLogoutRequest(null, encodedSamlResponse, relayState);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
assertTrue("Expected a successful logout message", response.getLocation().toString().contains("logged+out+successfully."));
}
use of org.opensaml.saml.saml2.core.Issuer in project ddf by codice.
the class SamlAssertionValidatorImplTest method testValidateUnsignedAssertion.
@Test(expected = AuthenticationFailureException.class)
public void testValidateUnsignedAssertion() throws Exception {
Assertion assertion = createAssertion(false, true, ISSUER, new DateTime().plusDays(3));
Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion));
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(securityToken), "default");
SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken(simplePrincipalCollection, simplePrincipalCollection, "127.0.0.1");
samlAssertionValidator.validate(samlAuthenticationToken);
}
use of org.opensaml.saml.saml2.core.Issuer in project ddf by codice.
the class SamlAssertionValidatorImplTest method testValidateExpiredAssertion.
@Test(expected = AuthenticationFailureException.class)
public void testValidateExpiredAssertion() throws Exception {
Assertion assertion = createAssertion(false, true, ISSUER, new DateTime().minusSeconds(10));
Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion));
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(securityToken), "default");
SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken(simplePrincipalCollection, simplePrincipalCollection, "127.0.0.1");
samlAssertionValidator.validate(samlAuthenticationToken);
}
Aggregations