@@ -59,28 +59,42 @@ public class PropertyConfigurationImporter
59
59
60
60
public enum PropertyKey
61
61
{
62
- TEMPLATE_LDAP ,
63
- DISPLAY_THEME ,
64
-
65
- ID_VAULT_HOST ,
66
- ID_VAULT_LDAPS_PORT ,
67
- ID_VAULT_ADMIN_LDAP ,
68
- ID_VAULT_PASSWORD ,
69
- UA_SERVER_HOST ,
70
- UA_ADMIN ,
71
-
72
- SSPR_SERVER_HOST ,
73
- SSPR_SERVER_PORT ,
74
- USER_CONTAINER ,
75
- SSO_SERVER_HOST ,
76
- SSO_SERVER_SSL_PORT ,
77
- SSO_SERVICE_PWD ,
78
-
79
- CONFIGURATION_PWD ,
80
-
81
- LDAP_SERVERCERTS ,
82
- OAUTH_IDSERVER_SERVERCERTS ,
83
- AUDIT_SERVERCERTS ,;
62
+ TEMPLATE_LDAP ( "NOVL_IDM" ),
63
+ DISPLAY_THEME ( null ),
64
+
65
+ ID_VAULT_HOST ( null ),
66
+ ID_VAULT_LDAPS_PORT ( "636" ),
67
+ ID_VAULT_ADMIN_LDAP ( null ),
68
+ ID_VAULT_PASSWORD ( null ),
69
+ UA_SERVER_HOST ( null ),
70
+ UA_SERVER_SSL_PORT ( "443" ),
71
+ UA_ADMIN ( null ),
72
+ RPT_ADMIN ( null ),
73
+
74
+ SSPR_SERVER_HOST ( null ),
75
+ SSPR_SERVER_SSL_PORT ( "443" ),
76
+ USER_CONTAINER ( null ),
77
+ SSO_SERVER_HOST ( null ),
78
+ SSO_SERVER_SSL_PORT ( "443" ),
79
+ SSO_SERVICE_PWD ( null ),
80
+
81
+ CONFIGURATION_PWD ( null ),
82
+
83
+ LDAP_SERVERCERTS ( null ),
84
+ OAUTH_IDSERVER_SERVERCERTS ( null ),
85
+ AUDIT_SERVERCERTS ( null ),;
86
+
87
+ private final String defaultValue ;
88
+
89
+ PropertyKey ( final String defaultValue )
90
+ {
91
+ this .defaultValue = defaultValue ;
92
+ }
93
+
94
+ public String getDefaultValue ()
95
+ {
96
+ return defaultValue ;
97
+ }
84
98
}
85
99
86
100
public PropertyConfigurationImporter ()
@@ -104,21 +118,21 @@ public StoredConfigurationImpl readConfiguration( final InputStream propertiesIn
104
118
105
119
final StoredConfigurationImpl storedConfiguration = StoredConfigurationImpl .newStoredConfiguration ( );
106
120
storedConfiguration .initNewRandomSecurityKey ( );
107
- storedConfiguration .writeConfigProperty (
121
+ storedConfiguration .writeConfigProperty (
108
122
ConfigurationProperty .CONFIG_IS_EDITABLE , Boolean .toString ( false ) );
109
- storedConfiguration .writeConfigProperty (
123
+ storedConfiguration .writeConfigProperty (
110
124
ConfigurationProperty .CONFIG_EPOCH , String .valueOf ( 0 ) );
111
125
storedConfiguration .writeConfigProperty (
112
126
ConfigurationProperty .IMPORT_LDAP_CERTIFICATES , Boolean .toString ( true ) );
113
127
114
128
// static values
115
- storedConfiguration .writeSetting ( PwmSetting .TEMPLATE_LDAP , new StringValue (
116
- inputMap .getOrDefault ( PropertyKey .TEMPLATE_LDAP .name ( ), "NOVL_IDM" ) ),
129
+ storedConfiguration .writeSetting ( PwmSetting .TEMPLATE_LDAP , new StringValue (
130
+ inputMap .getOrDefault ( PropertyKey .TEMPLATE_LDAP .name ( ), PropertyKey . TEMPLATE_LDAP . getDefaultValue () ) ),
117
131
null );
118
132
119
133
if ( inputMap .containsKey ( PropertyKey .DISPLAY_THEME .name ( ) ) )
120
134
{
121
- storedConfiguration .writeSetting ( PwmSetting .PASSWORD_POLICY_SOURCE , new StringValue (
135
+ storedConfiguration .writeSetting ( PwmSetting .PASSWORD_POLICY_SOURCE , new StringValue (
122
136
inputMap .get ( PropertyKey .DISPLAY_THEME .name ( ) ) ),
123
137
null );
124
138
}
@@ -190,28 +204,28 @@ public StoredConfigurationImpl readConfiguration( final InputStream propertiesIn
190
204
191
205
private String makeOAuthBaseUrl ( )
192
206
{
193
- return "https://" + inputMap .get ( PropertyKey .UA_SERVER_HOST .name ( ) )
194
- + ":" + inputMap .get ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ) )
207
+ return "https://" + inputMap .get ( PropertyKey .SSO_SERVER_HOST .name ( ) )
208
+ + ":" + inputMap .getOrDefault ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ), PropertyKey . SSO_SERVER_SSL_PORT . getDefaultValue ( ) )
195
209
+ "/osp/a/idm/auth/oauth2" ;
196
210
}
197
211
198
212
private StringArrayValue makeWhitelistUrl ( )
199
213
{
200
214
return new StringArrayValue ( Collections .singletonList ( "https://" + inputMap .get ( PropertyKey .SSO_SERVER_HOST .name ( ) )
201
- + ":" + inputMap .get ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ) ) ) );
215
+ + ":" + inputMap .getOrDefault ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ), PropertyKey . SSO_SERVER_SSL_PORT . getDefaultValue ( ) ) ) );
202
216
}
203
217
204
218
private StoredValue makeSelfUrl ( )
205
219
{
206
- return new StringValue ( "https://" + inputMap .get ( PropertyKey .SSO_SERVER_HOST .name ( ) )
207
- + ":" + inputMap .getOrDefault ( PropertyKey .SSPR_SERVER_PORT .name ( ), "9443" )
220
+ return new StringValue ( "https://" + inputMap .get ( PropertyKey .SSPR_SERVER_HOST .name ( ) )
221
+ + ":" + inputMap .getOrDefault ( PropertyKey .SSPR_SERVER_SSL_PORT .name ( ), PropertyKey . SSPR_SERVER_SSL_PORT . getDefaultValue () )
208
222
+ "/sspr" );
209
223
}
210
224
211
225
private StoredValue makeForwardUrl ( )
212
226
{
213
- return new StringValue ( "https://" + inputMap .get ( PropertyKey .SSPR_SERVER_HOST .name ( ) )
214
- + ":" + inputMap .get ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ) )
227
+ return new StringValue ( "https://" + inputMap .get ( PropertyKey .UA_SERVER_HOST .name ( ) )
228
+ + ":" + inputMap .getOrDefault ( PropertyKey .UA_SERVER_SSL_PORT .name ( ), PropertyKey . UA_SERVER_SSL_PORT . getDefaultValue ( ) )
215
229
+ "/idmdash/#/landing" );
216
230
}
217
231
@@ -220,36 +234,47 @@ private StoredValue makeLogoutUrl( )
220
234
final String targetValue = makeSelfUrl ().toNativeObject ().toString ();
221
235
222
236
return new StringValue ( "https://" + inputMap .get ( PropertyKey .SSO_SERVER_HOST .name ( ) )
223
- + ":" + inputMap .get ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ) )
237
+ + ":" + inputMap .getOrDefault ( PropertyKey .SSO_SERVER_SSL_PORT .name ( ), PropertyKey . SSO_SERVER_SSL_PORT . getDefaultValue ( ) )
224
238
+ "/osp/a/idm/auth/app/logout?target="
225
239
+ StringUtil .urlEncode ( targetValue ) );
226
240
}
227
241
228
242
private StoredValue makeLdapServerUrlValue ( )
229
243
{
230
244
final String ldapUrl = "ldaps://" + inputMap .get ( PropertyKey .ID_VAULT_HOST .name ( ) )
231
- + ":" + inputMap .get ( PropertyKey .ID_VAULT_LDAPS_PORT .name ( ) );
245
+ + ":" + inputMap .getOrDefault ( PropertyKey .ID_VAULT_LDAPS_PORT .name ( ), PropertyKey . ID_VAULT_LDAPS_PORT . getDefaultValue ( ) );
232
246
return new StringArrayValue ( Collections .singletonList ( ldapUrl ) );
233
247
}
234
248
235
249
private StoredValue makeAdminPermissions ( )
236
250
{
251
+ final List <PropertyKey > interestedProperties = new ArrayList <>();
252
+ interestedProperties .add ( PropertyKey .ID_VAULT_ADMIN_LDAP );
253
+ interestedProperties .add ( PropertyKey .UA_ADMIN );
254
+ interestedProperties .add ( PropertyKey .RPT_ADMIN );
255
+
237
256
final String filter = "( objectclass=* )" ;
238
257
final List <UserPermission > permissions = new ArrayList <>( );
239
- permissions .add ( new UserPermission ( UserPermission .Type .ldapQuery , LDAP_PROFILE , filter ,
240
- inputMap .get ( PropertyKey .ID_VAULT_ADMIN_LDAP .name ( ) ) ) );
241
- permissions .add ( new UserPermission ( UserPermission .Type .ldapQuery , LDAP_PROFILE , filter ,
242
- inputMap .get ( PropertyKey .UA_ADMIN .name ( ) ) ) );
258
+
259
+ for ( final PropertyKey propertyKey : interestedProperties )
260
+ {
261
+ final String value = inputMap .get ( propertyKey .name () );
262
+ if ( !StringUtil .isEmpty ( value ) )
263
+ {
264
+ permissions .add ( new UserPermission ( UserPermission .Type .ldapQuery , LDAP_PROFILE , filter , value ) );
265
+ }
266
+ }
267
+
243
268
return new UserPermissionValue ( permissions );
244
269
}
245
270
246
271
private void stripValueDelimiters ( final Map <String , String > map )
247
272
{
248
- final Pattern pattern = Pattern .compile ( "^'|'$" );
273
+ final Pattern pattern = Pattern .compile ( "^'|'$|^ \" | \" $ " );
249
274
map .replaceAll ( ( key , value ) -> pattern .matcher ( value ).replaceAll ( "" ) );
250
275
}
251
276
252
- private Optional <Collection <X509Certificate >> readCertificate (
277
+ private Optional <Collection <X509Certificate >> readCertificate (
253
278
final PropertyKey propertyKey
254
279
)
255
280
throws IOException
0 commit comments