[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security ...
Gavin King
gavin.king at jboss.com
Thu Feb 1 03:25:30 EST 2007
User: gavin
Date: 07/02/01 03:25:30
Modified: src/main/org/jboss/seam/security Identity.java
Log:
remember me
Revision Changes Path
1.38 +52 -30 jboss-seam/src/main/org/jboss/seam/security/Identity.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Identity.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/Identity.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- Identity.java 1 Feb 2007 05:39:53 -0000 1.37
+++ Identity.java 1 Feb 2007 08:25:30 -0000 1.38
@@ -5,7 +5,6 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.io.IOException;
-import java.io.Serializable;
import java.security.Principal;
import java.security.acl.Group;
import java.util.ArrayList;
@@ -28,15 +27,16 @@
import org.drools.WorkingMemory;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.Seam;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Intercept;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.AbstractMutable;
import org.jboss.seam.core.Events;
import org.jboss.seam.core.FacesMessages;
+import org.jboss.seam.core.Selector;
import org.jboss.seam.core.Expressions.MethodBinding;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
@@ -46,7 +46,7 @@
@Scope(SESSION)
@Install(precedence = BUILT_IN, classDependencies="org.drools.WorkingMemory")
@Intercept(NEVER)
-public class Identity extends AbstractMutable implements Serializable
+public class Identity extends Selector
{
private static final long serialVersionUID = 3751659008033189259L;
@@ -62,11 +62,25 @@
private WorkingMemory securityContext;
+ @Override
+ protected String getCookieName()
+ {
+ return "org.jboss.seam.security.credentials";
+ }
+
@Create
public void create()
{
subject = new Subject();
initSecurityContext();
+ initCredentialsFromCookie();
+ }
+
+ private void initCredentialsFromCookie()
+ {
+ setCookieEnabled(true);
+ username = getCookieValue();
+ setCookieEnabled(false);
}
protected void initSecurityContext()
@@ -165,8 +179,6 @@
{
preAuthenticate();
loginContext.login();
- password = null;
- setDirty();
postAuthenticate();
}
@@ -186,12 +198,7 @@
public void logout()
{
- username = null;
- password = null;
- principal = null;
- subject = new Subject();
- initSecurityContext();
- setDirty();
+ Seam.invalidateSession();
}
/**
@@ -260,9 +267,9 @@
PermissionCheck check = new PermissionCheck(name, action);
- synchronized(securityContext)
+ synchronized( getSecurityContext() )
{
- handles.add(securityContext.assertObject(check));
+ handles.add( getSecurityContext().assertObject(check) );
for (int i = 0; i < arg.length; i++)
{
@@ -270,22 +277,22 @@
{
for (Object value : (Collection) arg[i])
{
- if (securityContext.getFactHandle(value) == null)
+ if ( getSecurityContext().getFactHandle(value) == null )
{
- handles.add( securityContext.assertObject(value) );
+ handles.add( getSecurityContext().assertObject(value) );
}
}
}
else
{
- handles.add(securityContext.assertObject(arg[i]));
+ handles.add( getSecurityContext().assertObject(arg[i]) );
}
}
- securityContext.fireAllRules();
+ getSecurityContext().fireAllRules();
for (FactHandle handle : handles)
- securityContext.retractObject(handle);
+ getSecurityContext().retractObject(handle);
}
return check.isGranted();
@@ -333,8 +340,21 @@
*/
protected void postAuthenticate()
{
+ populateSecurityContext();
+
+ setCookieValue( getUsername() );
+
+ password = null;
+ setDirty();
+
+ Events.instance().raiseEvent("org.jboss.seam.postAuthenticate");
+
+ }
+
+ protected void populateSecurityContext()
+ {
// Populate the working memory with the user's principals
- for ( Principal p : subject.getPrincipals() )
+ for ( Principal p : getSubject().getPrincipals() )
{
if ( (p instanceof Group) && "roles".equals( ( (Group) p ).getName() ) )
{
@@ -342,7 +362,7 @@
while ( e.hasMoreElements() )
{
Principal role = (Principal) e.nextElement();
- securityContext.assertObject( new Role( role.getName() ) );
+ getSecurityContext().assertObject( new Role( role.getName() ) );
}
}
else
@@ -352,12 +372,10 @@
principal = p;
setDirty();
}
- securityContext.assertObject(p);
+ getSecurityContext().assertObject(p);
}
- Events.instance().raiseEvent("org.jboss.seam.postAuthenticate");
}
-
}
/**
@@ -386,15 +404,9 @@
this.username = username;
}
- /**
- * Needed by EL value bindings, always
- * returns null.
- *
- * @return null
- */
public String getPassword()
{
- return null;
+ return password;
}
public void setPassword(String password)
@@ -418,4 +430,14 @@
this.authenticateMethod = authMethod;
}
+ public boolean isRememberMe()
+ {
+ return isCookieEnabled();
+ }
+
+ public void setRememberMe(boolean remember)
+ {
+ setCookieEnabled(remember);
+ }
+
}
More information about the jboss-cvs-commits
mailing list