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