Search in sources :

Example 6 with SAMLCredential

use of org.springframework.security.saml.SAMLCredential in project webcert by sklintyg.

the class FakeElegAuthenticationProvider method createSamlCredential.

private SAMLCredential createSamlCredential(Authentication token) {
    FakeElegCredentials fakeCredentials = (FakeElegCredentials) token.getCredentials();
    Assertion assertion = new AssertionBuilder().buildObject();
    attachAuthenticationContext(assertion, FAKE_AUTHENTICATION_ELEG_CONTEXT_REF);
    AttributeStatement attributeStatement = new AttributeStatementBuilder().buildObject();
    assertion.getAttributeStatements().add(attributeStatement);
    attributeStatement.getAttributes().add(createAttribute(CgiElegAssertion.PERSON_ID_ATTRIBUTE, fakeCredentials.getPersonId()));
    attributeStatement.getAttributes().add(createAttribute(CgiElegAssertion.FORNAMN_ATTRIBUTE, fakeCredentials.getFirstName()));
    attributeStatement.getAttributes().add(createAttribute(CgiElegAssertion.MELLAN_OCH_EFTERNAMN_ATTRIBUTE, fakeCredentials.getLastName()));
    NameID nameId = new NameIDBuilder().buildObject();
    nameId.setValue(token.getCredentials().toString());
    return new SAMLCredential(nameId, assertion, "fake-idp", "webcert");
}
Also used : NameIDBuilder(org.opensaml.saml2.core.impl.NameIDBuilder) AttributeStatementBuilder(org.opensaml.saml2.core.impl.AttributeStatementBuilder) SAMLCredential(org.springframework.security.saml.SAMLCredential) NameID(org.opensaml.saml2.core.NameID) AttributeStatement(org.opensaml.saml2.core.AttributeStatement) Assertion(org.opensaml.saml2.core.Assertion) AssertionBuilder(org.opensaml.saml2.core.impl.AssertionBuilder)

Example 7 with SAMLCredential

use of org.springframework.security.saml.SAMLCredential in project webcert by sklintyg.

the class FakeElegAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    SAMLCredential credential = createSamlCredential(authentication);
    Object details = elegWebCertUserDetailsService.loadUserBySAML(credential);
    ExpiringUsernameAuthenticationToken result = new ExpiringUsernameAuthenticationToken(null, details, credential, new ArrayList<>());
    result.setDetails(details);
    return result;
}
Also used : SAMLCredential(org.springframework.security.saml.SAMLCredential) ExpiringUsernameAuthenticationToken(org.springframework.security.providers.ExpiringUsernameAuthenticationToken)

Example 8 with SAMLCredential

use of org.springframework.security.saml.SAMLCredential in project webcert by sklintyg.

the class CommonFakeAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication token) throws AuthenticationException {
    SAMLCredential credential = createSamlCredential(token);
    Object details = userDetails.loadUserBySAML(credential);
    addAbsentAttributesFromFakeCredentials(token, details);
    selectVardenhetFromFakeCredentials(token, details);
    overrideSekretessMarkeringFromFakeCredentials(token, details);
    updateFeatures(details);
    applyUserOrigin(token, details);
    applyAuthenticationMethod(token, details);
    applyPersonalNumberForBankID(token, details);
    ExpiringUsernameAuthenticationToken result = new ExpiringUsernameAuthenticationToken(null, details, credential, new ArrayList<>());
    result.setDetails(details);
    return result;
}
Also used : SAMLCredential(org.springframework.security.saml.SAMLCredential) ExpiringUsernameAuthenticationToken(org.springframework.security.providers.ExpiringUsernameAuthenticationToken)

Example 9 with SAMLCredential

use of org.springframework.security.saml.SAMLCredential in project webcert by sklintyg.

the class CommonFakeAuthenticationProvider method createSamlCredential.

private SAMLCredential createSamlCredential(Authentication token) {
    FakeCredentials fakeCredentials = (FakeCredentials) token.getCredentials();
    Assertion assertion = new AssertionBuilder().buildObject();
    attachAuthenticationContext(assertion, FAKE_AUTHENTICATION_SITHS_CONTEXT_REF);
    AttributeStatement attributeStatement = new AttributeStatementBuilder().buildObject();
    assertion.getAttributeStatements().add(attributeStatement);
    addAttribute(attributeStatement, BaseSakerhetstjanstAssertion.HSA_ID_ATTRIBUTE, fakeCredentials.getHsaId());
    NameID nameId = new NameIDBuilder().buildObject();
    nameId.setValue(token.getCredentials().toString());
    return new SAMLCredential(nameId, assertion, "fake-idp", "webcert");
}
Also used : NameIDBuilder(org.opensaml.saml2.core.impl.NameIDBuilder) AttributeStatementBuilder(org.opensaml.saml2.core.impl.AttributeStatementBuilder) FakeCredentials(se.inera.intyg.webcert.web.auth.fake.FakeCredentials) SAMLCredential(org.springframework.security.saml.SAMLCredential) NameID(org.opensaml.saml2.core.NameID) AttributeStatement(org.opensaml.saml2.core.AttributeStatement) Assertion(org.opensaml.saml2.core.Assertion) BaseSakerhetstjanstAssertion(se.inera.intyg.infra.security.siths.BaseSakerhetstjanstAssertion) AssertionBuilder(org.opensaml.saml2.core.impl.AssertionBuilder)

Example 10 with SAMLCredential

use of org.springframework.security.saml.SAMLCredential in project webcert by sklintyg.

the class ElegAuthenticationAttributeHelperTest method testReadStringAttribute.

@Test
public void testReadStringAttribute() {
    testee = new ElegAuthenticationAttributeHelperImpl();
    SAMLCredential cred = buildPrivatlakareSamlCredential();
    String personId = testee.getAttribute(cred, CgiElegAssertion.PERSON_ID_ATTRIBUTE);
    assertEquals("197705232382", personId);
}
Also used : SAMLCredential(org.springframework.security.saml.SAMLCredential) BaseSAMLCredentialTest(se.inera.intyg.webcert.web.auth.common.BaseSAMLCredentialTest) Test(org.junit.Test)

Aggregations

SAMLCredential (org.springframework.security.saml.SAMLCredential)12 Test (org.junit.Test)8 BaseSAMLCredentialTest (se.inera.intyg.webcert.web.auth.common.BaseSAMLCredentialTest)8 NameID (org.opensaml.saml2.core.NameID)4 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 Assertion (org.opensaml.saml2.core.Assertion)2 AttributeStatement (org.opensaml.saml2.core.AttributeStatement)2 AssertionBuilder (org.opensaml.saml2.core.impl.AssertionBuilder)2 AttributeStatementBuilder (org.opensaml.saml2.core.impl.AttributeStatementBuilder)2 NameIDBuilder (org.opensaml.saml2.core.impl.NameIDBuilder)2 ExpiringUsernameAuthenticationToken (org.springframework.security.providers.ExpiringUsernameAuthenticationToken)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 BaseSakerhetstjanstAssertion (se.inera.intyg.infra.security.siths.BaseSakerhetstjanstAssertion)1 FakeCredentials (se.inera.intyg.webcert.web.auth.fake.FakeCredentials)1