shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r892346 [2/2] - in /incubator/shiro/trunk: core/src/main/java/org/apache/shiro/authc/ core/src/main/java/org/apache/shiro/authz/ core/src/main/java/org/apache/shiro/mgt/ core/src/main/java/org/apache/shiro/session/ core/src/main/java/org/ap...
Date Fri, 18 Dec 2009 18:52:53 GMT
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/authc/AuthenticatingFilter.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/authc/AuthenticatingFilter.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/authc/AuthenticatingFilter.java
(original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/authc/AuthenticatingFilter.java
Fri Dec 18 18:52:39 2009
@@ -18,15 +18,13 @@
  */
 package org.apache.shiro.web.filter.authc;
 
-import java.net.InetAddress;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
 import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.AuthenticationToken;
 import org.apache.shiro.authc.UsernamePasswordToken;
 import org.apache.shiro.subject.Subject;
-import org.apache.shiro.web.WebUtils;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 
 /**
  * An <code>AuthenticationFilter</code> that is capable of automatically performing
an authentication attempt
@@ -60,13 +58,13 @@
     protected AuthenticationToken createToken(String username, String password,
                                               ServletRequest request, ServletResponse response)
{
         boolean rememberMe = isRememberMe(request);
-        InetAddress inet = getInetAddress(request);
-        return createToken(username, password, rememberMe, inet);
+        String host = getHost(request);
+        return createToken(username, password, rememberMe, host);
     }
 
     protected AuthenticationToken createToken(String username, String password,
-                                              boolean rememberMe, InetAddress inet) {
-        return new UsernamePasswordToken(username, password, rememberMe, inet);
+                                              boolean rememberMe, String host) {
+        return new UsernamePasswordToken(username, password, rememberMe, host);
     }
 
     protected boolean onLoginSuccess(AuthenticationToken token, Subject subject,
@@ -80,17 +78,16 @@
     }
 
     /**
-     * Returns the InetAddress associated with the current subject.  This method is primarily
provided for use
+     * Returns the host name or IP associated with the current subject.  This method is primarily
provided for use
      * during construction of an <code>AuthenticationToken</code>.
      * <p/>
-     * The default implementation merely returns
-     * {@link org.apache.shiro.web.WebUtils#getInetAddress(javax.servlet.ServletRequest)
WebUtils.getInetAddress(request)}.
+     * The default implementation merely returns {@link ServletRequest#getRemoteHost()}.
      *
      * @param request the incoming ServletRequest
      * @return the <code>InetAddress</code> to associate with the login attempt.
      */
-    protected InetAddress getInetAddress(ServletRequest request) {
-        return WebUtils.getInetAddress(request);
+    protected String getHost(ServletRequest request) {
+        return request.getRemoteHost();
     }
 
     /**

Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/mgt/DefaultWebSubjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/mgt/DefaultWebSubjectFactory.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/mgt/DefaultWebSubjectFactory.java
(original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/mgt/DefaultWebSubjectFactory.java
Fri Dec 18 18:52:39 2009
@@ -30,7 +30,6 @@
 
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import java.net.InetAddress;
 import java.util.Map;
 
 /**
@@ -40,7 +39,7 @@
  * threads when using the {@code Subject} {@link Subject#associateWith(java.util.concurrent.Callable)
createCallable}
  * and {@link Subject#associateWith(Runnable) createRunnable} methods.
  *
- * @see #newSubjectInstance(org.apache.shiro.subject.PrincipalCollection, boolean, java.net.InetAddress,
org.apache.shiro.session.Session, org.apache.shiro.mgt.SecurityManager)
+ * @see #newSubjectInstance(org.apache.shiro.subject.PrincipalCollection, boolean, String,
org.apache.shiro.session.Session, org.apache.shiro.mgt.SecurityManager)
  * @since 1.0
  */
 public class DefaultWebSubjectFactory extends DefaultSubjectFactory {
@@ -102,29 +101,29 @@
     }
 
     @Override
-    protected InetAddress getInetAddress(Map context, Session session) {
-        InetAddress inet = super.getInetAddress(context, session);
-        if (inet == null) {
+    protected String getHost(Map context, Session session) {
+        String host = super.getHost(context, session);
+        if (host == null) {
             ServletRequest request = getServletRequest(context);
-            inet = WebUtils.getInetAddress(request);
+            host = request.getRemoteHost();
         }
-        return inet;
+        return host;
     }
 
     public Subject createSubject(Map context) {
         Session session = getSession(context);
         PrincipalCollection principals = getPrincipals(context, session);
         boolean authenticated = isAuthenticated(context, session);
-        InetAddress inet = getInetAddress(context, session);
+        String host = getHost(context, session);
         ServletRequest request = getServletRequest(context);
         ServletResponse response = getServletResponse(context);
-        return newSubjectInstance(principals, authenticated, inet, session, request, response,
getSecurityManager());
+        return newSubjectInstance(principals, authenticated, host, session, request, response,
getSecurityManager());
     }
 
     protected Subject newSubjectInstance(PrincipalCollection principals, boolean authenticated,
-                                         InetAddress inet, Session session,
+                                         String host, Session session,
                                          ServletRequest request, ServletResponse response,
                                          SecurityManager securityManager) {
-        return new WebDelegatingSubject(principals, authenticated, inet, session, request,
response, securityManager);
+        return new WebDelegatingSubject(principals, authenticated, host, session, request,
response, securityManager);
     }
 }

Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/DelegatingWebSessionManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/DelegatingWebSessionManager.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/DelegatingWebSessionManager.java
(original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/DelegatingWebSessionManager.java
Fri Dec 18 18:52:39 2009
@@ -29,7 +29,6 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
-import java.net.InetAddress;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
@@ -119,7 +118,7 @@
         assertDelegateExists();
         //get the host address and bind it to the thread.  This call will both validate the
session as well as
         //make it accessible for futher host checks:
-        InetAddress host = this.delegateSessionManager.getHostAddress(id);
+        String host = this.delegateSessionManager.getHost(id);
         session = new DelegatingSession(this.delegateSessionManager, id, host);
         log.trace("Cached the session retrieved from the datasource in a thread-local for
continued thread access.");
         ThreadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
@@ -166,10 +165,10 @@
             }
         }
 
-        public Serializable start(final InetAddress originatingHost) throws AuthorizationException
{
+        public Serializable start(final String host) throws AuthorizationException {
             return (Serializable) execute(new SessionManagerCallback() {
                 public Object doWithSessionManager(SessionManager sm) throws SessionException
{
-                    return sm.start(originatingHost);
+                    return sm.start(host);
                 }
             });
         }
@@ -241,10 +240,10 @@
             });
         }
 
-        public InetAddress getHostAddress(final Serializable sessionId) {
-            return (InetAddress) execute(new SessionManagerCallback() {
+        public String getHost(final Serializable sessionId) {
+            return (String) execute(new SessionManagerCallback() {
                 public Object doWithSessionManager(SessionManager sm) throws SessionException
{
-                    return sm.getHostAddress(sessionId);
+                    return sm.getHost(sessionId);
                 }
             });
         }

Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/ServletContainerSessionManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/ServletContainerSessionManager.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/ServletContainerSessionManager.java
(original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/ServletContainerSessionManager.java
Fri Dec 18 18:52:39 2009
@@ -30,7 +30,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.io.Serializable;
-import java.net.InetAddress;
 import java.util.Map;
 
 
@@ -75,7 +74,7 @@
         Session session = null;
         HttpSession httpSession = ((HttpServletRequest) request).getSession(false);
         if (httpSession != null) {
-            session = createSession(httpSession, WebUtils.getInetAddress(request));
+            session = createSession(httpSession, request.getRemoteHost());
         }
         return session;
     }
@@ -94,18 +93,18 @@
         long timeoutMillis = getGlobalSessionTimeout();
         httpSession.setMaxInactiveInterval((int) (timeoutMillis / MILLIS_PER_SECOND));
 
-        InetAddress originatingHost;
-        if (initData != null && initData.containsKey(SessionFactory.ORIGINATING_HOST_KEY))
{
-            originatingHost = (InetAddress) initData.get(SessionFactory.ORIGINATING_HOST_KEY);
+        String originatingHost;
+        if (initData != null && initData.containsKey(SessionFactory.HOST_KEY)) {
+            originatingHost = (String) initData.get(SessionFactory.HOST_KEY);
         } else {
-            originatingHost = WebUtils.getInetAddress(request);
+            originatingHost = request.getRemoteHost();
         }
 
         return createSession(httpSession, originatingHost);
     }
 
-    protected Session createSession(HttpSession httpSession, InetAddress inet) {
-        return new WebSession(httpSession, inet);
+    protected Session createSession(HttpSession httpSession, String host) {
+        return new WebSession(httpSession, host);
     }
 
 }

Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/WebSession.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/WebSession.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/WebSession.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/session/WebSession.java Fri
Dec 18 18:52:39 2009
@@ -18,17 +18,17 @@
  */
 package org.apache.shiro.web.session;
 
+import org.apache.shiro.session.InvalidSessionException;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.util.StringUtils;
+import org.apache.shiro.web.servlet.ShiroHttpSession;
+
+import javax.servlet.http.HttpSession;
 import java.io.Serializable;
-import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Enumeration;
-import javax.servlet.http.HttpSession;
-
-import org.apache.shiro.session.InvalidSessionException;
-import org.apache.shiro.session.Session;
-import org.apache.shiro.web.servlet.ShiroHttpSession;
 
 
 /**
@@ -41,12 +41,12 @@
 
     //TODO - complete JavaDoc
 
-    private static final String INET_ADDRESS_SESSION_KEY = WebSession.class.getName() + "_INET_ADDRESS_SESSION_KEY";
-    private static final String TOUCH_OBJECT_SESSION_KEY = WebSession.class.getName() + "_TOUCH_OBJECT_SESSION_KEY";
+    private static final String HOST_SESSION_KEY = WebSession.class.getName() + ".HOST_SESSION_KEY";
+    private static final String TOUCH_OBJECT_SESSION_KEY = WebSession.class.getName() + ".TOUCH_OBJECT_SESSION_KEY";
 
     private HttpSession httpSession = null;
 
-    public WebSession(HttpSession httpSession, InetAddress inetAddress) {
+    public WebSession(HttpSession httpSession, String host) {
         if (httpSession == null) {
             String msg = "HttpSession constructor argument cannot be null.";
             throw new IllegalArgumentException(msg);
@@ -57,8 +57,8 @@
             throw new IllegalArgumentException(msg);
         }
         this.httpSession = httpSession;
-        if (inetAddress != null) {
-            setHostAddress(inetAddress);
+        if (StringUtils.hasText(host)) {
+            setHost(host);
         }
     }
 
@@ -91,12 +91,12 @@
         }
     }
 
-    protected void setHostAddress(InetAddress hostAddress) {
-        setAttribute(INET_ADDRESS_SESSION_KEY, hostAddress);
+    protected void setHost(String host) {
+        setAttribute(HOST_SESSION_KEY, host);
     }
 
-    public InetAddress getHostAddress() {
-        return (InetAddress) getAttribute(INET_ADDRESS_SESSION_KEY);
+    public String getHost() {
+        return (String) getAttribute(HOST_SESSION_KEY);
     }
 
     public void touch() throws InvalidSessionException {

Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/WebDelegatingSubject.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/WebDelegatingSubject.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/WebDelegatingSubject.java
(original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/WebDelegatingSubject.java
Fri Dec 18 18:52:39 2009
@@ -27,7 +27,6 @@
 
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import java.net.InetAddress;
 import java.util.concurrent.Callable;
 
 /**
@@ -39,10 +38,10 @@
     private final ServletResponse servletResponse;
 
     public WebDelegatingSubject(PrincipalCollection principals, boolean authenticated,
-                                InetAddress inetAddress, Session session,
+                                String host, Session session,
                                 ServletRequest request, ServletResponse response,
                                 SecurityManager securityManager) {
-        super(principals, authenticated, inetAddress, session, securityManager);
+        super(principals, authenticated, host, session, securityManager);
         this.servletRequest = request;
         this.servletResponse = response;
     }

Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/support/WebSubjectThreadState.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/support/WebSubjectThreadState.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/support/WebSubjectThreadState.java
(original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/subject/support/WebSubjectThreadState.java
Fri Dec 18 18:52:39 2009
@@ -37,7 +37,7 @@
     private final ServletResponse response;
 
     public WebSubjectThreadState(WebSubject subject) {
-        super(subject, WebUtils.getInetAddress(subject.getServletRequest()));
+        super(subject);
 
         ServletRequest request = subject.getServletRequest();
         if (request == null) {

Modified: incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DelegatingWebSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DelegatingWebSecurityManagerTest.java?rev=892346&r1=892345&r2=892346&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DelegatingWebSecurityManagerTest.java
(original)
+++ incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DelegatingWebSecurityManagerTest.java
Fri Dec 18 18:52:39 2009
@@ -36,8 +36,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.Map;
 import java.util.UUID;
 
@@ -77,16 +75,11 @@
         expect(mockRequest.getCookies()).andReturn(null);
         expect(mockRequest.getContextPath()).andReturn("/");
 
-        InetAddress host;
-        try {
-            host = InetAddress.getByName("192.168.1.1");
-        } catch (UnknownHostException e) {
-            throw new IllegalStateException(e);
-        }
+        String host = "192.168.1.1";
 
         Serializable sessionId = UUID.randomUUID().toString();
         expect(delegate.start(EasyMock.<Map>anyObject())).andReturn(sessionId);
-        expect(delegate.getHostAddress(sessionId)).andReturn(host);
+        expect(delegate.getHost(sessionId)).andReturn(host);
         expect(delegate.getTimeout(sessionId)).andReturn(AbstractSessionManager.DEFAULT_GLOBAL_SESSION_TIMEOUT);
         delegate.setTimeout(sessionId, 125L);
         expectLastCall().times(1);



Mime
View raw message