Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 43BC8200C10 for ; Fri, 3 Feb 2017 11:41:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 424A3160B48; Fri, 3 Feb 2017 10:41:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1788B160B55 for ; Fri, 3 Feb 2017 11:40:59 +0100 (CET) Received: (qmail 87724 invoked by uid 500); 3 Feb 2017 10:40:56 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 87715 invoked by uid 99); 3 Feb 2017 10:40:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Feb 2017 10:40:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id ADD8BDFB95; Fri, 3 Feb 2017 10:40:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Message-Id: <1196468f9fd945579852a1de18014a4d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf-fediz git commit: FEDIZ-188 - Make "Reply" a CallbackType in the Fediz plugin configuration Date: Fri, 3 Feb 2017 10:40:56 +0000 (UTC) archived-at: Fri, 03 Feb 2017 10:41:01 -0000 Repository: cxf-fediz Updated Branches: refs/heads/master 620b6b95b -> bf99b6245 FEDIZ-188 - Make "Reply" a CallbackType in the Fediz plugin configuration Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/bf99b624 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/bf99b624 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/bf99b624 Branch: refs/heads/master Commit: bf99b62458350e2523c480b4954b045d7804a446 Parents: 620b6b9 Author: Colm O hEigeartaigh Authored: Fri Feb 3 10:40:33 2017 +0000 Committer: Colm O hEigeartaigh Committed: Fri Feb 3 10:40:33 2017 +0000 ---------------------------------------------------------------------- .../fediz/core/config/FederationProtocol.java | 22 +++++++++-- .../core/processor/FederationProcessorImpl.java | 22 ++++++++++- .../cxf/fediz/core/spi/ReplyCallback.java | 40 ++++++++++++++++++++ .../src/main/resources/schemas/FedizConfig.xsd | 3 +- .../fediz/core/config/CallbackHandlerTest.java | 18 ++++++++- .../core/config/FedizConfigurationTest.java | 4 +- .../config/FedizConfigurationWriterTest.java | 4 +- .../fediz/core/config/TestCallbackHandler.java | 5 +++ .../core/federation/RequestedClaimsTest.java | 4 +- 9 files changed, 111 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java index 6b37505..f6f096a 100644 --- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java +++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java @@ -37,6 +37,7 @@ public class FederationProtocol extends Protocol { private Object homeRealm; private Object freshness; private Object signInQuery; + private Object reply; public FederationProtocol(ProtocolType protocolType) { super(protocolType); @@ -161,12 +162,25 @@ public class FederationProtocol extends Protocol { } } - public String getReply() { - return getFederationProtocol().getReply(); + public Object getReply() { + if (this.reply != null) { + return this.reply; + } + CallbackType cbt = getFederationProtocol().getRequest(); + this.reply = loadCallbackType(cbt, "Reply"); + return this.reply; } - public void setReply(String value) { - getFederationProtocol().setReply(value); + public void setReply(Object value) { + final boolean isString = value instanceof String; + final boolean isCallbackHandler = value instanceof CallbackHandler; + if (isString || isCallbackHandler) { + this.reply = value; + } else { + LOG.error("Unsupported 'Reply' object"); + throw new IllegalArgumentException("Unsupported 'Reply' object. Type must be " + + "java.lang.String or javax.security.auth.callback.CallbackHandler."); + } } public String getVersion() { http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java index 5cb626e..aecee13 100644 --- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java +++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java @@ -57,6 +57,7 @@ import org.apache.cxf.fediz.core.exception.ProcessingException.TYPE; import org.apache.cxf.fediz.core.metadata.MetadataWriter; import org.apache.cxf.fediz.core.spi.FreshnessCallback; import org.apache.cxf.fediz.core.spi.HomeRealmCallback; +import org.apache.cxf.fediz.core.spi.ReplyCallback; import org.apache.cxf.fediz.core.spi.SignInQueryCallback; import org.apache.cxf.fediz.core.spi.WAuthCallback; import org.apache.cxf.fediz.core.spi.WReqCallback; @@ -400,7 +401,7 @@ public class FederationProcessorImpl extends AbstractFedizProcessor { StringBuilder sb = new StringBuilder(); sb.append(FederationConstants.PARAM_ACTION).append('=').append(FederationConstants.ACTION_SIGNIN); - String reply = ((FederationProtocol)config.getProtocol()).getReply(); + String reply = resolveReply(request, config); if (reply == null || reply.length() == 0) { reply = request.getRequestURL().toString(); } else { @@ -680,6 +681,25 @@ public class FederationProcessorImpl extends AbstractFedizProcessor { return wReq; } + private String resolveReply(HttpServletRequest request, FedizContext config) throws IOException, + UnsupportedCallbackException { + Object replyObj = ((FederationProtocol)config.getProtocol()).getReply(); + String reply = null; + if (replyObj != null) { + if (replyObj instanceof String) { + reply = (String)replyObj; + } else if (replyObj instanceof CallbackHandler) { + CallbackHandler replyCB = (CallbackHandler)replyObj; + ReplyCallback callback = new ReplyCallback(request); + replyCB.handle(new Callback[] { + callback + }); + reply = callback.getReply(); + } + } + return reply; + } + private void testForMandatoryClaims(String roleURI, List requestedClaims, List receivedClaims, http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/ReplyCallback.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/ReplyCallback.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/ReplyCallback.java new file mode 100644 index 0000000..90dba1f --- /dev/null +++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/ReplyCallback.java @@ -0,0 +1,40 @@ +/** + * 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.cxf.fediz.core.spi; + +import javax.servlet.http.HttpServletRequest; + +public class ReplyCallback extends AbstractServletCallback { + + private String reply; + + public ReplyCallback(HttpServletRequest request) { + super(request); + } + + public String getReply() { + return reply; + } + + public void setReply(String reply) { + this.reply = reply; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/main/resources/schemas/FedizConfig.xsd ---------------------------------------------------------------------- diff --git a/plugins/core/src/main/resources/schemas/FedizConfig.xsd b/plugins/core/src/main/resources/schemas/FedizConfig.xsd index 47b3a98..879e08d 100644 --- a/plugins/core/src/main/resources/schemas/FedizConfig.xsd +++ b/plugins/core/src/main/resources/schemas/FedizConfig.xsd @@ -225,6 +225,7 @@ + @@ -233,8 +234,6 @@ - - http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java index 23b565b..1699691 100644 --- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java +++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java @@ -49,6 +49,7 @@ import org.apache.cxf.fediz.core.config.jaxb.ValidationType; import org.apache.cxf.fediz.core.spi.HomeRealmCallback; import org.apache.cxf.fediz.core.spi.IDPCallback; import org.apache.cxf.fediz.core.spi.RealmCallback; +import org.apache.cxf.fediz.core.spi.ReplyCallback; import org.apache.cxf.fediz.core.spi.SignInQueryCallback; import org.apache.cxf.fediz.core.spi.WAuthCallback; import org.apache.cxf.fediz.core.spi.WReqCallback; @@ -125,7 +126,9 @@ public class CallbackHandlerTest { realm.setValue(TARGET_REALM); protocol.setRealm(freshness); - ((FederationProtocolType)protocol).setReply(REPLY); + CallbackType reply = new CallbackType(); + reply.setValue(REPLY); + ((FederationProtocolType)protocol).setReply(reply); ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION); } else { protocol = new SamlProtocolType(); @@ -215,6 +218,11 @@ public class CallbackHandlerTest { signInQueryType.setType(ArgumentType.CLASS); signInQueryType.setValue(CALLBACKHANDLER_CLASS); ((FederationProtocolType)protocol).setSignInQuery(signInQueryType); + + CallbackType replyType = new CallbackType(); + replyType.setType(ArgumentType.CLASS); + replyType.setValue(CALLBACKHANDLER_CLASS); + ((FederationProtocolType)protocol).setReply(replyType); } return config; @@ -286,6 +294,14 @@ public class CallbackHandlerTest { Assert.assertEquals("myid", signinQueryMap.get("pubid")); Assert.assertEquals("<=>", signinQueryMap.get("testenc")); + Object replyObj = fp.getReply(); + Assert.assertTrue(replyObj instanceof CallbackHandler); + CallbackHandler replyCB = (CallbackHandler)replyObj; + ReplyCallback callbackReply = new ReplyCallback(null); + replyCB.handle(new Callback[] {callbackReply}); + String reply = callbackReply.getReply(); + Assert.assertEquals(TestCallbackHandler.TEST_REPLY, reply); + } @org.junit.Test http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java index f2b0381..7d05960 100644 --- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java +++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java @@ -174,7 +174,9 @@ public class FedizConfigurationTest { homeRealm.setValue(HOME_REALM_CLASS); ((FederationProtocolType)protocol).setHomeRealm(homeRealm); - ((FederationProtocolType)protocol).setReply(REPLY); + CallbackType reply = new CallbackType(); + reply.setValue(REPLY); + ((FederationProtocolType)protocol).setReply(reply); ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION); } else { protocol = new SamlProtocolType(); http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java index e396398..4b60206 100644 --- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java +++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java @@ -167,7 +167,9 @@ public class FedizConfigurationWriterTest { homeRealm.setValue(HOME_REALM_CLASS); ((FederationProtocolType)protocol).setHomeRealm(homeRealm); - ((FederationProtocolType)protocol).setReply(REPLY); + CallbackType reply = new CallbackType(); + reply.setValue(REPLY); + ((FederationProtocolType)protocol).setReply(reply); ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION); } else { protocol = new SamlProtocolType(); http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java index 5c73d00..4302c32 100644 --- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java +++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java @@ -31,6 +31,7 @@ import javax.security.auth.callback.UnsupportedCallbackException; import org.apache.cxf.fediz.core.spi.HomeRealmCallback; import org.apache.cxf.fediz.core.spi.IDPCallback; import org.apache.cxf.fediz.core.spi.RealmCallback; +import org.apache.cxf.fediz.core.spi.ReplyCallback; import org.apache.cxf.fediz.core.spi.SignInQueryCallback; import org.apache.cxf.fediz.core.spi.WAuthCallback; import org.apache.cxf.fediz.core.spi.WReqCallback; @@ -42,6 +43,7 @@ public class TestCallbackHandler implements CallbackHandler { static final String TEST_IDP = "http://rp.example.com/"; static final String TEST_WAUTH = "up"; static final String TEST_SIGNIN_QUERY = "pubid=myid"; + static final String TEST_REPLY = "http://apache.org/reply"; static final String TEST_WREQ = "" + "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" @@ -70,6 +72,9 @@ public class TestCallbackHandler implements CallbackHandler { queryParamMap.put("pubid", "myid"); queryParamMap.put("testenc", "<=>"); callback.setSignInQueryParamMap(queryParamMap); + } else if (callbacks[i] instanceof ReplyCallback) { + ReplyCallback callback = (ReplyCallback) callbacks[i]; + callback.setReply(TEST_REPLY); } else { throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback"); } http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf99b624/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/RequestedClaimsTest.java ---------------------------------------------------------------------- diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/RequestedClaimsTest.java b/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/RequestedClaimsTest.java index 2a2ba45..ef01936 100644 --- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/RequestedClaimsTest.java +++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/RequestedClaimsTest.java @@ -168,7 +168,9 @@ public class RequestedClaimsTest { homeRealm.setValue(HOME_REALM_CLASS); ((FederationProtocolType)protocol).setHomeRealm(homeRealm); - ((FederationProtocolType)protocol).setReply(REPLY); + CallbackType reply = new CallbackType(); + reply.setValue(REPLY); + ((FederationProtocolType)protocol).setReply(reply); ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION); config.setProtocol(protocol);