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