cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbernha...@apache.org
Subject cxf-fediz git commit: [FEDIZ-53] Add whr parameter forwarding to plugin
Date Wed, 18 Mar 2015 14:19:01 GMT
Repository: cxf-fediz
Updated Branches:
  refs/heads/master 799afc9a2 -> 8b0146d7d


[FEDIZ-53] Add whr parameter forwarding to plugin


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/8b0146d7
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/8b0146d7
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/8b0146d7

Branch: refs/heads/master
Commit: 8b0146d7d2b8484337c4354a9e9cece01b513671
Parents: 799afc9
Author: Jan Bernhardt <jbernhardt@talend.com>
Authored: Wed Mar 18 14:56:01 2015 +0100
Committer: Jan Bernhardt <jbernhardt@talend.com>
Committed: Wed Mar 18 15:18:44 2015 +0100

----------------------------------------------------------------------
 .../core/processor/FederationProcessorImpl.java | 27 +++++++++++-------
 .../core/federation/FederationRequestTest.java  | 30 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/8b0146d7/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 7a4dc52..40c3a93 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
@@ -567,16 +567,23 @@ public class FederationProcessorImpl extends AbstractFedizProcessor
{
 
     private String resolveHomeRealm(HttpServletRequest request, FedizContext config) throws
IOException,
         UnsupportedCallbackException {
-        Object homeRealmObj = ((FederationProtocol)config.getProtocol()).getHomeRealm();
-        String homeRealm = null;
-        if (homeRealmObj != null) {
-            if (homeRealmObj instanceof String) {
-                homeRealm = (String)homeRealmObj;
-            } else if (homeRealmObj instanceof CallbackHandler) {
-                CallbackHandler hrCB = (CallbackHandler)homeRealmObj;
-                HomeRealmCallback callback = new HomeRealmCallback(request);
-                hrCB.handle(new Callback[] {callback});
-                homeRealm = callback.getHomeRealm();
+        // Check if whr parameter was provided in request
+        String homeRealm = request.getParameter(FederationConstants.PARAM_HOME_REALM);
+        
+        if (homeRealm == null || homeRealm.isEmpty()) {
+            // Check if home realm is set in configuration
+            Object homeRealmObj = ((FederationProtocol)config.getProtocol()).getHomeRealm();
+            if (homeRealmObj != null) {
+                if (homeRealmObj instanceof String) {
+                    homeRealm = (String)homeRealmObj;
+                } else if (homeRealmObj instanceof CallbackHandler) {
+                    CallbackHandler hrCB = (CallbackHandler)homeRealmObj;
+                    HomeRealmCallback callback = new HomeRealmCallback(request);
+                    hrCB.handle(new Callback[] {
+                        callback
+                    });
+                    homeRealm = callback.getHomeRealm();
+                }
             }
         }
         return homeRealm;

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/8b0146d7/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/FederationRequestTest.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/FederationRequestTest.java
b/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/FederationRequestTest.java
index 6624f85..51596a7 100644
--- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/FederationRequestTest.java
+++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/federation/FederationRequestTest.java
@@ -21,11 +21,13 @@ package org.apache.cxf.fediz.core.federation;
 
 import java.io.File;
 import java.net.URL;
+import java.net.URLEncoder;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.cxf.fediz.common.SecurityTestUtil;
+import org.apache.cxf.fediz.core.FederationConstants;
 import org.apache.cxf.fediz.core.config.FedizConfigurator;
 import org.apache.cxf.fediz.core.config.FedizContext;
 import org.apache.cxf.fediz.core.processor.FederationProcessorImpl;
@@ -92,6 +94,7 @@ public class FederationRequestTest {
         FedizContext config = getFederationConfigurator().getFedizContext("ROOT");
         
         HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
+        EasyMock.expect(req.getParameter(FederationConstants.PARAM_HOME_REALM)).andReturn(null);
         EasyMock.expect(req.getRequestURL()).andReturn(new StringBuffer(TEST_REQUEST_URL)).times(1,
2);
         EasyMock.expect(req.getContextPath()).andReturn(TEST_REQUEST_URI);
         EasyMock.replay(req);
@@ -110,6 +113,33 @@ public class FederationRequestTest {
     }
     
     @org.junit.Test
+    public void createFederationSignInRequestWithUrlDefinedHomeRealm() throws Exception {
+        // Mock up a Request
+        FedizContext config = getFederationConfigurator().getFedizContext("ROOT");
+
+        HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
+        EasyMock.expect(req.getParameter(FederationConstants.PARAM_HOME_REALM))
+            .andReturn("urn:org:apache:cxf:fediz:idp:realm-A");
+        EasyMock.expect(req.getRequestURL()).andReturn(new StringBuffer(TEST_REQUEST_URL)).times(1,
2);
+        EasyMock.expect(req.getContextPath()).andReturn(TEST_REQUEST_URI);
+        EasyMock.replay(req);
+
+        FedizProcessor wfProc = new FederationProcessorImpl();
+        RedirectionResponse response = wfProc.createSignInRequest(req, config);
+
+        String redirectionURL = response.getRedirectionURL();
+        Assert.assertTrue(redirectionURL.startsWith(TEST_IDP_ISSUER));
+        Assert.assertTrue(redirectionURL.contains("wa=wsignin1.0"));
+        Assert.assertTrue(redirectionURL.contains("wreq=REQUEST"));
+        Assert.assertTrue(redirectionURL.contains("wfresh=10000"));
+        Assert.assertTrue(redirectionURL.contains("wct="));
+        Assert.assertTrue(redirectionURL.contains("wtrealm=target+realm"));
+        Assert.assertTrue(redirectionURL.contains("wreply="));
+        Assert.assertTrue(redirectionURL.contains("whr="
+                                                + URLEncoder.encode("urn:org:apache:cxf:fediz:idp:realm-A",
"UTF-8")));
+    }
+    
+    @org.junit.Test
     public void createFederationSignOutRequest() throws Exception {
         // Mock up a Request
         FedizContext config = getFederationConfigurator().getFedizContext("ROOT");


Mime
View raw message