[SYNCOPE-1418] Minor modifications in preparation to Spring Boot
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Thu, 27 Dec 2018 15:47:38 +0000 (16:47 +0100)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Thu, 27 Dec 2018 15:47:38 +0000 (16:47 +0100)
13 files changed:
core/idrepo/rest-cxf/src/main/resources/META-INF/web-fragment.xml
core/idrepo/rest-cxf/src/main/resources/restCXFContext.xml
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPlainSchemaDAO.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/CommonEntityManagerFactoryConf.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/DomainEntityManagerFactoryBean.java
core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/cache/VirAttrCache.java
core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/job/JobManager.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/cache/DisabledVirAttrCache.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/cache/MemoryVirAttrCache.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/JobManagerImpl.java
core/provisioning-java/src/main/resources/provisioningContext.xml
core/spring/src/main/java/org/apache/syncope/core/spring/security/Encryptor.java
fit/core-reference/src/main/resources/jboss/restCXFContext.xml

index b4d20e5..b0062a4 100644 (file)
@@ -49,7 +49,7 @@ under the License.
   <servlet-mapping>
     <servlet-name>WADLServlet</servlet-name>
     <url-pattern>/index.html</url-pattern>
-    <url-pattern>/schema_1_syncope21.html</url-pattern>
+    <url-pattern>/schema_1_syncope30.html</url-pattern>
     <url-pattern>/syncope.wadl</url-pattern>
   </servlet-mapping>
 
index b611a9b..11e97d8 100644 (file)
@@ -41,8 +41,8 @@ under the License.
   <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
     <property name="namespacePrefixes">
       <map>
-        <entry key="http://syncope.apache.org/2.1">
-          <value>syncope21</value>
+        <entry key="http://syncope.apache.org/30">
+          <value>syncope30</value>
         </entry>
       </map>      
     </property>
@@ -96,7 +96,7 @@ under the License.
   
   <bean id="wadlGenerator" class="org.apache.syncope.core.rest.cxf.WadlGenerator">
     <property name="applicationTitle" value="Apache Syncope ${syncope.version}"/>
-    <property name="namespacePrefix" value="syncope21"/>
+    <property name="namespacePrefix" value="syncope30"/>
     <property name="incrementNamespacePrefix" value="false"/>    
     <property name="linkAnyMediaTypeToXmlSchema" value="true"/>
     <property name="useJaxbContextForQnames" value="true"/>
index 46df742..efef0ba 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.syncope.core.persistence.api.entity.PlainAttr;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
 import org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 
 public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema> implements PlainSchemaDAO {
 
@@ -43,6 +44,7 @@ public class JPAPlainSchemaDAO extends AbstractDAO<PlainSchema> implements Plain
     private PlainAttrDAO plainAttrDAO;
 
     @Autowired
+    @Lazy
     private ExternalResourceDAO resourceDAO;
 
     @Override
index bd1aba5..2afe4da 100644 (file)
@@ -22,21 +22,14 @@ import java.util.HashMap;
 import java.util.Map;
 import javax.persistence.ValidationMode;
 import javax.sql.DataSource;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.core.persistence.api.DomainsHolder;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
 import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor;
 
 /**
  * Container for common configuration options among all EntityManagerFactory entities (one for each domain).
  * Acts as a commodity place for fetching each domain's {@link DataSource}..
  */
-public class CommonEntityManagerFactoryConf implements DomainsHolder, InitializingBean, ApplicationContextAware {
-
-    private ApplicationContext ctx;
+public class CommonEntityManagerFactoryConf implements DomainsHolder {
 
     private final Map<String, DataSource> domains = new HashMap<>();
 
@@ -48,20 +41,8 @@ public class CommonEntityManagerFactoryConf implements DomainsHolder, Initializi
 
     private final Map<String, Object> jpaPropertyMap = new HashMap<>();
 
-    @Override
-    public void setApplicationContext(final ApplicationContext ctx) throws BeansException {
-        this.ctx = ctx;
-    }
-
-    @Override
-    public void afterPropertiesSet() {
-        for (Map.Entry<String, DataSource> entry : ctx.getBeansOfType(DataSource.class).entrySet()) {
-            if (!entry.getKey().startsWith("local")) {
-                this.domains.put(
-                        StringUtils.substringBefore(entry.getKey(), DataSource.class.getSimpleName()),
-                        entry.getValue());
-            }
-        }
+    public void addDomain(final String domain, final DataSource datasource) {
+        this.domains.put(domain, datasource);
     }
 
     @Override
@@ -102,5 +83,4 @@ public class CommonEntityManagerFactoryConf implements DomainsHolder, Initializi
             this.jpaPropertyMap.putAll(jpaProperties);
         }
     }
-
 }
index a959f96..e7ae681 100644 (file)
@@ -40,6 +40,7 @@ public class DomainEntityManagerFactoryBean extends LocalContainerEntityManagerF
         if (commonEMFConf.getPersistenceUnitPostProcessors() != null) {
             super.setPersistenceUnitPostProcessors(commonEMFConf.getPersistenceUnitPostProcessors());
         }
-    }
 
+        commonEMFConf.addDomain(this.getPersistenceUnitName(), this.getDataSource());
+    }
 }
index 4e50a11..c12d823 100644 (file)
@@ -23,6 +23,12 @@ package org.apache.syncope.core.provisioning.api.cache;
  */
 public interface VirAttrCache {
 
+    default void setTtl(int ttl) {
+    }
+
+    default void setMaxCacheSize(int maxCacheSize) {
+    }
+
     /**
      * Force entry expiring.
      *
index 35f331b..eb536df 100644 (file)
@@ -26,10 +26,6 @@ import org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue;
  */
 public class DisabledVirAttrCache implements VirAttrCache {
 
-    public DisabledVirAttrCache(final int ttl, final int maxCacheSize) {
-        // ignore
-    }
-
     @Override
     public void expire(final String type, final String key, final String schemaKey) {
         // nothing to do
@@ -49,5 +45,4 @@ public class DisabledVirAttrCache implements VirAttrCache {
     public void put(final String type, final String key, final String schemaName, final VirAttrCacheValue value) {
         // nothing to do
     }
-
 }
index 127ad87..e5c1b42 100644 (file)
@@ -35,20 +35,25 @@ public class MemoryVirAttrCache implements VirAttrCache {
     /**
      * Elapsed time in seconds.
      */
-    protected int ttl;
+    protected int ttl = 60;
 
     /**
      * Max cache size.
      */
-    protected int maxCacheSize;
+    protected int maxCacheSize = 5000;
 
     /**
      * Cache entries.
      */
     protected final Map<VirAttrCacheKey, VirAttrCacheValue> cache = new HashMap<>();
 
-    public MemoryVirAttrCache(final int ttl, final int maxCacheSize) {
+    @Override
+    public void setTtl(final int ttl) {
         this.ttl = ttl;
+    }
+
+    @Override
+    public void setMaxCacheSize(final int maxCacheSize) {
         this.maxCacheSize = maxCacheSize;
     }
 
index 274153e..c59c881 100644 (file)
@@ -396,7 +396,7 @@ public class JobManagerImpl implements JobManager, SyncopeLoader {
         try {
             SystemLoadReporterJob job = createSpringBean(SystemLoadReporterJob.class);
             registerJob(
-                    "systemLoadReporterJob",
+                    StringUtils.uncapitalize(SystemLoadReporterJob.class.getSimpleName()),
                     job,
                     "0 * * * * ?",
                     null,
index a301cb7..e8436f7 100644 (file)
@@ -108,8 +108,8 @@ under the License.
   <bean class="org.apache.syncope.core.provisioning.java.propagation.PropagationManagerImpl"/>
 
   <bean id="virAttrCache" class="${virAttrCache}" scope="singleton">
-    <constructor-arg value="60"/>
-    <constructor-arg value="5000"/>
+    <property name="ttl" value="60"/>
+    <property name="maxCacheSize" value="5000"/>
   </bean>
 
   <bean id="connIdBundleManager" class="org.apache.syncope.core.provisioning.java.ConnIdBundleManagerImpl">
index e47d62e..db36f44 100644 (file)
@@ -142,6 +142,8 @@ public final class Encryptor {
         return instance;
     }
 
+    private final Map<CipherAlgorithm, StandardStringDigester> digesters = new ConcurrentHashMap<>();
+
     private SecretKeySpec keySpec;
 
     private Encryptor(final String secretKey) {
@@ -230,24 +232,30 @@ public final class Encryptor {
     }
 
     private StandardStringDigester getDigester(final CipherAlgorithm cipherAlgorithm) {
-        StandardStringDigester digester = new StandardStringDigester();
-
-        if (cipherAlgorithm.getAlgorithm().startsWith("S-")) {
-            // Salted ...
-            digester.setAlgorithm(cipherAlgorithm.getAlgorithm().replaceFirst("S\\-", ""));
-            digester.setIterations(SALT_ITERATIONS);
-            digester.setSaltSizeBytes(SALT_SIZE_BYTES);
-            digester.setInvertPositionOfPlainSaltInEncryptionResults(IPOPSIER);
-            digester.setInvertPositionOfSaltInMessageBeforeDigesting(IPOSIMBD);
-            digester.setUseLenientSaltSizeCheck(ULSSC);
-        } else {
-            // Not salted ...
-            digester.setAlgorithm(cipherAlgorithm.getAlgorithm());
-            digester.setIterations(1);
-            digester.setSaltSizeBytes(0);
+        StandardStringDigester digester = digesters.get(cipherAlgorithm);
+        if (digester == null) {
+            digester = new StandardStringDigester();
+
+            if (cipherAlgorithm.getAlgorithm().startsWith("S-")) {
+                // Salted ...
+                digester.setAlgorithm(cipherAlgorithm.getAlgorithm().replaceFirst("S\\-", ""));
+                digester.setIterations(SALT_ITERATIONS);
+                digester.setSaltSizeBytes(SALT_SIZE_BYTES);
+                digester.setInvertPositionOfPlainSaltInEncryptionResults(IPOPSIER);
+                digester.setInvertPositionOfSaltInMessageBeforeDigesting(IPOSIMBD);
+                digester.setUseLenientSaltSizeCheck(ULSSC);
+            } else {
+                // Not salted ...
+                digester.setAlgorithm(cipherAlgorithm.getAlgorithm());
+                digester.setIterations(1);
+                digester.setSaltSizeBytes(0);
+            }
+
+            digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL);
+
+            digesters.put(cipherAlgorithm, digester);
         }
 
-        digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL);
         return digester;
     }
 }
index 8ba7de6..fb6f1f7 100644 (file)
@@ -41,8 +41,8 @@ under the License.
   <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
     <property name="namespacePrefixes">
       <map>
-        <entry key="http://syncope.apache.org/2.1">
-          <value>syncope21</value>
+        <entry key="http://syncope.apache.org/3.0">
+          <value>syncope30</value>
         </entry>
       </map>      
     </property>
@@ -96,7 +96,7 @@ under the License.
   
   <bean id="wadlGenerator" class="org.apache.syncope.core.rest.cxf.WadlGenerator">
     <property name="applicationTitle" value="Apache Syncope ${syncope.version}"/>
-    <property name="namespacePrefix" value="syncope21"/>
+    <property name="namespacePrefix" value="syncope30"/>
     <property name="incrementNamespacePrefix" value="false"/>    
     <property name="linkAnyMediaTypeToXmlSchema" value="true"/>
     <property name="useJaxbContextForQnames" value="true"/>