You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2023/01/16 09:29:48 UTC
[syncope] 02/02: Keeping up with latest pac4j SNAPSHOT
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 0c64d0d259c9d9faa2bc1ca934d7aae2cfb01d2d
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Mon Jan 16 10:29:34 2023 +0100
Keeping up with latest pac4j SNAPSHOT
---
.../apache/syncope/core/logic/OIDCC4UILogic.java | 5 ++-
.../core/logic/oidc/BaseProfileManagerFactory.java | 38 ++++++++++++++++++++++
.../apache/syncope/core/logic/SAML2SP4UILogic.java | 16 ++++++---
pom.xml | 2 +-
.../saml2/SAML2LogoutResponseWebFilter.java | 2 +-
.../saml2/SAML2RequestServerLogoutHandler.java | 9 +++--
.../SAML2WebSsoAuthenticationRequestWebFilter.java | 4 ++-
7 files changed, 65 insertions(+), 11 deletions(-)
diff --git a/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/OIDCC4UILogic.java b/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/OIDCC4UILogic.java
index e29b5c7def..9ae4e56988 100644
--- a/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/OIDCC4UILogic.java
+++ b/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/OIDCC4UILogic.java
@@ -40,6 +40,7 @@ import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.CipherAlgorithm;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
+import org.apache.syncope.core.logic.oidc.BaseProfileManagerFactory;
import org.apache.syncope.core.logic.oidc.NoOpSessionStore;
import org.apache.syncope.core.logic.oidc.OIDC4UIContext;
import org.apache.syncope.core.logic.oidc.OIDCClientCache;
@@ -110,7 +111,8 @@ public class OIDCC4UILogic extends AbstractTransactionalLogic<EntityTO> {
oidcClient.setCallbackUrl(redirectURI);
// 2. create OIDCRequest
- WithLocationAction action = oidcClient.getRedirectionAction(new OIDC4UIContext(), NoOpSessionStore.INSTANCE).
+ WithLocationAction action = oidcClient.getRedirectionAction(
+ new OIDC4UIContext(), NoOpSessionStore.INSTANCE, BaseProfileManagerFactory.INSTANCE).
map(WithLocationAction.class::cast).
orElseThrow(() -> {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
@@ -274,6 +276,7 @@ public class OIDCC4UILogic extends AbstractTransactionalLogic<EntityTO> {
WithLocationAction action = oidcClient.getLogoutAction(
new OIDC4UIContext(),
NoOpSessionStore.INSTANCE,
+ BaseProfileManagerFactory.INSTANCE,
profile,
redirectURI).
map(WithLocationAction.class::cast).
diff --git a/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/oidc/BaseProfileManagerFactory.java b/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/oidc/BaseProfileManagerFactory.java
new file mode 100644
index 0000000000..08d34b9824
--- /dev/null
+++ b/ext/oidcc4ui/logic/src/main/java/org/apache/syncope/core/logic/oidc/BaseProfileManagerFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.logic.oidc;
+
+import org.pac4j.core.context.WebContext;
+import org.pac4j.core.context.session.SessionStore;
+import org.pac4j.core.profile.ProfileManager;
+import org.pac4j.core.profile.factory.ProfileManagerFactory;
+
+public final class BaseProfileManagerFactory implements ProfileManagerFactory {
+
+ public static final BaseProfileManagerFactory INSTANCE = new BaseProfileManagerFactory();
+
+ private BaseProfileManagerFactory() {
+ // private constructor for singleton
+ }
+
+ @Override
+ public ProfileManager apply(final WebContext wc, final SessionStore ss) {
+ return new ProfileManager(wc, ss);
+ }
+}
diff --git a/ext/saml2sp4ui/logic/src/main/java/org/apache/syncope/core/logic/SAML2SP4UILogic.java b/ext/saml2sp4ui/logic/src/main/java/org/apache/syncope/core/logic/SAML2SP4UILogic.java
index d83a38f888..610b6d152c 100644
--- a/ext/saml2sp4ui/logic/src/main/java/org/apache/syncope/core/logic/SAML2SP4UILogic.java
+++ b/ext/saml2sp4ui/logic/src/main/java/org/apache/syncope/core/logic/SAML2SP4UILogic.java
@@ -78,6 +78,7 @@ import org.pac4j.core.exception.http.RedirectionAction;
import org.pac4j.core.exception.http.WithContentAction;
import org.pac4j.core.exception.http.WithLocationAction;
import org.pac4j.core.logout.NoLogoutActionBuilder;
+import org.pac4j.core.profile.factory.ProfileManagerFactory;
import org.pac4j.saml.client.SAML2Client;
import org.pac4j.saml.config.SAML2Configuration;
import org.pac4j.saml.context.SAML2MessageContext;
@@ -276,7 +277,9 @@ public class SAML2SP4UILogic extends AbstractTransactionalLogic<EntityTO> {
@Override
public Optional<RedirectionAction> getRedirectionAction(
- final WebContext wc, final SessionStore sessionStore) {
+ final WebContext wc,
+ final SessionStore sessionStore,
+ final ProfileManagerFactory profileManagerFactory) {
this.saml2ObjectBuilder = new SAML2AuthnRequestBuilder() {
@@ -287,7 +290,7 @@ public class SAML2SP4UILogic extends AbstractTransactionalLogic<EntityTO> {
return authnRequest;
}
};
- return super.getRedirectionAction(wc, sessionStore);
+ return super.getRedirectionAction(wc, sessionStore, profileManagerFactory);
}
});
});
@@ -296,7 +299,8 @@ public class SAML2SP4UILogic extends AbstractTransactionalLogic<EntityTO> {
SAML2SP4UIContext ctx = new SAML2SP4UIContext(
saml2Client.getConfiguration().getAuthnRequestBindingType(),
null);
- RedirectionAction action = saml2Client.getRedirectionAction(ctx, NoOpSessionStore.INSTANCE).
+ RedirectionAction action = saml2Client.getRedirectionAction(
+ ctx, NoOpSessionStore.INSTANCE, BaseProfileManagerFactory.INSTANCE).
orElseThrow(() -> {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
sce.getElements().add("No RedirectionAction generated for AuthnRequest");
@@ -481,7 +485,9 @@ public class SAML2SP4UILogic extends AbstractTransactionalLogic<EntityTO> {
RedirectionAction action = saml2Client.getLogoutAction(
ctx,
NoOpSessionStore.INSTANCE,
- saml2Profile, null).
+ BaseProfileManagerFactory.INSTANCE,
+ saml2Profile,
+ null).
orElseThrow(() -> {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
sce.getElements().add("No RedirectionAction generated for LogoutRequest");
@@ -513,7 +519,7 @@ public class SAML2SP4UILogic extends AbstractTransactionalLogic<EntityTO> {
LogoutResponse logoutResponse;
try {
SAML2MessageContext saml2Ctx = saml2Client.getContextProvider().
- buildContext(saml2Client, ctx, NoOpSessionStore.INSTANCE);
+ buildContext(saml2Client, ctx, NoOpSessionStore.INSTANCE, BaseProfileManagerFactory.INSTANCE);
saml2Client.getLogoutProfileHandler().receive(saml2Ctx);
logoutResponse = (LogoutResponse) saml2Ctx.getMessageContext().getMessage();
diff --git a/pom.xml b/pom.xml
index d3603ca7dc..62cea3e12c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -440,7 +440,7 @@ under the License.
<pac4j.version>6.0.0-RC5-SNAPSHOT</pac4j.version>
<cas.version>7.0.0-SNAPSHOT</cas.version>
- <cas-client.version>4.0.0</cas-client.version>
+ <cas-client.version>4.0.1</cas-client.version>
<h2.version>2.1.214</h2.version>
diff --git a/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2LogoutResponseWebFilter.java b/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2LogoutResponseWebFilter.java
index f503a7cfc5..d6b9804ad3 100644
--- a/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2LogoutResponseWebFilter.java
+++ b/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2LogoutResponseWebFilter.java
@@ -85,7 +85,7 @@ public class SAML2LogoutResponseWebFilter implements WebFilter {
try {
SAML2MessageContext ctx = saml2Client.getContextProvider().
- buildContext(this.saml2Client, swec, NoOpSessionStore.INSTANCE);
+ buildContext(this.saml2Client, swec, NoOpSessionStore.INSTANCE, BaseProfileManagerFactory.INSTANCE);
saml2Client.getLogoutProfileHandler().receive(ctx);
} catch (OkAction e) {
LOG.debug("LogoutResponse was actually validated but no postLogoutURL was set", e);
diff --git a/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2RequestServerLogoutHandler.java b/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2RequestServerLogoutHandler.java
index 6c7e783864..3c2d3acc86 100644
--- a/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2RequestServerLogoutHandler.java
+++ b/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2RequestServerLogoutHandler.java
@@ -19,6 +19,7 @@
package org.apache.syncope.sra.security.saml2;
import org.apache.syncope.sra.SessionConfig;
+import org.apache.syncope.sra.security.pac4j.BaseProfileManagerFactory;
import org.apache.syncope.sra.security.pac4j.NoOpSessionStore;
import org.apache.syncope.sra.security.pac4j.RedirectionActionUtils;
import org.apache.syncope.sra.security.pac4j.ServerWebExchangeContext;
@@ -58,8 +59,12 @@ public class SAML2RequestServerLogoutHandler implements ServerLogoutHandler {
cacheManager.getCache(SessionConfig.DEFAULT_CACHE).evictIfPresent(session.getId());
return session.invalidate().then(
- saml2Client.getLogoutAction(swec,
- NoOpSessionStore.INSTANCE, credentials.getUserProfile(), null).
+ saml2Client.getLogoutAction(
+ swec,
+ NoOpSessionStore.INSTANCE,
+ BaseProfileManagerFactory.INSTANCE,
+ credentials.getUserProfile(),
+ null).
map(action -> RedirectionActionUtils.handle(action, swec)).
orElseThrow(() -> new IllegalStateException("No action generated")));
}).onErrorResume(Mono::error);
diff --git a/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2WebSsoAuthenticationRequestWebFilter.java b/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2WebSsoAuthenticationRequestWebFilter.java
index 6d9e9ec2ac..fcaff70733 100644
--- a/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2WebSsoAuthenticationRequestWebFilter.java
+++ b/sra/src/main/java/org/apache/syncope/sra/security/saml2/SAML2WebSsoAuthenticationRequestWebFilter.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.sra.security.saml2;
+import org.apache.syncope.sra.security.pac4j.BaseProfileManagerFactory;
import org.apache.syncope.sra.security.pac4j.NoOpSessionStore;
import org.apache.syncope.sra.security.pac4j.RedirectionActionUtils;
import org.apache.syncope.sra.security.pac4j.ServerWebExchangeContext;
@@ -58,7 +59,8 @@ public class SAML2WebSsoAuthenticationRequestWebFilter implements WebFilter {
ServerWebExchangeContext swec = new ServerWebExchangeContext(exchange);
- return saml2Client.getRedirectionAction(swec, NoOpSessionStore.INSTANCE).
+ return saml2Client.getRedirectionAction(
+ swec, NoOpSessionStore.INSTANCE, BaseProfileManagerFactory.INSTANCE).
map(action -> RedirectionActionUtils.handle(action, swec)).
orElseThrow(() -> new IllegalStateException("No action generated"));
}).onErrorResume(Mono::error);