use of ddf.security.assertion.saml.impl.SecurityAssertionSaml 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);
}
use of ddf.security.assertion.saml.impl.SecurityAssertionSaml in project ddf by codice.
the class SamlRealm method createPrincipalFromToken.
/**
* Creates a new principal object from an incoming security token.
*
* @param token SecurityToken that contains the principals.
* @return new SimplePrincipalCollection
*/
private SimplePrincipalCollection createPrincipalFromToken(Element token) {
SimplePrincipalCollection principals = new SimplePrincipalCollection();
SecurityAssertion securityAssertion = null;
try {
securityAssertion = new SecurityAssertionSaml(token, usernameAttributeList);
Principal principal = securityAssertion.getPrincipal();
if (principal != null) {
principals.add(principal.getName(), getName());
}
} catch (Exception e) {
LOGGER.warn("Encountered error while trying to get the Principal for the SecurityToken. Security functions may not work properly.", e);
}
if (securityAssertion != null) {
principals.add(securityAssertion, getName());
}
return principals;
}
use of ddf.security.assertion.saml.impl.SecurityAssertionSaml in project ddf by codice.
the class SecurityAssertionSamlTest method testIsPresentlyValidWithNullNotBefore.
@Test
public void testIsPresentlyValidWithNullNotBefore() throws Exception {
Element issuedAssertion = this.readDocument("/saml.xml").getDocumentElement();
// Remove NotBefore
issuedAssertion.getElementsByTagName("saml2:Conditions").item(0).getAttributes().removeNamedItem("NotBefore");
SecurityAssertionSaml assertion = getSecurityAssertion(issuedAssertion);
assertTrue(assertion.isPresentlyValid());
}
use of ddf.security.assertion.saml.impl.SecurityAssertionSaml in project ddf by codice.
the class SecurityAssertionSamlTest method testEmptyAssertion.
@Test
public void testEmptyAssertion() {
SecurityAssertionSaml assertion = new SecurityAssertionSaml();
assertNull(assertion.getIssuer());
assertEquals(0, assertion.getAttributeStatements().size());
assertEquals(0, assertion.getAuthnStatements().size());
assertNull(assertion.getPrincipal());
assertNull(assertion.getNotBefore());
assertNull(assertion.getNotOnOrAfter());
assertTrue(assertion.isPresentlyValid());
}
use of ddf.security.assertion.saml.impl.SecurityAssertionSaml in project ddf by codice.
the class SecurityAssertionSamlTest method testIsPresentlyValidWithNullNotOnOrAfter.
@Test
public void testIsPresentlyValidWithNullNotOnOrAfter() throws Exception {
Element issuedAssertion = this.readDocument("/saml.xml").getDocumentElement();
// Remove NotOnOrAfter
issuedAssertion.getElementsByTagName("saml2:Conditions").item(0).getAttributes().removeNamedItem("NotOnOrAfter");
SecurityAssertionSaml assertion = getSecurityAssertion(issuedAssertion);
assertTrue(assertion.isPresentlyValid());
}
Aggregations