You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2009/05/20 21:55:39 UTC
svn commit: r776821 - in /incubator/jsecurity/trunk:
core/src/main/java/org/apache/ki/mgt/
core/src/main/java/org/apache/ki/session/mgt/
web/src/main/java/org/apache/ki/web/
Author: lhazlewood
Date: Wed May 20 19:55:38 2009
New Revision: 776821
URL: http://svn.apache.org/viewvc?rev=776821&view=rev
Log:
added SessionFactoryAware for passthrough configuration via the SecurityManager
Added:
incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/SessionFactoryAware.java
Modified:
incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/mgt/SessionsSecurityManager.java
incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/DefaultSessionManager.java
incubator/jsecurity/trunk/web/src/main/java/org/apache/ki/web/DefaultWebSecurityManager.java
Modified: incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/mgt/SessionsSecurityManager.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/mgt/SessionsSecurityManager.java?rev=776821&r1=776820&r2=776821&view=diff
==============================================================================
--- incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/mgt/SessionsSecurityManager.java (original)
+++ incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/mgt/SessionsSecurityManager.java Wed May 20 19:55:38 2009
@@ -24,10 +24,7 @@
import org.apache.ki.session.Session;
import org.apache.ki.session.SessionListener;
import org.apache.ki.session.SessionListenerRegistrar;
-import org.apache.ki.session.mgt.AbstractSessionManager;
-import org.apache.ki.session.mgt.AbstractValidatingSessionManager;
-import org.apache.ki.session.mgt.DefaultSessionManager;
-import org.apache.ki.session.mgt.SessionManager;
+import org.apache.ki.session.mgt.*;
import org.apache.ki.util.LifecycleUtils;
import java.io.Serializable;
@@ -112,6 +109,18 @@
applyCacheManagerToSessionManager();
}
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ SessionManager sm = getSessionManager();
+ if (sm instanceof SessionFactoryAware) {
+ ((SessionFactoryAware) sm).setSessionFactory(sessionFactory);
+ } else {
+ String msg = "The underlying session manager is null or does not implement the " +
+ SessionFactory.class.getName() + " interface, which is required if the underlying " +
+ "instance is to receive the sessionFactory argument.";
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
/**
* Ensures the internal delegate <code>SessionManager</code> is injected with the newly set
* {@link #setCacheManager CacheManager} so it may use it for its internal caching needs.
@@ -152,13 +161,13 @@
}
if (!(requiredType.isInstance(this.sessionManager))) {
String msg = "Property configuration failed. The target property is only configurable when the " +
- "underlying SessionManager instance is a part of the " +
- "[" + requiredType.getName() + "] class hierarchy. " +
- "The current SessionManager is of type [" + this.sessionManager.getClass().getName() + "]. " +
- "This might occur for example if you're trying to set the validation interval or auto session " +
- "creation in a servlet container-backed session environment ('http' session mode). If that is " +
- "the case however, that property is only useful when using 'ki' session mode and using " +
- "Ki enterprise sessions which do not rely on a servlet container.";
+ "underlying SessionManager instance is a part of the " +
+ "[" + requiredType.getName() + "] class hierarchy. " +
+ "The current SessionManager is of type [" + this.sessionManager.getClass().getName() + "]. " +
+ "This might occur for example if you're trying to set the validation interval or auto session " +
+ "creation in a servlet container-backed session environment ('http' session mode). If that is " +
+ "the case however, that property is only useful when using 'ki' session mode and using " +
+ "Ki enterprise sessions which do not rely on a servlet container.";
throw new IllegalStateException(msg);
}
}
@@ -247,9 +256,9 @@
private void assertSessionListenerSupport() throws IllegalStateException {
if (!(this.sessionManager instanceof SessionListenerRegistrar)) {
String msg = "SessionListener registration failed: The underlying SessionManager instance of " +
- "type [" + sessionManager.getClass().getName() + "] does not implement the " +
- SessionListenerRegistrar.class.getName() + " interface and therefore cannot support " +
- "session notifications.";
+ "type [" + sessionManager.getClass().getName() + "] does not implement the " +
+ SessionListenerRegistrar.class.getName() + " interface and therefore cannot support " +
+ "session notifications.";
throw new IllegalStateException(msg);
}
}
@@ -277,7 +286,7 @@
*/
public boolean remove(SessionListener listener) {
return (this.sessionManager instanceof SessionListenerRegistrar) &&
- ((SessionListenerRegistrar) this.sessionManager).remove(listener);
+ ((SessionListenerRegistrar) this.sessionManager).remove(listener);
}
public Serializable start(InetAddress originatingHost) throws HostUnauthorizedException, IllegalArgumentException {
Modified: incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/DefaultSessionManager.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/DefaultSessionManager.java?rev=776821&r1=776820&r2=776821&view=diff
==============================================================================
--- incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/DefaultSessionManager.java (original)
+++ incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/DefaultSessionManager.java Wed May 20 19:55:38 2009
@@ -41,7 +41,8 @@
* @author Les Hazlewood
* @since 0.1
*/
-public class DefaultSessionManager extends AbstractValidatingSessionManager implements CacheManagerAware {
+public class DefaultSessionManager extends AbstractValidatingSessionManager
+ implements CacheManagerAware, SessionFactoryAware {
//TODO - complete JavaDoc
Added: incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/SessionFactoryAware.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/SessionFactoryAware.java?rev=776821&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/SessionFactoryAware.java (added)
+++ incubator/jsecurity/trunk/core/src/main/java/org/apache/ki/session/mgt/SessionFactoryAware.java Wed May 20 19:55:38 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.ki.session.mgt;
+
+/**
+ * Allows interested components to receive a configured {@link SessionFactory} instance.
+ *
+ * @author Les Hazlewood
+ * @since 1.0
+ */
+public interface SessionFactoryAware {
+
+ /**
+ * Sets the session factory to use to generate {@link org.apache.ki.session.Session Session}s.
+ *
+ * @param sessionFactory the session factory to use to generate {@link org.apache.ki.session.Session Session}s.
+ */
+ void setSessionFactory(SessionFactory sessionFactory);
+}
Modified: incubator/jsecurity/trunk/web/src/main/java/org/apache/ki/web/DefaultWebSecurityManager.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/web/src/main/java/org/apache/ki/web/DefaultWebSecurityManager.java?rev=776821&r1=776820&r2=776821&view=diff
==============================================================================
--- incubator/jsecurity/trunk/web/src/main/java/org/apache/ki/web/DefaultWebSecurityManager.java (original)
+++ incubator/jsecurity/trunk/web/src/main/java/org/apache/ki/web/DefaultWebSecurityManager.java Wed May 20 19:55:38 2009
@@ -18,12 +18,6 @@
*/
package org.apache.ki.web;
-import java.util.Collection;
-import javax.servlet.ServletRequest;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.ki.mgt.DefaultSecurityManager;
import org.apache.ki.realm.Realm;
import org.apache.ki.session.mgt.SessionManager;
@@ -33,6 +27,11 @@
import org.apache.ki.web.session.DefaultWebSessionManager;
import org.apache.ki.web.session.ServletContainerSessionManager;
import org.apache.ki.web.session.WebSessionManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.ServletRequest;
+import java.util.Collection;
/**
@@ -51,24 +50,19 @@
public static final String HTTP_SESSION_MODE = "http";
public static final String KI_SESSION_MODE = "ki";
- /**
- * The key that is used to store subject principals in the session.
- */
+ /** The key that is used to store subject principals in the session. */
public static final String PRINCIPALS_SESSION_KEY = DefaultWebSecurityManager.class.getName() + "_PRINCIPALS_SESSION_KEY";
- /**
- * The key that is used to store whether or not the user is authenticated in the session.
- */
+ /** The key that is used to store whether or not the user is authenticated in the session. */
public static final String AUTHENTICATED_SESSION_KEY = DefaultWebSecurityManager.class.getName() + "_AUTHENTICATED_SESSION_KEY";
private String sessionMode = HTTP_SESSION_MODE; //default
public DefaultWebSecurityManager() {
super();
+ setRememberMeManager(new WebRememberMeManager());
WebSessionManager sm = new ServletContainerSessionManager();
setSessionManager(sm);
- setRememberMeManager(new WebRememberMeManager());
- setSubjectFactory(new WebSubjectFactory(this, sm));
}
public DefaultWebSecurityManager(Realm singleRealm) {
@@ -80,7 +74,14 @@
this();
setRealms(realms);
}
-
+
+ @Override
+ protected void afterSessionManagerSet() {
+ super.afterSessionManagerSet();
+ WebSessionManager sessionManager = (WebSessionManager) getSessionManager();
+ setSubjectFactory(new WebSubjectFactory(this, sessionManager));
+ }
+
/**
* Sets the path used to store the remember me cookie. This determines which paths
* are able to view the remember me cookie.
@@ -154,8 +155,6 @@
LifecycleUtils.destroy(getSessionManager());
WebSessionManager sessionManager = createSessionManager(mode);
setSessionManager(sessionManager);
- //the factory needs to reflect this new SessionManager:
- setSubjectFactory(new WebSubjectFactory(this,sessionManager));
}
}
@@ -186,7 +185,7 @@
protected void removeRequestIdentity() {
ServletRequest request = WebUtils.getServletRequest();
- if ( request != null ) {
+ if (request != null) {
request.setAttribute(KiHttpServletRequest.IDENTITY_REMOVED_KEY, Boolean.TRUE);
}
}