[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security ...
Shane Bryzak
sbryzak at redhat.com
Thu Feb 22 01:40:54 EST 2007
User: sbryzak2
Date: 07/02/22 01:40:54
Modified: src/main/org/jboss/seam/security RuleBasedIdentity.java
Log:
JBSEAM-838
Revision Changes Path
1.4 +58 -43 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.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- RuleBasedIdentity.java 22 Feb 2007 01:27:54 -0000 1.3
+++ RuleBasedIdentity.java 22 Feb 2007 06:40:54 -0000 1.4
@@ -20,6 +20,8 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
@Name("org.jboss.seam.security.identity")
@Scope(SESSION)
@@ -30,6 +32,8 @@
{
public static final String RULES_COMPONENT_NAME = "securityRules";
+ private static final LogProvider log = Logging.getLogProvider(RuleBasedIdentity.class);
+
private WorkingMemory securityContext;
private RuleBase securityRules;
@@ -53,7 +57,11 @@
securityContext = securityRules.newWorkingMemory(false);
}
- assertSecurityContextExists();
+ if (securityContext == null)
+ {
+ log.warn("no security rule base available - please install a RuleBase with the name '" +
+ RULES_COMPONENT_NAME + "'");
+ }
}
@Override
@@ -62,8 +70,9 @@
super.postAuthenticate();
WorkingMemory securityContext = getSecurityContext();
- assertSecurityContextExists();
+ if (securityContext != null)
+ {
// Populate the working memory with the user's principals
for ( Principal p : getSubject().getPrincipals() )
{
@@ -80,15 +89,6 @@
securityContext.assertObject(getPrincipal());
}
-
- private void assertSecurityContextExists()
- {
- if (securityContext==null)
- {
- throw new IllegalStateException(
- "no security rule base available - please install a RuleBase with the name '" +
- RULES_COMPONENT_NAME + "'");
- }
}
/**
@@ -102,12 +102,14 @@
@Override
public boolean hasPermission(String name, String action, Object...arg)
{
+ WorkingMemory securityContext = getSecurityContext();
+
+ if (securityContext == null) return false;
+
List<FactHandle> handles = new ArrayList<FactHandle>();
PermissionCheck check = new PermissionCheck(name, action);
- WorkingMemory securityContext = getSecurityContext();
- assertSecurityContextExists();
synchronized( securityContext )
{
handles.add( securityContext.assertObject(check) );
@@ -142,9 +144,14 @@
@Override
protected void unAuthenticate()
{
- for (Role role : (List<Role>) getSecurityContext().getObjects(Role.class))
+ WorkingMemory securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
+ for (Role role : (List<Role>) securityContext.getObjects(Role.class))
{
- getSecurityContext().retractObject(getSecurityContext().getFactHandle(role));
+ getSecurityContext().retractObject(securityContext.getFactHandle(role));
+ }
}
super.unAuthenticate();
@@ -155,18 +162,25 @@
{
if (super.addRole(role))
{
+ WorkingMemory securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
getSecurityContext().assertObject(new Role(role));
return true;
}
- else
- {
- return false;
}
+
+ return false;
}
@Override
public void removeRole(String role)
{
+ WorkingMemory securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
for (Role r : (List<Role>) getSecurityContext().getObjects(Role.class))
{
if (r.getName().equals(role))
@@ -176,6 +190,7 @@
break;
}
}
+ }
super.removeRole(role);
}
More information about the jboss-cvs-commits
mailing list