View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.wa.bootstrap;
20  
21  import org.apache.syncope.wa.bootstrap.mapping.AttrReleaseMapper;
22  import org.apache.syncope.wa.bootstrap.mapping.AttrRepoPropertySourceMapper;
23  import org.apache.syncope.wa.bootstrap.mapping.AuthModulePropertySourceMapper;
24  import org.apache.syncope.wa.bootstrap.mapping.DefaultAttrReleaseMapper;
25  import org.apereo.cas.configuration.support.CasConfigurationJasyptCipherExecutor;
26  import org.apereo.cas.util.crypto.CipherExecutor;
27  import org.springframework.beans.factory.annotation.Qualifier;
28  import org.springframework.beans.factory.annotation.Value;
29  import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
30  import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
31  import org.springframework.context.annotation.Bean;
32  import org.springframework.context.annotation.Configuration;
33  import org.springframework.context.annotation.PropertySource;
34  import org.springframework.core.env.Environment;
35  
36  @Configuration(proxyBeanMethods = false)
37  @PropertySource("classpath:wa.properties")
38  @PropertySource(value = "file:${syncope.conf.dir}/wa.properties", ignoreResourceNotFound = true)
39  public class WABootstrapConfiguration {
40  
41      @Configuration(proxyBeanMethods = false)
42      public static class WAClientConfiguration {
43  
44          @Value("${wa.anonymousUser}")
45          private String anonymousUser;
46  
47          @Value("${wa.anonymousKey}")
48          private String anonymousKey;
49  
50          @Value("${wa.useGZIPCompression:true}")
51          private boolean useGZIPCompression;
52  
53          @Value("${service.discovery.address}")
54          private String serviceDiscoveryAddress;
55  
56          @Bean
57          public WARestClient waRestClient() {
58              return new WARestClient(anonymousUser, anonymousKey, useGZIPCompression, serviceDiscoveryAddress);
59          }
60      }
61  
62      @Configuration(proxyBeanMethods = false)
63      public static class PropertySourceConfiguration {
64  
65          @ConditionalOnMissingBean(name = "waConfigurationCipher")
66          @Bean
67          public CipherExecutor<String, String> waConfigurationCipher(final Environment environment) {
68              return new CasConfigurationJasyptCipherExecutor(environment);
69          }
70  
71          @ConditionalOnMissingBean
72          @Bean
73          public AuthModulePropertySourceMapper authModulePropertySourceMapper(final WARestClient waRestClient) {
74              return new AuthModulePropertySourceMapper(waRestClient);
75          }
76  
77          @ConditionalOnMissingBean
78          @Bean
79          public AttrRepoPropertySourceMapper attrRepoPropertySourceMapper(final WARestClient waRestClient) {
80              return new AttrRepoPropertySourceMapper(waRestClient);
81          }
82  
83          @ConditionalOnMissingBean
84          @Bean
85          public AttrReleaseMapper attrReleaseMapper() {
86              return new DefaultAttrReleaseMapper();
87          }
88  
89          @Bean
90          public PropertySourceLocator configPropertySourceLocator(
91                  @Qualifier("waConfigurationCipher")
92                  final CipherExecutor<String, String> waConfigurationCipher,
93                  final WARestClient waRestClient,
94                  final AuthModulePropertySourceMapper authModulePropertySourceMapper,
95                  final AttrRepoPropertySourceMapper attrRepoPropertySourceMapper,
96                  final AttrReleaseMapper attrReleaseMapper) {
97  
98              return new WAPropertySourceLocator(
99                      waRestClient,
100                     authModulePropertySourceMapper,
101                     attrRepoPropertySourceMapper,
102                     attrReleaseMapper,
103                     waConfigurationCipher);
104         }
105     }
106 }