Skip to content

Commit 105beca

Browse files
committed
property config importer updates
1 parent f2cc3b0 commit 105beca

File tree

1 file changed

+67
-42
lines changed

1 file changed

+67
-42
lines changed

server/src/main/java/password/pwm/util/PropertyConfigurationImporter.java

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,42 @@ public class PropertyConfigurationImporter
5959

6060
public enum PropertyKey
6161
{
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+
}
8498
}
8599

86100
public PropertyConfigurationImporter()
@@ -104,21 +118,21 @@ public StoredConfigurationImpl readConfiguration( final InputStream propertiesIn
104118

105119
final StoredConfigurationImpl storedConfiguration = StoredConfigurationImpl.newStoredConfiguration( );
106120
storedConfiguration.initNewRandomSecurityKey( );
107-
storedConfiguration.writeConfigProperty(
121+
storedConfiguration.writeConfigProperty(
108122
ConfigurationProperty.CONFIG_IS_EDITABLE, Boolean.toString( false ) );
109-
storedConfiguration.writeConfigProperty(
123+
storedConfiguration.writeConfigProperty(
110124
ConfigurationProperty.CONFIG_EPOCH, String.valueOf( 0 ) );
111125
storedConfiguration.writeConfigProperty(
112126
ConfigurationProperty.IMPORT_LDAP_CERTIFICATES, Boolean.toString( true ) );
113127

114128
// 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() ) ),
117131
null );
118132

119133
if ( inputMap.containsKey( PropertyKey.DISPLAY_THEME.name( ) ) )
120134
{
121-
storedConfiguration.writeSetting( PwmSetting.PASSWORD_POLICY_SOURCE, new StringValue(
135+
storedConfiguration.writeSetting( PwmSetting.PASSWORD_POLICY_SOURCE, new StringValue(
122136
inputMap.get( PropertyKey.DISPLAY_THEME.name( ) ) ),
123137
null );
124138
}
@@ -190,28 +204,28 @@ public StoredConfigurationImpl readConfiguration( final InputStream propertiesIn
190204

191205
private String makeOAuthBaseUrl( )
192206
{
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() )
195209
+ "/osp/a/idm/auth/oauth2";
196210
}
197211

198212
private StringArrayValue makeWhitelistUrl( )
199213
{
200214
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() ) ) );
202216
}
203217

204218
private StoredValue makeSelfUrl( )
205219
{
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() )
208222
+ "/sspr" );
209223
}
210224

211225
private StoredValue makeForwardUrl( )
212226
{
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() )
215229
+ "/idmdash/#/landing" );
216230
}
217231

@@ -220,36 +234,47 @@ private StoredValue makeLogoutUrl( )
220234
final String targetValue = makeSelfUrl().toNativeObject().toString();
221235

222236
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() )
224238
+ "/osp/a/idm/auth/app/logout?target="
225239
+ StringUtil.urlEncode( targetValue ) );
226240
}
227241

228242
private StoredValue makeLdapServerUrlValue( )
229243
{
230244
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() );
232246
return new StringArrayValue( Collections.singletonList( ldapUrl ) );
233247
}
234248

235249
private StoredValue makeAdminPermissions( )
236250
{
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+
237256
final String filter = "( objectclass=* )";
238257
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+
243268
return new UserPermissionValue( permissions );
244269
}
245270

246271
private void stripValueDelimiters( final Map<String, String> map )
247272
{
248-
final Pattern pattern = Pattern.compile( "^'|'$" );
273+
final Pattern pattern = Pattern.compile( "^'|'$|^\"|\"$" );
249274
map.replaceAll( ( key, value ) -> pattern.matcher( value ).replaceAll( "" ) );
250275
}
251276

252-
private Optional<Collection<X509Certificate>> readCertificate(
277+
private Optional<Collection<X509Certificate>> readCertificate(
253278
final PropertyKey propertyKey
254279
)
255280
throws IOException

0 commit comments

Comments
 (0)