Skip to content

Commit e22c21a

Browse files
committed
UY-1561 update to fixed samly2, update to changed API
1 parent 4674762 commit e22c21a

5 files changed

Lines changed: 29 additions & 29 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@
533533
<dependency>
534534
<groupId>io.imunity.samly</groupId>
535535
<artifactId>samly2</artifactId>
536-
<version>3.0.0</version>
536+
<version>3.2.0</version>
537537
</dependency>
538538
<dependency>
539539
<groupId>io.imunity.samly</groupId>

saml/src/main/java/pl/edu/icm/unity/saml/metadata/cfg/MetadataVerificator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.w3c.dom.Document;
1212

1313
import eu.unicore.security.dsig.DSigException;
14-
import eu.unicore.security.dsig.DigSignatureUtil;
14+
import eu.unicore.security.dsig.DigSignatureVerificator;
1515
import eu.unicore.security.dsig.IdAttribute;
1616
import pl.edu.icm.unity.saml.sp.SAMLSPProperties.MetadataSignatureValidation;
1717
import xmlbeans.org.oasis.saml2.metadata.EntitiesDescriptorDocument;
@@ -82,7 +82,7 @@ protected void validateSignature(X509Certificate issuerCertificate, String name,
8282
{
8383
try
8484
{
85-
DigSignatureUtil sigUtil = new DigSignatureUtil();
85+
DigSignatureVerificator sigUtil = new DigSignatureVerificator();
8686
boolean result = sigUtil.verifyEnvelopedSignature(doc,
8787
Collections.singletonList(doc.getDocumentElement()),
8888
ID_QNAME,

saml/src/test/java/pl/edu/icm/unity/saml/TestSAMLResponseValidatorUtil.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public void shouldReturnAuthnContextFromAssertionAsAttribute() throws Exception
4141

4242
ResponseDocument respDoc = ResponseDocument.Factory.parse(
4343
new File("src/test/resources/responseDocSigned.xml"));
44-
List<AssertionDocument> authnAssertions = SAMLUtils.extractAllAssertions(
45-
respDoc.getResponse(), null).stream()
46-
.filter(a -> a.getAssertion().getAuthnStatementArray().length > 0)
47-
.collect(Collectors.toList());
44+
List<AssertionDocument> authnAssertions =
45+
SAMLUtils.extractAllAssertions(respDoc.getResponse(), null).stream()
46+
.map(wrap -> wrap.xmlBean)
47+
.filter(a -> a.getAssertion().getAuthnStatementArray().length > 0)
48+
.collect(Collectors.toList());
4849

4950
SSOAuthnResponseValidator validator = mock(SSOAuthnResponseValidator.class);
5051
when(validator.getAuthNAssertions()).thenReturn(authnAssertions);
@@ -55,7 +56,7 @@ public void shouldReturnAuthnContextFromAssertionAsAttribute() throws Exception
5556
RemoteAttribute authnCtxAttr = authnInput.getAttributes().get(AUTHN_CONTEXT_CLASS_REF_ATTR);
5657
assertThat(authnCtxAttr).isNotNull();
5758
assertThat(authnCtxAttr.getValues().isEmpty()).isFalse();
58-
assertThat(authnInput.getAttributes().get(AUTHN_CONTEXT_CLASS_REF_ATTR).getValues().get(0)).
59+
assertThat(authnInput.getAttributes().get(AUTHN_CONTEXT_CLASS_REF_ATTR).getValues().getFirst()).
5960
isEqualTo("urn:oasis:names:tc:SAML:2.0:ac:classes:Password");
6061

6162
}
@@ -70,10 +71,11 @@ public void shouldReturnAuthnContextFromAssertionAsRemoteMetaContext() throws Ex
7071

7172
ResponseDocument respDoc = ResponseDocument.Factory.parse(
7273
new File("src/test/resources/responseDocSigned.xml"));
73-
List<AssertionDocument> authnAssertions = SAMLUtils.extractAllAssertions(
74-
respDoc.getResponse(), null).stream()
75-
.filter(a -> a.getAssertion().getAuthnStatementArray().length > 0)
76-
.collect(Collectors.toList());
74+
List<AssertionDocument> authnAssertions =
75+
SAMLUtils.extractAllAssertions(respDoc.getResponse(), null).stream()
76+
.map(wrap -> wrap.xmlBean)
77+
.filter(a -> a.getAssertion().getAuthnStatementArray().length > 0)
78+
.collect(Collectors.toList());
7779

7880
SSOAuthnResponseValidator validator = mock(SSOAuthnResponseValidator.class);
7981
when(validator.getAuthNAssertions()).thenReturn(authnAssertions);
@@ -84,7 +86,7 @@ public void shouldReturnAuthnContextFromAssertionAsRemoteMetaContext() throws Ex
8486
RemoteAuthnMetadata remoteAuthnMeta = authnInput.getRemoteAuthnMetadata();
8587
assertThat(remoteAuthnMeta).isNotNull();
8688
assertThat(remoteAuthnMeta.classReferences().isEmpty()).isFalse();
87-
assertThat(remoteAuthnMeta.classReferences().get(0)).
89+
assertThat(remoteAuthnMeta.classReferences().getFirst()).
8890
isEqualTo("urn:oasis:names:tc:SAML:2.0:ac:classes:Password");
8991
assertThat(remoteAuthnMeta.protocol()).isEqualTo(Protocol.SAML);
9092
assertThat(remoteAuthnMeta.remoteIdPId()).isEqualTo("http://centos6-unity1:8080/simplesaml/saml2/idp/metadata.php");
@@ -101,8 +103,8 @@ public void shouldSaveAuthenticationTimeInAuthInput() throws Exception
101103
ResponseDocument respDoc = ResponseDocument.Factory.parse(new File("src/test/resources/responseDocSigned.xml"));
102104
List<AssertionDocument> authnAssertions = SAMLUtils.extractAllAssertions(respDoc.getResponse(), null)
103105
.stream()
104-
.filter(a -> a.getAssertion()
105-
.getAuthnStatementArray().length > 0)
106+
.map(wrap -> wrap.xmlBean)
107+
.filter(a -> a.getAssertion().getAuthnStatementArray().length > 0)
106108
.collect(Collectors.toList());
107109

108110
SSOAuthnResponseValidator validator = mock(SSOAuthnResponseValidator.class);

saml/src/test/java/pl/edu/icm/unity/saml/metadata/cfg/MetadataParsingIntegrationTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import eu.unicore.samly2.SAMLUtils;
24+
import eu.unicore.samly2.SAMLUtils.XMLBeansWithDom;
2425
import eu.unicore.samly2.messages.XMLExpandedMessage;
2526
import eu.unicore.samly2.trust.ResponseTrustCheckResult;
2627
import eu.unicore.samly2.trust.SamlTrustChecker;
27-
import pl.edu.icm.unity.base.exceptions.EngineException;
2828
import pl.edu.icm.unity.base.translation.TranslationProfile;
2929
import pl.edu.icm.unity.engine.api.PKIManagement;
3030
import pl.edu.icm.unity.saml.sp.FakeSAMLSPConfiguration;
@@ -59,12 +59,12 @@ public void shouldTrustResponseSignedByIdpFromParsedMetadata() throws Exception
5959

6060
ResponseDocument respDoc = ResponseDocument.Factory.parse(
6161
new File("src/test/resources/responseDocSigned.xml"));
62-
List<AssertionDocument> authnAssertions = getAuthAssertions(respDoc);
62+
List<XMLBeansWithDom<AssertionDocument>> authnAssertions = getAuthAssertions(respDoc);
6363
XMLExpandedMessage response = new XMLExpandedMessage(respDoc, respDoc.getResponse());
6464

6565
ResponseTrustCheckResult responseTrustCheckResult = checkerForIdP.checkTrust(response, respDoc.getResponse());
6666
Throwable assertionValidationError = catchThrowable(() ->
67-
checkerForIdP.checkTrust(authnAssertions.get(0), responseTrustCheckResult));
67+
checkerForIdP.checkTrust(authnAssertions.getFirst(), responseTrustCheckResult));
6868

6969
assertThat(assertionValidationError).isNull();
7070
assertThat(responseTrustCheckResult.isTrustEstablished()).isTrue();
@@ -80,15 +80,14 @@ private RemoteMetadataSource getDummyMetadataSource()
8080
.build();
8181
}
8282

83-
private List<AssertionDocument> getAuthAssertions(ResponseDocument respDoc) throws Exception
83+
private List<XMLBeansWithDom<AssertionDocument>> getAuthAssertions(ResponseDocument respDoc) throws Exception
8484
{
85-
return SAMLUtils.extractAllAssertions(
86-
respDoc.getResponse(), null).stream()
87-
.filter(a -> a.getAssertion().getAuthnStatementArray().length > 0)
85+
return SAMLUtils.extractAllAssertions(respDoc.getResponse(), null).stream()
86+
.filter(a -> a.xmlBean.getAssertion().getAuthnStatementArray().length > 0)
8887
.collect(Collectors.toList());
8988
}
9089

91-
private SAMLSPConfiguration createConfig() throws EngineException
90+
private SAMLSPConfiguration createConfig()
9291
{
9392
return FakeSAMLSPConfiguration.getFakeBuilder()
9493
.build();

saml/src/test/java/pl/edu/icm/unity/saml/sp/TrustAllTrustChecker.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
package pl.edu.icm.unity.saml.sp;
66

7-
import eu.unicore.samly2.exceptions.SAMLValidationException;
7+
import eu.unicore.samly2.SAMLUtils;
88
import eu.unicore.samly2.messages.SAMLVerifiableElement;
99
import eu.unicore.samly2.trust.CheckingMode;
1010
import eu.unicore.samly2.trust.ResponseTrustCheckResult;
@@ -25,26 +25,25 @@
2525
public class TrustAllTrustChecker implements SamlTrustChecker
2626
{
2727
@Override
28-
public void checkTrust(SAMLVerifiableElement message, RequestAbstractType request) throws SAMLValidationException
28+
public void checkTrust(SAMLVerifiableElement message, RequestAbstractType request)
2929
{
3030
}
3131

3232
@Override
33-
public void checkTrust(AssertionDocument assertionDoc,
33+
public void checkTrust(SAMLUtils.XMLBeansWithDom<AssertionDocument> assertionDoc,
3434
ResponseTrustCheckResult responseCheckResult)
35-
throws SAMLValidationException
3635
{
3736
}
3837

3938
@Override
4039
public ResponseTrustCheckResult checkTrust(SAMLVerifiableElement message,
41-
StatusResponseType response) throws SAMLValidationException
40+
StatusResponseType response)
4241
{
4342
return new ResponseTrustCheckResult(true);
4443
}
4544

4645
@Override
47-
public void checkTrust(AssertionDocument assertionDoc) throws SAMLValidationException
46+
public void checkTrust(SAMLUtils.XMLBeansWithDom<AssertionDocument> assertionDoc)
4847
{
4948
checkTrust(assertionDoc, new ResponseTrustCheckResult(true));
5049
}

0 commit comments

Comments
 (0)