Author: owulff
Date: Tue Aug 20 18:38:31 2013
New Revision: 1515912
URL: http://svn.apache.org/r1515912
Log:
[FEDIZ-64] Patch applied. Thanks Tom.
Added:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/handler/RealmCallbackHandler.java
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/RealmCallback.java
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/FederationProcessorImpl.java
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
cxf/fediz/trunk/plugins/core/src/main/resources/schemas/FedizConfig.xsd
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/FederationProcessorImpl.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/FederationProcessorImpl.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/FederationProcessorImpl.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/FederationProcessorImpl.java
Tue Aug 20 18:38:31 2013
@@ -49,6 +49,7 @@ import org.apache.cxf.fediz.core.metadat
import org.apache.cxf.fediz.core.spi.FreshnessCallback;
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.SignInQueryCallback;
import org.apache.cxf.fediz.core.spi.WAuthCallback;
import org.apache.cxf.fediz.core.util.DOMUtils;
@@ -393,12 +394,10 @@ public class FederationProcessorImpl imp
sb.append('&').append(FederationConstants.PARAM_REPLY).append('=');
sb.append(URLEncoder.encode(reply, "UTF-8"));
- String realm =
((FederationProtocol)config.getProtocol()).getRealm();
- if (realm == null) {
- realm = extractFullContextPath(request);
- }
+ String realm = resolveWTRealm(request, config);
LOG.debug("wtrealm=" + realm);
+ //add wtrealm parameter
sb.append('&').append(FederationConstants.PARAM_TREALM).append('=')
.append(URLEncoder.encode(realm, "UTF-8"));
@@ -532,7 +531,27 @@ public class FederationProcessorImpl imp
}
return issuerURL;
}
-
+
+ private String resolveWTRealm(HttpServletRequest request,
FederationContext config) throws IOException,
+ UnsupportedCallbackException {
+ Object wtRealmObj =
((FederationProtocol)config.getProtocol()).getRealm();
+ String wtRealm = null;
+ if (wtRealmObj != null) {
+ if (wtRealmObj instanceof String) {
+ wtRealm = (String)wtRealmObj;
+ } else if (wtRealmObj instanceof CallbackHandler) {
+ CallbackHandler hrCB = (CallbackHandler)wtRealmObj;
+ RealmCallback callback = new RealmCallback(request);
+ hrCB.handle(new Callback[] {callback});
+ wtRealm = callback.getRealm();
+ }
+ } else {
+ wtRealm = extractFullContextPath(request); //default value
+ }
+ return wtRealm;
+ }
+
+
private String extractFullContextPath(HttpServletRequest request) throws
MalformedURLException {
String result = null;
String contextPath = request.getContextPath();
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationProtocol.java
Tue Aug 20 18:38:31 2013
@@ -44,6 +44,7 @@ public class FederationProtocol extends
private Object homeRealm;
private Object freshness;
private Object signInQuery;
+ private Object realm;
private List<TokenValidator> validators = new ArrayList<TokenValidator>();
public FederationProtocol(ProtocolType protocolType) {
@@ -86,12 +87,41 @@ public class FederationProtocol extends
return getFederationProtocol().hashCode();
}
- public String getRealm() {
- return getFederationProtocol().getRealm();
+ public Object getRealm() {
+ if (this.realm != null) {
+ return this.realm;
+ }
+ CallbackType cbt = getFederationProtocol().getRealm();
+ if (cbt == null) {
+ return null;
+ }
+ if (cbt.getType() == null ||
cbt.getType().equals(ArgumentType.STRING)) {
+ this.realm = new String(cbt.getValue());
+ } else if (cbt.getType().equals(ArgumentType.CLASS)) {
+ try {
+ this.realm =
+
Thread.currentThread().getContextClassLoader().loadClass(cbt.getValue()).newInstance();
+ } catch (Exception e) {
+ LOG.error("Failed to create instance of " + cbt.getValue(), e);
+ throw new IllegalStateException("Failed to create instance of
" + cbt.getValue());
+ }
+ } else {
+ LOG.error("Only String and Class are supported for 'Realm'");
+ throw new IllegalStateException("Only String and Class are
supported for 'Realm'");
+ }
+ return this.realm;
}
- public void setRealm(String value) {
- getFederationProtocol().setRealm(value);
+ public void setRealm(Object value) {
+ final boolean isString = value instanceof String;
+ final boolean isCallbackHandler = value instanceof CallbackHandler;
+ if (isString || isCallbackHandler) {
+ this.realm = value;
+ } else {
+ LOG.error("Unsupported 'Realm' object");
+ throw new IllegalArgumentException("Unsupported 'Realm' object.
Type must be "
+ + "java.lang.String or
javax.security.auth.callback.CallbackHandler.");
+ }
}
public boolean equals(Object obj) {
Added:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/handler/RealmCallbackHandler.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/handler/RealmCallbackHandler.java?rev=1515912&view=auto
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/handler/RealmCallbackHandler.java
(added)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/handler/RealmCallbackHandler.java
Tue Aug 20 18:38:31 2013
@@ -0,0 +1,53 @@
+/**
+ * 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.handler;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.apache.cxf.fediz.core.FederationConstants;
+import org.apache.cxf.fediz.core.spi.RealmCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RealmCallbackHandler implements CallbackHandler {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(RealmCallbackHandler.class);
+
+ public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+ if (callbacks[i] instanceof RealmCallback) {
+ RealmCallback callback = (RealmCallback) callbacks[i];
+ String param = FederationConstants.PARAM_TREALM;
+ String wtRealm =
(String)callback.getRequest().getAttribute(param);
+ if (wtRealm == null || wtRealm.length() == 0) {
+ LOG.debug("No wtrealm found in request");
+ } else {
+ LOG.info("WTRealm '" + wtRealm + "' found in request");
+ callback.setRealm(wtRealm);
+ }
+ } else {
+ throw new UnsupportedCallbackException(callbacks[i],
"Unrecognized Callback");
+ }
+ }
+ }
+}
\ No newline at end of file
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
Tue Aug 20 18:38:31 2013
@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import javax.security.auth.callback.CallbackHandler;
import javax.xml.crypto.dsig.CanonicalizationMethod;
import javax.xml.crypto.dsig.DigestMethod;
import javax.xml.crypto.dsig.Reference;
@@ -145,7 +146,16 @@ public class MetadataWriter {
if (protocol instanceof FederationProtocol) {
FederationProtocol fedprotocol = (FederationProtocol)protocol;
- String realm = fedprotocol.getRealm();
+
+ Object realmObj = fedprotocol.getRealm();
+ String realm = null;
+ if (realmObj instanceof String) {
+ realm = (String)realmObj;
+ } else if (realmObj instanceof CallbackHandler) {
+ //TODO
+ //If realm is resolved at runtime, metadata not updated
+ }
+
if (!(realm == null || "".equals(realm))) {
writer.writeCharacters(realm);
}
@@ -155,8 +165,6 @@ public class MetadataWriter {
writer.writeEndElement(); // EndpointReference
writer.writeEndElement(); // TargetScope
- // TODO loop over Context config and populate claims from there
instead the dummy code below
-
if (protocol instanceof FederationProtocol) {
FederationProtocol fedprotocol = (FederationProtocol)protocol;
List<Claim> claims = fedprotocol.getClaimTypesRequested();
Added:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/RealmCallback.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/RealmCallback.java?rev=1515912&view=auto
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/RealmCallback.java
(added)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/spi/RealmCallback.java
Tue Aug 20 18:38:31 2013
@@ -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 RealmCallback extends AbstractServletCallback {
+
+ private String realm;
+
+ public RealmCallback(HttpServletRequest request) {
+ super(request);
+ }
+
+ public String getRealm() {
+ return realm;
+ }
+
+ public void setRealm(String realm) {
+ this.realm = realm;
+ }
+
+}
Modified:
cxf/fediz/trunk/plugins/core/src/main/resources/schemas/FedizConfig.xsd
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/resources/schemas/FedizConfig.xsd?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
--- cxf/fediz/trunk/plugins/core/src/main/resources/schemas/FedizConfig.xsd
(original)
+++ cxf/fediz/trunk/plugins/core/src/main/resources/schemas/FedizConfig.xsd Tue
Aug 20 18:38:31 2013
@@ -108,7 +108,7 @@
<xs:element name="roleDelimiter" type="xs:string" />
<xs:element name="roleURI" type="xs:string" />
- <xs:element name="realm" type="xs:string" />
+ <xs:element name="realm" type="CallbackType" />
<xs:element name="applicationServiceURL" type="xs:string" />
Modified:
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
Tue Aug 20 18:38:31 2013
@@ -48,6 +48,7 @@ import org.apache.cxf.fediz.core.config.
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.SignInQueryCallback;
import org.apache.cxf.fediz.core.spi.WAuthCallback;
import org.junit.AfterClass;
@@ -126,7 +127,10 @@ public class CallbackHandlerTest {
freshness.setValue(FRESHNESS_VALUE);
protocol.setFreshness(freshness);
- protocol.setRealm(TARGET_REALM);
+ CallbackType realm = new CallbackType();
+ realm.setValue(TARGET_REALM);
+ protocol.setRealm(freshness);
+
protocol.setReply(REPLY);
protocol.setRequest("REQUEST");
protocol.setVersion(PROTOCOL_VERSION);
@@ -187,6 +191,11 @@ public class CallbackHandlerTest {
signInQueryType.setValue(CALLBACKHANDLER_CLASS);
protocol.setSignInQuery(signInQueryType);
+ CallbackType realmType = new CallbackType();
+ realmType.setType(ArgumentType.CLASS);
+ realmType.setValue(CALLBACKHANDLER_CLASS);
+ protocol.setRealm(realmType);
+
return config;
}
@@ -230,6 +239,14 @@ public class CallbackHandlerTest {
String hr = callbackHR.getHomeRealm();
Assert.assertEquals(TestCallbackHandler.TEST_HOME_REALM, hr);
+ Object wtRealmObj = fp.getRealm();
+ Assert.assertTrue(wtRealmObj instanceof CallbackHandler);
+ CallbackHandler wtrCB = (CallbackHandler)wtRealmObj;
+ RealmCallback callbackWTR = new RealmCallback(null);
+ wtrCB.handle(new Callback[]{callbackWTR});
+ String wtr = callbackWTR.getRealm();
+ Assert.assertEquals(TestCallbackHandler.TEST_WTREALM, wtr);
+
Object signInQueryObj = fp.getSignInQuery();
Assert.assertTrue(signInQueryObj instanceof CallbackHandler);
CallbackHandler siqCB = (CallbackHandler)signInQueryObj;
Modified:
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
Tue Aug 20 18:38:31 2013
@@ -190,9 +190,12 @@ public class FedizConfigurationTest {
CallbackType homeRealm = new CallbackType();
homeRealm.setType(ArgumentType.CLASS);
homeRealm.setValue(HOME_REALM_CLASS);
-
protocol.setHomeRealm(homeRealm);
- protocol.setRealm(TARGET_REALM);
+
+ CallbackType realm = new CallbackType();
+ realm.setValue(TARGET_REALM);
+ protocol.setRealm(realm);
+
protocol.setReply(REPLY);
protocol.setRequest("REQUEST");
protocol.setVersion(PROTOCOL_VERSION);
Modified:
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
Tue Aug 20 18:38:31 2013
@@ -165,9 +165,12 @@ public class FedizConfigurationWriterTes
CallbackType homeRealm = new CallbackType();
homeRealm.setType(ArgumentType.CLASS);
homeRealm.setValue(HOME_REALM_CLASS);
-
protocol.setHomeRealm(homeRealm);
- protocol.setRealm(TARGET_REALM);
+
+ CallbackType realm = new CallbackType();
+ realm.setValue(TARGET_REALM);
+ protocol.setRealm(realm);
+
protocol.setReply(REPLY);
protocol.setRequest("REQUEST");
protocol.setVersion(PROTOCOL_VERSION);
Modified:
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java?rev=1515912&r1=1515911&r2=1515912&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/TestCallbackHandler.java
Tue Aug 20 18:38:31 2013
@@ -30,12 +30,14 @@ import javax.security.auth.callback.Unsu
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.SignInQueryCallback;
import org.apache.cxf.fediz.core.spi.WAuthCallback;
public class TestCallbackHandler implements CallbackHandler {
static final String TEST_HOME_REALM = "http://test.com/homerealm";
+ static final String TEST_WTREALM = "http://test.com/wtrealm";
static final String TEST_IDP = "http://rp.example.com/";
static final String TEST_WAUTH = "up";
static final String TEST_SIGNIN_QUERY = "pubid=myid";
@@ -45,6 +47,9 @@ public class TestCallbackHandler impleme
if (callbacks[i] instanceof HomeRealmCallback) {
HomeRealmCallback callback = (HomeRealmCallback) callbacks[i];
callback.setHomeRealm(TEST_HOME_REALM);
+ } else if (callbacks[i] instanceof RealmCallback) {
+ RealmCallback callback = (RealmCallback)callbacks[i];
+ callback.setRealm(TEST_WTREALM);
} else if (callbacks[i] instanceof WAuthCallback) {
WAuthCallback callback = (WAuthCallback) callbacks[i];
callback.setWauth(TEST_WAUTH);