Author: shane.bryzak(a)jboss.com
Date: 2009-05-11 21:09:20 -0400 (Mon, 11 May 2009)
New Revision: 10881
Modified:
modules/trunk/security/pom.xml
modules/trunk/security/src/main/java/org/jboss/seam/security/RememberMe.java
Log:
get the rememberme bean compiling
Modified: modules/trunk/security/pom.xml
===================================================================
--- modules/trunk/security/pom.xml 2009-05-12 00:52:25 UTC (rev 10880)
+++ modules/trunk/security/pom.xml 2009-05-12 01:09:20 UTC (rev 10881)
@@ -70,6 +70,11 @@
<groupId>${seam.groupId}</groupId>
<artifactId>seam-faces</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>${seam.groupId}</groupId>
+ <artifactId>seam-view</artifactId>
+ </dependency>
<!--
<dependency>
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/RememberMe.java
===================================================================
---
modules/trunk/security/src/main/java/org/jboss/seam/security/RememberMe.java 2009-05-12
00:52:25 UTC (rev 10880)
+++
modules/trunk/security/src/main/java/org/jboss/seam/security/RememberMe.java 2009-05-12
01:09:20 UTC (rev 10881)
@@ -9,18 +9,18 @@
import javax.annotation.Named;
import javax.context.SessionScoped;
import javax.event.Observes;
-//import javax.faces.context.FacesContext;
import javax.inject.Current;
import javax.inject.Initializer;
+import javax.inject.manager.Bean;
+import javax.inject.manager.Manager;
-//import org.jboss.seam.faces.Selector;
import org.jboss.seam.security.events.CredentialsInitializedEvent;
-import org.jboss.seam.security.events.CredentialsUpdatedEvent;
import org.jboss.seam.security.events.LoggedOutEvent;
import org.jboss.seam.security.events.PostAuthenticateEvent;
import org.jboss.seam.security.events.QuietLoginEvent;
import org.jboss.seam.security.management.IdentityManager;
import org.jboss.seam.security.util.Base64;
+import org.jboss.seam.view.Selector;
/**
* Remember-me functionality is provided by this class, in two different flavours. The
first mode
@@ -36,49 +36,8 @@
@SessionScoped
public class RememberMe implements Serializable
{
- /*
- class UsernameSelector extends Selector
- {
- @Override
- public String getCookieName()
- {
- return "org.jboss.seam.security.username";
- }
-
- @Override
- public void setDirty()
- {
- super.setDirty();
- }
-
- @Override
- public String getCookieValue()
- {
- return super.getCookieValue();
- }
-
- @Override
- public void clearCookieValue()
- {
- super.clearCookieValue();
- }
-
- @Override
- public void setCookieValueIfEnabled(String value)
- {
- super.setCookieValueIfEnabled(value);
- }
- }
-
- class TokenSelector extends UsernameSelector
- {
- @Override
- public String getCookieName()
- {
- return "org.jboss.seam.security.authtoken";
- }
- }
-
+ private static final long serialVersionUID = 2242379431576068199L;
+
private class DecodedToken
{
private String username;
@@ -112,13 +71,15 @@
}
}
- private UsernameSelector usernameSelector;
+ private Selector usernameSelector;
+ private Selector tokenSelector;
- private TokenSelector tokenSelector;
private TokenStore tokenStore;
- */
+
+ @Current Manager manager;
+
private boolean enabled;
-/*
+
private int cookieMaxAge = Selector.DEFAULT_MAX_AGE;
private boolean autoLoggedIn;
@@ -141,7 +102,7 @@
public void setMode(Mode mode)
{
this.mode = mode;
- }*/
+ }
public boolean isEnabled()
{
@@ -154,20 +115,18 @@
{
this.enabled = enabled;
// selector is null during component initialization (setup handled in @Create
method)
-// if (usernameSelector != null && mode.equals(Mode.usernameOnly))
-// {
-// usernameSelector.setCookieEnabled(enabled);
-// usernameSelector.setDirty();
-// }
+ if (usernameSelector != null && mode.equals(Mode.usernameOnly))
+ {
+ usernameSelector.setCookieEnabled(enabled);
+ }
// selector is null during component initialization (setup handled in @Create
method)
-// else if (tokenSelector != null && mode.equals(Mode.autoLogin))
-// {
-// tokenSelector.setCookieEnabled(enabled);
-// tokenSelector.setDirty();
-// }
+ else if (tokenSelector != null && mode.equals(Mode.autoLogin))
+ {
+ tokenSelector.setCookieEnabled(enabled);
+ }
}
}
-/*
+
public int getCookieMaxAge() {
return cookieMaxAge;
}
@@ -189,24 +148,28 @@
@Initializer
public void create()
{
+ Bean<Selector> selectorBean =
manager.resolveByType(Selector.class).iterator().next();
+
if (mode.equals(Mode.usernameOnly))
{
- usernameSelector = new UsernameSelector();
+ usernameSelector = manager.getInstance(selectorBean);
+ usernameSelector.setCookieName("org.jboss.seam.security.username");
usernameSelector.setCookieEnabled(enabled);
}
else if (mode.equals(Mode.autoLogin))
{
- tokenSelector = new TokenSelector();
+ tokenSelector = manager.getInstance(selectorBean);
+ tokenSelector.setCookieName("org.jboss.seam.security.authtoken");
tokenSelector.setCookieEnabled(enabled);
-
+
// Default to JpaTokenStore
if (tokenStore == null)
{
- tokenStore = (TokenStore) Component.getInstance(JpaTokenStore.class, true);
+ tokenStore = manager.getInstanceByType(JpaTokenStore.class);
}
}
}
-
+
protected String generateTokenValue()
{
StringBuilder sb = new StringBuilder();
@@ -224,16 +187,12 @@
sb.append(value);
return Base64.encodeBytes(sb.toString().getBytes());
}
-
- public String getCookiePath()
- {
- FacesContext ctx = FacesContext.getCurrentInstance();
- return ctx != null ? ctx.getExternalContext().getRequestContextPath() : null;
- }
-
+
public void initCredentials(@Observes CredentialsInitializedEvent event)
{
- String cookiePath = getCookiePath();
+ // FIXME use the context path as the cookie path
+ // String cookiePath = getCookiePath();
+ String cookiePath = "/";
if (mode.equals(Mode.usernameOnly))
{
@@ -248,8 +207,6 @@
setEnabled(true);
event.getCredentials().setUsername(username);
}
-
- usernameSelector.setDirty();
}
else if (mode.equals(Mode.autoLogin))
{
@@ -287,7 +244,6 @@
boolean value;
}
- /*
public void quietLogin(@Observes QuietLoginEvent event)
{
if (mode.equals(Mode.autoLogin) && isEnabled())
@@ -347,10 +303,7 @@
public void postAuthenticate(@Observes PostAuthenticateEvent event)
{
if (mode.equals(Mode.usernameOnly))
- {
- // Password is set to null during authentication, so we set dirty
- usernameSelector.setDirty();
-
+ {
if ( !enabled )
{
usernameSelector.clearCookieValue();
@@ -362,9 +315,7 @@
}
}
else if (mode.equals(Mode.autoLogin))
- {
- tokenSelector.setDirty();
-
+ {
DecodedToken decoded = new DecodedToken(tokenSelector.getCookieValue());
// Invalidate the current token (if it exists) whether enabled or not
@@ -386,27 +337,15 @@
tokenSelector.setCookieValueIfEnabled(encodeToken(identity.getPrincipal().getName(),
value));
}
}
- }
+ }
- public void credentialsUpdated(@Observes CredentialsUpdatedEvent event)
- {
- if (mode.equals(Mode.usernameOnly))
- {
- usernameSelector.setDirty();
- }
- }
- */
-
/**
* A flag that an application can use to protect sensitive operations if the user has
been
* auto-authenticated.
- */
- /*
+ */
public boolean isAutoLoggedIn()
{
return autoLoggedIn;
}
- */
-
}
Show replies by date