Search in sources :

Example 6 with SecurityAssertionSaml

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);
}
Also used : Element(org.w3c.dom.Element) Assertion(org.opensaml.saml.saml2.core.Assertion) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SAMLAuthenticationToken(org.codice.ddf.security.handler.SAMLAuthenticationToken) DateTime(org.joda.time.DateTime) SecurityAssertionSaml(ddf.security.assertion.saml.impl.SecurityAssertionSaml) Test(org.junit.Test)

Example 7 with SecurityAssertionSaml

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;
}
Also used : SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion) SecurityAssertionSaml(ddf.security.assertion.saml.impl.SecurityAssertionSaml) Principal(java.security.Principal) AuthenticationException(org.apache.shiro.authc.AuthenticationException) AuthenticationFailureException(org.codice.ddf.platform.filter.AuthenticationFailureException)

Example 8 with SecurityAssertionSaml

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());
}
Also used : Element(org.w3c.dom.Element) SecurityAssertionSaml(ddf.security.assertion.saml.impl.SecurityAssertionSaml) Test(org.junit.Test)

Example 9 with SecurityAssertionSaml

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());
}
Also used : SecurityAssertionSaml(ddf.security.assertion.saml.impl.SecurityAssertionSaml) Test(org.junit.Test)

Example 10 with SecurityAssertionSaml

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());
}
Also used : Element(org.w3c.dom.Element) SecurityAssertionSaml(ddf.security.assertion.saml.impl.SecurityAssertionSaml) Test(org.junit.Test)

Aggregations

SecurityAssertionSaml (ddf.security.assertion.saml.impl.SecurityAssertionSaml)19 Element (org.w3c.dom.Element)15 Test (org.junit.Test)14 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)10 SAMLAuthenticationToken (org.codice.ddf.security.handler.SAMLAuthenticationToken)9 Assertion (org.opensaml.saml.saml2.core.Assertion)6 DateTime (org.joda.time.DateTime)5 IOException (java.io.IOException)2 Principal (java.security.Principal)2 X509Certificate (java.security.cert.X509Certificate)2 Cookie (javax.servlet.http.Cookie)2 HandlerResultImpl (org.codice.ddf.security.handler.HandlerResultImpl)2 HandlerResult (org.codice.ddf.security.handler.api.HandlerResult)2 AuthenticationStatement (ddf.security.assertion.AuthenticationStatement)1 SecurityAssertion (ddf.security.assertion.SecurityAssertion)1 SecurityAssertionPrincipal (ddf.security.assertion.SecurityAssertionPrincipal)1 StringReader (java.io.StringReader)1 Instant (java.time.Instant)1 Objects (java.util.Objects)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1