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