1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.provisioning.java.data;
20
21 import java.util.Base64;
22 import org.apache.syncope.common.lib.to.SAML2IdPEntityTO;
23 import org.apache.syncope.core.persistence.api.entity.EntityFactory;
24 import org.apache.syncope.core.persistence.api.entity.am.SAML2IdPEntity;
25 import org.apache.syncope.core.provisioning.api.data.SAML2IdPEntityDataBinder;
26
27 public class SAML2IdPEntityDataBinderImpl implements SAML2IdPEntityDataBinder {
28
29 protected final EntityFactory entityFactory;
30
31 public SAML2IdPEntityDataBinderImpl(final EntityFactory entityFactory) {
32 this.entityFactory = entityFactory;
33 }
34
35 @Override
36 public SAML2IdPEntity create(final SAML2IdPEntityTO entityTO) {
37 SAML2IdPEntity entity = entityFactory.newEntity(SAML2IdPEntity.class);
38 entity.setKey(entityTO.getKey());
39 return update(entity, entityTO);
40 }
41
42 @Override
43 public SAML2IdPEntity update(final SAML2IdPEntity entity, final SAML2IdPEntityTO entityTO) {
44 entity.setEncryptionCertificate(entityTO.getEncryptionCertificate() == null
45 ? null
46 : Base64.getDecoder().decode(entityTO.getEncryptionCertificate()));
47 entity.setEncryptionKey(entityTO.getEncryptionKey() == null
48 ? null
49 : Base64.getDecoder().decode(entityTO.getEncryptionKey()));
50 entity.setMetadata(entityTO.getMetadata() == null
51 ? null
52 : Base64.getDecoder().decode(entityTO.getMetadata()));
53 entity.setSigningCertificate(entityTO.getSigningCertificate() == null
54 ? null
55 : Base64.getDecoder().decode(entityTO.getSigningCertificate()));
56 entity.setSigningKey(entityTO.getSigningKey() == null
57 ? null
58 : Base64.getDecoder().decode(entityTO.getSigningKey()));
59 return entity;
60 }
61
62 @Override
63 public SAML2IdPEntityTO getSAML2IdPEntityTO(final SAML2IdPEntity entity) {
64 SAML2IdPEntityTO entityTO = new SAML2IdPEntityTO();
65 entityTO.setKey(entity.getKey());
66 entityTO.setMetadata(Base64.getEncoder().encodeToString(entity.getMetadata()));
67 if (entity.getEncryptionCertificate() != null) {
68 entityTO.setEncryptionCertificate(
69 Base64.getEncoder().encodeToString(entity.getEncryptionCertificate()));
70 }
71 if (entity.getEncryptionKey() != null) {
72 entityTO.setEncryptionKey(
73 Base64.getEncoder().encodeToString(entity.getEncryptionKey()));
74 }
75 if (entity.getSigningCertificate() != null) {
76 entityTO.setSigningCertificate(
77 Base64.getEncoder().encodeToString(entity.getSigningCertificate()));
78 }
79 if (entity.getSigningKey() != null) {
80 entityTO.setSigningKey(Base64.getEncoder().encodeToString(entity.getSigningKey()));
81 }
82 return entityTO;
83 }
84 }