]> source.dussan.org Git - archiva.git/blob
3ce727c712aa830443e8ba6262469d23f1af273e
[archiva.git] /
1 package org.apache.archiva.admin.repository.runtime;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.CacheConfiguration;
23 import org.apache.archiva.admin.model.beans.LdapConfiguration;
24 import org.apache.archiva.admin.model.beans.LdapGroupMapping;
25 import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
26 import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
27 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
28 import org.apache.archiva.configuration.ArchivaConfiguration;
29 import org.apache.archiva.configuration.Configuration;
30 import org.apache.archiva.configuration.IndeterminateConfigurationException;
31 import org.apache.archiva.redback.components.cache.Cache;
32 import org.apache.archiva.redback.components.registry.RegistryException;
33 import org.apache.archiva.redback.configuration.UserConfiguration;
34 import org.apache.archiva.redback.configuration.UserConfigurationException;
35 import org.apache.archiva.redback.configuration.UserConfigurationKeys;
36 import org.apache.commons.lang.StringUtils;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.stereotype.Service;
40
41 import javax.annotation.PostConstruct;
42 import javax.inject.Inject;
43 import javax.inject.Named;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.Collection;
47 import java.util.HashSet;
48 import java.util.List;
49 import java.util.Map;
50 import java.util.Set;
51
52 /**
53  * @author Olivier Lamy
54  * @since 1.4-M4
55  */
56 @Service( "redbackRuntimeConfigurationAdmin#default" )
57 public class DefaultRedbackRuntimeConfigurationAdmin
58     extends AbstractRepositoryAdmin
59     implements RedbackRuntimeConfigurationAdmin, UserConfiguration
60 {
61
62     protected Logger log = LoggerFactory.getLogger( getClass() );
63
64     private ArchivaConfiguration archivaConfiguration;
65
66     private UserConfiguration userConfiguration;
67
68     private Cache usersCache;
69
70     @Inject
71     public DefaultRedbackRuntimeConfigurationAdmin( ArchivaConfiguration archivaConfiguration,//
72                                                     @Named( value = "userConfiguration#redback" ) //
73                                                         UserConfiguration userConfiguration,
74                                                     @Named( value = "cache#users" ) Cache usersCache )
75     {
76         this.archivaConfiguration = archivaConfiguration;
77         this.userConfiguration = userConfiguration;
78         this.usersCache = usersCache;
79     }
80
81     @PostConstruct
82     @Override
83     public void initialize()
84         throws UserConfigurationException
85     {
86         try
87         {
88             RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration();
89             // migrate or not data from redback
90             if ( !redbackRuntimeConfiguration.isMigratedFromRedbackConfiguration() )
91             {
92                 // not migrated so build a new fresh one
93                 redbackRuntimeConfiguration = new RedbackRuntimeConfiguration();
94                 // so migrate if available
95                 String userManagerImpl =
96                     userConfiguration.getConcatenatedList( UserConfigurationKeys.USER_MANAGER_IMPL, //
97                                                            DEFAULT_USER_MANAGER_IMPL );
98                 if ( StringUtils.isNotEmpty( userManagerImpl ) )
99                 {
100                     String[] impls = StringUtils.split( userManagerImpl, ',' );
101                     for ( String impl : impls )
102                     {
103                         redbackRuntimeConfiguration.getUserManagerImpls().add( impl );
104                     }
105                 }
106                 else
107                 {
108                     redbackRuntimeConfiguration.getUserManagerImpls().add( DEFAULT_USER_MANAGER_IMPL );
109                 }
110
111                 String rbacManagerImpls =
112                     userConfiguration.getConcatenatedList( UserConfigurationKeys.RBAC_MANAGER_IMPL, //
113                                                            DEFAULT_RBAC_MANAGER_IMPL );
114
115                 if ( StringUtils.isNotEmpty( rbacManagerImpls ) )
116                 {
117                     String[] impls = StringUtils.split( rbacManagerImpls, ',' );
118                     for ( String impl : impls )
119                     {
120                         redbackRuntimeConfiguration.getRbacManagerImpls().add( impl );
121                     }
122                 }
123                 else
124                 {
125                     redbackRuntimeConfiguration.getRbacManagerImpls().add( DEFAULT_RBAC_MANAGER_IMPL );
126                 }
127
128                 // now ldap
129
130                 LdapConfiguration ldapConfiguration = redbackRuntimeConfiguration.getLdapConfiguration();
131                 if ( ldapConfiguration == null )
132                 {
133                     ldapConfiguration = new LdapConfiguration();
134                     redbackRuntimeConfiguration.setLdapConfiguration( ldapConfiguration );
135                 }
136
137                 ldapConfiguration.setHostName(
138                     userConfiguration.getString( UserConfigurationKeys.LDAP_HOSTNAME, null ) );
139                 ldapConfiguration.setPort( userConfiguration.getInt( UserConfigurationKeys.LDAP_PORT, -1 ) );
140                 ldapConfiguration.setSsl( userConfiguration.getBoolean( UserConfigurationKeys.LDAP_SSL, false ) );
141                 ldapConfiguration.setBaseDn(
142                     userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BASEDN, null ) );
143
144                 ldapConfiguration.setBaseGroupsDn(
145                     userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_GROUPS_BASEDN,
146                                                            ldapConfiguration.getBaseDn() ) );
147
148                 ldapConfiguration.setContextFactory(
149                     userConfiguration.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY,
150                                                  isSunContextFactoryAvailable()
151                                                      ? "com.sun.jndi.ldap.LdapCtxFactory"
152                                                      : "" ) );
153                 ldapConfiguration.setBindDn(
154                     userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, null ) );
155                 ldapConfiguration.setPassword(
156                     userConfiguration.getString( UserConfigurationKeys.LDAP_PASSWORD, null ) );
157                 ldapConfiguration.setAuthenticationMethod(
158                     userConfiguration.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, null ) );
159
160                 ldapConfiguration.setWritable(
161                     userConfiguration.getBoolean( UserConfigurationKeys.LDAP_WRITABLE, false ) );
162
163                 ldapConfiguration.setUseRoleNameAsGroup(
164                     userConfiguration.getBoolean( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME, false ) );
165
166                 boolean ldapBindAuthenticatorEnabled =
167                     userConfiguration.getBoolean( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED, false );
168                 ldapConfiguration.setBindAuthenticatorEnabled( ldapBindAuthenticatorEnabled );
169
170                 // LDAP groups mapping reading !!
171                 // UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY
172                 // userConfiguration.getKeys()
173
174                 Collection<String> keys = userConfiguration.getKeys();
175
176                 List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>();
177
178                 for ( String key : keys )
179                 {
180                     if ( key.startsWith( UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
181                     {
182                         String group =
183                             StringUtils.substringAfter( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY );
184                         String val = userConfiguration.getConcatenatedList( key, "" );
185                         if ( !StringUtils.isEmpty( val ) )
186                         {
187                             String[] roles = StringUtils.split( val, ',' );
188                             ldapGroupMappings.add( new LdapGroupMapping( group, roles ) );
189                         }
190                     }
191                 }
192
193                 redbackRuntimeConfiguration.setLdapGroupMappings( ldapGroupMappings );
194
195                 redbackRuntimeConfiguration.setMigratedFromRedbackConfiguration( true );
196
197                 updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
198
199             }
200             // we must ensure userManagerImpls list is not empty if so put at least jdo one !
201             if ( redbackRuntimeConfiguration.getUserManagerImpls().isEmpty() )
202             {
203                 log.info(
204                     "redbackRuntimeConfiguration with empty userManagerImpls so force at least jdo implementation !" );
205                 redbackRuntimeConfiguration.getUserManagerImpls().add( "jdo" );
206                 updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
207             }
208             else
209             {
210                 log.info( "using userManagerImpls: {}", redbackRuntimeConfiguration.getUserManagerImpls() );
211             }
212
213             // we ensure rbacManagerImpls is not empty if so put at least cached
214             if ( redbackRuntimeConfiguration.getRbacManagerImpls().isEmpty() )
215             {
216                 log.info(
217                     "redbackRuntimeConfiguration with empty rbacManagerImpls so force at least cached implementation !" );
218                 redbackRuntimeConfiguration.getRbacManagerImpls().add( "cached" );
219                 updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
220             }
221             else
222             {
223                 log.info( "using rbacManagerImpls: {}", redbackRuntimeConfiguration.getRbacManagerImpls() );
224             }
225
226             boolean save = false;
227
228             // NPE free
229             if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
230             {
231                 redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
232             }
233             // if -1 it means non initialized to take values from the spring bean
234             if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() < 0 )
235             {
236                 redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToIdleSeconds(
237                     usersCache.getTimeToIdleSeconds() );
238                 save = true;
239
240             }
241             usersCache.setTimeToIdleSeconds(
242                 redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() );
243
244             if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0 )
245             {
246                 redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToLiveSeconds(
247                     usersCache.getTimeToLiveSeconds() );
248                 save = true;
249
250             }
251             usersCache.setTimeToLiveSeconds(
252                 redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() );
253
254             if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory() < 0 )
255             {
256                 redbackRuntimeConfiguration.getUsersCacheConfiguration().setMaxElementsInMemory(
257                     usersCache.getMaxElementsInMemory() );
258                 save = true;
259             }
260             usersCache.setMaxElementsInMemory(
261                 redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory() );
262
263             if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() < 0 )
264             {
265                 redbackRuntimeConfiguration.getUsersCacheConfiguration().setMaxElementsOnDisk(
266                     usersCache.getMaxElementsOnDisk() );
267                 save = true;
268             }
269             usersCache.setMaxElementsOnDisk(
270                 redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() );
271
272             if ( save )
273             {
274                 updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
275             }
276
277         }
278         catch ( RepositoryAdminException e )
279         {
280             throw new UserConfigurationException( e.getMessage(), e );
281         }
282     }
283
284     private boolean isSunContextFactoryAvailable()
285     {
286         try
287         {
288             return Thread.currentThread().getContextClassLoader().loadClass( "com.sun.jndi.ldap.LdapCtxFactory" )
289                 != null;
290         }
291         catch ( ClassNotFoundException e )
292         {
293             return false;
294         }
295     }
296
297     @Override
298     public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration()
299     {
300         return build( archivaConfiguration.getConfiguration().getRedbackRuntimeConfiguration() );
301     }
302
303     @Override
304     public void updateRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration )
305         throws RepositoryAdminException
306     {
307         org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration =
308             build( redbackRuntimeConfiguration );
309         Configuration configuration = archivaConfiguration.getConfiguration();
310         configuration.setRedbackRuntimeConfiguration( runtimeConfiguration );
311         try
312         {
313             archivaConfiguration.save( configuration );
314         }
315         catch ( RegistryException e )
316         {
317             throw new RepositoryAdminException( e.getMessage(), e );
318         }
319         catch ( IndeterminateConfigurationException e )
320         {
321             throw new RepositoryAdminException( e.getMessage(), e );
322         }
323     }
324
325     private RedbackRuntimeConfiguration build(
326         org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration )
327     {
328         RedbackRuntimeConfiguration redbackRuntimeConfiguration =
329             getModelMapper().map( runtimeConfiguration, RedbackRuntimeConfiguration.class );
330
331         if ( runtimeConfiguration.getLdapConfiguration() != null )
332         {
333             redbackRuntimeConfiguration.setLdapConfiguration(
334                 getModelMapper().map( runtimeConfiguration.getLdapConfiguration(), LdapConfiguration.class ) );
335         }
336
337         if ( runtimeConfiguration.getUsersCacheConfiguration() != null )
338         {
339             redbackRuntimeConfiguration.setUsersCacheConfiguration(
340                 getModelMapper().map( runtimeConfiguration.getUsersCacheConfiguration(), CacheConfiguration.class ) );
341         }
342
343         if ( redbackRuntimeConfiguration.getLdapConfiguration() == null )
344         {
345             // prevent NPE
346             redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() );
347         }
348
349         if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
350         {
351             redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
352         }
353
354         List<org.apache.archiva.configuration.LdapGroupMapping> mappings = runtimeConfiguration.getLdapGroupMappings();
355
356         if ( mappings != null && mappings.size() > 0 )
357         {
358             List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>( mappings.size() );
359
360             for ( org.apache.archiva.configuration.LdapGroupMapping mapping : mappings )
361             {
362                 ldapGroupMappings.add( new LdapGroupMapping( mapping.getGroup(), mapping.getRoleNames() ) );
363             }
364
365             redbackRuntimeConfiguration.setLdapGroupMappings( ldapGroupMappings );
366         }
367
368         cleanupProperties( redbackRuntimeConfiguration );
369
370         return redbackRuntimeConfiguration;
371     }
372
373     /**
374      * cleaning from map properties used directly in archiva configuration fields
375      *
376      * @param redbackRuntimeConfiguration
377      */
378     private void cleanupProperties( RedbackRuntimeConfiguration redbackRuntimeConfiguration )
379     {
380         Map<String, String> properties = redbackRuntimeConfiguration.getConfigurationProperties();
381         properties.remove( UserConfigurationKeys.LDAP_HOSTNAME );
382         properties.remove( UserConfigurationKeys.LDAP_PORT );
383         properties.remove( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED );
384         properties.remove( UserConfigurationKeys.LDAP_SSL );
385         properties.remove( UserConfigurationKeys.LDAP_BASEDN );
386         properties.remove( UserConfigurationKeys.LDAP_GROUPS_BASEDN );
387         properties.remove( UserConfigurationKeys.LDAP_CONTEX_FACTORY );
388         properties.remove( UserConfigurationKeys.LDAP_BINDDN );
389         properties.remove( UserConfigurationKeys.LDAP_PASSWORD );
390         properties.remove( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD );
391         properties.remove( UserConfigurationKeys.LDAP_WRITABLE );
392         properties.remove( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME );
393
394         // cleanup groups <-> role mapping
395         /**for ( Map.Entry<String, String> entry : new HashMap<String, String>( properties ).entrySet() )
396          {
397          if ( entry.getKey().startsWith( UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
398          {
399          properties.remove( entry.getKey() );
400          }
401          }*/
402     }
403
404     private org.apache.archiva.configuration.RedbackRuntimeConfiguration build(
405         RedbackRuntimeConfiguration redbackRuntimeConfiguration )
406     {
407         org.apache.archiva.configuration.RedbackRuntimeConfiguration res =
408             getModelMapper().map( redbackRuntimeConfiguration,
409                                   org.apache.archiva.configuration.RedbackRuntimeConfiguration.class );
410
411         if ( redbackRuntimeConfiguration.getLdapConfiguration() == null )
412         {
413             redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() );
414         }
415         res.setLdapConfiguration( getModelMapper().map( redbackRuntimeConfiguration.getLdapConfiguration(),
416                                                         org.apache.archiva.configuration.LdapConfiguration.class ) );
417
418         if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
419         {
420             redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
421         }
422
423         res.setUsersCacheConfiguration( getModelMapper().map( redbackRuntimeConfiguration.getUsersCacheConfiguration(),
424                                                               org.apache.archiva.configuration.CacheConfiguration.class ) );
425
426         List<LdapGroupMapping> ldapGroupMappings = redbackRuntimeConfiguration.getLdapGroupMappings();
427
428         if ( ldapGroupMappings != null && ldapGroupMappings.size() > 0 )
429         {
430
431             List<org.apache.archiva.configuration.LdapGroupMapping> mappings =
432                 new ArrayList<>( ldapGroupMappings.size() );
433
434             for ( LdapGroupMapping ldapGroupMapping : ldapGroupMappings )
435             {
436
437                 org.apache.archiva.configuration.LdapGroupMapping mapping =
438                     new org.apache.archiva.configuration.LdapGroupMapping();
439                 mapping.setGroup( ldapGroupMapping.getGroup() );
440                 mapping.setRoleNames( new ArrayList<>( ldapGroupMapping.getRoleNames() ) );
441                 mappings.add( mapping );
442
443             }
444             res.setLdapGroupMappings( mappings );
445         }
446         return res;
447     }
448
449     // wrapper for UserConfiguration to intercept values (and store it not yet migrated)
450
451
452     @Override
453     public String getString( String key )
454     {
455         if ( UserConfigurationKeys.USER_MANAGER_IMPL.equals( key ) )
456         {
457             // possible false for others than archiva user manager
458             return getRedbackRuntimeConfiguration().getUserManagerImpls().get( 0 );
459         }
460
461         if ( StringUtils.startsWith( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
462         {
463             RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration();
464             int index = redbackRuntimeConfiguration.getLdapGroupMappings().indexOf( new LdapGroupMapping(
465                 StringUtils.substringAfter( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) ) );
466             if ( index > -1 )
467             {
468                 return StringUtils.join( redbackRuntimeConfiguration.getLdapGroupMappings().get( index ).getRoleNames(),
469                                          ',' );
470             }
471         }
472
473         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
474
475         if ( conf.getConfigurationProperties().containsKey( key ) )
476         {
477             return conf.getConfigurationProperties().get( key );
478         }
479
480         String value = userConfiguration.getString( key );
481         if ( value == null )
482         {
483             return null;
484         }
485         conf.getConfigurationProperties().put( key, value );
486
487         try
488         {
489             updateRedbackRuntimeConfiguration( conf );
490         }
491         catch ( RepositoryAdminException e )
492         {
493             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
494             throw new RuntimeException( e.getMessage(), e );
495         }
496
497         return value;
498     }
499
500     @Override
501     public String getString( String key, String defaultValue )
502     {
503         if ( UserConfigurationKeys.LDAP_HOSTNAME.equals( key ) )
504         {
505             return getRedbackRuntimeConfiguration().getLdapConfiguration().getHostName();
506         }
507         if ( UserConfigurationKeys.LDAP_CONTEX_FACTORY.equals( key ) )
508         {
509             return getRedbackRuntimeConfiguration().getLdapConfiguration().getContextFactory();
510         }
511         if ( UserConfigurationKeys.LDAP_PASSWORD.equals( key ) )
512         {
513             return getRedbackRuntimeConfiguration().getLdapConfiguration().getPassword();
514         }
515         if ( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD.equals( key ) )
516         {
517             return getRedbackRuntimeConfiguration().getLdapConfiguration().getAuthenticationMethod();
518         }
519
520         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
521
522         if ( conf.getConfigurationProperties().containsKey( key ) )
523         {
524             return conf.getConfigurationProperties().get( key );
525         }
526
527         String value = userConfiguration.getString( key, defaultValue );
528
529         if ( value == null )
530         {
531             return null;
532         }
533
534         conf.getConfigurationProperties().put( key, value );
535         try
536         {
537             updateRedbackRuntimeConfiguration( conf );
538         }
539         catch ( RepositoryAdminException e )
540         {
541             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
542             throw new RuntimeException( e.getMessage(), e );
543         }
544
545         return value;
546     }
547
548     @Override
549     public int getInt( String key )
550     {
551         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
552
553         if ( conf.getConfigurationProperties().containsKey( key ) )
554         {
555             return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
556         }
557
558         int value = userConfiguration.getInt( key );
559
560         conf.getConfigurationProperties().put( key, Integer.toString( value ) );
561         try
562         {
563             updateRedbackRuntimeConfiguration( conf );
564         }
565         catch ( RepositoryAdminException e )
566         {
567             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
568             throw new RuntimeException( e.getMessage(), e );
569         }
570
571         return value;
572     }
573
574     @Override
575     public int getInt( String key, int defaultValue )
576     {
577         if ( UserConfigurationKeys.LDAP_PORT.equals( key ) )
578         {
579             return getRedbackRuntimeConfiguration().getLdapConfiguration().getPort();
580         }
581
582         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
583
584         if ( conf.getConfigurationProperties().containsKey( key ) )
585         {
586             return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
587         }
588
589         int value = userConfiguration.getInt( key, defaultValue );
590
591         conf.getConfigurationProperties().put( key, Integer.toString( value ) );
592         try
593         {
594             updateRedbackRuntimeConfiguration( conf );
595         }
596         catch ( RepositoryAdminException e )
597         {
598             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
599             throw new RuntimeException( e.getMessage(), e );
600         }
601
602         return value;
603     }
604
605     @Override
606     public boolean getBoolean( String key )
607     {
608         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
609
610         if ( UserConfigurationKeys.LDAP_WRITABLE.equals( key ) )
611         {
612             return conf.getLdapConfiguration().isWritable();
613         }
614
615         if ( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME.equals( key ) )
616         {
617             return conf.getLdapConfiguration().isUseRoleNameAsGroup();
618         }
619
620         if ( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED.equals( key ) )
621         {
622             return conf.getLdapConfiguration().isBindAuthenticatorEnabled();
623         }
624
625         if ( conf.getConfigurationProperties().containsKey( key ) )
626         {
627             return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
628         }
629
630         boolean value = userConfiguration.getBoolean( key );
631
632         conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
633         try
634         {
635             updateRedbackRuntimeConfiguration( conf );
636         }
637         catch ( RepositoryAdminException e )
638         {
639             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
640             throw new RuntimeException( e.getMessage(), e );
641         }
642
643         return value;
644     }
645
646     @Override
647     public boolean getBoolean( String key, boolean defaultValue )
648     {
649         if ( UserConfigurationKeys.LDAP_SSL.equals( key ) )
650         {
651             return getRedbackRuntimeConfiguration().getLdapConfiguration().isSsl();
652         }
653
654         if ( UserConfigurationKeys.LDAP_WRITABLE.equals( key ) )
655         {
656             return getRedbackRuntimeConfiguration().getLdapConfiguration().isWritable();
657         }
658
659         if ( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME.equals( key ) )
660         {
661             return getRedbackRuntimeConfiguration().getLdapConfiguration().isUseRoleNameAsGroup();
662         }
663
664         if ( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED.equals( key ) )
665         {
666             return getRedbackRuntimeConfiguration().getLdapConfiguration().isBindAuthenticatorEnabled();
667         }
668
669         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
670
671         if ( conf.getConfigurationProperties().containsKey( key ) )
672         {
673             return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
674         }
675
676         boolean value = userConfiguration.getBoolean( key, defaultValue );
677
678         conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
679         try
680         {
681             updateRedbackRuntimeConfiguration( conf );
682         }
683         catch ( RepositoryAdminException e )
684         {
685             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
686             throw new RuntimeException( e.getMessage(), e );
687         }
688
689         return value;
690     }
691
692     @Override
693     public List<String> getList( String key )
694     {
695         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
696         if (conf.getConfigurationProperties().containsKey(key)) {
697             return Arrays.asList(conf.getConfigurationProperties().get(key).split(","));
698         }
699
700         List<String> value = userConfiguration.getList( key );
701
702         conf.getConfigurationProperties().put( key, "" );
703         try
704         {
705             updateRedbackRuntimeConfiguration( conf );
706         }
707         catch ( RepositoryAdminException e )
708         {
709             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
710             throw new RuntimeException( e.getMessage(), e );
711         }
712
713         return value;
714     }
715
716     @Override
717     public String getConcatenatedList( String key, String defaultValue )
718     {
719         if ( UserConfigurationKeys.LDAP_BASEDN.equals( key ) )
720         {
721             return getRedbackRuntimeConfiguration().getLdapConfiguration().getBaseDn();
722         }
723         if ( UserConfigurationKeys.LDAP_BINDDN.equals( key ) )
724         {
725             return getRedbackRuntimeConfiguration().getLdapConfiguration().getBindDn();
726         }
727         if ( UserConfigurationKeys.LDAP_GROUPS_BASEDN.equals( key ) )
728         {
729             return getRedbackRuntimeConfiguration().getLdapConfiguration().getBaseGroupsDn();
730         }
731         return userConfiguration.getConcatenatedList( key, defaultValue );
732     }
733
734     @Override
735     public Collection<String> getKeys()
736     {
737         Collection<String> keys = userConfiguration.getKeys();
738
739         Set<String> keysSet = new HashSet<>( keys );
740
741         keysSet.addAll( getRedbackRuntimeConfiguration().getConfigurationProperties().keySet() );
742
743         return keysSet;
744     }
745
746
747 }