]> source.dussan.org Git - archiva.git/blob
37ffe0aa816103447f852d3ec815760e083dfed7
[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 redbackRuntimeConfiguration )
379     {
380         org.apache.archiva.configuration.RedbackRuntimeConfiguration res =
381             new BeanReplicator().replicateBean( redbackRuntimeConfiguration,
382                                                 org.apache.archiva.configuration.RedbackRuntimeConfiguration.class );
383
384         if ( redbackRuntimeConfiguration.getLdapConfiguration() == null )
385         {
386             redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() );
387         }
388         res.setLdapConfiguration(
389             new BeanReplicator().replicateBean( redbackRuntimeConfiguration.getLdapConfiguration(),
390                                                 org.apache.archiva.configuration.LdapConfiguration.class ) );
391
392         if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
393         {
394             redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
395         }
396
397
398         res.setUsersCacheConfiguration(
399             new BeanReplicator().replicateBean( redbackRuntimeConfiguration.getUsersCacheConfiguration(),
400                                                 org.apache.archiva.configuration.CacheConfiguration.class ) );
401
402         List<LdapGroupMapping> ldapGroupMappings = redbackRuntimeConfiguration.getLdapGroupMappings();
403
404         if ( ldapGroupMappings != null && ldapGroupMappings.size() > 0 )
405         {
406
407             List<org.apache.archiva.configuration.LdapGroupMapping> mappings =
408                 new ArrayList<org.apache.archiva.configuration.LdapGroupMapping>( ldapGroupMappings.size() );
409
410             for ( LdapGroupMapping ldapGroupMapping : ldapGroupMappings )
411             {
412
413                 org.apache.archiva.configuration.LdapGroupMapping mapping =
414                     new org.apache.archiva.configuration.LdapGroupMapping();
415                 mapping.setGroup( ldapGroupMapping.getGroup() );
416                 mapping.setRoleNames( new ArrayList<String>( ldapGroupMapping.getRoleNames() ) );
417                 mappings.add( mapping );
418
419             }
420             res.setLdapGroupMappings( mappings );
421         }
422         return res;
423     }
424
425     // wrapper for UserConfiguration to intercept values (and store it not yet migrated)
426
427
428     public String getString( String key )
429     {
430         if ( UserConfigurationKeys.USER_MANAGER_IMPL.equals( key ) )
431         {
432             // possible false for others than archiva user manager
433             return getRedbackRuntimeConfiguration().getUserManagerImpls().get( 0 );
434         }
435
436         if ( StringUtils.startsWith( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
437         {
438             RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration();
439             int index = redbackRuntimeConfiguration.getLdapGroupMappings().indexOf( new LdapGroupMapping(
440                 StringUtils.substringAfter( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) ) );
441             if ( index > -1 )
442             {
443                 return StringUtils.join( redbackRuntimeConfiguration.getLdapGroupMappings().get( index ).getRoleNames(),
444                                          ',' );
445             }
446         }
447
448         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
449
450         if ( conf.getConfigurationProperties().containsKey( key ) )
451         {
452             return conf.getConfigurationProperties().get( key );
453         }
454
455         String value = userConfiguration.getString( key );
456         if ( value == null )
457         {
458             return null;
459         }
460         conf.getConfigurationProperties().put( key, value );
461
462         try
463         {
464             updateRedbackRuntimeConfiguration( conf );
465         }
466         catch ( RepositoryAdminException e )
467         {
468             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
469             throw new RuntimeException( e.getMessage(), e );
470         }
471
472         return value;
473     }
474
475     public String getString( String key, String defaultValue )
476     {
477         if ( UserConfigurationKeys.LDAP_HOSTNAME.equals( key ) )
478         {
479             return getRedbackRuntimeConfiguration().getLdapConfiguration().getHostName();
480         }
481         if ( UserConfigurationKeys.LDAP_CONTEX_FACTORY.equals( key ) )
482         {
483             return getRedbackRuntimeConfiguration().getLdapConfiguration().getContextFactory();
484         }
485         if ( UserConfigurationKeys.LDAP_PASSWORD.equals( key ) )
486         {
487             return getRedbackRuntimeConfiguration().getLdapConfiguration().getPassword();
488         }
489         if ( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD.equals( key ) )
490         {
491             return getRedbackRuntimeConfiguration().getLdapConfiguration().getAuthenticationMethod();
492         }
493
494         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
495
496         if ( conf.getConfigurationProperties().containsKey( key ) )
497         {
498             return conf.getConfigurationProperties().get( key );
499         }
500
501         String value = userConfiguration.getString( key, defaultValue );
502
503         if ( value == null )
504         {
505             return null;
506         }
507
508         conf.getConfigurationProperties().put( key, value );
509         try
510         {
511             updateRedbackRuntimeConfiguration( conf );
512         }
513         catch ( RepositoryAdminException e )
514         {
515             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
516             throw new RuntimeException( e.getMessage(), e );
517         }
518
519         return value;
520     }
521
522     public int getInt( String key )
523     {
524         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
525
526         if ( conf.getConfigurationProperties().containsKey( key ) )
527         {
528             return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
529         }
530
531         int value = userConfiguration.getInt( key );
532
533         conf.getConfigurationProperties().put( key, Integer.toString( value ) );
534         try
535         {
536             updateRedbackRuntimeConfiguration( conf );
537         }
538         catch ( RepositoryAdminException e )
539         {
540             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
541             throw new RuntimeException( e.getMessage(), e );
542         }
543
544         return value;
545     }
546
547     public int getInt( String key, int defaultValue )
548     {
549         if ( UserConfigurationKeys.LDAP_PORT.equals( key ) )
550         {
551             return getRedbackRuntimeConfiguration().getLdapConfiguration().getPort();
552         }
553
554         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
555
556         if ( conf.getConfigurationProperties().containsKey( key ) )
557         {
558             return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
559         }
560
561         int value = userConfiguration.getInt( key, defaultValue );
562
563         conf.getConfigurationProperties().put( key, Integer.toString( value ) );
564         try
565         {
566             updateRedbackRuntimeConfiguration( conf );
567         }
568         catch ( RepositoryAdminException e )
569         {
570             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
571             throw new RuntimeException( e.getMessage(), e );
572         }
573
574         return value;
575     }
576
577     public boolean getBoolean( String key )
578     {
579         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
580
581         if ( UserConfigurationKeys.LDAP_WRITABLE.equals( key ) )
582         {
583             return conf.getLdapConfiguration().isWritable();
584         }
585
586         if ( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME.equals( key ) )
587         {
588             return conf.getLdapConfiguration().isUseRoleNameAsGroup();
589         }
590
591         if ( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED.equals( key ) )
592         {
593             return conf.getLdapConfiguration().isBindAuthenticatorEnabled();
594         }
595
596         if ( conf.getConfigurationProperties().containsKey( key ) )
597         {
598             return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
599         }
600
601         boolean value = userConfiguration.getBoolean( key );
602
603         conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
604         try
605         {
606             updateRedbackRuntimeConfiguration( conf );
607         }
608         catch ( RepositoryAdminException e )
609         {
610             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
611             throw new RuntimeException( e.getMessage(), e );
612         }
613
614         return value;
615     }
616
617     public boolean getBoolean( String key, boolean defaultValue )
618     {
619         if ( UserConfigurationKeys.LDAP_SSL.equals( key ) )
620         {
621             return getRedbackRuntimeConfiguration().getLdapConfiguration().isSsl();
622         }
623
624         if ( UserConfigurationKeys.LDAP_WRITABLE.equals( key ) )
625         {
626             return getRedbackRuntimeConfiguration().getLdapConfiguration().isWritable();
627         }
628
629         if ( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME.equals( key ) )
630         {
631             return getRedbackRuntimeConfiguration().getLdapConfiguration().isUseRoleNameAsGroup();
632         }
633
634         if ( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED.equals( key ) )
635         {
636             return getRedbackRuntimeConfiguration().getLdapConfiguration().isBindAuthenticatorEnabled();
637         }
638
639         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
640
641         if ( conf.getConfigurationProperties().containsKey( key ) )
642         {
643             return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
644         }
645
646         boolean value = userConfiguration.getBoolean( key, defaultValue );
647
648         conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
649         try
650         {
651             updateRedbackRuntimeConfiguration( conf );
652         }
653         catch ( RepositoryAdminException e )
654         {
655             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
656             throw new RuntimeException( e.getMessage(), e );
657         }
658
659         return value;
660     }
661
662     public List<String> getList( String key )
663     {
664         List<String> value = userConfiguration.getList( key );
665
666         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
667         // TODO concat values
668         conf.getConfigurationProperties().put( key, "" );
669         try
670         {
671             updateRedbackRuntimeConfiguration( conf );
672         }
673         catch ( RepositoryAdminException e )
674         {
675             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
676             throw new RuntimeException( e.getMessage(), e );
677         }
678
679         return value;
680     }
681
682     public String getConcatenatedList( String key, String defaultValue )
683     {
684         if ( UserConfigurationKeys.LDAP_BASEDN.equals( key ) )
685         {
686             return getRedbackRuntimeConfiguration().getLdapConfiguration().getBaseDn();
687         }
688         if ( UserConfigurationKeys.LDAP_BINDDN.equals( key ) )
689         {
690             return getRedbackRuntimeConfiguration().getLdapConfiguration().getBindDn();
691         }
692         if ( UserConfigurationKeys.LDAP_GROUPS_BASEDN.equals( key ) )
693         {
694             return getRedbackRuntimeConfiguration().getLdapConfiguration().getBaseGroupsDn();
695         }
696         return userConfiguration.getConcatenatedList( key, defaultValue );
697     }
698
699     public Collection<String> getKeys()
700     {
701         Collection<String> keys = userConfiguration.getKeys();
702
703         Set<String> keysSet = new HashSet<String>( keys );
704
705         keysSet.addAll( getRedbackRuntimeConfiguration().getConfigurationProperties().keySet() );
706
707         return keysSet;
708     }
709
710
711 }