This is an automated email from the ASF dual-hosted git repository. ilgrosso pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 8d484ef612a6ce4229b4b31e5092178b53b586b9 Author: Francesco Chicchiriccò <[email protected]> AuthorDate: Mon Sep 21 12:09:45 2020 +0200 [SYNCOPE-1585] Cleanup --- .../ui/commons/panels/OIDCC4UIConstants.java | 2 - .../resources/oidcc4ui/CodeConsumerResource.java | 16 +++---- .../resources/ConsoleCodeConsumerResource.java | 5 ++- .../client/enduser/pages/OIDCClientSelfReg.java | 49 ---------------------- .../resources/EnduserCodeConsumerResource.java | 10 ++++- .../client/ui/commons/SAML2SP4UIConstants.java | 2 - .../saml2sp4ui/AssertionConsumerResource.java | 16 ++++--- .../ConsoleAssertionConsumerResource.java | 5 ++- .../EnduserAssertionConsumerResource.java | 10 ++++- 9 files changed, 42 insertions(+), 73 deletions(-) diff --git a/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/panels/OIDCC4UIConstants.java b/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/panels/OIDCC4UIConstants.java index aeb8bff..fddb6ef 100644 --- a/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/panels/OIDCC4UIConstants.java +++ b/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/panels/OIDCC4UIConstants.java @@ -26,8 +26,6 @@ public final class OIDCC4UIConstants { public static final String OIDCC4UI_JWT = "oidcc4ui.jwt"; - public static final String OIDCC4UI_NEW_USER = "oidcc4ui.newUser"; - public static final String OIDCC4UI_SLO_SUPPORTED = "oidcc4ui.sloSupported"; private OIDCC4UIConstants() { diff --git a/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/oidcc4ui/CodeConsumerResource.java b/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/oidcc4ui/CodeConsumerResource.java index b76a2d0..fbabb3d 100644 --- a/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/oidcc4ui/CodeConsumerResource.java +++ b/ext/oidcc4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/oidcc4ui/CodeConsumerResource.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import javax.servlet.http.HttpServletRequest; +import org.apache.commons.lang3.tuple.Pair; import org.apache.syncope.client.ui.commons.BaseSession; import org.apache.syncope.client.ui.commons.panels.OIDCC4UIConstants; import org.apache.syncope.common.lib.oidc.OIDCConstants; @@ -39,16 +40,17 @@ import org.slf4j.LoggerFactory; public abstract class CodeConsumerResource extends AbstractResource { + private static final long serialVersionUID = -692581789294259519L; + protected static final Logger LOG = LoggerFactory.getLogger(CodeConsumerResource.class); - private static final ObjectMapper MAPPER = + protected static final ObjectMapper MAPPER = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - private static final long serialVersionUID = -692581789294259519L; - protected abstract Class<? extends WebPage> getLoginPageClass(); - protected abstract Class<? extends WebPage> getSelfRegPageClass(); + protected abstract Pair<Class<? extends WebPage>, PageParameters> getSelfRegInfo(UserTO newUser) + throws JsonProcessingException; @Override protected ResourceResponse newResourceResponse(final Attributes attributes) { @@ -69,10 +71,8 @@ public abstract class CodeConsumerResource extends AbstractResource { newUser.getPlainAttrs().addAll(oidcResponse.getAttrs()); try { - throw new RestartResponseException( - getSelfRegPageClass(), - new PageParameters(). - set(OIDCC4UIConstants.OIDCC4UI_NEW_USER, MAPPER.writeValueAsString(newUser))); + Pair<Class<? extends WebPage>, PageParameters> selfRegInfo = getSelfRegInfo(newUser); + throw new RestartResponseException(selfRegInfo.getLeft(), selfRegInfo.getRight()); } catch (JsonProcessingException e) { LOG.error("Could not serialize new user {}", newUser, e); throw new WicketRuntimeException(e); diff --git a/ext/oidcc4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleCodeConsumerResource.java b/ext/oidcc4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleCodeConsumerResource.java index 3638cdc..8809e23 100644 --- a/ext/oidcc4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleCodeConsumerResource.java +++ b/ext/oidcc4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleCodeConsumerResource.java @@ -18,11 +18,14 @@ */ package org.apache.syncope.client.console.resources; +import org.apache.commons.lang3.tuple.Pair; import org.apache.syncope.client.console.pages.OIDCClientLogin; import org.apache.syncope.client.ui.commons.annotations.Resource; import org.apache.syncope.client.ui.commons.panels.OIDCC4UIConstants; import org.apache.syncope.client.ui.commons.resources.oidcc4ui.CodeConsumerResource; +import org.apache.syncope.common.lib.to.UserTO; import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.request.mapper.parameter.PageParameters; @Resource( key = OIDCC4UIConstants.URL_CONTEXT + ".codeConsumer", @@ -37,7 +40,7 @@ public class ConsoleCodeConsumerResource extends CodeConsumerResource { } @Override - protected Class<? extends WebPage> getSelfRegPageClass() { + protected Pair<Class<? extends WebPage>, PageParameters> getSelfRegInfo(final UserTO newUser) { throw new UnsupportedOperationException("Self-registration not supported by Admin Console"); } } diff --git a/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/pages/OIDCClientSelfReg.java b/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/pages/OIDCClientSelfReg.java deleted file mode 100644 index 8270e99..0000000 --- a/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/pages/OIDCClientSelfReg.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.client.enduser.pages; - -import org.apache.syncope.client.ui.commons.panels.OIDCC4UIConstants; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.protocol.http.servlet.ServletWebRequest; -import org.apache.wicket.request.mapper.parameter.PageParameters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class OIDCClientSelfReg extends WebPage { - - private static final Logger LOG = LoggerFactory.getLogger(OIDCClientSelfReg.class); - - private static final long serialVersionUID = -2533879075075645461L; - - public OIDCClientSelfReg(final PageParameters parameters) { - super(parameters); - - PageParameters params = new PageParameters(); - try { - params.add(Self.NEW_USER_PARAM, - ((ServletWebRequest) getRequest()).getContainerRequest(). - getSession().getAttribute(OIDCC4UIConstants.OIDCC4UI_NEW_USER)); - } catch (Exception e) { - LOG.error("While getting user data from social registration", e); - - params.add("errorMessage", "OpenID Connect error - while getting user data from social registration"); - } - setResponsePage(Self.class, params); - } -} diff --git a/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserCodeConsumerResource.java b/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserCodeConsumerResource.java index d83940d..2e7055c 100644 --- a/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserCodeConsumerResource.java +++ b/ext/oidcc4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserCodeConsumerResource.java @@ -18,12 +18,16 @@ */ package org.apache.syncope.client.enduser.resources; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.tuple.Pair; import org.apache.syncope.client.enduser.pages.OIDCClientLogin; import org.apache.syncope.client.enduser.pages.Self; import org.apache.syncope.client.ui.commons.annotations.Resource; import org.apache.syncope.client.ui.commons.panels.OIDCC4UIConstants; import org.apache.syncope.client.ui.commons.resources.oidcc4ui.CodeConsumerResource; +import org.apache.syncope.common.lib.to.UserTO; import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.request.mapper.parameter.PageParameters; @Resource( key = OIDCC4UIConstants.URL_CONTEXT + ".codeConsumer", @@ -38,7 +42,9 @@ public class EnduserCodeConsumerResource extends CodeConsumerResource { } @Override - protected Class<? extends WebPage> getSelfRegPageClass() { - return Self.class; + protected Pair<Class<? extends WebPage>, PageParameters> getSelfRegInfo(final UserTO newUser) + throws JsonProcessingException { + + return Pair.of(Self.class, new PageParameters().add(Self.NEW_USER_PARAM, MAPPER.writeValueAsString(newUser))); } } diff --git a/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/SAML2SP4UIConstants.java b/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/SAML2SP4UIConstants.java index 7b00bdb..073dca6 100644 --- a/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/SAML2SP4UIConstants.java +++ b/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/SAML2SP4UIConstants.java @@ -30,8 +30,6 @@ public final class SAML2SP4UIConstants { public static final String SAML2SP4UI_IDP_ENTITY_ID = "saml2sp4ui.idpEntityID"; - public static final String SAML2SP4UI_NEW_USER = "saml2sp4ui.newUser"; - private SAML2SP4UIConstants() { // private constructor for static utility class } diff --git a/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/saml2sp4ui/AssertionConsumerResource.java b/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/saml2sp4ui/AssertionConsumerResource.java index 2186c88..b65aac3 100644 --- a/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/saml2sp4ui/AssertionConsumerResource.java +++ b/ext/saml2sp4ui/client-common-ui/src/main/java/org/apache/syncope/client/ui/commons/resources/saml2sp4ui/AssertionConsumerResource.java @@ -21,6 +21,7 @@ package org.apache.syncope.client.ui.commons.resources.saml2sp4ui; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.tuple.Pair; import org.apache.syncope.client.ui.commons.BaseSession; import org.apache.syncope.client.ui.commons.SAML2SP4UIConstants; import org.apache.syncope.common.lib.saml2.SAML2LoginResponse; @@ -31,17 +32,22 @@ import org.apache.wicket.Session; import org.apache.wicket.WicketRuntimeException; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class AssertionConsumerResource extends AbstractSAML2SP4UIResource { private static final long serialVersionUID = 3858609271031003370L; - private static final ObjectMapper MAPPER = + protected static final Logger LOG = LoggerFactory.getLogger(AssertionConsumerResource.class); + + protected static final ObjectMapper MAPPER = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY); protected abstract Class<? extends WebPage> getLoginPageClass(); - protected abstract Class<? extends WebPage> getSelfRegPageClass(); + protected abstract Pair<Class<? extends WebPage>, PageParameters> getSelfRegInfo(UserTO newUser) + throws JsonProcessingException; @Override protected ResourceResponse newResourceResponse(final Attributes attributes) { @@ -54,10 +60,8 @@ public abstract class AssertionConsumerResource extends AbstractSAML2SP4UIResour newUser.getPlainAttrs().addAll(saml2Response.getAttrs()); try { - throw new RestartResponseException( - getSelfRegPageClass(), - new PageParameters(). - set(SAML2SP4UIConstants.SAML2SP4UI_NEW_USER, MAPPER.writeValueAsString(newUser))); + Pair<Class<? extends WebPage>, PageParameters> selfRegInfo = getSelfRegInfo(newUser); + throw new RestartResponseException(selfRegInfo.getLeft(), selfRegInfo.getRight()); } catch (JsonProcessingException e) { LOG.error("Could not serialize new user {}", newUser, e); throw new WicketRuntimeException(e); diff --git a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleAssertionConsumerResource.java b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleAssertionConsumerResource.java index a2cee48..8f5aa13 100644 --- a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleAssertionConsumerResource.java +++ b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/resources/ConsoleAssertionConsumerResource.java @@ -18,11 +18,14 @@ */ package org.apache.syncope.client.console.resources; +import org.apache.commons.lang3.tuple.Pair; import org.apache.syncope.client.console.pages.SAML2SPLogin; import org.apache.syncope.client.ui.commons.SAML2SP4UIConstants; import org.apache.syncope.client.ui.commons.annotations.Resource; import org.apache.syncope.client.ui.commons.resources.saml2sp4ui.AssertionConsumerResource; +import org.apache.syncope.common.lib.to.UserTO; import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.request.mapper.parameter.PageParameters; @Resource( key = SAML2SP4UIConstants.URL_CONTEXT + ".assertionConsumer", @@ -37,7 +40,7 @@ public class ConsoleAssertionConsumerResource extends AssertionConsumerResource } @Override - protected Class<? extends WebPage> getSelfRegPageClass() { + protected Pair<Class<? extends WebPage>, PageParameters> getSelfRegInfo(final UserTO newUser) { throw new UnsupportedOperationException("Self-registration not supported by Admin Console"); } } diff --git a/ext/saml2sp4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserAssertionConsumerResource.java b/ext/saml2sp4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserAssertionConsumerResource.java index 132222a..a072111 100644 --- a/ext/saml2sp4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserAssertionConsumerResource.java +++ b/ext/saml2sp4ui/client-enduser/src/main/java/org/apache/syncope/client/enduser/resources/EnduserAssertionConsumerResource.java @@ -18,12 +18,16 @@ */ package org.apache.syncope.client.enduser.resources; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.tuple.Pair; import org.apache.syncope.client.enduser.pages.SAML2SPLogin; import org.apache.syncope.client.enduser.pages.Self; import org.apache.syncope.client.ui.commons.SAML2SP4UIConstants; import org.apache.syncope.client.ui.commons.annotations.Resource; import org.apache.syncope.client.ui.commons.resources.saml2sp4ui.AssertionConsumerResource; +import org.apache.syncope.common.lib.to.UserTO; import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.request.mapper.parameter.PageParameters; @Resource( key = SAML2SP4UIConstants.URL_CONTEXT + ".assertionConsumer", @@ -38,7 +42,9 @@ public class EnduserAssertionConsumerResource extends AssertionConsumerResource } @Override - protected Class<? extends WebPage> getSelfRegPageClass() { - return Self.class; + protected Pair<Class<? extends WebPage>, PageParameters> getSelfRegInfo(final UserTO newUser) + throws JsonProcessingException { + + return Pair.of(Self.class, new PageParameters().add(Self.NEW_USER_PARAM, MAPPER.writeValueAsString(newUser))); } }
