[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security ...
Shane Bryzak
sbryzak at redhat.com
Sun May 20 23:47:38 EDT 2007
User: sbryzak2
Date: 07/05/20 23:47:38
Modified: src/main/org/jboss/seam/security Identity.java
RuleBasedIdentity.java
Log:
JBSEAM-743
Revision Changes Path
1.79 +36 -0 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.78
retrieving revision 1.79
diff -u -b -r1.78 -r1.79
--- Identity.java 8 May 2007 03:36:19 -0000 1.78
+++ Identity.java 21 May 2007 03:47:38 -0000 1.79
@@ -53,6 +53,8 @@
{
public static final String ROLES_GROUP = "Roles";
+ private static final String LOGIN_TRIED = "org.jboss.seam.security.loginTried";
+
private static final long serialVersionUID = 3751659008033189259L;
private static final LogProvider log = Logging.getLogProvider(Identity.class);
@@ -121,6 +123,13 @@
*/
public boolean isLoggedIn()
{
+ // See if the user can log in
+ if (getPrincipal() == null && isCredentialsSet() && !Contexts.getEventContext().isSet(LOGIN_TRIED))
+ {
+ Contexts.getEventContext().set(LOGIN_TRIED, true);
+ quietLogin();
+ }
+
return getPrincipal() != null;
}
@@ -134,6 +143,11 @@
return subject;
}
+ protected boolean isCredentialsSet()
+ {
+ return username != null;
+ }
+
/**
* Performs an authorization check, based on the specified security expression.
*
@@ -186,6 +200,20 @@
}
}
+ /**
+ * Attempts a quiet login, suppressing any login exceptions and not creating
+ * any faces messages. This method is intended to be used primarily as an
+ * internal API call, however has been made public for convenience.
+ */
+ public void quietLogin()
+ {
+ try
+ {
+ if (isCredentialsSet()) authenticate();
+ }
+ catch (LoginException ex) { }
+ }
+
protected void addLoginFailedMessage(LoginException ex)
{
FacesMessages.instance().addFromResourceBundleOrDefault(
@@ -334,6 +362,8 @@
*/
public boolean hasRole(String role)
{
+ isLoggedIn();
+
for ( Group sg : subject.getPrincipals(Group.class) )
{
if ( ROLES_GROUP.equals( sg.getName() ) )
@@ -408,6 +438,8 @@
*/
public void checkRole(String role)
{
+ isLoggedIn();
+
if ( !hasRole(role) )
{
if ( !isLoggedIn() )
@@ -434,6 +466,8 @@
*/
public void checkPermission(String name, String action, Object...arg)
{
+ isLoggedIn();
+
if ( !hasPermission(name, action, arg) )
{
if ( !isLoggedIn() )
@@ -561,6 +595,8 @@
public void checkEntityPermission(Object entity, EntityAction action)
{
+ isLoggedIn();
+
Entity e = Entity.forClass(entity.getClass());
if (e != null)
1.11 +2 -0 jboss-seam/src/main/org/jboss/seam/security/RuleBasedIdentity.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RuleBasedIdentity.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/RuleBasedIdentity.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- RuleBasedIdentity.java 10 May 2007 02:04:32 -0000 1.10
+++ RuleBasedIdentity.java 21 May 2007 03:47:38 -0000 1.11
@@ -104,6 +104,8 @@
@Override
public boolean hasPermission(String name, String action, Object...arg)
{
+ isLoggedIn();
+
WorkingMemory securityContext = getSecurityContext();
if (securityContext == null) return false;
More information about the jboss-cvs-commits
mailing list