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