[seam-commits] Seam SVN: r10541 - modules/trunk/security/src/main/java/org/jboss/seam/security.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 21 04:51:33 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-04-21 04:51:33 -0400 (Tue, 21 Apr 2009)
New Revision: 10541

Added:
   modules/trunk/security/src/main/java/org/jboss/seam/security/RequestSecurityState.java
Modified:
   modules/trunk/security/src/main/java/org/jboss/seam/security/Identity.java
Log:
replace context variables with jsr-299 equivalent

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/Identity.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/Identity.java	2009-04-21 05:43:10 UTC (rev 10540)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/Identity.java	2009-04-21 08:51:33 UTC (rev 10541)
@@ -57,10 +57,6 @@
    
    public static final String ROLES_GROUP = "Roles";
    
-   // Context variables
-   private static final String LOGIN_TRIED = "org.jboss.seam.security.loginTried";
-   private static final String SILENT_LOGIN = "org.jboss.seam.security.silentLogin";
-   
    private static final LogProvider log = Logging.getLogProvider(Identity.class);
         
    private Principal principal;   
@@ -124,26 +120,15 @@
     */
    public boolean tryLogin()
    {
-      /*Context ctx = null;
-      try
+      RequestSecurityState state = manager.getInstanceByType(RequestSecurityState.class);
+      
+      if (!authenticating && getPrincipal() == null && credentials.isSet() && !state.isLoginTried())
       {
-         ctx = manager.getContext(RequestScoped.class);
+         state.setLoginTried(true);
+         quietLogin();
       }
-      catch (ContextNotActiveException ex)
-      {
-         // Ignore
-      }*/
       
-      // TODO work out some other way of implementing this, perhaps with a thread local? 
-      /*
-      if (!authenticating && getPrincipal() == null && credentials.isSet() &&
-            ctx != null && ctx.isActive() && !ctx.get(contextual)isSet(LOGIN_TRIED))
-      {
-           ctx.set(LOGIN_TRIED, true);
-           quietLogin();
-      } */    
-        
-        return isLoggedIn();      
+      return isLoggedIn();      
    }
 
    public Principal getPrincipal()
@@ -208,8 +193,9 @@
          {
             // If authentication has already occurred during this request via a silent login,
             // and login() is explicitly called then we still want to raise the LOGIN_SUCCESSFUL event,
-            // and then return.
-            if (Contexts.isEventContextActive() && Contexts.getEventContext().isSet(SILENT_LOGIN))
+            // and then return.            
+            RequestSecurityState state = manager.getInstanceByType(RequestSecurityState.class);            
+            if (state.isSilentLogin())
             {
                manager.fireEvent(new LoggedInEvent(principal));               
                return "loggedIn";            
@@ -266,9 +252,11 @@
             if (credentials.isSet()) 
             {
                authenticate();
-               if (isLoggedIn() && Contexts.isEventContextActive())
+               
+               RequestSecurityState state = manager.getInstanceByType(RequestSecurityState.class);                              
+               if (isLoggedIn())
                {
-                  Contexts.getEventContext().set(SILENT_LOGIN, true);
+                  state.setSilentLogin(true);
                }
             }
          }

Added: modules/trunk/security/src/main/java/org/jboss/seam/security/RequestSecurityState.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/RequestSecurityState.java	                        (rev 0)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/RequestSecurityState.java	2009-04-21 08:51:33 UTC (rev 10541)
@@ -0,0 +1,35 @@
+package org.jboss.seam.security;
+
+import javax.context.RequestScoped;
+
+/**
+ * Contains the authentication state of the current request
+ * 
+ * @author Shane Bryzak
+ */
+ at RequestScoped
+public class RequestSecurityState
+{
+   private boolean silentLogin;
+   private boolean loginTried;
+   
+   public boolean isSilentLogin()
+   {
+      return silentLogin;
+   }
+   
+   public void setSilentLogin(boolean silentLogin)
+   {
+      this.silentLogin = silentLogin;
+   }
+   
+   public boolean isLoginTried()
+   {
+      return loginTried;
+   }
+   
+   public void setLoginTried(boolean loginTried)
+   {
+      this.loginTried = loginTried;
+   }
+}




More information about the seam-commits mailing list