syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [2/2] syncope git commit: Various small fixes
Date Tue, 04 Apr 2017 14:49:52 GMT
Various small fixes


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4fdf1c43
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4fdf1c43
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4fdf1c43

Branch: refs/heads/master
Commit: 4fdf1c4356b8b527e7482c9983b53c28f85b5501
Parents: 0f51a1a
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Tue Apr 4 16:49:34 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Tue Apr 4 16:49:41 2017 +0200

----------------------------------------------------------------------
 .../console/SyncopeConsoleApplication.java      | 57 ++++++++++++++------
 .../client/console/SyncopeConsoleSession.java   | 38 +++++--------
 .../syncope/client/console/pages/Login.java     |  4 +-
 .../client/console/rest/BaseRestClient.java     |  3 +-
 .../java/DefaultUserProvisioningManager.java    |  2 +-
 .../core/spring/security/AuthContextUtils.java  |  7 +++
 6 files changed, 66 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/4fdf1c43/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleApplication.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleApplication.java
b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleApplication.java
index 07a80b6..88a6965 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleApplication.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleApplication.java
@@ -24,6 +24,7 @@ import de.agilecoders.wicket.core.settings.IBootstrapSettings;
 import de.agilecoders.wicket.core.settings.SingleThemeProvider;
 import java.io.File;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -32,7 +33,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
-import javax.ws.rs.core.MediaType;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.ListUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.ClassUtils;
@@ -47,8 +49,13 @@ import org.apache.syncope.client.console.resources.FilesystemResource;
 import org.apache.syncope.client.console.resources.WorkflowDefGETResource;
 import org.apache.syncope.client.console.resources.WorkflowDefPUTResource;
 import org.apache.syncope.client.console.themes.AdminLTE;
+import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
 import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
+import org.apache.syncope.common.lib.EntityTOUtils;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.to.DomainTO;
 import org.apache.syncope.common.lib.types.StandardEntitlement;
+import org.apache.syncope.common.rest.api.service.DomainService;
 import org.apache.wicket.Page;
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
@@ -93,7 +100,17 @@ public class SyncopeConsoleApplication extends AuthenticatedWebApplication
{
 
     private String reconciliationReportKey;
 
-    private SyncopeClientFactoryBean clientFactory;
+    private String scheme;
+
+    private String host;
+
+    private String port;
+
+    private String rootPath;
+
+    private String useGZIPCompression;
+
+    private List<String> domains;
 
     private Map<String, Class<? extends BasePage>> pageClasses;
 
@@ -146,21 +163,17 @@ public class SyncopeConsoleApplication extends AuthenticatedWebApplication
{
         anonymousKey = props.getProperty("anonymousKey");
         Args.notNull(anonymousKey, "<anonymousKey>");
 
-        String scheme = props.getProperty("scheme");
+        scheme = props.getProperty("scheme");
         Args.notNull(scheme, "<scheme>");
-        String host = props.getProperty("host");
+        host = props.getProperty("host");
         Args.notNull(host, "<host>");
-        String port = props.getProperty("port");
+        port = props.getProperty("port");
         Args.notNull(port, "<port>");
-        String rootPath = props.getProperty("rootPath");
+        rootPath = props.getProperty("rootPath");
         Args.notNull(rootPath, "<rootPath>");
-        String useGZIPCompression = props.getProperty("useGZIPCompression");
+        useGZIPCompression = props.getProperty("useGZIPCompression");
         Args.notNull(useGZIPCompression, "<useGZIPCompression>");
 
-        clientFactory = new SyncopeClientFactoryBean().
-                setAddress(scheme + "://" + host + ":" + port + "/" + rootPath).
-                setUseCompression(BooleanUtils.toBoolean(useGZIPCompression));
-
         // process page properties
         pageClasses = new HashMap<>();
         populatePageClasses(props);
@@ -287,12 +300,24 @@ public class SyncopeConsoleApplication extends AuthenticatedWebApplication
{
         return reconciliationReportKey;
     }
 
-    public SyncopeClientFactoryBean getClientFactory() {
-        return clientFactory;
+    public SyncopeClientFactoryBean newClientFactory() {
+        return new SyncopeClientFactoryBean().
+                setAddress(scheme + "://" + host + ":" + port + "/" + rootPath).
+                setUseCompression(BooleanUtils.toBoolean(useGZIPCompression));
     }
 
-    public MediaType getMediaType() {
-        return clientFactory.getContentType().getMediaType();
+    public List<String> getDomains() {
+        synchronized (LOG) {
+            if (domains == null) {
+                domains = new ArrayList<>();
+                domains.add(SyncopeConstants.MASTER_DOMAIN);
+                CollectionUtils.collect(newClientFactory().create(
+                        new AnonymousAuthenticationHandler(anonymousUser, anonymousKey)).
+                        getService(DomainService.class).list(),
+                        EntityTOUtils.<DomainTO>keyTransformer(), domains);
+                domains = ListUtils.unmodifiableList(domains);
+            }
+        }
+        return domains;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/4fdf1c43/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
index 4064acf..5c3c750 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
@@ -19,10 +19,8 @@
 package org.apache.syncope.client.console;
 
 import java.text.DateFormat;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -30,7 +28,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
-import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.commons.lang3.tuple.Pair;
@@ -39,12 +36,9 @@ import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
 import org.apache.syncope.client.lib.SyncopeClient;
 import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
 import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.EntityTOUtils;
-import org.apache.syncope.common.lib.to.DomainTO;
 import org.apache.syncope.common.lib.info.PlatformInfo;
 import org.apache.syncope.common.lib.info.SystemInfo;
 import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.rest.api.service.DomainService;
 import org.apache.syncope.common.rest.api.service.SyncopeService;
 import org.apache.wicket.Session;
 import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
@@ -72,14 +66,14 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
         THREAD_POOL_FACTORY.setDaemon(true);
     }
 
+    private final SyncopeClientFactoryBean clientFactory;
+
     private final SyncopeClient anonymousClient;
 
     private final PlatformInfo platformInfo;
 
     private final SystemInfo systemInfo;
 
-    private final List<String> domains;
-
     private String domain;
 
     private final Map<Class<?>, Object> services = Collections.synchronizedMap(new
HashMap<Class<?>, Object>());
@@ -101,18 +95,18 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
     public SyncopeConsoleSession(final Request request) {
         super(request);
 
-        anonymousClient = SyncopeConsoleApplication.get().getClientFactory().
+        clientFactory = SyncopeConsoleApplication.get().newClientFactory();
+        anonymousClient = clientFactory.
                 create(new AnonymousAuthenticationHandler(
                         SyncopeConsoleApplication.get().getAnonymousUser(),
                         SyncopeConsoleApplication.get().getAnonymousKey()));
 
         platformInfo = anonymousClient.getService(SyncopeService.class).platform();
         systemInfo = anonymousClient.getService(SyncopeService.class).system();
+    }
 
-        domains = new ArrayList<>();
-        domains.add(SyncopeConstants.MASTER_DOMAIN);
-        CollectionUtils.collect(anonymousClient.getService(DomainService.class).list(),
-                EntityTOUtils.<DomainTO>keyTransformer(), domains);
+    public MediaType getMediaType() {
+        return clientFactory.getContentType().getMediaType();
     }
 
     public SyncopeClient getAnonymousClient() {
@@ -131,10 +125,6 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
         return systemInfo;
     }
 
-    public List<String> getDomains() {
-        return domains;
-    }
-
     public void setDomain(final String domain) {
         this.domain = domain;
     }
@@ -158,7 +148,7 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
         boolean authenticated = false;
 
         try {
-            client = SyncopeConsoleApplication.get().getClientFactory().
+            client = clientFactory.
                     setDomain(getDomain()).create(username, password);
 
             afterAuthentication();
@@ -175,7 +165,7 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
         boolean authenticated = false;
 
         try {
-            client = SyncopeConsoleApplication.get().getClientFactory().
+            client = clientFactory.
                     setDomain(getDomain()).create(jwt);
 
             afterAuthentication();
@@ -275,15 +265,15 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
     public <T> T getService(final MediaType mediaType, final Class<T> serviceClass)
{
         T service;
 
-        synchronized (SyncopeConsoleApplication.get().getClientFactory()) {
-            SyncopeClientFactoryBean.ContentType preType = SyncopeConsoleApplication.get().getClientFactory().
+        synchronized (clientFactory) {
+            SyncopeClientFactoryBean.ContentType preType = clientFactory.
                     getContentType();
 
-            SyncopeConsoleApplication.get().getClientFactory().
+            clientFactory.
                     setContentType(SyncopeClientFactoryBean.ContentType.fromString(mediaType.toString()));
-            service = SyncopeConsoleApplication.get().getClientFactory().create(getJWT()).getService(serviceClass);
+            service = clientFactory.create(getJWT()).getService(serviceClass);
 
-            SyncopeConsoleApplication.get().getClientFactory().setContentType(preType);
+            clientFactory.setContentType(preType);
         }
 
         return service;

http://git-wip-us.apache.org/repos/asf/syncope/blob/4fdf1c43/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java
b/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java
index 296576d..4c7364f 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java
@@ -100,7 +100,7 @@ public class Login extends WebPage {
         form.add(languageSelect);
 
         domainSelect = new DomainDropDown("domain");
-        if (SyncopeConsoleSession.get().getDomains().size() == 1) {
+        if (SyncopeConsoleApplication.get().getDomains().size() == 1) {
             domainSelect.setOutputMarkupPlaceholderTag(true);
         }
         form.add(domainSelect);
@@ -219,7 +219,7 @@ public class Login extends WebPage {
         private static final long serialVersionUID = -7401167913360133325L;
 
         DomainDropDown(final String id) {
-            super(id, SyncopeConsoleSession.get().getDomains());
+            super(id, SyncopeConsoleApplication.get().getDomains());
 
             setModel(new IModel<String>() {
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/4fdf1c43/client/console/src/main/java/org/apache/syncope/client/console/rest/BaseRestClient.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/BaseRestClient.java
b/client/console/src/main/java/org/apache/syncope/client/console/rest/BaseRestClient.java
index d2c73f1..8b3dce2 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/BaseRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/BaseRestClient.java
@@ -20,7 +20,6 @@ package org.apache.syncope.client.console.rest;
 
 import java.net.URI;
 import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.syncope.client.console.SyncopeConsoleApplication;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.lib.SyncopeClient;
 import org.apache.syncope.common.lib.search.OrderByClauseBuilder;
@@ -74,7 +73,7 @@ public abstract class BaseRestClient implements RestClient {
             final E service, final URI location, final Class<T> resultClass) {
 
         WebClient webClient = WebClient.fromClient(WebClient.client(service));
-        webClient.accept(SyncopeConsoleApplication.get().getMediaType()).to(location.toASCIIString(),
false);
+        webClient.accept(SyncopeConsoleSession.get().getMediaType()).to(location.toASCIIString(),
false);
         return webClient.
                 header(RESTHeaders.DOMAIN, SyncopeConsoleSession.get().getDomain()).
                 header(RESTHeaders.TOKEN, SyncopeConsoleSession.get().getJWT()).

http://git-wip-us.apache.org/repos/asf/syncope/blob/4fdf1c43/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultUserProvisioningManager.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultUserProvisioningManager.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultUserProvisioningManager.java
index 694610b..ba2481e 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultUserProvisioningManager.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultUserProvisioningManager.java
@@ -56,7 +56,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 
 public class DefaultUserProvisioningManager implements UserProvisioningManager {
 
-    private static final Logger LOG = LoggerFactory.getLogger(UserProvisioningManager.class);
+    protected static final Logger LOG = LoggerFactory.getLogger(UserProvisioningManager.class);
 
     @Autowired
     protected UserWorkflowAdapter uwfAdapter;

http://git-wip-us.apache.org/repos/asf/syncope/blob/4fdf1c43/core/spring/src/main/java/org/apache/syncope/core/spring/security/AuthContextUtils.java
----------------------------------------------------------------------
diff --git a/core/spring/src/main/java/org/apache/syncope/core/spring/security/AuthContextUtils.java
b/core/spring/src/main/java/org/apache/syncope/core/spring/security/AuthContextUtils.java
index 9bc03f7..36e4188 100644
--- a/core/spring/src/main/java/org/apache/syncope/core/spring/security/AuthContextUtils.java
+++ b/core/spring/src/main/java/org/apache/syncope/core/spring/security/AuthContextUtils.java
@@ -30,6 +30,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.SyncopeConstants;
 import org.apache.syncope.core.provisioning.api.EntitlementsHolder;
 import org.apache.syncope.core.spring.ApplicationContextProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
@@ -39,6 +41,8 @@ import org.springframework.security.core.userdetails.User;
 
 public final class AuthContextUtils {
 
+    private static final Logger LOG = LoggerFactory.getLogger(AuthContextUtils.class);
+
     public interface Executable<T> {
 
         T exec();
@@ -112,6 +116,9 @@ public final class AuthContextUtils {
         setFakeAuth(domainKey);
         try {
             return executable.exec();
+        } catch (Throwable t) {
+            LOG.debug("Error during execution with domain {} context", domainKey, t);
+            throw t;
         } finally {
             SecurityContextHolder.clearContext();
             SecurityContextHolder.setContext(ctx);


Mime
View raw message