1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.inner;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24 import static org.junit.jupiter.api.Assertions.assertNull;
25
26 import java.util.UUID;
27 import org.apache.syncope.common.lib.types.SAML2SPNameId;
28 import org.apache.syncope.common.lib.types.XmlSecAlgorithm;
29 import org.apache.syncope.core.persistence.api.dao.SAML2SPClientAppDAO;
30 import org.apache.syncope.core.persistence.api.entity.am.SAML2SPClientApp;
31 import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
32 import org.apache.syncope.core.persistence.api.entity.policy.AuthPolicy;
33 import org.junit.jupiter.api.Test;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.transaction.annotation.Transactional;
36
37 @Transactional("Master")
38 public class SAML2SPTest extends AbstractClientAppTest {
39
40 @Autowired
41 private SAML2SPClientAppDAO saml2spDAO;
42
43 @Test
44 public void find() {
45 int beforeCount = saml2spDAO.findAll().size();
46 SAML2SPClientApp sp = entityFactory.newEntity(SAML2SPClientApp.class);
47 sp.setName("SAML2");
48 sp.setClientAppId(UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE);
49 sp.setDescription("This is a sample SAML2 SP");
50 sp.setEntityId("urn:example:saml2:sp");
51 sp.setMetadataLocation("https://example.org/metadata.xml");
52 sp.setRequiredNameIdFormat(SAML2SPNameId.EMAIL_ADDRESS);
53 sp.setEncryptionOptional(true);
54 sp.setEncryptAssertions(true);
55 sp.getEncryptionDataAlgorithms().add(XmlSecAlgorithm.AES_128_GCM);
56 sp.getEncryptionKeyAlgorithms().add(XmlSecAlgorithm.RSA_OAEP_11);
57 sp.getSigningSignatureReferenceDigestMethods().add(XmlSecAlgorithm.SHA1);
58 sp.getSigningSignatureAlgorithms().add(XmlSecAlgorithm.SHA256);
59 sp.getSigningSignatureAlgorithms().add(XmlSecAlgorithm.SHA512);
60
61 AccessPolicy accessPolicy = buildAndSaveAccessPolicy();
62 sp.setAccessPolicy(accessPolicy);
63
64 AuthPolicy authnPolicy = buildAndSaveAuthPolicy();
65 sp.setAuthPolicy(authnPolicy);
66
67 saml2spDAO.save(sp);
68
69 assertNotNull(sp);
70 assertNotNull(sp.getKey());
71
72 int afterCount = saml2spDAO.findAll().size();
73 assertEquals(afterCount, beforeCount + 1);
74
75 sp = saml2spDAO.findByEntityId(sp.getEntityId());
76 assertNotNull(sp);
77
78 sp = saml2spDAO.findByName(sp.getName());
79 assertNotNull(sp);
80
81 sp = saml2spDAO.findByClientAppId(sp.getClientAppId());
82 assertNotNull(sp);
83
84 assertFalse(sp.getSigningSignatureAlgorithms().isEmpty());
85 assertFalse(sp.getSigningSignatureReferenceDigestMethods().isEmpty());
86 assertFalse(sp.getEncryptionDataAlgorithms().isEmpty());
87 assertFalse(sp.getEncryptionKeyAlgorithms().isEmpty());
88
89 saml2spDAO.deleteByEntityId(sp.getEntityId());
90 assertNull(saml2spDAO.findByName(sp.getName()));
91 }
92 }