You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ja...@apache.org on 2007/10/11 11:53:52 UTC

svn commit: r583759 - /lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/cms/cocoon/acting/SslRedirectAction.java

Author: jann
Date: Thu Oct 11 02:53:51 2007
New Revision: 583759

URL: http://svn.apache.org/viewvc?rev=583759&view=rev
Log:
Adding SslRedirectAction adapted from lenya 2.0

Added:
    lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/cms/cocoon/acting/SslRedirectAction.java

Added: lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/cms/cocoon/acting/SslRedirectAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/cms/cocoon/acting/SslRedirectAction.java?rev=583759&view=auto
==============================================================================
--- lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/cms/cocoon/acting/SslRedirectAction.java (added)
+++ lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/cms/cocoon/acting/SslRedirectAction.java Thu Oct 11 02:53:51 2007
@@ -0,0 +1,103 @@
+/*
+ * 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.lenya.cms.cocoon.acting;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.acting.ConfigurableServiceableAction;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.lenya.ac.AccessControllerResolver;
+import org.apache.lenya.ac.AccreditableManager;
+import org.apache.lenya.ac.Policy;
+import org.apache.lenya.ac.impl.DefaultAccessController;
+import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.util.OutgoingLinkRewriter;
+import org.apache.cocoon.environment.Session;
+import org.apache.lenya.util.ServletHelper;
+
+
+/**
+ * Returns a map if the current request needs a redirect to the <code>https://</code> protocol.
+ * This is the case if the policy requires SSL protection and the current request is not secure. The
+ * map contains the redirect URI as value for the key <em>redirectUri</em>. Otherwise,
+ * <code>null</code> is returned.
+ */
+public class SslRedirectAction extends ConfigurableServiceableAction {
+
+    /**
+     * The key to obtain the redirect URI from the returned map.
+     */
+    public static final String KEY_REDIRECT_URI = "redirectUri";
+
+    public Map act(Redirector redirector, SourceResolver sourceResolver, Map objectModel,
+            String source, Parameters parameters) throws Exception {
+
+        ServiceSelector selector = null;
+        DefaultAccessController accessController = null;
+        AccessControllerResolver resolver = null;
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+
+        try {
+        	
+            selector = (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
+            resolver =
+                (AccessControllerResolver) selector.select(
+                    AccessControllerResolver.DEFAULT_RESOLVER);
+
+            String url = ServletHelper.getWebappURI(request);
+            accessController = (DefaultAccessController) resolver.resolveAccessController(url);
+                    
+
+            if (accessController != null) {
+
+            		AccreditableManager accMgr = accessController.getAccreditableManager();
+                Policy policy = accessController.getPolicyManager().getPolicy(accMgr, url);
+
+                URLInformation info = new URLInformation(url);
+                String area = info.getCompleteArea();
+
+                if (policy.isSSLProtected() && !area.startsWith(Publication.INFO_AREA_PREFIX)) {
+                    Session session = request.getSession(true);
+                    OutgoingLinkRewriter rewriter = new OutgoingLinkRewriter(this.manager, getLogger());
+                    String sslUri = rewriter.rewrite(url);
+                    return Collections.singletonMap(KEY_REDIRECT_URI, sslUri);
+                }
+            }
+
+        } finally {
+            if (selector != null) {
+                if (resolver != null) {
+                    if (accessController != null) {
+                        resolver.release(accessController);
+                    }
+                    selector.release(resolver);
+                }
+                this.manager.release(selector);
+            }
+        }
+        return null;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org