]> source.dussan.org Git - archiva.git/blob
1ed25d946ec5ba9a0c2e7a1d30f6a88565aafed5
[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
428     private org.apache.archiva.configuration.RedbackRuntimeConfiguration build(
429         RedbackRuntimeConfiguration redbackRuntimeConfiguration )
430     {
431         org.apache.archiva.configuration.RedbackRuntimeConfiguration res =
432             getModelMapper().map( redbackRuntimeConfiguration,
433                                   org.apache.archiva.configuration.RedbackRuntimeConfiguration.class );
434
435         if ( redbackRuntimeConfiguration.getLdapConfiguration() == null )
436         {
437             redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() );
438         }
439         res.setLdapConfiguration( getModelMapper().map( redbackRuntimeConfiguration.getLdapConfiguration(),
440                                                         org.apache.archiva.configuration.LdapConfiguration.class ) );
441
442         if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
443         {
444             redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
445         }
446
447         res.setUsersCacheConfiguration( getModelMapper().map( redbackRuntimeConfiguration.getUsersCacheConfiguration(),
448                                                               org.apache.archiva.configuration.CacheConfiguration.class ) );
449
450         List<LdapGroupMapping> ldapGroupMappings = redbackRuntimeConfiguration.getLdapGroupMappings();
451
452         if ( ldapGroupMappings != null && ldapGroupMappings.size() > 0 )
453         {
454
455             List<org.apache.archiva.configuration.LdapGroupMapping> mappings =
456                 new ArrayList<>( ldapGroupMappings.size() );
457
458             for ( LdapGroupMapping ldapGroupMapping : ldapGroupMappings )
459             {
460
461                 org.apache.archiva.configuration.LdapGroupMapping mapping =
462                     new org.apache.archiva.configuration.LdapGroupMapping();
463                 mapping.setGroup( ldapGroupMapping.getGroup() );
464                 mapping.setRoleNames( new ArrayList<>( ldapGroupMapping.getRoleNames() ) );
465                 mappings.add( mapping );
466
467             }
468             res.setLdapGroupMappings( mappings );
469         }
470         return res;
471     }
472
473     // wrapper for UserConfiguration to intercept values (and store it not yet migrated)
474
475
476     @Override
477     public String getString( String key )
478     {
479         final RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
480         if (LDAP_MAPPER.isStringMapping( key )) {
481             final LdapConfiguration ldapConf = conf.getLdapConfiguration( );
482             return LDAP_MAPPER.getString( key, ldapConf );
483         }
484         if (LDAP_MAPPER.isPrefixMapping( key )) {
485             return LDAP_MAPPER.getPrefixString( key, conf.getLdapGroupMappings( ) );
486         }
487         if (conf.getLdapConfiguration().getExtraProperties().containsKey( key )) {
488             return conf.getLdapConfiguration( ).getExtraProperties( ).get( key );
489         }
490
491         if ( USER_MANAGER_IMPL.equals( key ) )
492         {
493             // possible false for others than archiva user manager
494             return conf.getUserManagerImpls().get( 0 );
495         }
496
497         if ( conf.getConfigurationProperties().containsKey( key ) )
498         {
499             return conf.getConfigurationProperties().get( key );
500         }
501
502         String value = userConfiguration.getString( key );
503         if ( value == null )
504         {
505             return null;
506         }
507         conf.getConfigurationProperties().put( key, value );
508
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     @Override
523     public String getString( String key, String defaultValue )
524     {
525         final RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
526         if (LDAP_MAPPER.isStringMapping( key )) {
527             final LdapConfiguration ldapConf = conf.getLdapConfiguration( );
528             return LDAP_MAPPER.getString( key, ldapConf );
529         }
530         if (LDAP_MAPPER.isPrefixMapping( key )) {
531             return LDAP_MAPPER.getPrefixString( key, conf.getLdapGroupMappings( ) );
532         }
533         if (conf.getLdapConfiguration().getExtraProperties().containsKey( key )) {
534             return conf.getLdapConfiguration( ).getExtraProperties( ).get( key );
535         }
536
537         if ( conf.getConfigurationProperties().containsKey( key ) )
538         {
539             return conf.getConfigurationProperties().get( key );
540         }
541
542         String value = userConfiguration.getString( key, defaultValue );
543
544         if ( value == null )
545         {
546             return null;
547         }
548
549         conf.getConfigurationProperties().put( key, value );
550         try
551         {
552             updateRedbackRuntimeConfiguration( conf );
553         }
554         catch ( RepositoryAdminException e )
555         {
556             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
557             throw new RuntimeException( e.getMessage(), e );
558         }
559
560         return value;
561     }
562
563     @Override
564     public int getInt( String key )
565     {
566         final RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
567         if (LDAP_MAPPER.isIntMapping( key )) {
568             return LDAP_MAPPER.getInt( key, conf.getLdapConfiguration( ) );
569         }
570
571         if ( conf.getConfigurationProperties().containsKey( key ) )
572         {
573             return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
574         }
575
576         int value = userConfiguration.getInt( key );
577
578         conf.getConfigurationProperties().put( key, Integer.toString( value ) );
579         try
580         {
581             updateRedbackRuntimeConfiguration( conf );
582         }
583         catch ( RepositoryAdminException e )
584         {
585             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
586             throw new RuntimeException( e.getMessage(), e );
587         }
588
589         return value;
590     }
591
592     @Override
593     public int getInt( String key, int defaultValue )
594     {
595         final RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
596         if (LDAP_MAPPER.isIntMapping( key )) {
597             return LDAP_MAPPER.getInt( key, conf.getLdapConfiguration( ) );
598         }
599
600         if ( conf.getConfigurationProperties().containsKey( key ) )
601         {
602             return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
603         }
604
605         int value = userConfiguration.getInt( key, defaultValue );
606
607         conf.getConfigurationProperties().put( key, Integer.toString( value ) );
608         try
609         {
610             updateRedbackRuntimeConfiguration( conf );
611         }
612         catch ( RepositoryAdminException e )
613         {
614             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
615             throw new RuntimeException( e.getMessage(), e );
616         }
617
618         return value;
619     }
620
621     @Override
622     public boolean getBoolean( String key )
623     {
624         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
625         if (LDAP_MAPPER.isBooleanMapping( key )) {
626             return LDAP_MAPPER.getBoolean( key, conf.getLdapConfiguration( ) );
627         }
628
629         if ( conf.getConfigurationProperties().containsKey( key ) )
630         {
631             return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
632         }
633
634         boolean value = userConfiguration.getBoolean( key );
635
636         conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
637         try
638         {
639             updateRedbackRuntimeConfiguration( conf );
640         }
641         catch ( RepositoryAdminException e )
642         {
643             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
644             throw new RuntimeException( e.getMessage(), e );
645         }
646
647         return value;
648     }
649
650     @Override
651     public boolean getBoolean( String key, boolean defaultValue )
652     {
653         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
654         if (LDAP_MAPPER.isBooleanMapping( key )) {
655             return LDAP_MAPPER.getBoolean( key, conf.getLdapConfiguration( ) );
656         }
657
658         if ( conf.getConfigurationProperties().containsKey( key ) )
659         {
660             return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
661         }
662
663         boolean value = userConfiguration.getBoolean( key, defaultValue );
664
665         conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
666         try
667         {
668             updateRedbackRuntimeConfiguration( conf );
669         }
670         catch ( RepositoryAdminException e )
671         {
672             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
673             throw new RuntimeException( e.getMessage(), e );
674         }
675
676         return value;
677     }
678
679     @Override
680     public List<String> getList( String key )
681     {
682         RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();
683         if (conf.getConfigurationProperties().containsKey(key)) {
684             return Arrays.asList(conf.getConfigurationProperties().get(key).split(","));
685         }
686
687         List<String> value = userConfiguration.getList( key );
688
689         conf.getConfigurationProperties().put( key, "" );
690         try
691         {
692             updateRedbackRuntimeConfiguration( conf );
693         }
694         catch ( RepositoryAdminException e )
695         {
696             log.error( "fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e );
697             throw new RuntimeException( e.getMessage(), e );
698         }
699
700         return value;
701     }
702
703     @Override
704     public String getConcatenatedList( String key, String defaultValue )
705     {
706         if (LDAP_MAPPER.isStringMapping( key )) {
707             return LDAP_MAPPER.getString( key,  getRedbackRuntimeConfiguration().getLdapConfiguration());
708         }
709         return userConfiguration.getConcatenatedList( key, defaultValue );
710     }
711
712     @Override
713     public Collection<String> getKeys()
714     {
715         Collection<String> keys = userConfiguration.getKeys();
716
717         Set<String> keysSet = new HashSet<>( keys );
718
719         keysSet.addAll( getRedbackRuntimeConfiguration().getConfigurationProperties().keySet() );
720
721         return keysSet;
722     }
723
724
725 }