1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.mylutece.modules.saml.authentication.engine;
35
36 import fr.paris.lutece.plugins.mylutece.modules.saml.authentication.config.ConfigProperties;
37 import fr.paris.lutece.plugins.mylutece.modules.saml.authentication.metadata.IDPMetadataManager;
38 import fr.paris.lutece.plugins.mylutece.modules.saml.authentication.metadata.SPMetadataManager;
39 import fr.paris.lutece.portal.service.util.AppException;
40 import fr.paris.lutece.portal.service.util.AppLogService;
41
42 import org.opensaml.Configuration;
43 import org.opensaml.DefaultBootstrap;
44
45 import org.opensaml.saml2.metadata.provider.DOMMetadataProvider;
46 import org.opensaml.saml2.metadata.provider.MetadataProviderException;
47
48 import org.opensaml.security.MetadataCredentialResolver;
49
50 import org.opensaml.xml.ConfigurationException;
51 import org.opensaml.xml.security.keyinfo.KeyInfoCredentialResolver;
52 import org.opensaml.xml.signature.impl.ExplicitKeySignatureTrustEngine;
53
54
55 public class BootStrap
56 {
57 private static BootStrap instance = null;
58 private IDPMetadataManager idpMetaDataManager = null;
59 private SPMetadataManager spMetaDataManager = null;
60 private ExplicitKeySignatureTrustEngine trustEngine = null;
61
62 protected BootStrap( )
63 {
64
65 try
66 {
67 DefaultBootstrap.bootstrap( );
68 }
69 catch ( ConfigurationException e )
70 {
71 String message = "Erreur d'initialisation de OpenSAML" + e.getLocalizedMessage( );
72 AppLogService.error( message );
73 throw new AppException( message, e );
74 }
75
76
77 try
78 {
79 ConfigProperties.init( );
80 }
81 catch ( Exception e )
82 {
83 String message = "Erreur d'initialisation des propri�t�s du plugin MyLutece-SAML" +
84 e.getLocalizedMessage( );
85 AppLogService.error( message );
86 throw new AppException( message, e );
87 }
88
89
90 initializeIDPMetaData( null );
91 initializeSPMetaData( null );
92 }
93
94 public ExplicitKeySignatureTrustEngine getTrustEngine( )
95 {
96 return trustEngine;
97 }
98
99 public IDPMetadataManager getIdpMetaDataManager( )
100 {
101 return idpMetaDataManager;
102 }
103
104 public SPMetadataManager getSpMetaDataManager( )
105 {
106 return spMetaDataManager;
107 }
108
109 public static void init( )
110 {
111 if ( instance == null )
112 {
113 instance = new BootStrap( );
114 }
115 }
116
117 public static BootStrap getInstance( )
118 {
119 return instance;
120 }
121
122 public void initializeIDPMetaData( String inFilePath )
123 {
124
125
126 idpMetaDataManager = new IDPMetadataManager( );
127 idpMetaDataManager.loadMetadata( inFilePath );
128
129
130 DOMMetadataProvider mdProvider = new DOMMetadataProvider( idpMetaDataManager.getMetaData( ).getDOM( ) );
131
132 try
133 {
134 mdProvider.initialize( );
135 }
136 catch ( MetadataProviderException e )
137 {
138 String message = "Erreur d'initialisation des MetaDataProvider" + e.getLocalizedMessage( );
139 AppLogService.error( message );
140 throw new AppException( message, e );
141 }
142
143
144 MetadataCredentialResolver mdCredResolver = new MetadataCredentialResolver( mdProvider );
145
146
147 KeyInfoCredentialResolver keyInfoCredResolver = Configuration.getGlobalSecurityConfiguration( )
148 .getDefaultKeyInfoCredentialResolver( );
149
150 trustEngine = new ExplicitKeySignatureTrustEngine( mdCredResolver, keyInfoCredResolver );
151 }
152
153 public void initializeSPMetaData( String inFilePath )
154 {
155
156 spMetaDataManager = new SPMetadataManager( );
157 spMetaDataManager.loadMetadata( inFilePath );
158 }
159 }