Return-Path: X-Original-To: apmail-syncope-commits-archive@www.apache.org Delivered-To: apmail-syncope-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4AB0EC6AC for ; Mon, 5 Jan 2015 13:34:07 +0000 (UTC) Received: (qmail 83438 invoked by uid 500); 5 Jan 2015 13:34:08 -0000 Delivered-To: apmail-syncope-commits-archive@syncope.apache.org Received: (qmail 83365 invoked by uid 500); 5 Jan 2015 13:34:08 -0000 Mailing-List: contact commits-help@syncope.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@syncope.apache.org Delivered-To: mailing list commits@syncope.apache.org Received: (qmail 82435 invoked by uid 99); 5 Jan 2015 13:34:07 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jan 2015 13:34:07 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 53FB5A3F7AC; Mon, 5 Jan 2015 13:34:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ilgrosso@apache.org To: commits@syncope.apache.org Date: Mon, 05 Jan 2015 13:34:39 -0000 Message-Id: <93619525b68346ad86c348789dc226a5@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [34/53] [abbrv] syncope git commit: Fixes #4 - Route functionalities are displayed only with Camel PM Fixes #4 - Route functionalities are displayed only with Camel PM Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/b19ff851 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/b19ff851 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/b19ff851 Branch: refs/heads/master Commit: b19ff8512f082d7d74ff40b0a53f6380d0905771 Parents: d8ec8da Author: giacomolm Authored: Tue Dec 30 16:47:31 2014 +0100 Committer: giacomolm Committed: Tue Dec 30 16:47:31 2014 +0100 ---------------------------------------------------------------------- .../apache/syncope/client/SyncopeClient.java | 26 +++++++ .../syncope/common/services/RouteService.java | 44 ++++++++--- .../syncope/common/types/RESTHeaders.java | 11 +++ .../apache/syncope/console/SyncopeSession.java | 7 ++ .../syncope/console/pages/Configuration.java | 15 +++- .../syncope/console/rest/RouteRestClient.java | 22 +++++- .../syncope/console/pages/Configuration.html | 2 +- .../core/provisioning/camel/CamelDetector.java | 77 ++++++++++++++++++++ .../syncope/core/services/RouteServiceImpl.java | 31 +++++++- core/src/main/resources/provisioning.properties | 4 +- 10 files changed, 218 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/client/src/main/java/org/apache/syncope/client/SyncopeClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/syncope/client/SyncopeClient.java b/client/src/main/java/org/apache/syncope/client/SyncopeClient.java index a471d54..f955951 100644 --- a/client/src/main/java/org/apache/syncope/client/SyncopeClient.java +++ b/client/src/main/java/org/apache/syncope/client/SyncopeClient.java @@ -26,6 +26,7 @@ import org.apache.syncope.client.rest.RestClientFactoryBean; import org.apache.syncope.common.search.OrderByClauseBuilder; import org.apache.syncope.common.search.RoleFiqlSearchConditionBuilder; import org.apache.syncope.common.search.UserFiqlSearchConditionBuilder; +import org.apache.syncope.common.services.RouteService; import org.apache.syncope.common.services.UserSelfService; import org.apache.syncope.common.services.WorkflowService; import org.apache.syncope.common.types.Preference; @@ -265,6 +266,31 @@ public class SyncopeClient { return result; } + + /** + * Checks whether Camel is enabled for users / roles, by calling RouteService's options. + * + * @param subjectType user / role + * @return whether Camel Provisioning is enabled for given attributable type + * @see RouteService#getOptions(org.apache.syncope.common.types.SubjectType) + */ + public boolean isCamelEnabledFor(final SubjectType subjectType) { + Response options = getService(RouteService.class).getOptions(subjectType); + + boolean result; + switch (subjectType) { + case ROLE: + result = Boolean.valueOf(options.getHeaderString(RESTHeaders.CAMEL_ROLE_PROVISIONING_MANAGER)); + break; + + case USER: + default: + result = Boolean.valueOf(options.getHeaderString(RESTHeaders.CAMEL_USER_PROVISIONING_MANAGER)); + break; + } + + return result; + } /** * Fetches ETag header value from latest service run (if available). http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/common/src/main/java/org/apache/syncope/common/services/RouteService.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/syncope/common/services/RouteService.java b/common/src/main/java/org/apache/syncope/common/services/RouteService.java index feb7db7..6e3090f 100644 --- a/common/src/main/java/org/apache/syncope/common/services/RouteService.java +++ b/common/src/main/java/org/apache/syncope/common/services/RouteService.java @@ -16,34 +16,56 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.syncope.common.services; import java.util.List; +import javax.validation.constraints.NotNull; import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.OPTIONS; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.cxf.jaxrs.model.wadl.Description; +import org.apache.cxf.jaxrs.model.wadl.Descriptions; +import org.apache.cxf.jaxrs.model.wadl.DocTarget; import org.apache.syncope.common.to.RouteTO; +import org.apache.syncope.common.types.SubjectType; + +@Path("routes/{kind}") +public interface RouteService extends JAXRSService { + + /** + * Checks whether Camel is choosed as default provisioning engine. + * + * @param kind user or role + * @return Response contains special syncope HTTP header indicating if Camel is enabled for + * users / roles provisioning + * @see org.apache.syncope.common.types.RESTHeaders#CAMEL_USER_PROVISIONING_MANAGER + * @see org.apache.syncope.common.types.RESTHeaders#CAMEL_ROLE_PROVISIONING_MANAGER + * + * @Descriptions({ + * @Description(target = DocTarget.RESPONSE, + * value = "Contains special syncope HTTP header indicating if Camel is the default provisioning manager") + * }) */ + @OPTIONS + Response getOptions(@NotNull @PathParam("kind") SubjectType kind); -@Path("routes") -public interface RouteService extends JAXRSService{ - @GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - List getRoutes(); - + List getRoutes(@NotNull @PathParam("kind") SubjectType kind); + @GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Path("{id}") - public RouteTO getRoute(@PathParam("id") Long Id); - + public RouteTO getRoute(@NotNull @PathParam("kind") SubjectType kind, @PathParam("id") Long Id); + @PUT @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Path("{id}") - void importRoute(@PathParam("id") Long id, RouteTO route); - -} \ No newline at end of file + void importRoute(@NotNull @PathParam("kind") SubjectType kind,@PathParam("id") Long id, RouteTO route); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/common/src/main/java/org/apache/syncope/common/types/RESTHeaders.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/syncope/common/types/RESTHeaders.java b/common/src/main/java/org/apache/syncope/common/types/RESTHeaders.java index ddbfca2..3e7cdc3 100644 --- a/common/src/main/java/org/apache/syncope/common/types/RESTHeaders.java +++ b/common/src/main/java/org/apache/syncope/common/types/RESTHeaders.java @@ -57,6 +57,17 @@ public final class RESTHeaders { * Option key stating if Activiti workflow adapter is in use for roles. */ public static final String ACTIVITI_ROLE_ENABLED = "Syncope.Activiti.Role.Enabled"; + + /** + * Option key stating if Camel is the current provisioning manager engine. + */ + public static final String CAMEL_USER_PROVISIONING_MANAGER ="Syncope.Provisioning.Camel.User.Enabled"; + + /** + * Option key stating if Camel is the current provisioning manager engine. + */ + public static final String CAMEL_ROLE_PROVISIONING_MANAGER ="Syncope.Provisioning.Camel.Role.Enabled"; + /** * HTTP header key for object ID assigned to an object after its creation. http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/console/src/main/java/org/apache/syncope/console/SyncopeSession.java ---------------------------------------------------------------------- diff --git a/console/src/main/java/org/apache/syncope/console/SyncopeSession.java b/console/src/main/java/org/apache/syncope/console/SyncopeSession.java index ae81852..53b03c0 100644 --- a/console/src/main/java/org/apache/syncope/console/SyncopeSession.java +++ b/console/src/main/java/org/apache/syncope/console/SyncopeSession.java @@ -114,6 +114,13 @@ public class SyncopeSession extends WebSession { : clients.values().iterator().next(); return client.isActivitiEnabledFor(type); } + + public boolean isCamelEnabledFor(final SubjectType type) { + SyncopeClient client = clients.isEmpty() + ? clientFactory.createAnonymous() + : clients.values().iterator().next(); + return client.isCamelEnabledFor(type); + } public T getService(final Class service) { return getService(service, this.username, this.password); http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/console/src/main/java/org/apache/syncope/console/pages/Configuration.java ---------------------------------------------------------------------- diff --git a/console/src/main/java/org/apache/syncope/console/pages/Configuration.java b/console/src/main/java/org/apache/syncope/console/pages/Configuration.java index 10dcfc7..05316dd 100644 --- a/console/src/main/java/org/apache/syncope/console/pages/Configuration.java +++ b/console/src/main/java/org/apache/syncope/console/pages/Configuration.java @@ -52,6 +52,7 @@ import org.apache.syncope.console.wicket.extensions.markup.html.repeater.data.ta import org.apache.syncope.console.wicket.markup.html.form.ActionLink; import org.apache.syncope.console.wicket.markup.html.form.ActionLinksPanel; import org.apache.syncope.console.wicket.markup.html.link.VeilPopupSettings; +import org.apache.wicket.Component; import org.apache.wicket.Page; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; @@ -278,7 +279,8 @@ public class Configuration extends BasePage { add(new LayoutsPanel("selfMembershipLayoutPanel", AttrLayoutType.SELF_MEMBERSHIP, feedbackPanel)); //Route Management - add(editRouteWin = new ModalWindow("editRouteWin")); + editRouteWin = new ModalWindow("editRouteWin"); + add(editRouteWin); setupRoutes(); } @@ -828,7 +830,18 @@ public class Configuration extends BasePage { WebMarkupContainer routeContainer = new WebMarkupContainer("routesContainer"); routeContainer.add(routeTable); routeContainer.setOutputMarkupId(true); + + ListItem li = new ListItem("routeTab", 0); + if (routeRestClient.isCamelEnabledForUsers() == false) { + li.setVisible(false); + routeContainer.setVisible(false); + } + else{ + li.setVisible(true); + routeContainer.setVisible(true); + } + add(li); add(routeContainer); editRouteWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY); http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/console/src/main/java/org/apache/syncope/console/rest/RouteRestClient.java ---------------------------------------------------------------------- diff --git a/console/src/main/java/org/apache/syncope/console/rest/RouteRestClient.java b/console/src/main/java/org/apache/syncope/console/rest/RouteRestClient.java index 673652a..dcfb8c3 100644 --- a/console/src/main/java/org/apache/syncope/console/rest/RouteRestClient.java +++ b/console/src/main/java/org/apache/syncope/console/rest/RouteRestClient.java @@ -19,8 +19,11 @@ package org.apache.syncope.console.rest; import java.util.List; +import org.apache.syncope.common.SyncopeClientException; import org.apache.syncope.common.services.RouteService; import org.apache.syncope.common.to.RouteTO; +import org.apache.syncope.common.types.SubjectType; +import org.apache.syncope.console.SyncopeSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -31,17 +34,30 @@ public class RouteRestClient extends BaseRestClient{ protected static final Logger LOG = LoggerFactory.getLogger(RouteRestClient.class); public List readRoutes(){ - return getService(RouteService.class).getRoutes(); + return getService(RouteService.class).getRoutes(SubjectType.USER); } public RouteTO readRoute(Long id){ - return getService(RouteService.class).getRoute(id); + return getService(RouteService.class).getRoute(SubjectType.USER, id); } public void updateRoute(Long id, String definition){ RouteTO routeTO = readRoute(id); routeTO.setRouteContent(definition); - getService(RouteService.class).importRoute(routeTO.getId(), routeTO); + getService(RouteService.class).importRoute(SubjectType.USER, routeTO.getId(), routeTO); + } + + public boolean isCamelEnabledForUsers() { + Boolean result = null; + try { + result = SyncopeSession.get().isCamelEnabledFor(SubjectType.USER); + } catch (SyncopeClientException e) { + LOG.error("While seeking if Camel is enabled for users", e); + } + + return result == null + ? false + : result.booleanValue(); } } http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/console/src/main/resources/org/apache/syncope/console/pages/Configuration.html ---------------------------------------------------------------------- diff --git a/console/src/main/resources/org/apache/syncope/console/pages/Configuration.html b/console/src/main/resources/org/apache/syncope/console/pages/Configuration.html index 62f97a8..130c89a 100644 --- a/console/src/main/resources/org/apache/syncope/console/pages/Configuration.html +++ b/console/src/main/resources/org/apache/syncope/console/pages/Configuration.html @@ -38,7 +38,7 @@ under the License.
  • -
  • +
  • http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/core/src/main/java/org/apache/syncope/core/provisioning/camel/CamelDetector.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/syncope/core/provisioning/camel/CamelDetector.java b/core/src/main/java/org/apache/syncope/core/provisioning/camel/CamelDetector.java new file mode 100644 index 0000000..646c350 --- /dev/null +++ b/core/src/main/java/org/apache/syncope/core/provisioning/camel/CamelDetector.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.core.provisioning.camel; + +import java.io.InputStream; +import java.util.Properties; +import org.apache.commons.io.IOUtils; +import org.apache.syncope.core.persistence.dao.impl.ContentLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author giacomolm + */ +public class CamelDetector { + + private static final Logger LOG = LoggerFactory.getLogger(CamelDetector.class); + + private static final String PROVISIONING_PROPERTIES = "/provisioning.properties"; + + private static String userPMClassName; + + private static String rolePMClassName; + + /** + * Read classpath:/provisioning.properties in order to determine the configured provisioning adapter class name. + */ + static { + Properties props = new Properties(); + InputStream propStream = null; + try { + propStream = ContentLoader.class.getResourceAsStream(PROVISIONING_PROPERTIES); + props.load(propStream); + userPMClassName = props.getProperty("userProvisioningManager"); + rolePMClassName = props.getProperty("roleProvisioningManager"); + } catch (Exception e) { + LOG.error("Could not load workflow.properties", e); + } finally { + IOUtils.closeQuietly(propStream); + } + } + + /** + * Check if the configured user provisioning manager is Camel's. + * + * @return whether Activiti is configured for user workflow or not + */ + public static boolean isCamelEnabledForUsers() { + return userPMClassName != null && userPMClassName.equals(CamelUserProvisioningManager.class.getName()); + } + + /** + * Check if the configured role provisioning manager is Camel's. + * + * @return whether Activiti is configured for role workflow or not + */ + public static boolean isCamelEnabledForRoles() { + return rolePMClassName != null && rolePMClassName.equals(CamelRoleProvisioningManager.class.getName()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/core/src/main/java/org/apache/syncope/core/services/RouteServiceImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/syncope/core/services/RouteServiceImpl.java b/core/src/main/java/org/apache/syncope/core/services/RouteServiceImpl.java index ecc323e..29359f8 100644 --- a/core/src/main/java/org/apache/syncope/core/services/RouteServiceImpl.java +++ b/core/src/main/java/org/apache/syncope/core/services/RouteServiceImpl.java @@ -18,33 +18,58 @@ */ package org.apache.syncope.core.services; +import static org.apache.syncope.core.services.AbstractServiceImpl.OPTIONS_ALLOW; + import java.util.List; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; import org.apache.syncope.common.services.RouteService; import org.apache.syncope.common.to.RouteTO; +import org.apache.syncope.common.types.RESTHeaders; +import org.apache.syncope.common.types.SubjectType; +import org.apache.syncope.core.provisioning.camel.CamelDetector; import org.apache.syncope.core.rest.controller.RouteController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class RouteServiceImpl extends AbstractServiceImpl implements RouteService { + + @Override + public Response getOptions(final SubjectType kind) { + String key; + String value; + if (kind == SubjectType.USER) { + key = RESTHeaders.CAMEL_USER_PROVISIONING_MANAGER; + value = Boolean.toString(CamelDetector.isCamelEnabledForUsers()); + } else { + key = RESTHeaders.CAMEL_ROLE_PROVISIONING_MANAGER; + value = Boolean.toString(CamelDetector.isCamelEnabledForRoles()); + } + Response.ResponseBuilder builder = Response.ok().header(HttpHeaders.ALLOW, OPTIONS_ALLOW); + if (key != null && value != null) { + builder.header(key, value); + } + return builder.build(); + } @Autowired private RouteController controller; @Override - public List getRoutes() { + public List getRoutes(SubjectType kind) { return controller.listRoutes(); } @Override - public RouteTO getRoute(Long id) { + public RouteTO getRoute(SubjectType kind, Long id) { return controller.readRoute(id); } @Override - public void importRoute(Long id, RouteTO route) { + public void importRoute(SubjectType kind,Long id, RouteTO route) { controller.updateRoute(route); } http://git-wip-us.apache.org/repos/asf/syncope/blob/b19ff851/core/src/main/resources/provisioning.properties ---------------------------------------------------------------------- diff --git a/core/src/main/resources/provisioning.properties b/core/src/main/resources/provisioning.properties index a8e49bf..de6c3cd 100644 --- a/core/src/main/resources/provisioning.properties +++ b/core/src/main/resources/provisioning.properties @@ -15,5 +15,5 @@ # specific language governing permissions and limitations # under the License. -userProvisioningManager=org.apache.syncope.core.provisioning.camel.CamelUserProvisioningManager -roleProvisioningManager=org.apache.syncope.core.provisioning.camel.CamelRoleProvisioningManager \ No newline at end of file +userProvisioningManager=org.apache.syncope.core.provisioning.DefaultUserProvisioningManager +roleProvisioningManager=org.apache.syncope.core.provisioning.DefaultRoleProvisioningManager \ No newline at end of file