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.client.enduser;
20  
21  import com.giffing.wicket.spring.boot.starter.web.config.WicketWebInitializerAutoConfig.WebSocketWicketWebInitializerAutoConfiguration;
22  import java.util.List;
23  import java.util.Map;
24  import org.apache.syncope.client.enduser.init.ClassPathScanImplementationLookup;
25  import org.apache.syncope.client.ui.commons.actuate.SyncopeCoreHealthIndicator;
26  import org.apache.syncope.common.keymaster.client.api.ServiceOps;
27  import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
28  import org.apache.syncope.common.keymaster.client.api.startstop.KeymasterStart;
29  import org.apache.syncope.common.keymaster.client.api.startstop.KeymasterStop;
30  import org.apache.wicket.request.resource.IResource;
31  import org.springframework.boot.autoconfigure.SpringBootApplication;
32  import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
33  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
34  import org.springframework.boot.builder.SpringApplicationBuilder;
35  import org.springframework.boot.context.properties.EnableConfigurationProperties;
36  import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
37  import org.springframework.context.annotation.Bean;
38  import org.springframework.core.io.ResourceLoader;
39  
40  @SpringBootApplication(proxyBeanMethods = false)
41  @EnableConfigurationProperties(EnduserProperties.class)
42  public class SyncopeEnduserApplication extends SpringBootServletInitializer {
43  
44      public static void main(final String[] args) {
45          new SpringApplicationBuilder(SyncopeEnduserApplication.class).
46                  properties("spring.config.name:enduser").
47                  build().run(args);
48      }
49  
50      @Override
51      protected SpringApplicationBuilder configure(final SpringApplicationBuilder builder) {
52          return builder.properties(Map.of(
53                  WebSocketWicketWebInitializerAutoConfiguration.REGISTER_SERVER_ENDPOINT_ENABLED, false,
54                  "spring.config.name", "enduser")).
55                  sources(SyncopeEnduserApplication.class);
56      }
57  
58      @ConditionalOnMissingBean
59      @Bean
60      public SyncopeWebApplication syncopeWebApplication(
61              final ResourceLoader resourceLoader,
62              final EnduserProperties props,
63              final ClassPathScanImplementationLookup lookup,
64              final ServiceOps serviceOps,
65              final List<IResource> resources) {
66  
67          return new SyncopeWebApplication(resourceLoader, props, lookup, serviceOps, resources);
68      }
69  
70      @ConditionalOnMissingBean
71      @Bean
72      public SyncopeCoreHealthIndicator syncopeCoreHealthIndicator(
73              final ServiceOps serviceOps, final EnduserProperties props) {
74  
75          return new SyncopeCoreHealthIndicator(
76                  serviceOps,
77                  props.getAnonymousUser(),
78                  props.getAnonymousKey(),
79                  props.isUseGZIPCompression());
80      }
81  
82      @ConditionalOnProperty(
83              prefix = "keymaster", name = "enableAutoRegistration", havingValue = "true", matchIfMissing = true)
84      @Bean
85      public KeymasterStart keymasterStart() {
86          return new KeymasterStart(NetworkService.Type.ENDUSER);
87      }
88  
89      @ConditionalOnProperty(
90              prefix = "keymaster", name = "enableAutoRegistration", havingValue = "true", matchIfMissing = true)
91      @Bean
92      public KeymasterStop keymasterStop() {
93          return new KeymasterStop(NetworkService.Type.ENDUSER);
94      }
95  }