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.mapping;
20  
21  import java.util.Map;
22  import java.util.Optional;
23  import java.util.stream.Collectors;
24  import org.apache.commons.lang3.tuple.Pair;
25  import org.apache.syncope.common.lib.AbstractJDBCConf;
26  import org.apache.syncope.common.lib.AbstractLDAPConf;
27  import org.apache.syncope.common.lib.AbstractLDAPConf.LdapTrustManager;
28  import org.apereo.cas.configuration.model.support.ConnectionPoolingProperties;
29  import org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties;
30  import org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties.LdapConnectionPoolPassivator;
31  import org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties.LdapHostnameVerifierOptions;
32  import org.apereo.cas.configuration.model.support.ldap.AbstractLdapSearchProperties;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  public abstract class PropertySourceMapper {
37  
38      protected static final Logger LOG = LoggerFactory.getLogger(PropertySourceMapper.class);
39  
40      protected static Map<String, Object> prefix(final String prefix, final Map<String, Object> map) {
41          return map.entrySet().stream().
42                  map(e -> Pair.of(prefix + e.getKey(), e.getValue())).
43                  collect(Collectors.toMap(Pair::getKey, Pair::getValue));
44      }
45  
46      protected void fill(final AbstractLdapSearchProperties props, final AbstractLDAPConf conf) {
47          props.setLdapUrl(conf.getLdapUrl());
48          props.setBaseDn(conf.getBaseDn());
49          props.setSearchFilter(conf.getSearchFilter());
50          props.setSubtreeSearch(conf.isSubtreeSearch());
51          props.setPageSize(conf.getPageSize());
52          props.setBindDn(conf.getBindDn());
53          props.setBindCredential(conf.getBindCredential());
54          props.setDisablePooling(conf.isDisablePooling());
55          props.setMinPoolSize(conf.getMinPoolSize());
56          props.setMaxPoolSize(conf.getMaxPoolSize());
57          props.setPoolPassivator(LdapConnectionPoolPassivator.valueOf(conf.getPoolPassivator().name()).name());
58          props.setHostnameVerifier(LdapHostnameVerifierOptions.valueOf(conf.getHostnameVerifier().name()));
59          props.setTrustManager(Optional.ofNullable(conf.getTrustManager()).map(LdapTrustManager::name).orElse(null));
60          props.setValidateOnCheckout(conf.isValidateOnCheckout());
61          props.setValidatePeriodically(conf.isValidatePeriodically());
62          props.setValidateTimeout(conf.getValidateTimeout().toString());
63          props.setValidatePeriod(conf.getValidatePeriod().toString());
64          props.setFailFast(conf.isFailFast());
65          props.setIdleTime(conf.getIdleTime().toString());
66          props.setPrunePeriod(conf.getPrunePeriod().toString());
67          props.setBlockWaitTime(conf.getBlockWaitTime().toString());
68          props.setUseStartTls(conf.isUseStartTls());
69          props.setConnectTimeout(conf.getConnectTimeout().toString());
70          props.setResponseTimeout(conf.getResponseTimeout().toString());
71          props.setAllowMultipleDns(conf.isAllowMultipleDns());
72          props.setAllowMultipleEntries(conf.isAllowMultipleEntries());
73          props.setFollowReferrals(conf.isFollowReferrals());
74          props.setBinaryAttributes(conf.getBinaryAttributes());
75      }
76  
77      protected void fill(final AbstractJpaProperties props, final AbstractJDBCConf conf) {
78          props.setDialect(conf.getDialect());
79          props.setDriverClass(conf.getDriverClass());
80          props.setUrl(conf.getUrl());
81          props.setUser(conf.getUser());
82          props.setPassword(conf.getPassword());
83          props.setDefaultCatalog(conf.getDefaultCatalog());
84          props.setDefaultSchema(conf.getDefaultSchema());
85          props.setHealthQuery(conf.getHealthQuery());
86          props.setIdleTimeout(conf.getIdleTimeout().toString());
87          props.setDataSourceName(conf.getDataSourceName());
88          props.setLeakThreshold(conf.getPoolLeakThreshold());
89  
90          ConnectionPoolingProperties connProps = new ConnectionPoolingProperties();
91          connProps.setMinSize(conf.getMinPoolSize());
92          connProps.setMaxSize(conf.getMaxPoolSize());
93          connProps.setMaxWait(conf.getMaxPoolWait().toString());
94          connProps.setSuspension(conf.isPoolSuspension());
95          connProps.setTimeoutMillis(conf.getPoolTimeoutMillis());
96          props.setPool(connProps);
97      }
98  }