incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r682946 - in /incubator/sling/trunk/engine: pom.xml src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
Date Tue, 05 Aug 2008 21:00:54 GMT
Author: fmeschbe
Date: Tue Aug  5 14:00:52 2008
New Revision: 682946

URL: http://svn.apache.org/viewvc?rev=682946&view=rev
Log:
SLING-599 Applied patch and marked import of useradmin package
optional in case the framework has no useradmin package exported.

Modified:
    incubator/sling/trunk/engine/pom.xml
    incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java

Modified: incubator/sling/trunk/engine/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/engine/pom.xml?rev=682946&r1=682945&r2=682946&view=diff
==============================================================================
--- incubator/sling/trunk/engine/pom.xml (original)
+++ incubator/sling/trunk/engine/pom.xml Tue Aug  5 14:00:52 2008
@@ -64,6 +64,7 @@
                             org.apache.sling.engine.impl.*
                         </Private-Package>
                         <Import-Package>
+                            org.osgi.service.useradmin;
                             javax.portlet;resolution:=optional,
                             *
                         </Import-Package>

Modified: incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java?rev=682946&r1=682945&r2=682946&view=diff
==============================================================================
--- incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
(original)
+++ incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
Tue Aug  5 14:00:52 2008
@@ -20,7 +20,9 @@
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
+import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -47,6 +49,8 @@
 import org.apache.sling.engine.impl.parameters.ParameterSupport;
 import org.apache.sling.engine.impl.request.RequestData;
 import org.apache.sling.engine.impl.request.SlingRequestDispatcher;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.useradmin.Authorization;
 
 /**
  * The <code>SlingHttpServletRequestImpl</code> TODO
@@ -248,4 +252,74 @@
             IOException {
         return this.getRequestData().getReader();
     }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#getUserPrincipal()
+     */
+    @Override
+    public Principal getUserPrincipal() {
+        String remoteUser = getRemoteUser();
+        return (remoteUser != null) ? new UserPrincipal(remoteUser) : null;
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServletRequestWrapper#isUserInRole()
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean isUserInRole(String role) {
+        Object authorization = getAttribute(HttpContext.AUTHORIZATION);
+        return (authorization instanceof Authorization)
+                ? ((Authorization) authorization).hasRole(role)
+                : false;
+    }
+
+    /**
+     * A <code>UserPrincipal</code> ...
+     */
+    private static class UserPrincipal implements Principal, Serializable {
+
+        private final String name;
+
+        /**
+         * Creates a <code>UserPrincipal</code> with the given name.
+         *
+         * @param name the name of this principal
+         * @throws IllegalArgumentException if <code>name</code> is <code>null</code>.
+         */
+        public UserPrincipal(String name) throws IllegalArgumentException {
+            if (name == null) {
+                throw new IllegalArgumentException("name can not be null");
+            }
+            this.name = name;
+        }
+
+        public String toString() {
+            return ("UserPrincipal: " + name);
+        }
+
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof UserPrincipal) {
+                UserPrincipal other = (UserPrincipal) obj;
+                return name.equals(other.name);
+            }
+            return false;
+        }
+
+        public int hashCode() {
+            return name.hashCode();
+        }
+
+        //------------------------------------------------------------< Principal >
+        /**
+         * {@inheritDoc}
+         */
+        public String getName() {
+            return name;
+        }
+    }
+
 }



Mime
View raw message