[jboss-cvs] Picketbox SVN: r254 - in trunk: security-jboss-sx/acl and 13 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 20 16:39:20 EDT 2011
Author: mmoyses
Date: 2011-09-20 16:39:20 -0400 (Tue, 20 Sep 2011)
New Revision: 254
Added:
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/StringPropertyReplacer.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/SysPropertyActions.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/IllegalTransitionException.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/State.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/StateMachine.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/Transition.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/xml/
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/xml/StateMachineParser.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/DOMUtils.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/JBossEntityResolver.java
Removed:
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/SynchronizedJaasSecurityManager.java
trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/TstTimedCache.java
Modified:
trunk/picketbox/pom.xml
trunk/security-jboss-sx/acl/pom.xml
trunk/security-jboss-sx/jbosssx/pom.xml
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/ConfigUtil.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/RoleMappingLoginModule.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/UsersRolesLoginModule.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfiguration.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfigurationFactory.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/mapping/providers/role/PropertiesRolesMappingProvider.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/JaasSecurityManagerBase.java
trunk/security-jboss-sx/jbosssx/src/main/java/org/picketbox/plugins/vault/PicketBoxSecurityVault.java
trunk/security-jboss-sx/parent/pom.xml
Log:
removing common-core dependency from the implementation
Modified: trunk/picketbox/pom.xml
===================================================================
--- trunk/picketbox/pom.xml 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/picketbox/pom.xml 2011-09-20 20:39:20 UTC (rev 254)
@@ -44,6 +44,12 @@
<artifactId>picketbox-acl-impl</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>jboss-common-core</artifactId>
+ <groupId>jboss</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.picketbox</groupId>
Modified: trunk/security-jboss-sx/acl/pom.xml
===================================================================
--- trunk/security-jboss-sx/acl/pom.xml 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/acl/pom.xml 2011-09-20 20:39:20 UTC (rev 254)
@@ -70,12 +70,6 @@
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.1.ga</version>
<scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.picketbox</groupId>
@@ -118,11 +112,5 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>2.2.17.GA</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
Modified: trunk/security-jboss-sx/jbosssx/pom.xml
===================================================================
--- trunk/security-jboss-sx/jbosssx/pom.xml 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/pom.xml 2011-09-20 20:39:20 UTC (rev 254)
@@ -143,6 +143,12 @@
<artifactId>picketbox-acl-impl</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>jboss-common-core</artifactId>
+ <groupId>jboss</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.picketbox</groupId>
@@ -186,16 +192,15 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>2.2.17.GA</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>sleepycat</groupId>
<artifactId>je</artifactId>
<version>3.2.43</version>
<scope>test</scope>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.picketbox</groupId>
+ <artifactId>picketbox-commons</artifactId>
+ <version>1.0.0.CR1</version>
+ </dependency>
</dependencies>
</project>
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/ConfigUtil.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/ConfigUtil.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/ConfigUtil.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -26,7 +26,7 @@
import javax.security.auth.login.AppConfigurationEntry;
-import org.jboss.util.xml.DOMUtils;
+import org.jboss.security.util.xml.DOMUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/RoleMappingLoginModule.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/RoleMappingLoginModule.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/RoleMappingLoginModule.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -31,7 +31,7 @@
import javax.security.auth.spi.LoginModule;
import org.jboss.logging.Logger;
-import org.jboss.util.StringPropertyReplacer;
+import org.jboss.security.util.StringPropertyReplacer;
//$Id$
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/UsersRolesLoginModule.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/UsersRolesLoginModule.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/spi/UsersRolesLoginModule.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -30,7 +30,7 @@
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
-import org.jboss.util.StringPropertyReplacer;
+import org.jboss.security.util.StringPropertyReplacer;
/** A simple Properties map based login module that consults two Java Properties
formatted text files for username to password("users.properties") and
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfiguration.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfiguration.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfiguration.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -28,9 +28,9 @@
import javax.security.jacc.PolicyContextException;
import org.jboss.logging.Logger;
-import org.jboss.util.state.IllegalTransitionException;
-import org.jboss.util.state.State;
-import org.jboss.util.state.StateMachine;
+import org.jboss.security.util.state.IllegalTransitionException;
+import org.jboss.security.util.state.State;
+import org.jboss.security.util.state.StateMachine;
/** The JACC PolicyConfiguration implementation. This class associates a
* context id with the permission ops it passes along to the global
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfigurationFactory.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfigurationFactory.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/jacc/JBossPolicyConfigurationFactory.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -29,8 +29,8 @@
import javax.security.jacc.PolicyConfigurationFactory;
import javax.security.jacc.PolicyContextException;
-import org.jboss.util.state.StateMachine;
-import org.jboss.util.state.xml.StateMachineParser;
+import org.jboss.security.util.state.StateMachine;
+import org.jboss.security.util.state.xml.StateMachineParser;
/** org.jboss.security.provider
*
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/mapping/providers/role/PropertiesRolesMappingProvider.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/mapping/providers/role/PropertiesRolesMappingProvider.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/mapping/providers/role/PropertiesRolesMappingProvider.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -28,7 +28,7 @@
import org.jboss.logging.Logger;
import org.jboss.security.identity.RoleGroup;
-import org.jboss.util.StringPropertyReplacer;
+import org.jboss.security.util.StringPropertyReplacer;
/**
* A {@code MappingProvider} that reads roles from a properties file in the format
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/JaasSecurityManagerBase.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/JaasSecurityManagerBase.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/JaasSecurityManagerBase.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -24,10 +24,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.Principal;
-import java.security.acl.Group;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -46,8 +42,6 @@
import org.jboss.security.SecurityUtil;
import org.jboss.security.SubjectSecurityManager;
import org.jboss.security.auth.callback.JBossCallbackHandler;
-import org.jboss.util.CachePolicy;
-import org.jboss.util.TimedCachePolicy;
/** The JaasSecurityManager is responsible both for authenticating credentials
associated with principals and for role mapping. This implementation relies
@@ -67,135 +61,6 @@
public class JaasSecurityManagerBase
implements SubjectSecurityManager, RealmMapping
{
- /** The authentication cache object.
- */
- public static class DomainInfo implements TimedCachePolicy.TimedEntry
- {
- private static Logger log = Logger.getLogger(DomainInfo.class);
- private static boolean trace = log.isTraceEnabled();
- protected LoginContext loginCtx;
- protected Subject subject;
- protected Object credential;
- protected Principal callerPrincipal;
- private long expirationTime;
- /** Is there an active authentication in process */
- private boolean needsDestroy;
- /** The number of users sharing this DomainInfo */
- private int activeUsers;
-
- /**
- Create a cache entry with the given lifetime in seconds. Since this comes
- from the TimedCachePolicy, its expected to be <= Integer.MAX_VALUE.
-
- @param lifetime - lifetime in seconds. A lifetime <= 0 means no caching
- with the exception of -1 which indicates that the cache entry never
- expires.
- */
- public DomainInfo(long lifetime)
- {
- expirationTime = lifetime;
- if( expirationTime != -1 )
- expirationTime *= 1000;
- }
-
- synchronized int acquire()
- {
- return activeUsers ++;
- }
- synchronized int release()
- {
- int users = activeUsers --;
- if( needsDestroy == true && users == 0 )
- {
- if( trace )
- log.trace("needsDestroy is true, doing logout");
- logout();
- }
- return users;
- }
- synchronized void logout()
- {
- if( trace )
- log.trace("logout, subject="+subject+", this="+this);
- try
- {
- if( loginCtx != null )
- loginCtx.logout();
- }
- catch(Throwable e)
- {
- if( trace )
- log.trace("Cache entry logout failed", e);
- }
- }
-
- public void init(long now)
- {
- expirationTime += now;
- }
- public boolean isCurrent(long now)
- {
- boolean isCurrent = expirationTime == -1;
- if( isCurrent == false )
- isCurrent = expirationTime > now;
- return isCurrent;
- }
- public boolean refresh()
- {
- return false;
- }
- /**
- * This
- */
- public void destroy()
- {
- if( trace )
- {
- log.trace("destroy, subject="+subject+", this="+this
- +", activeUsers="+activeUsers);
- }
-
- synchronized( this )
- {
- if( activeUsers == 0 )
- logout();
- else
- {
- if( trace )
- log.trace("destroy saw activeUsers="+activeUsers);
- needsDestroy = true;
- }
- }
- }
- public Object getValue()
- {
- return this;
- }
- public String toString()
- {
- StringBuffer tmp = new StringBuffer(super.toString());
- tmp.append('[');
- tmp.append(SubjectActions.toString(subject));
- tmp.append(",credential.class=");
- if( credential != null )
- {
- Class<?> c = credential.getClass();
- tmp.append(c.getName());
- tmp.append('@');
- tmp.append(System.identityHashCode(c));
- }
- else
- {
- tmp.append("null");
- }
- tmp.append(",expirationTime=");
- tmp.append(expirationTime);
- tmp.append(']');
-
- return tmp.toString();
- }
- }
-
/** The name of the domain this instance is securing. It is used as
the appName into the SecurityPolicy.
*/
@@ -203,7 +68,6 @@
/** A cache of DomainInfo objects keyd by Principal. This is now
always set externally by our security manager service.
*/
- private CachePolicy domainCache;
/** The JAAS callback handler to use in defaultLogin */
private CallbackHandler handler;
/** The setSecurityInfo(Principal, Object) method of the handler obj */
@@ -253,17 +117,6 @@
log.debug("CallbackHandler: "+handler);
}
- /** The domainCache is typically a shared object that is populated
- by the login code(LoginModule, etc.) and read by this class in the
- isValid() method.
- @see #isValid(Principal, Object, Subject)
- */
- public void setCachePolicy(CachePolicy domainCache)
- {
- this.domainCache = domainCache;
- log.debug("CachePolicy set to: "+domainCache);
- }
-
/**
* Flag to specify if deep copy of subject sets needs to be
* enabled
@@ -285,15 +138,6 @@
this.authorizationManager = authorizationManager;
}
- /** Not really used anymore as the security manager service manages the
- security domain authentication caches.
- */
- public void flushCache()
- {
- if( domainCache != null )
- domainCache.flush();
- }
-
/** Get the name of the security domain associated with this security mgr.
@return Name of the security manager security domain.
*/
@@ -349,18 +193,10 @@
public boolean isValid(Principal principal, Object credential,
Subject activeSubject)
{
- // Check the cache first
- DomainInfo cacheInfo = getCacheInfo(principal, true);
if( trace )
- log.trace("Begin isValid, principal:"+principal+", cache info: "+cacheInfo);
+ log.trace("Begin isValid, principal:"+principal);
boolean isValid = false;
- if( cacheInfo != null )
- {
- isValid = validateCache(cacheInfo, credential, activeSubject);
- if( cacheInfo != null )
- cacheInfo.release();
- }
if( isValid == false )
isValid = authenticate(principal, credential, activeSubject);
if( trace )
@@ -379,26 +215,7 @@
*/
public Principal getPrincipal(Principal principal)
{
- if(domainCache == null)
- return principal;
- Principal result = principal;
- // Get the CallerPrincipal group member
- synchronized( domainCache )
- {
- DomainInfo info = getCacheInfo(principal, false);
- if( trace )
- log.trace("getPrincipal, cache info: "+info);
- if( info != null )
- {
- result = info.callerPrincipal;
- // If the mapping did not have a callerPrincipal just use principal
- if( result == null )
- result = principal;
- info.release();
- }
- }
-
- return result;
+ return principal;
}
/** Does the current Subject have a role(a Principal) that equates to one
@@ -442,7 +259,6 @@
@return The Set<Principal> for the application domain roles that the
principal has been assigned.
*/
- @SuppressWarnings("deprecation")
public Set<Principal> getUserRoles(Principal principal)
{
if(this.authorizationManager == null)
@@ -501,8 +317,6 @@
}
authenticated = true;
- // Build the Subject based DomainInfo cache value
- updateCache(lc, subject, principal, credential);
}
}
catch(LoginException e)
@@ -556,203 +370,4 @@
return lc;
}
- /** Validate the cache credential value against the provided credential
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- private boolean validateCache(DomainInfo info, Object credential,
- Subject theSubject)
- {
- if( trace )
- {
- StringBuffer tmp = new StringBuffer("Begin validateCache, info=");
- tmp.append(info.toString());
- tmp.append(";credential.class=");
- if( credential != null )
- {
- Class c = credential.getClass();
- tmp.append(c.getName());
- tmp.append('@');
- tmp.append(System.identityHashCode(c));
- }
- else
- {
- tmp.append("null");
- }
- log.trace(tmp.toString());
- }
-
- Object subjectCredential = info.credential;
- boolean isValid = false;
- // Check for a null credential as can be the case for an anonymous user
- if( credential == null || subjectCredential == null )
- {
- // Both credentials must be null
- isValid = (credential == null) && (subjectCredential == null);
- }
- // See if the credential is assignable to the cache value
- else if( subjectCredential.getClass().isAssignableFrom(credential.getClass()) )
- {
- /* Validate the credential by trying Comparable, char[], byte[],
- Object[], and finally Object.equals()
- */
- if( subjectCredential instanceof Comparable )
- {
- Comparable c = (Comparable) subjectCredential;
- isValid = c.compareTo(credential) == 0;
- }
- else if( subjectCredential instanceof char[] )
- {
- char[] a1 = (char[]) subjectCredential;
- char[] a2 = (char[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
- else if( subjectCredential instanceof byte[] )
- {
- byte[] a1 = (byte[]) subjectCredential;
- byte[] a2 = (byte[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
- else if( subjectCredential.getClass().isArray() )
- {
- Object[] a1 = (Object[]) subjectCredential;
- Object[] a2 = (Object[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
- else
- {
- isValid = subjectCredential.equals(credential);
- }
- }
- else if( subjectCredential instanceof char[] && credential instanceof String )
- {
- char[] a1 = (char[]) subjectCredential;
- char[] a2 = ((String) credential).toCharArray();
- isValid = Arrays.equals(a1, a2);
- }
- else if( subjectCredential instanceof String && credential instanceof char[] )
- {
- char[] a1 = ((String) subjectCredential).toCharArray();
- char[] a2 = (char[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
-
- // If the credentials match, set the thread's active Subject
- if( isValid )
- {
- // Copy the current subject into theSubject
- if( theSubject != null )
- {
- SubjectActions.copySubject(info.subject, theSubject, false,this.deepCopySubjectOption);
- }
- }
- if( trace )
- log.trace("End validateCache, isValid="+isValid);
-
- return isValid;
- }
-
- /** An accessor method that synchronizes access on the domainCache
- to avoid a race condition that can occur when the cache entry expires
- in the presence of multi-threaded access. The allowRefresh flag should
- be true for authentication accesses and false for other accesses.
- Previously the other accesses included authorization and caller principal
- mapping. Now the only use of the
-
- @param principal - the caller identity whose cached credentials are to
- be accessed.
- @param allowRefresh - a flag indicating if the cache access should flush
- any expired entries.
- */
- private DomainInfo getCacheInfo(Principal principal, boolean allowRefresh)
- {
- if( domainCache == null )
- return null;
-
- DomainInfo cacheInfo = null;
- synchronized( domainCache )
- {
- if( allowRefresh == true )
- cacheInfo = (DomainInfo) domainCache.get(principal);
- else
- cacheInfo = (DomainInfo) domainCache.peek(principal);
- if( cacheInfo != null )
- cacheInfo.acquire();
- }
- return cacheInfo;
- }
-
- private Subject updateCache(LoginContext lc, Subject subject,
- Principal principal, Object credential)
- {
- // If we don't have a cache there is nothing to update
- if( domainCache == null )
- return subject;
-
- long lifetime = 0;
- if( domainCache instanceof TimedCachePolicy )
- {
- TimedCachePolicy cache = (TimedCachePolicy) domainCache;
- lifetime = cache.getDefaultLifetime();
- }
- DomainInfo info = new DomainInfo(lifetime);
- info.loginCtx = lc;
- info.subject = new Subject();
- SubjectActions.copySubject(subject, info.subject, true, this.deepCopySubjectOption);
- info.credential = credential;
-
- if( trace )
- {
- log.trace("updateCache, inputSubject="+SubjectActions.toString(subject)
- +", cacheSubject="+SubjectActions.toString(info.subject));
- }
-
- /* Get the Subject callerPrincipal by looking for a Group called
- 'CallerPrincipal'
- */
- Set<Group> subjectGroups = subject.getPrincipals(Group.class);
- Iterator<Group> iter = subjectGroups.iterator();
- while( iter.hasNext() )
- {
- Group grp = iter.next();
- String name = grp.getName();
- if( name.equals("CallerPrincipal") )
- {
- Enumeration<? extends Principal> members = grp.members();
- if( members.hasMoreElements() )
- info.callerPrincipal = members.nextElement();
- }
- }
-
- /* Handle null principals with no callerPrincipal. This is an indication
- of an user that has not provided any authentication info, but
- has been authenticated by the domain login module stack. Here we look
- for the first non-Group Principal and use that.
- */
- if( principal == null && info.callerPrincipal == null )
- {
- Set<Principal> subjectPrincipals = subject.getPrincipals(Principal.class);
- Iterator<? extends Principal> iterPrincipals = subjectPrincipals.iterator();
- while( iterPrincipals.hasNext() )
- {
- Principal p = iterPrincipals.next();
- if( (p instanceof Group) == false )
- info.callerPrincipal = p;
- }
- }
-
- /* If the user already exists another login is active. Currently
- only one is allowed so remove the old and insert the new. Synchronize
- on the domainCache to ensure the removal and addition are an atomic
- operation so that getCacheInfo cannot see stale data.
- */
- synchronized( domainCache )
- {
- if( domainCache.peek(principal) != null )
- domainCache.remove(principal);
- domainCache.insert(principal, info);
- if( trace )
- log.trace("Inserted cache info: "+info);
- }
- return info.subject;
- }
}
\ No newline at end of file
Deleted: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/SynchronizedJaasSecurityManager.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/SynchronizedJaasSecurityManager.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/plugins/auth/SynchronizedJaasSecurityManager.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -1,617 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.plugins.auth;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.security.Principal;
-import java.security.acl.Group;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-
-import org.jboss.logging.Logger;
-import org.jboss.security.AuthenticationManager;
-import org.jboss.security.AuthorizationManager;
-import org.jboss.security.RealmMapping;
-import org.jboss.security.SecurityConstants;
-import org.jboss.security.SecurityContext;
-import org.jboss.security.SecurityContextAssociation;
-import org.jboss.security.SecurityUtil;
-import org.jboss.security.SubjectSecurityManager;
-import org.jboss.security.auth.callback.JBossCallbackHandler;
-import org.jboss.security.plugins.auth.JaasSecurityManagerBase.DomainInfo;
-import org.jboss.util.CachePolicy;
-import org.jboss.util.TimedCachePolicy;
-
-/** The JaasSecurityManager is responsible both for authenticating credentials
- associated with principals and for role mapping. This implementation relies
- on the JAAS LoginContext/LoginModules associated with the security
- domain name associated with the class for authentication,
- and the context JAAS Subject object for role mapping.
-
- @see #isValid(Principal, Object, Subject)
- @see #getPrincipal(Principal)
- @see #doesUserHaveRole(Principal, Set)
-
- @author <a href="on at ibis.odessa.ua">Oleg Nitz</a>
- @author Scott.Stark at jboss.org
- @author Anil.Saldhana at jboss.org
- @author <a href="mmoyses at redhat.com">Marcus Moyses</a>
- @version $Revision: 62860 $
-*/
-public class SynchronizedJaasSecurityManager implements SubjectSecurityManager, RealmMapping
-{
- /** The name of the domain this instance is securing. It is used as
- the appName into the SecurityPolicy.
- */
- private String securityDomain;
-
- /** A cache of DomainInfo objects keyd by Principal. This is now
- always set externally by our security manager service.
- */
- private CachePolicy domainCache;
-
- /** The JAAS callback handler to use in defaultLogin */
- private CallbackHandler handler;
-
- /** The setSecurityInfo(Principal, Object) method of the handler obj */
- private transient Method setSecurityInfo;
-
- /** The flag to indicate that the Subject sets need to be deep copied*/
- private boolean deepCopySubjectOption = false;
-
- /** The log4j category for the security manager domain
- */
- protected Logger log;
-
- protected boolean trace;
-
- /** Creates a default JaasSecurityManager for with a securityDomain
- name of 'other'.
- */
- public SynchronizedJaasSecurityManager()
- {
- this("other", new JBossCallbackHandler());
- }
-
- /** Creates a JaasSecurityManager for with a securityDomain
- name of that given by the 'securityDomain' argument.
- @param securityDomain the name of the security domain
- @param handler the JAAS callback handler instance to use
- @exception UndeclaredThrowableException thrown if handler does not
- implement a setSecurityInfo(Princpal, Object) method
- */
- public SynchronizedJaasSecurityManager(String securityDomain, CallbackHandler handler)
- {
- this.securityDomain = securityDomain;
- this.handler = handler;
- String categoryName = getClass().getName() + '.' + securityDomain;
- this.log = Logger.getLogger(categoryName);
- this.trace = log.isTraceEnabled();
-
- // Get the setSecurityInfo(Principal principal, Object credential) method
- Class<?>[] sig =
- {Principal.class, Object.class};
- try
- {
- setSecurityInfo = handler.getClass().getMethod("setSecurityInfo", sig);
- }
- catch (Exception e)
- {
- String msg = "Failed to find setSecurityInfo(Princpal, Object) method in handler";
- throw new UndeclaredThrowableException(e, msg);
- }
- log.debug("CallbackHandler: " + handler);
- }
-
- /** The domainCache is typically a shared object that is populated
- by the login code(LoginModule, etc.) and read by this class in the
- isValid() method.
- @see #isValid(Principal, Object, Subject)
- */
- public void setCachePolicy(CachePolicy domainCache)
- {
- this.domainCache = domainCache;
- log.debug("CachePolicy set to: " + domainCache);
- }
-
- /**
- * Flag to specify if deep copy of subject sets needs to be
- * enabled
- *
- * @param flag
- */
- public void setDeepCopySubjectOption(Boolean flag)
- {
- log.debug("setDeepCopySubjectOption=" + flag);
- this.deepCopySubjectOption = (flag == Boolean.TRUE);
- }
-
- /** Not really used anymore as the security manager service manages the
- security domain authentication caches.
- */
- public void flushCache()
- {
- if (domainCache != null)
- domainCache.flush();
- }
-
- /** Get the name of the security domain associated with this security mgr.
- @return Name of the security manager security domain.
- */
- public String getSecurityDomain()
- {
- return securityDomain;
- }
-
- /** Get the currently authenticated Subject. This is a thread local
- property shared across all JaasSecurityManager instances.
- @return The Subject authenticated in the current thread if one
- exists, null otherwise.
- */
- public Subject getActiveSubject()
- {
- /* This does not use SubjectActions.getActiveSubject since the caller
- must have the correct permissions to access the
- SecurityAssociation.getSubject method.
- */
- //return SecurityAssociation.getSubject();
- Subject subj = null;
- SecurityContext sc = SecurityContextAssociation.getSecurityContext();
- if (sc != null)
- {
- subj = sc.getUtil().getSubject();
- }
- return subj;
- }
-
- /** Validate that the given credential is correct for principal. This
- returns the value from invoking isValid(principal, credential, null).
- @param principal - the security domain principal attempting access
- @param credential - the proof of identity offered by the principal
- @return true if the principal was authenticated, false otherwise.
- */
- public boolean isValid(Principal principal, Object credential)
- {
- return isValid(principal, credential, null);
- }
-
- /** Validate that the given credential is correct for principal. This first
- will check the current CachePolicy object if one exists to see if the
- user's cached credentials match the given credential. If there is no
- credential cache or the cache information is invalid or does not match,
- the user is authenticated against the JAAS login modules configured for
- the security domain. This is done as an atomic operation synchronized
- in the principal's name to avoid multiple threads authenticating the
- same principal concurrently.
- @param principal - the security domain principal attempting access
- @param credential the proof of identity offered by the principal
- @param activeSubject - if not null, a Subject that will be populated with
- the state of the authenticated Subject.
- @return true if the principal was authenticated, false otherwise.
- */
- public boolean isValid(Principal principal, Object credential, Subject activeSubject)
- {
- // Check the cache first
- DomainInfo cacheInfo = getCacheInfo(principal, true);
- if (trace)
- log.trace("Begin isValid, principal:" + principal + ", cache info: " + cacheInfo);
-
- boolean isValid = false;
- if (principal != null && principal.getName() != null)
- {
- synchronized (principal.getName().intern())
- {
- if (cacheInfo != null)
- {
- isValid = validateCache(cacheInfo, credential, activeSubject);
- cacheInfo.release();
- }
- if (isValid == false)
- isValid = authenticate(principal, credential, activeSubject);
- }
- }
- else
- {
- if (cacheInfo != null)
- cacheInfo.release();
- isValid = authenticate(principal, credential, activeSubject);
- }
- if (trace)
- log.trace("End isValid, " + isValid);
- return isValid;
- }
-
- /** Map the argument principal from the deployment environment principal
- to the developer environment. This is called by the EJB context
- getCallerPrincipal() to return the Principal as described by
- the EJB developer domain.
- @return a Principal object that is valid in the deployment environment
- if one exists. If no Subject exists or the Subject has no principals
- then the argument principal is returned.
- */
- public Principal getPrincipal(Principal principal)
- {
- if (domainCache == null)
- return principal;
- Principal result = principal;
- // Get the CallerPrincipal group member
- synchronized (domainCache)
- {
- DomainInfo info = getCacheInfo(principal, false);
- if (trace)
- log.trace("getPrincipal, cache info: " + info);
- if (info != null)
- {
- result = info.callerPrincipal;
- // If the mapping did not have a callerPrincipal just use principal
- if (result == null)
- result = principal;
- info.release();
- }
- }
-
- return result;
- }
-
- /** Does the current Subject have a role(a Principal) that equates to one
- of the role names. This method obtains the Group named 'Roles' from
- the principal set of the currently authenticated Subject as determined
- by the SecurityAssociation.getSubject() method and then creates a
- SimplePrincipal for each name in roleNames. If the role is a member of the
- Roles group, then the user has the role. This requires that the caller
- establish the correct SecurityAssociation subject prior to calling this
- method. In the past this was done as a side-effect of an isValid() call,
- but this is no longer the case.
-
- @param principal - ignored. The current authenticated Subject determines
- the active user and assigned user roles.
- @param rolePrincipals - a Set of Principals for the roles to check.
-
- @see java.security.acl.Group;
- @see Subject#getPrincipals()
- */
- public boolean doesUserHaveRole(Principal principal, Set<Principal> rolePrincipals)
- {
- AuthorizationManager am = SecurityUtil.getAuthorizationManager(securityDomain,
- SecurityConstants.JAAS_CONTEXT_ROOT);
- return am.doesUserHaveRole(principal, rolePrincipals);
- }
-
- /** Return the set of domain roles the current active Subject 'Roles' group
- found in the subject Principals set.
-
- @param principal - ignored. The current authenticated Subject determines
- the active user and assigned user roles.
- @return The Set<Principal> for the application domain roles that the
- principal has been assigned.
- */
- @SuppressWarnings("deprecation")
- public Set<Principal> getUserRoles(Principal principal)
- {
- AuthorizationManager am = SecurityUtil.getAuthorizationManager(securityDomain,
- SecurityConstants.JAAS_CONTEXT_ROOT);
- return am.getUserRoles(principal);
- }
-
- /**
- * @see AuthenticationManager#getTargetPrincipal(Principal,Map)
- */
- public Principal getTargetPrincipal(Principal anotherDomainPrincipal, Map<String, Object> contextMap)
- {
- throw new RuntimeException("Not implemented yet");
- }
-
- /** Currently this simply calls defaultLogin() to do a JAAS login using the
- security domain name as the login module configuration name.
-
- * @param principal - the user id to authenticate
- * @param credential - an opaque credential.
- * @return false on failure, true on success.
- */
- private boolean authenticate(Principal principal, Object credential, Subject theSubject)
- {
- Subject subject = null;
- boolean authenticated = false;
- LoginException authException = null;
-
- try
- {
- // Validate the principal using the login configuration for this domain
- LoginContext lc = defaultLogin(principal, credential);
- subject = lc.getSubject();
-
- // Set the current subject if login was successful
- if (subject != null)
- {
- // Copy the current subject into theSubject
- if (theSubject != null)
- {
- SubjectActions.copySubject(subject, theSubject, false, this.deepCopySubjectOption);
- }
- else
- {
- theSubject = subject;
- }
-
- authenticated = true;
- // Build the Subject based DomainInfo cache value
- updateCache(lc, subject, principal, credential);
- }
- }
- catch (LoginException e)
- {
- // Don't log anonymous user failures unless trace level logging is on
- if (principal != null && principal.getName() != null || trace)
- log.trace("Login failure", e);
- authException = e;
- }
- // Set the security association thread context info exception
- SubjectActions.setContextInfo("org.jboss.security.exception", authException);
-
- return authenticated;
- }
-
- /** Pass the security info to the login modules configured for
- this security domain using our SecurityAssociationHandler.
- @return The authenticated Subject if successful.
- @exception LoginException throw if login fails for any reason.
- */
- private LoginContext defaultLogin(Principal principal, Object credential) throws LoginException
- {
- /* We use our internal CallbackHandler to provide the security info. A
- copy must be made to ensure there is a unique handler per active
- login since there can be multiple active logins.
- */
- Object[] securityInfo =
- {principal, credential};
- CallbackHandler theHandler = null;
- try
- {
- theHandler = (CallbackHandler) handler.getClass().newInstance();
- setSecurityInfo.invoke(theHandler, securityInfo);
- }
- catch (Throwable e)
- {
- if (trace)
- log.trace("Failed to create/setSecurityInfo on handler", e);
- LoginException le = new LoginException("Failed to setSecurityInfo on handler");
- le.initCause(e);
- throw le;
- }
- Subject subject = new Subject();
- LoginContext lc = null;
- if (trace)
- log.trace("defaultLogin, principal=" + principal);
- lc = SubjectActions.createLoginContext(securityDomain, subject, theHandler);
- lc.login();
- if (trace)
- log.trace("defaultLogin, lc=" + lc + ", subject=" + SubjectActions.toString(subject));
- return lc;
- }
-
- /** Validate the cache credential value against the provided credential
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- private boolean validateCache(DomainInfo info, Object credential, Subject theSubject)
- {
- if (trace)
- {
- StringBuffer tmp = new StringBuffer("Begin validateCache, info=");
- tmp.append(info.toString());
- tmp.append(";credential.class=");
- if (credential != null)
- {
- Class c = credential.getClass();
- tmp.append(c.getName());
- tmp.append('@');
- tmp.append(System.identityHashCode(c));
- }
- else
- {
- tmp.append("null");
- }
- log.trace(tmp.toString());
- }
-
- Object subjectCredential = info.credential;
- boolean isValid = false;
- // Check for a null credential as can be the case for an anonymous user
- if (credential == null || subjectCredential == null)
- {
- // Both credentials must be null
- isValid = (credential == null) && (subjectCredential == null);
- }
- // See if the credential is assignable to the cache value
- else if (subjectCredential.getClass().isAssignableFrom(credential.getClass()))
- {
- /* Validate the credential by trying Comparable, char[], byte[],
- Object[], and finally Object.equals()
- */
- if (subjectCredential instanceof Comparable)
- {
- Comparable c = (Comparable) subjectCredential;
- isValid = c.compareTo(credential) == 0;
- }
- else if (subjectCredential instanceof char[])
- {
- char[] a1 = (char[]) subjectCredential;
- char[] a2 = (char[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
- else if (subjectCredential instanceof byte[])
- {
- byte[] a1 = (byte[]) subjectCredential;
- byte[] a2 = (byte[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
- else if (subjectCredential.getClass().isArray())
- {
- Object[] a1 = (Object[]) subjectCredential;
- Object[] a2 = (Object[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
- else
- {
- isValid = subjectCredential.equals(credential);
- }
- }
- else if (subjectCredential instanceof char[] && credential instanceof String)
- {
- char[] a1 = (char[]) subjectCredential;
- char[] a2 = ((String) credential).toCharArray();
- isValid = Arrays.equals(a1, a2);
- }
- else if (subjectCredential instanceof String && credential instanceof char[])
- {
- char[] a1 = ((String) subjectCredential).toCharArray();
- char[] a2 = (char[]) credential;
- isValid = Arrays.equals(a1, a2);
- }
-
- // If the credentials match, set the thread's active Subject
- if (isValid)
- {
- // Copy the current subject into theSubject
- if (theSubject != null)
- {
- SubjectActions.copySubject(info.subject, theSubject, false, this.deepCopySubjectOption);
- }
- }
- if (trace)
- log.trace("End validateCache, isValid=" + isValid);
-
- return isValid;
- }
-
- /** An accessor method that synchronizes access on the domainCache
- to avoid a race condition that can occur when the cache entry expires
- in the presence of multi-threaded access. The allowRefresh flag should
- be true for authentication accesses and false for other accesses.
- Previously the other accesses included authorization and caller principal
- mapping. Now the only use of the
-
- @param principal - the caller identity whose cached credentials are to
- be accessed.
- @param allowRefresh - a flag indicating if the cache access should flush
- any expired entries.
- */
- private DomainInfo getCacheInfo(Principal principal, boolean allowRefresh)
- {
- if (domainCache == null)
- return null;
-
- DomainInfo cacheInfo = null;
- synchronized (domainCache)
- {
- if (allowRefresh == true)
- cacheInfo = (DomainInfo) domainCache.get(principal);
- else
- cacheInfo = (DomainInfo) domainCache.peek(principal);
- if (cacheInfo != null)
- cacheInfo.acquire();
- }
- return cacheInfo;
- }
-
- private Subject updateCache(LoginContext lc, Subject subject, Principal principal, Object credential)
- {
- // If we don't have a cache there is nothing to update
- if (domainCache == null)
- return subject;
-
- long lifetime = 0;
- if (domainCache instanceof TimedCachePolicy)
- {
- TimedCachePolicy cache = (TimedCachePolicy) domainCache;
- lifetime = cache.getDefaultLifetime();
- }
- DomainInfo info = new DomainInfo(lifetime);
- info.loginCtx = lc;
- info.subject = new Subject();
- SubjectActions.copySubject(subject, info.subject, true, this.deepCopySubjectOption);
- info.credential = credential;
-
- if (trace)
- {
- log.trace("updateCache, inputSubject=" + SubjectActions.toString(subject) + ", cacheSubject="
- + SubjectActions.toString(info.subject));
- }
-
- /* Get the Subject callerPrincipal by looking for a Group called
- 'CallerPrincipal'
- */
- Set<Group> subjectGroups = subject.getPrincipals(Group.class);
- Iterator<Group> iter = subjectGroups.iterator();
- while (iter.hasNext())
- {
- Group grp = iter.next();
- String name = grp.getName();
- if (name.equals("CallerPrincipal"))
- {
- Enumeration<? extends Principal> members = grp.members();
- if (members.hasMoreElements())
- info.callerPrincipal = members.nextElement();
- }
- }
-
- /* Handle null principals with no callerPrincipal. This is an indication
- of an user that has not provided any authentication info, but
- has been authenticated by the domain login module stack. Here we look
- for the first non-Group Principal and use that.
- */
- if (principal == null && info.callerPrincipal == null)
- {
- Set<Principal> subjectPrincipals = subject.getPrincipals(Principal.class);
- Iterator<? extends Principal> iterPrincipals = subjectPrincipals.iterator();
- while (iterPrincipals.hasNext())
- {
- Principal p = iterPrincipals.next();
- if ((p instanceof Group) == false)
- info.callerPrincipal = p;
- }
- }
-
- /* If the user already exists another login is active. Currently
- only one is allowed so remove the old and insert the new. Synchronize
- on the domainCache to ensure the removal and addition are an atomic
- operation so that getCacheInfo cannot see stale data.
- */
- synchronized (domainCache)
- {
- if (domainCache.peek(principal) != null)
- domainCache.remove(principal);
- domainCache.insert(principal, info);
- if (trace)
- log.trace("Inserted cache info: " + info);
- }
- return info.subject;
- }
-}
\ No newline at end of file
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/StringPropertyReplacer.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/StringPropertyReplacer.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/StringPropertyReplacer.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,263 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util;
+
+import java.util.Properties;
+import java.io.File;
+
+/**
+ * A utility class for replacing properties in strings.
+ *
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @author <a href="Scott.Stark at jboss.org">Scott Stark</a>
+ * @author <a href="claudio.vesco at previnet.it">Claudio Vesco</a>
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision$</tt>
+ */
+public final class StringPropertyReplacer
+{
+ /** New line string constant */
+ public static final String NEWLINE = SysPropertyActions.getProperty("line.separator", "\n");
+
+ /** File separator value */
+ private static final String FILE_SEPARATOR = File.separator;
+
+ /** Path separator value */
+ private static final String PATH_SEPARATOR = File.pathSeparator;
+
+ /** File separator alias */
+ private static final String FILE_SEPARATOR_ALIAS = "/";
+
+ /** Path separator alias */
+ private static final String PATH_SEPARATOR_ALIAS = ":";
+
+ // States used in property parsing
+ private static final int NORMAL = 0;
+ private static final int SEEN_DOLLAR = 1;
+ private static final int IN_BRACKET = 2;
+
+ /**
+ * Go through the input string and replace any occurance of ${p} with
+ * the System.getProperty(p) value. If there is no such property p defined,
+ * then the ${p} reference will remain unchanged.
+ *
+ * If the property reference is of the form ${p:v} and there is no such property p,
+ * then the default value v will be returned.
+ *
+ * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then
+ * the primary and the secondary properties will be tried in turn, before
+ * returning either the unchanged input, or the default value.
+ *
+ * The property ${/} is replaced with System.getProperty("file.separator")
+ * value and the property ${:} is replaced with System.getProperty("path.separator").
+ *
+ * @param string - the string with possible ${} references
+ * @return the input string with all property references replaced if any.
+ * If there are no valid references the input string will be returned.
+ */
+ public static String replaceProperties(final String string)
+ {
+ return replaceProperties(string, null);
+ }
+
+ /**
+ * Go through the input string and replace any occurance of ${p} with
+ * the props.getProperty(p) value. If there is no such property p defined,
+ * then the ${p} reference will remain unchanged.
+ *
+ * If the property reference is of the form ${p:v} and there is no such property p,
+ * then the default value v will be returned.
+ *
+ * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then
+ * the primary and the secondary properties will be tried in turn, before
+ * returning either the unchanged input, or the default value.
+ *
+ * The property ${/} is replaced with System.getProperty("file.separator")
+ * value and the property ${:} is replaced with System.getProperty("path.separator").
+ *
+ * @param string - the string with possible ${} references
+ * @param props - the source for ${x} property ref values, null means use System.getProperty()
+ * @return the input string with all property references replaced if any.
+ * If there are no valid references the input string will be returned.
+ */
+ public static String replaceProperties(final String string, final Properties props)
+ {
+ final char[] chars = string.toCharArray();
+ StringBuffer buffer = new StringBuffer();
+ boolean properties = false;
+ int state = NORMAL;
+ int start = 0;
+ for (int i = 0; i < chars.length; ++i)
+ {
+ char c = chars[i];
+
+ // Dollar sign outside brackets
+ if (c == '$' && state != IN_BRACKET)
+ state = SEEN_DOLLAR;
+
+ // Open bracket immediatley after dollar
+ else if (c == '{' && state == SEEN_DOLLAR)
+ {
+ buffer.append(string.substring(start, i - 1));
+ state = IN_BRACKET;
+ start = i - 1;
+ }
+
+ // No open bracket after dollar
+ else if (state == SEEN_DOLLAR)
+ state = NORMAL;
+
+ // Closed bracket after open bracket
+ else if (c == '}' && state == IN_BRACKET)
+ {
+ // No content
+ if (start + 2 == i)
+ {
+ buffer.append("${}"); // REVIEW: Correct?
+ }
+ else // Collect the system property
+ {
+ String value = null;
+
+ String key = string.substring(start + 2, i);
+
+ // check for alias
+ if (FILE_SEPARATOR_ALIAS.equals(key))
+ {
+ value = FILE_SEPARATOR;
+ }
+ else if (PATH_SEPARATOR_ALIAS.equals(key))
+ {
+ value = PATH_SEPARATOR;
+ }
+ else
+ {
+ // check from the properties
+ if (props != null)
+ value = props.getProperty(key);
+ else
+ value = System.getProperty(key);
+
+ if (value == null)
+ {
+ // Check for a default value ${key:default}
+ int colon = key.indexOf(':');
+ if (colon > 0)
+ {
+ String realKey = key.substring(0, colon);
+ if (props != null)
+ value = props.getProperty(realKey);
+ else
+ value = System.getProperty(realKey);
+
+ if (value == null)
+ {
+ // Check for a composite key, "key1,key2"
+ value = resolveCompositeKey(realKey, props);
+
+ // Not a composite key either, use the specified default
+ if (value == null)
+ value = key.substring(colon+1);
+ }
+ }
+ else
+ {
+ // No default, check for a composite key, "key1,key2"
+ value = resolveCompositeKey(key, props);
+ }
+ }
+ }
+
+ if (value != null)
+ {
+ properties = true;
+ buffer.append(value);
+ }
+ else
+ {
+ buffer.append("${");
+ buffer.append(key);
+ buffer.append('}');
+ }
+
+ }
+ start = i + 1;
+ state = NORMAL;
+ }
+ }
+
+ // No properties
+ if (properties == false)
+ return string;
+
+ // Collect the trailing characters
+ if (start != chars.length)
+ buffer.append(string.substring(start, chars.length));
+
+ // Done
+ return buffer.toString();
+ }
+
+ /**
+ * Try to resolve a "key" from the provided properties by
+ * checking if it is actually a "key1,key2", in which case
+ * try first "key1", then "key2". If all fails, return null.
+ *
+ * It also accepts "key1," and ",key2".
+ *
+ * @param key the key to resolve
+ * @param props the properties to use
+ * @return the resolved key or null
+ */
+ private static String resolveCompositeKey(String key, Properties props)
+ {
+ String value = null;
+
+ // Look for the comma
+ int comma = key.indexOf(',');
+ if (comma > -1)
+ {
+ // If we have a first part, try resolve it
+ if (comma > 0)
+ {
+ // Check the first part
+ String key1 = key.substring(0, comma);
+ if (props != null)
+ value = props.getProperty(key1);
+ else
+ value = System.getProperty(key1);
+ }
+ // Check the second part, if there is one and first lookup failed
+ if (value == null && comma < key.length() - 1)
+ {
+ String key2 = key.substring(comma + 1);
+ if (props != null)
+ value = props.getProperty(key2);
+ else
+ value = System.getProperty(key2);
+ }
+ }
+ // Return whatever we've found or null
+ return value;
+ }
+}
\ No newline at end of file
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/SysPropertyActions.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/SysPropertyActions.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/SysPropertyActions.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util;
+
+import java.security.PrivilegedAction;
+import java.security.AccessController;
+
+/**
+ * Priviledged actions for the package
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+class SysPropertyActions
+{
+ interface SysProps
+ {
+ SysProps NON_PRIVILEDGED = new SysProps()
+ {
+ public String getProperty(final String name, final String defaultValue)
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ SysProps PRIVILEDGED = new SysProps()
+ {
+ public String getProperty(final String name, final String defaultValue)
+ {
+ PrivilegedAction action = new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ return (String) AccessController.doPrivileged(action);
+ }
+ };
+ String getProperty(String name, String defaultValue);
+ }
+
+ public static String getProperty(String name, String defaultValue)
+ {
+ String prop;
+ if( System.getSecurityManager() == null )
+ prop = SysProps.NON_PRIVILEDGED.getProperty(name, defaultValue);
+ else
+ prop = SysProps.PRIVILEDGED.getProperty(name, defaultValue);
+ return prop;
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/IllegalTransitionException.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/IllegalTransitionException.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/IllegalTransitionException.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util.state;
+
+/** An exception thrown when an invalid transition is attempted from a state.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class IllegalTransitionException extends Exception
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -3392564168782896452L;
+ public IllegalTransitionException(String msg)
+ {
+ super(msg);
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/State.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/State.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/State.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,128 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.util.state;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
+
+/** The respresentation of a state in a state machine.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+public class State
+{
+ /** The name of the state */
+ private String name;
+ /** HashMap<String, Transition> */
+ private HashMap allowedTransitions = new HashMap();
+ /** Arbitrary state data */
+ private Object data;
+
+ public State(String name)
+ {
+ this(name, null);
+ }
+ public State(String name, Map transitions)
+ {
+ this.name = name;
+ if( transitions != null )
+ {
+ allowedTransitions.putAll(transitions);
+ }
+ }
+
+ /** Get the state name.
+ * @return the name of the state.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ public Object getData()
+ {
+ return data;
+ }
+ public void setData(Object data)
+ {
+ this.data = data;
+ }
+
+ /** An accept state is indicated by no transitions
+ * @return true if this is an accept state, false otherwise.
+ */
+ public boolean isAcceptState()
+ {
+ return allowedTransitions.size() == 0;
+ }
+
+ /** Add a transition to the allowed transition map.
+ *
+ * @param transition
+ * @return this to allow chained addTransition calls
+ */
+ public State addTransition(Transition transition)
+ {
+ allowedTransitions.put(transition.getName(), transition);
+ return this;
+ }
+
+ /** Lookup an allowed transition given its name.
+ *
+ * @param name - the name of a valid transition from this state.
+ * @return the valid transition if it exists, null otherwise.
+ */
+ public Transition getTransition(String name)
+ {
+ Transition t = (Transition) allowedTransitions.get(name);
+ return t;
+ }
+
+ /** Get the Map<String, Transition> of allowed transitions for this state.
+ * @return the allowed transitions map.
+ */
+ public Map getTransitions()
+ {
+ return allowedTransitions;
+ }
+
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer("State(name=");
+ tmp.append(name);
+ Iterator i = allowedTransitions.entrySet().iterator();
+ while( i.hasNext() )
+ {
+ Map.Entry e = (Map.Entry) i.next();
+ tmp.append("\n\t on: ");
+ tmp.append(e.getKey());
+ Transition t = (Transition) e.getValue();
+ tmp.append(" go to: ");
+ tmp.append(t.getTarget().getName());
+ }
+ tmp.append(')');
+ return tmp.toString();
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/StateMachine.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/StateMachine.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/StateMachine.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,157 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.security.util.state;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Iterator;
+import org.jboss.logging.Logger;
+
+/** The representation of a finite state machine.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+public class StateMachine implements Cloneable
+{
+ private static Logger log = Logger.getLogger(StateMachine.class);
+ /** A description of the state machine */
+ private String description;
+ /** The set of states making up the state machine */
+ private HashSet states;
+ /** The starting state */
+ private State startState;
+ /** The current state of the state machine */
+ private State currentState;
+
+ /** Create a state machine given its states and start state.
+ *
+ * @param states - Set<State> for the state machine
+ * @param startState - the starting state
+ */
+ public StateMachine(Set states, State startState)
+ {
+ this(states, startState, null);
+ }
+ /** Create a state machine given its states and start state.
+ *
+ * @param states - Set<State> for the state machine
+ * @param startState - the starting state
+ * @param description - an optional description of the state machine
+ */
+ public StateMachine(Set states, State startState, String description)
+ {
+ this.states = new HashSet(states);
+ this.startState = startState;
+ this.currentState = startState;
+ this.description = description;
+ }
+
+ /** Make a copy of the StateMachine maintaining the current state.
+ *
+ * @return a copy of the StateMachine.
+ */
+ public Object clone()
+ {
+ StateMachine clone = new StateMachine(states, startState, description);
+ clone.currentState = currentState;
+ return clone;
+ }
+
+ /** Get the state machine description.
+ * @return an possibly null description.
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /** Get the current state of the state machine.
+ * @return the current state.
+ */
+ public State getCurrentState()
+ {
+ return currentState;
+ }
+
+ /** Get the start state of the state machine.
+ * @return the start state.
+ */
+ public State getStartState()
+ {
+ return startState;
+ }
+
+ /** Get the states of the state machine.
+ * @return the machine states.
+ */
+ public Set getStates()
+ {
+ return states;
+ }
+
+ /** Transition to the next state given the name of a valid transition.
+ * @param actionName - the name of transition that is valid for the
+ * current state.
+ * @return the next state
+ * @throws IllegalTransitionException
+ */
+ public State nextState(String actionName)
+ throws IllegalTransitionException
+ {
+ Transition t = currentState.getTransition(actionName);
+ if( t == null )
+ {
+ String msg = "No transition for action: '" + actionName
+ + "' from state: '" + currentState.getName() + "'";
+ throw new IllegalTransitionException(msg);
+ }
+ State nextState = t.getTarget();
+ log.trace("nextState("+actionName+") = "+nextState);
+ currentState = nextState;
+ return currentState;
+ }
+
+ /** Reset the state machine back to the start state
+ *
+ * @return the start state
+ */
+ public State reset()
+ {
+ this.currentState = startState;
+ return currentState;
+ }
+
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer("StateMachine[:\n");
+ tmp.append("\tCurrentState: "+currentState.getName());
+ Iterator i = states.iterator();
+ while( i.hasNext() )
+ {
+ tmp.append('\n').append(i.next());
+ }
+ tmp.append(']');
+ return tmp.toString();
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/Transition.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/Transition.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/Transition.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util.state;
+
+/** A representation of a transition from a state to another state.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class Transition
+{
+ private String name;
+ private State target;
+
+ public Transition(String name, State target)
+ {
+ this.name = name;
+ this.target = target;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public State getTarget()
+ {
+ return target;
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/xml/StateMachineParser.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/xml/StateMachineParser.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/state/xml/StateMachineParser.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util.state.xml;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.util.state.State;
+import org.jboss.security.util.state.StateMachine;
+import org.jboss.security.util.state.Transition;
+import org.jboss.security.util.xml.DOMUtils;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/** Parse an xml representation of a state machine. A sample document is:
+
+<state-machine description="JACC PolicyConfiguration States">
+ <state name="open">
+ <transition name="inService" target="open" />
+ <transition name="getContextID" target="open" />
+ <transition name="getPolicyConfiguration" target="open" />
+ <transition name="addToRole" target="open" />
+ <transition name="removeRole" target="open" />
+ <transition name="addToExcludedPolicy" target="open" />
+ <transition name="removeExcludedPolicy" target="open" />
+ <transition name="addToUncheckedPolicy" target="open" />
+ <transition name="removeUncheckedPolicy" target="open" />
+ <transition name="linkConfiguration" target="open" />
+ <transition name="commit" target="inService" />
+ <transition name="delete" target="deleted" />
+ </state>
+ <state name="inService">
+ <transition name="getPolicyConfiguration" target="open" />
+ <transition name="getContextID" target="inService" />
+ <transition name="inService" target="inService" />
+ <transition name="delete" target="deleted" />
+ </state>
+ <state name="deleted" isStartState="true">
+ <transition name="getPolicyConfiguration" target="open" />
+ <transition name="delete" target="deleted" />
+ <transition name="inService" target="deleted" />
+ <transition name="getContextID" target="deleted" />
+ </state>
+</state-machine>
+
+ @author Scott.Stark at jboss.org
+ @author Dimitris.Andreadis at jboss.org
+ @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+public class StateMachineParser
+{
+ private static Logger log = Logger.getLogger(StateMachineParser.class);
+
+ public StateMachine parse(URL source) throws Exception
+ {
+ // parse the XML document into a DOM structure
+ InputStream in = source.openConnection().getInputStream();
+ Element root = DOMUtils.parse(in);
+
+ String description = root.getAttribute("description");
+ HashMap nameToStateMap = new HashMap();
+ HashMap nameToTransitionsMap = new HashMap();
+ HashSet states = new HashSet();
+ State startState = null;
+
+ // parse states
+ NodeList stateList = root.getChildNodes();
+ for (int i = 0; i < stateList.getLength(); i++)
+ {
+ Node stateNode = stateList.item(i);
+ if (stateNode.getNodeName().equals("state"))
+ {
+ Element stateElement = (Element)stateNode;
+ String stateName = stateElement.getAttribute("name");
+ State s = new State(stateName);
+ states.add(s);
+ nameToStateMap.put(stateName, s);
+ HashMap transitions = new HashMap();
+
+ // parse transitions
+ NodeList transitionList = stateElement.getChildNodes();
+ for (int j = 0; j < transitionList.getLength(); j++)
+ {
+ Node transitionNode = transitionList.item(j);
+ if (transitionNode.getNodeName().equals("transition"))
+ {
+ Element transitionElement = (Element)transitionNode;
+ String name = transitionElement.getAttribute("name");
+ String targetName = transitionElement.getAttribute("target");
+ transitions.put(name, targetName);
+ }
+ }
+ nameToTransitionsMap.put(stateName, transitions);
+ if (Boolean.valueOf(stateElement.getAttribute("isStartState")) == Boolean.TRUE)
+ startState = s;
+ }
+ }
+
+ // Resolve all transition targets
+ Iterator transitions = nameToTransitionsMap.keySet().iterator();
+ StringBuffer resolveFailed = new StringBuffer();
+ while (transitions.hasNext())
+ {
+ String stateName = (String)transitions.next();
+ State s = (State)nameToStateMap.get(stateName);
+ HashMap stateTransitions = (HashMap)nameToTransitionsMap.get(stateName);
+ Iterator it = stateTransitions.keySet().iterator();
+ while (it.hasNext())
+ {
+ String name = (String)it.next();
+ String targetName = (String)stateTransitions.get(name);
+ State target = (State)nameToStateMap.get(targetName);
+ if (target == null)
+ {
+ String msg = "Failed to resolve target state: " + targetName + " for transition: " + name;
+ resolveFailed.append(msg);
+ log.debug(msg);
+ }
+ Transition t = new Transition(name, target);
+ s.addTransition(t);
+ }
+ }
+
+ if (resolveFailed.length() > 0)
+ throw new Exception("Failed to resolve transition targets: " + resolveFailed);
+
+ StateMachine sm = new StateMachine(states, startState, description);
+ return sm;
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/DOMUtils.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/DOMUtils.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/DOMUtils.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,582 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util.xml;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.util.StringPropertyReplacer;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * DOM2 utilites
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+public final class DOMUtils
+{
+ private static Logger log = Logger.getLogger(DOMUtils.class);
+
+ // All elements created by the same thread are created by the same builder and belong to the same doc
+ private static ThreadLocal documentThreadLocal = new ThreadLocal();
+ private static ThreadLocal builderThreadLocal = new ThreadLocal() {
+ protected Object initialValue() {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(new JBossEntityResolver());
+ return builder;
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new RuntimeException("Failed to create DocumentBuilder", e);
+ }
+ }
+ };
+
+ // Hide the constructor
+ private DOMUtils()
+ {
+ }
+
+ public static DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilder builder = (DocumentBuilder)builderThreadLocal.get();
+ return builder;
+ }
+
+ /** Parse the given XML string and return the root Element
+ * @param xmlString
+ * @return the element
+ * @throws IOException
+ */
+ public static Element parse(String xmlString) throws IOException
+ {
+ try
+ {
+ return parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
+ }
+ catch (IOException e)
+ {
+ log.error("Cannot parse: " + xmlString);
+ throw e;
+ }
+ }
+
+ /** Parse the given XML stream and return the root Element
+ * @param xmlStream
+ * @return the element
+ * @throws IOException
+ */
+ public static Element parse(InputStream xmlStream) throws IOException
+ {
+ try
+ {
+ Document doc = getDocumentBuilder().parse(xmlStream);
+ Element root = doc.getDocumentElement();
+ return root;
+ }
+ catch (SAXException e)
+ {
+ throw new IOException(e.toString());
+ }
+ }
+
+ /** Parse the given input source and return the root Element
+ * @param source
+ * @return the element
+ * @throws IOException
+ */
+ public static Element parse(InputSource source) throws IOException
+ {
+ try
+ {
+ Document doc = getDocumentBuilder().parse(source);
+ Element root = doc.getDocumentElement();
+ return root;
+ }
+ catch (SAXException e)
+ {
+ throw new IOException(e.toString());
+ }
+ }
+
+ /** Create an Element for a given name
+ * @param localPart
+ * @return the element
+ */
+ public static Element createElement(String localPart)
+ {
+ Document doc = getOwnerDocument();
+ log.trace("createElement {}" + localPart);
+ return doc.createElement(localPart);
+ }
+
+ /** Create an Element for a given name and prefix
+ * @param localPart
+ * @param prefix
+ * @return the element
+ */
+ public static Element createElement(String localPart, String prefix)
+ {
+ Document doc = getOwnerDocument();
+ log.trace("createElement {}" + prefix + ":" + localPart);
+ return doc.createElement(prefix + ":" + localPart);
+ }
+
+ /** Create an Element for a given name, prefix and uri
+ * @param localPart
+ * @param prefix
+ * @param uri
+ * @return the element
+ */
+ public static Element createElement(String localPart, String prefix, String uri)
+ {
+ Document doc = getOwnerDocument();
+ if (prefix == null || prefix.length() == 0)
+ {
+ log.trace("createElement {" + uri + "}" + localPart);
+ return doc.createElementNS(uri, localPart);
+ }
+ else
+ {
+ log.trace("createElement {" + uri + "}" + prefix + ":" + localPart);
+ return doc.createElementNS(uri, prefix + ":" + localPart);
+ }
+ }
+
+ /** Create an Element for a given QName
+ * @param qname
+ * @return the element
+ */
+ public static Element createElement(QName qname)
+ {
+ return createElement(qname.getLocalPart(), qname.getPrefix(), qname.getNamespaceURI());
+ }
+
+ /** Create a org.w3c.dom.Text node
+ * @param value
+ * @return the text node
+ */
+ public static Text createTextNode(String value)
+ {
+ Document doc = getOwnerDocument();
+ return doc.createTextNode(value);
+ }
+
+ /** @return the qname of the given node.
+ * @param el
+ */
+ public static QName getElementQName(Element el)
+ {
+ String qualifiedName = el.getNodeName();
+ return resolveQName(el, qualifiedName);
+ }
+
+ /** Transform the giveen qualified name into a QName
+ * @param el
+ * @param qualifiedName
+ * @return the resolved name
+ */
+ public static QName resolveQName(Element el, String qualifiedName)
+ {
+ QName qname;
+ String prefix = "";
+ String namespaceURI = "";
+ String localPart = qualifiedName;
+
+ int colIndex = qualifiedName.indexOf(":");
+ if (colIndex > 0)
+ {
+ prefix = qualifiedName.substring(0, colIndex);
+ localPart = qualifiedName.substring(colIndex + 1);
+
+ if ("xmlns".equals(prefix))
+ {
+ namespaceURI = "URI:XML_PREDEFINED_NAMESPACE";
+ }
+ else
+ {
+ Element nsElement = el;
+ while (namespaceURI.equals("") && nsElement != null)
+ {
+ namespaceURI = nsElement.getAttribute("xmlns:" + prefix);
+ if (namespaceURI.equals(""))
+ nsElement = getParentElement(nsElement);
+ }
+ }
+
+ if (namespaceURI.equals(""))
+ throw new IllegalArgumentException("Cannot find namespace uri for: " + qualifiedName);
+ }
+
+ qname = new QName(namespaceURI, localPart, prefix);
+ return qname;
+ }
+
+ /** Get the value from the given attribute
+ * @param el
+ * @param attrName
+ *
+ * @return null if the attribute value is empty or the attribute is not present
+ */
+ public static String getAttributeValue(Element el, String attrName)
+ {
+ return getAttributeValue(el, new QName(attrName));
+ }
+
+ /** Get the value from the given attribute
+ * @param el
+ * @param attrName
+ *
+ * @return null if the attribute value is empty or the attribute is not present
+ */
+ public static String getAttributeValue(Element el, QName attrName)
+ {
+ String attr = null;
+ if ("".equals(attrName.getNamespaceURI()))
+ attr = el.getAttribute(attrName.getLocalPart());
+ else attr = el.getAttributeNS(attrName.getNamespaceURI(), attrName.getLocalPart());
+
+ if ("".equals(attr))
+ attr = null;
+
+ return attr;
+ }
+
+ /** @return the qname value from the given attribute
+ * @param el
+ * @param attrName
+ */
+ public static QName getAttributeValueAsQName(Element el, String attrName)
+ {
+ return getAttributeValueAsQName(el, new QName(attrName));
+
+ }
+
+ /** @return the qname value from the given attribute
+ * @param el
+ * @param attrName
+ */
+ public static QName getAttributeValueAsQName(Element el, QName attrName)
+ {
+ QName qname = null;
+
+ String qualifiedName = getAttributeValue(el, attrName);
+ if (qualifiedName != null)
+ {
+ qname = resolveQName(el, qualifiedName);
+ }
+
+ return qname;
+ }
+
+ /** @return the boolean value from the given attribute
+ * @param el
+ * @param attrName
+ */
+ public static boolean getAttributeValueAsBoolean(Element el, String attrName)
+ {
+ return getAttributeValueAsBoolean(el, new QName(attrName));
+ }
+
+ /** @return the boolean value from the given attribute
+ * @param el
+ * @param attrName
+ */
+ public static boolean getAttributeValueAsBoolean(Element el, QName attrName)
+ {
+ String attrVal = getAttributeValue(el, attrName);
+ boolean ret = "true".equalsIgnoreCase(attrVal) || "1".equalsIgnoreCase(attrVal);
+ return ret;
+ }
+
+ /** @return the integer value from the given attribute
+ * @param el
+ * @param attrName
+ */
+ public static Integer getAttributeValueAsInteger(Element el, String attrName)
+ {
+ return getAttributeValueAsInteger(el, new QName(attrName));
+ }
+
+ /** @param el
+ * @param attrName
+ * @return the integer value from the given attribute
+ */
+ public static Integer getAttributeValueAsInteger(Element el, QName attrName)
+ {
+ String attrVal = getAttributeValue(el, attrName);
+ return (attrVal != null ? new Integer(attrVal) : null);
+ }
+
+ /** @param el
+ * @return the attributes as Map<QName, String>
+ */
+ public static Map getAttributes(Element el)
+ {
+ Map attmap = new HashMap();
+ NamedNodeMap attribs = el.getAttributes();
+ for (int i = 0; i < attribs.getLength(); i++)
+ {
+ Attr attr = (Attr)attribs.item(i);
+ String name = attr.getName();
+ QName qname = resolveQName(el, name);
+ String value = attr.getNodeValue();
+ attmap.put(qname, value);
+ }
+ return attmap;
+ }
+
+ /** Copy attributes between elements
+ * @param destElement
+ * @param srcElement
+ */
+ public static void copyAttributes(Element destElement, Element srcElement)
+ {
+ NamedNodeMap attribs = srcElement.getAttributes();
+ for (int i = 0; i < attribs.getLength(); i++)
+ {
+ Attr attr = (Attr)attribs.item(i);
+ String uri = attr.getNamespaceURI();
+ String qname = attr.getName();
+ String value = attr.getNodeValue();
+
+ // Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or
+ // change an object in a way which is incorrect with regard to namespaces.
+ if (uri == null && qname.startsWith("xmlns"))
+ {
+ log.trace("Ignore attribute: [uri=" + uri + ",qname=" + qname + ",value=" + value + "]");
+ }
+ else
+ {
+ destElement.setAttributeNS(uri, qname, value);
+ }
+ }
+ }
+
+ /** True if the node has child elements
+ * @param node
+ * @return true when has child elements
+ */
+ public static boolean hasChildElements(Node node)
+ {
+ NodeList nlist = node.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
+ {
+ Node child = nlist.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ return true;
+ }
+ return false;
+ }
+
+ /** Gets child elements
+ * @param node
+ * @return the iterator
+ */
+ public static Iterator getChildElements(Node node)
+ {
+ ArrayList list = new ArrayList();
+ NodeList nlist = node.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
+ {
+ Node child = nlist.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ list.add(child);
+ }
+ return list.iterator();
+ }
+
+ /** Get the concatenated text content, or null.
+ * @param node
+ * @return getTextContent(node, false).
+ */
+ public static String getTextContent(Node node)
+ {
+ return getTextContent(node, false);
+ }
+ /** Get the concatenated text content, or null.
+ * @param node node to search for TEXT_NODE conent
+ * @param replaceProps flag indicating if ${x} property refs should be replace
+ * @return the text content
+ */
+ public static String getTextContent(Node node, boolean replaceProps)
+ {
+ boolean hasTextContent = false;
+ StringBuffer buffer = new StringBuffer();
+ NodeList nlist = node.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
+ {
+ Node child = nlist.item(i);
+ if (child.getNodeType() == Node.TEXT_NODE)
+ {
+ buffer.append(child.getNodeValue());
+ hasTextContent = true;
+ }
+ }
+ String text = (hasTextContent ? buffer.toString() : null);
+ if ( text != null && replaceProps)
+ text = StringPropertyReplacer.replaceProperties(text);
+
+ return text;
+ }
+
+ /** @return the first child element
+ * @param node
+ */
+ public static Element getFirstChildElement(Node node)
+ {
+ return getFirstChildElementIntern(node, null);
+ }
+
+ /** @param node
+ * @param nodeName
+ * @return the first child element for a given local name without namespace
+ */
+ public static Element getFirstChildElement(Node node, String nodeName)
+ {
+ return getFirstChildElementIntern(node, new QName(nodeName));
+ }
+
+ /** @param node
+ * @param nodeName
+ * @return the first child element for a given qname
+ */
+ public static Element getFirstChildElement(Node node, QName nodeName)
+ {
+ return getFirstChildElementIntern(node, nodeName);
+ }
+
+ private static Element getFirstChildElementIntern(Node node, QName nodeName)
+ {
+ Element childElement = null;
+ Iterator it = getChildElementsIntern(node, nodeName);
+ if (it.hasNext())
+ {
+ childElement = (Element)it.next();
+ }
+ return childElement;
+ }
+
+ /** Gets the child elements for a given local name without namespace
+ * @param node
+ * @param nodeName
+ * @return the iterator
+ */
+ public static Iterator getChildElements(Node node, String nodeName)
+ {
+ return getChildElementsIntern(node, new QName(nodeName));
+ }
+
+ /** Gets the child element for a given qname
+ * @param node
+ * @param nodeName
+ * @return the iterator
+ */
+ public static Iterator getChildElements(Node node, QName nodeName)
+ {
+ return getChildElementsIntern(node, nodeName);
+ }
+
+ private static Iterator getChildElementsIntern(Node node, QName nodeName)
+ {
+ ArrayList list = new ArrayList();
+ NodeList nlist = node.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
+ {
+ Node child = nlist.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ {
+ if (nodeName == null)
+ {
+ list.add(child);
+ }
+ else
+ {
+ QName qname;
+ if (nodeName.getNamespaceURI().length() > 0)
+ {
+ qname = new QName(child.getNamespaceURI(), child.getLocalName());
+ }
+ else
+ {
+ qname = new QName(child.getLocalName());
+ }
+ if (qname.equals(nodeName))
+ {
+ list.add(child);
+ }
+ }
+ }
+ }
+ return list.iterator();
+ }
+
+ /** Gets parent element or null if there is none
+ * @param node
+ * @return the element
+ */
+ public static Element getParentElement(Node node)
+ {
+ Node parent = node.getParentNode();
+ return (parent instanceof Element ? (Element)parent : null);
+ }
+
+ /** @return the owner document that is associated with the current thread */
+ public static Document getOwnerDocument()
+ {
+ Document doc = (Document)documentThreadLocal.get();
+ if (doc == null)
+ {
+ doc = getDocumentBuilder().newDocument();
+ documentThreadLocal.set(doc);
+ }
+ return doc;
+ }
+}
Added: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/JBossEntityResolver.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/JBossEntityResolver.java (rev 0)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/util/xml/JBossEntityResolver.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -0,0 +1,618 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.util.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.util.StringPropertyReplacer;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Local entity resolver to handle standard J2EE DTDs and Schemas as well as JBoss
+ * specific DTDs.
+ * <p/>
+ * Function boolean isEntityResolved() is here to avoid validation errors in
+ * descriptors that do not have a DOCTYPE declaration.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author Thomas.Diesler at jboss.org
+ * @author Dimitris.Andreadis at jboss.org
+ * @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+public class JBossEntityResolver implements EntityResolver
+{
+ private static final Logger log = Logger.getLogger(JBossEntityResolver.class);
+
+ /** A class wide Map<String, String> of publicId/systemId to dtd/xsd file */
+ private static Map entities = new ConcurrentHashMap ();
+ /** A class flag indicating whether an attempt to resolve a systemID as a
+ non-file URL should produce a warning rather than a trace level log msg.
+ */
+ private static boolean warnOnNonFileURLs;
+
+ private boolean entityResolved = false;
+ /** Should system property refs in system ids be replaced */
+ private boolean replaceSystemProperties = true;
+
+ /** A local entities map that overrides the class level entities */
+ private Map localEntities;
+
+ static
+ {
+ AccessController.doPrivileged(new PrivilegedAction()
+ {
+ public Object run()
+ {
+ warnOnNonFileURLs = new Boolean(System.getProperty("org.jboss.resolver.warning", "false")).booleanValue();
+ return null;
+ }
+ });
+
+ // xml
+ registerEntity("-//W3C//DTD/XMLSCHEMA 200102//EN", "XMLSchema.dtd");
+ registerEntity("http://www.w3.org/2001/XMLSchema.dtd", "XMLSchema.dtd");
+ registerEntity("datatypes", "datatypes.dtd"); // This dtd doesn't have a publicId - see XMLSchema.dtd
+ registerEntity("http://www.w3.org/XML/1998/namespace", "xml.xsd");
+ registerEntity("http://www.w3.org/2001/xml.xsd", "xml.xsd");
+ registerEntity("http://www.w3.org/2005/05/xmlmime", "xml-media-types.xsd");
+
+ // Java EE common
+ registerEntity("http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd", "j2ee_1_4.xsd");
+ registerEntity("http://java.sun.com/xml/ns/javaee/javaee_5.xsd", "javaee_5.xsd");
+ // JBoss common
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss-common_5_1.xsd", "jboss-common_5_1.xsd");
+
+ // Java EE WS
+ registerEntity("http://schemas.xmlsoap.org/soap/encoding/", "soap-encoding_1_1.xsd");
+ registerEntity("http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd", "j2ee_web_services_client_1_1.xsd");
+ registerEntity("http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd", "j2ee_web_services_1_1.xsd");
+ registerEntity("http://www.ibm.com/webservices/xsd/j2ee_jaxrpc_mapping_1_1.xsd", "j2ee_jaxrpc_mapping_1_1.xsd");
+ registerEntity("http://java.sun.com/xml/ns/javaee/javaee_web_services_client_1_2.xsd", "javaee_web_services_client_1_2.xsd");
+
+ // ejb
+ registerEntity("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", "ejb-jar_1_1.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN", "ejb-jar_2_0.dtd");
+ registerEntity("http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd", "ejb-jar_2_1.xsd");
+ // ejb3
+ registerEntity("http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd", "ejb-jar_3_0.xsd");
+ // jboss ejb2
+ registerEntity("-//JBoss//DTD JBOSS//EN", "jboss.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 2.4//EN", "jboss_2_4.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 3.0//EN", "jboss_3_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 3.2//EN", "jboss_3_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 4.0//EN", "jboss_4_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 4.2//EN", "jboss_4_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 5.0//EN", "jboss_5_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 5.1.EAP//EN", "jboss_5_1_eap.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 6.0//EN", "jboss_6_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN", "jbosscmp-jdbc_3_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN", "jbosscmp-jdbc_3_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN", "jbosscmp-jdbc_4_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 4.2//EN", "jbosscmp-jdbc_4_2.dtd");
+ // jboss ejb3
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss_5_0.xsd", "jboss_5_0.xsd");
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss_5_1.xsd", "jboss_5_1.xsd");
+
+ // ear stuff
+ registerEntity("-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN", "application_1_2.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN", "application_1_3.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN", "application-client_1_3.dtd");
+ registerEntity("http://java.sun.com/xml/ns/j2ee/application_1_4.xsd", "application_1_4.xsd");
+ registerEntity("http://java.sun.com/xml/ns/javaee/application_5.xsd", "application_5.xsd");
+ // jboss-app
+ registerEntity("-//JBoss//DTD J2EE Application 1.3//EN", "jboss-app_3_0.dtd");
+ registerEntity("-//JBoss//DTD J2EE Application 1.3V2//EN", "jboss-app_3_2.dtd");
+ registerEntity("-//JBoss//DTD J2EE Application 1.4//EN", "jboss-app_4_0.dtd");
+ registerEntity("-//JBoss//DTD J2EE Application 4.2//EN", "jboss-app_4_2.dtd");
+ registerEntity("-//JBoss//DTD Java EE Application 5.0//EN", "jboss-app_5_0.dtd");
+
+ // connector descriptors
+ registerEntity("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN", "connector_1_0.dtd");
+ registerEntity("http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd", "connector_1_5.xsd");
+ registerEntity("http://java.sun.com/xml/ns/j2ee/connector_1_6.xsd", "connector_1_6.xsd");
+ // jboss-ds
+ registerEntity("-//JBoss//DTD JBOSS JCA Config 1.0//EN", "jboss-ds_1_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS JCA Config 1.5//EN", "jboss-ds_1_5.dtd");
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss-ds_5_0.xsd", "jboss-ds_5_0.xsd");
+ // jboss-ra
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss-ra_1_0.xsd", "jboss-ra_1_0.xsd");
+
+ // war meta-data
+ registerEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", "web-app_2_2.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", "web-app_2_3.dtd");
+ registerEntity("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd", "web-app_2_4.xsd");
+ registerEntity("http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd", "web-app_2_5.xsd");
+ // jboss-web
+ registerEntity("-//JBoss//DTD Web Application 2.2//EN", "jboss-web.dtd");
+ registerEntity("-//JBoss//DTD Web Application 2.3//EN", "jboss-web_3_0.dtd");
+ registerEntity("-//JBoss//DTD Web Application 2.3V2//EN", "jboss-web_3_2.dtd");
+ registerEntity("-//JBoss//DTD Web Application 2.4//EN", "jboss-web_4_0.dtd");
+ registerEntity("-//JBoss//DTD Web Application 4.2//EN", "jboss-web_4_2.dtd");
+ registerEntity("-//JBoss//DTD Web Application 5.0//EN", "jboss-web_5_0.dtd");
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd", "jboss-web_5_1.xsd");
+
+ // application client
+ registerEntity("http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd", "application-client_1_4.xsd");
+ registerEntity("http://java.sun.com/xml/ns/javaee/application-client_5.xsd", "application-client_5.xsd");
+ // jboss-client
+ registerEntity("-//JBoss//DTD Application Client 3.2//EN", "jboss-client_3_2.dtd");
+ registerEntity("-//JBoss//DTD Application Client 4.0//EN", "jboss-client_4_0.dtd");
+ registerEntity("-//JBoss//DTD Application Client 4.2//EN", "jboss-client_4_2.dtd");
+ registerEntity("-//JBoss//DTD Application Client 5.0//EN", "jboss-client_5_0.dtd");
+ registerEntity("http://www.jboss.org/j2ee/schema/jboss-client_5_1.xsd", "jboss-client_5_1.xsd");
+
+ // jboss-specific
+ registerEntity("-//JBoss//DTD Web Service Reference 4.0//EN", "service-ref_4_0.dtd");
+ registerEntity("-//JBoss//DTD Web Service Reference 4.2//EN", "service-ref_4_2.dtd");
+ registerEntity("-//JBoss//DTD Web Service Reference 5.0//EN", "service-ref_5_0.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 3.2//EN", "jboss-service_3_2.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 4.0//EN", "jboss-service_4_0.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 4.2//EN", "jboss-service_4_2.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 5.0//EN", "jboss-service_5_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS XMBEAN 1.0//EN", "jboss_xmbean_1_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS XMBEAN 1.1//EN", "jboss_xmbean_1_1.dtd");
+ registerEntity("-//JBoss//DTD JBOSS XMBEAN 1.2//EN", "jboss_xmbean_1_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSS Security Config 3.0//EN", "security_config.dtd");
+ registerEntity("http://www.jboss.org/j2ee/schema/security-config_4_0.xsd", "security-config_4_0.xsd");
+ registerEntity("urn:jboss:aop-deployer", "aop-deployer_1_1.xsd");
+ registerEntity("urn:jboss:aop-beans:1.0", "aop-beans_1_0.xsd");
+ registerEntity("urn:jboss:bean-deployer", "bean-deployer_1_0.xsd");
+ registerEntity("urn:jboss:bean-deployer:2.0", "bean-deployer_2_0.xsd");
+ registerEntity("urn:jboss:javabean:1.0", "javabean_1_0.xsd");
+ registerEntity("urn:jboss:javabean:2.0", "javabean_2_0.xsd");
+ registerEntity("urn:jboss:spring-beans:2.0", "mc-spring-beans_2_0.xsd");
+ registerEntity("urn:jboss:policy:1.0", "policy_1_0.xsd");
+ registerEntity("urn:jboss:osgi-beans:1.0", "osgi-beans_1_0.xsd");
+ registerEntity("urn:jboss:seam-components:1.0", "seam-components_1_0.xsd");
+ registerEntity("urn:jboss:security-config:4.1", "security-config_4_1.xsd");
+ registerEntity("urn:jboss:security-config:5.0", "security-config_5_0.xsd");
+ registerEntity("urn:jboss:jndi-binding-service:1.0", "jndi-binding-service_1_0.xsd");
+ registerEntity("urn:jboss:user-roles:1.0", "user-roles_1_0.xsd");
+ }
+
+ /**
+ Obtain a read-only view of the current entity map.
+
+ @return Map<String, String> of the publicID/systemID to dtd/schema file name
+ */
+ public static Map getEntityMap()
+ {
+ return Collections.unmodifiableMap(entities);
+ }
+
+ public static boolean isWarnOnNonFileURLs()
+ {
+ return warnOnNonFileURLs;
+ }
+
+ public static void setWarnOnNonFileURLs(boolean warnOnNonFileURLs)
+ {
+ JBossEntityResolver.warnOnNonFileURLs = warnOnNonFileURLs;
+ }
+
+ /**
+ * Register the mapping from the public id/system id to the dtd/xsd file
+ * name. This overwrites any existing mapping.
+ *
+ * @param id the DOCTYPE public id or system id such as
+ * "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"
+ * @param dtdFileName the simple dtd/xsd file name, "ejb-jar.dtd"
+ */
+ public static void registerEntity(String id, String dtdFileName)
+ {
+ entities.put(id, dtdFileName);
+ }
+
+
+ public boolean isReplaceSystemProperties()
+ {
+ return replaceSystemProperties;
+ }
+ public void setReplaceSystemProperties(boolean replaceSystemProperties)
+ {
+ this.replaceSystemProperties = replaceSystemProperties;
+ }
+
+ /**
+ * Register the mapping from the public id/system id to the dtd/xsd file
+ * name. This overwrites any existing mapping.
+ *
+ * @param id the DOCTYPE public id or system id such as
+ * "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"
+ * @param dtdOrSchema the simple dtd/xsd file name, "ejb-jar.dtd"
+ */
+ public synchronized void registerLocalEntity(String id, String dtdOrSchema)
+ {
+ if( localEntities == null )
+ localEntities = new ConcurrentHashMap();
+ localEntities.put(id, dtdOrSchema);
+ }
+
+ /**
+ Returns DTD/Schema inputSource. The resolution logic is:
+
+ 1. Check the publicId against the current registered values in the class
+ mapping of entity name to dtd/schema file name. If found, the resulting
+ file name is passed to the loadClasspathResource to locate the file as a
+ classpath resource.
+
+ 2. Check the systemId against the current registered values in the class
+ mapping of entity name to dtd/schema file name. If found, the resulting
+ file name is passed to the loadClasspathResource to locate the file as a
+ classpath resource.
+
+ 3. Strip the systemId name down to the simple file name by removing an URL
+ style path elements (myschemas/x.dtd becomes x.dtd), and call
+ loadClasspathResource to locate the simple file name as a classpath resource.
+
+ 4. Attempt to resolve the systemId as a URL from which the schema can be
+ read. If the URL input stream can be opened this returned as the resolved
+ input.
+
+ @param publicId - Public ID of DTD, or null if it is a schema
+ @param systemId - the system ID of DTD or Schema
+ @return InputSource of entity
+ */
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
+ {
+ entityResolved = false;
+
+ // nothing to resolve
+ if( publicId == null && systemId == null )
+ return null;
+
+ boolean trace = log.isTraceEnabled();
+
+ boolean resolvePublicIdFirst = true;
+ if(publicId != null && systemId != null)
+ {
+ String registeredSystemId = null;
+ if(localEntities != null)
+ registeredSystemId = (String) localEntities.get(publicId);
+ if(registeredSystemId == null)
+ registeredSystemId = (String) entities.get(publicId);
+
+ if(registeredSystemId != null && !registeredSystemId.equals(systemId))
+ {
+ resolvePublicIdFirst = false;
+ if(trace)
+ log.trace("systemId argument '" + systemId + "' for publicId '" +
+ publicId + "' is different from the registered systemId '" +
+ registeredSystemId + "', resolution will be based on the argument");
+ }
+ }
+
+ InputSource inputSource = null;
+
+ if(resolvePublicIdFirst)
+ {
+ // Look for a registered publicID
+ inputSource = resolvePublicID(publicId, trace);
+ }
+
+ if( inputSource == null )
+ {
+ // Try to resolve the systemID from the registry
+ inputSource = resolveSystemID(systemId, trace);
+ }
+
+ if( inputSource == null )
+ {
+ // Try to resolve the systemID as a classpath reference under dtd or schema
+ inputSource = resolveClasspathName(systemId, trace);
+ }
+
+ if( inputSource == null )
+ {
+ // Try to resolve the systemID as a absolute URL
+ inputSource = resolveSystemIDasURL(systemId, trace);
+ }
+
+ entityResolved = (inputSource != null);
+
+ if (entityResolved == false)
+ log.debug("Cannot resolve [publicID=" + publicId + ",systemID=" + systemId + "]");
+
+ return inputSource;
+ }
+
+ /**
+ * Returns the boolean value to inform id DTD was found in the XML file or not
+ *
+ * @todo this is not thread safe and should be removed?
+ *
+ * @return boolean - true if DTD was found in XML
+ */
+ public boolean isEntityResolved()
+ {
+ return entityResolved;
+ }
+
+ /**
+ Load the schema from the class entity to schema file mapping.
+ @see #registerEntity(String, String)
+
+ @param publicId - the public entity name of the schema
+ @param trace - trace level logging flag
+ @return the InputSource for the schema file found on the classpath, null
+ if the publicId is not registered or found.
+ */
+ protected InputSource resolvePublicID(String publicId, boolean trace)
+ {
+ if( publicId == null )
+ return null;
+
+ if (trace)
+ log.trace("resolvePublicID, publicId=" + publicId);
+
+ InputSource inputSource = null;
+
+ String filename = null;
+ if( localEntities != null )
+ filename = (String) localEntities.get(publicId);
+ if( filename == null )
+ filename = (String) entities.get(publicId);
+
+ if( filename != null )
+ {
+ if (trace)
+ log.trace("Found entity from publicId=" + publicId + " fileName=" + filename);
+
+ InputStream ins = loadClasspathResource(filename, trace);
+ if( ins != null )
+ {
+ inputSource = new InputSource(ins);
+ inputSource.setPublicId(publicId);
+ }
+ else
+ {
+ log.trace("Cannot load publicId from classpath resource: " + filename);
+
+ // Try the file name as a URI
+ inputSource = resolveSystemIDasURL(filename, trace);
+
+ if (inputSource == null)
+ log.warn("Cannot load publicId from resource: " + filename);
+ }
+ }
+
+ return inputSource;
+ }
+
+ /**
+ Attempt to use the systemId as a URL from which the schema can be read. This
+ checks to see whether the systemId is a key to an entry in the class
+ entity map.
+
+ @param systemId - the systemId
+ @param trace - trace level logging flag
+ @return the URL InputSource if the URL input stream can be opened, null
+ if the systemId is not a URL or could not be opened.
+ */
+ protected InputSource resolveSystemID(String systemId, boolean trace)
+ {
+ if( systemId == null )
+ return null;
+
+ if( trace )
+ log.trace("resolveSystemID, systemId="+systemId);
+
+ InputSource inputSource = null;
+
+ // Try to resolve the systemId as an entity key
+ String filename = null;
+ if( localEntities != null )
+ filename = (String) localEntities.get(systemId);
+ if( filename == null )
+ filename = (String) entities.get(systemId);
+
+ if ( filename != null )
+ {
+ if( trace )
+ log.trace("Found entity systemId=" + systemId + " fileName=" + filename);
+
+ InputStream ins = loadClasspathResource(filename, trace);
+ if( ins != null )
+ {
+ inputSource = new InputSource(ins);
+ inputSource.setSystemId(systemId);
+ }
+ else
+ {
+ log.warn("Cannot load systemId from resource: " + filename);
+ }
+ }
+
+ return inputSource;
+ }
+
+ /**
+ Attempt to use the systemId as a URL from which the schema can be read. This
+ uses the systemID as a URL.
+
+ @param systemId - the systemId
+ @param trace - trace level logging flag
+ @return the URL InputSource if the URL input stream can be opened, null
+ if the systemId is not a URL or could not be opened.
+ */
+ protected InputSource resolveSystemIDasURL(String systemId, boolean trace)
+ {
+ if( systemId == null )
+ return null;
+
+ if( trace )
+ log.trace("resolveSystemIDasURL, systemId="+systemId);
+
+ InputSource inputSource = null;
+
+ // Try to use the systemId as a URL to the schema
+ try
+ {
+ if (trace)
+ log.trace("Trying to resolve systemId as a URL");
+ // Replace any system property refs if isReplaceSystemProperties is true
+ if(isReplaceSystemProperties())
+ systemId = StringPropertyReplacer.replaceProperties(systemId);
+ URL url = new URL(systemId);
+ if (warnOnNonFileURLs && url.getProtocol().equalsIgnoreCase("file") == false)
+ {
+ log.warn("Trying to resolve systemId as a non-file URL: " + systemId);
+ }
+
+ InputStream ins = url.openStream();
+ if (ins != null)
+ {
+ inputSource = new InputSource(ins);
+ inputSource.setSystemId(systemId);
+ }
+ else
+ {
+ log.warn("Cannot load systemId as URL: " + systemId);
+ }
+
+ if (trace)
+ log.trace("Resolved systemId as a URL");
+ }
+ catch (MalformedURLException ignored)
+ {
+ if (trace)
+ log.trace("SystemId is not a url: " + systemId, ignored);
+ }
+ catch (IOException e)
+ {
+ if (trace)
+ log.trace("Failed to obtain URL.InputStream from systemId: " + systemId, e);
+ }
+ return inputSource;
+ }
+
+ /**
+ Resolve the systemId as a classpath resource. If not found, the
+ systemId is simply used as a classpath resource name.
+
+ @param systemId - the system ID of DTD or Schema
+ @param trace - trace level logging flag
+ @return the InputSource for the schema file found on the classpath, null
+ if the systemId is not registered or found.
+ */
+ protected InputSource resolveClasspathName(String systemId, boolean trace)
+ {
+ if( systemId == null )
+ return null;
+
+ if( trace )
+ log.trace("resolveClasspathName, systemId="+systemId);
+ String filename = systemId;
+ // Parse the systemId as a uri to get the final path component
+ try
+ {
+ URI url = new URI(systemId);
+ String path = url.getPath();
+ if( path == null )
+ path = url.getSchemeSpecificPart();
+ int slash = path.lastIndexOf('/');
+ if( slash >= 0 )
+ filename = path.substring(slash + 1);
+ else
+ filename = path;
+
+ if(filename.length() == 0)
+ return null;
+
+ if (trace)
+ log.trace("Mapped systemId to filename: " + filename);
+ }
+ catch (URISyntaxException e)
+ {
+ if (trace)
+ log.trace("systemId: is not a URI, using systemId as resource", e);
+ }
+
+ // Resolve the filename as a classpath resource
+ InputStream is = loadClasspathResource(filename, trace);
+ InputSource inputSource = null;
+ if( is != null )
+ {
+ inputSource = new InputSource(is);
+ inputSource.setSystemId(systemId);
+ }
+ return inputSource;
+ }
+
+ /**
+ Look for the resource name on the thread context loader resource path. This
+ first simply tries the resource name as is, and if not found, the resource
+ is prepended with either "dtd/" or "schema/" depending on whether the
+ resource ends in ".dtd" or ".xsd".
+
+ @param resource - the classpath resource name of the schema
+ @param trace - trace level logging flag
+ @return the resource InputStream if found, null if not found.
+ */
+ protected InputStream loadClasspathResource(String resource, boolean trace)
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL url = loader.getResource(resource);
+ if( url == null )
+ {
+ /* Prefix the simple filename with the schema type patch as this is the
+ naming convention for the jboss bundled schemas.
+ */
+ if( resource.endsWith(".dtd") )
+ resource = "dtd/" + resource;
+ else if( resource.endsWith(".xsd") )
+ resource = "schema/" + resource;
+ url = loader.getResource(resource);
+ }
+
+ InputStream inputStream = null;
+ if( url != null )
+ {
+ if( trace )
+ log.trace(resource+" maps to URL: "+url);
+ try
+ {
+ inputStream = url.openStream();
+ }
+ catch(IOException e)
+ {
+ log.debug("Failed to open url stream", e);
+ }
+ }
+ return inputStream;
+ }
+
+}
Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/picketbox/plugins/vault/PicketBoxSecurityVault.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/picketbox/plugins/vault/PicketBoxSecurityVault.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/picketbox/plugins/vault/PicketBoxSecurityVault.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -49,7 +49,7 @@
import org.jboss.security.plugins.PBEUtils;
import org.jboss.security.vault.SecurityVault;
import org.jboss.security.vault.SecurityVaultException;
-import org.jboss.util.Base64;
+import org.picketbox.commons.cipher.Base64;
import org.picketbox.util.EncryptionUtil;
import org.picketbox.util.KeyStoreUtil;
import org.picketbox.util.StringUtil;
Deleted: trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/TstTimedCache.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/TstTimedCache.java 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/TstTimedCache.java 2011-09-20 20:39:20 UTC (rev 254)
@@ -1,107 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test;
-
-import org.jboss.util.TimedCachePolicy;
-
-/** Tests of the TimedCachePolicy class.
-
- at see org.jboss.util.TimedCachePolicy
-
- at author Scott.Stark at jboss.org
- at version $Revision$
-*/
-public class TstTimedCache
-{
- static class Refreshable implements TimedCachePolicy.TimedEntry
- {
- int refreshes;
- long expirationTime;
- Object value;
- Refreshable(long lifetime, Object value, int refreshes)
- {
- this.expirationTime = 1000 * lifetime;
- this.value = value;
- this.refreshes = refreshes;
- }
- public void init(long now)
- {
- expirationTime += now;
- System.out.println(value+".init("+now+"), expirationTime="+expirationTime);
- }
- public boolean isCurrent(long now)
- {
- System.out.println(value+".isCurrent("+now+") = "+(expirationTime > now));
- return expirationTime > now;
- }
- public boolean refresh()
- {
- refreshes --;
- System.out.println(value+".refresh() = "+(refreshes > 0));
- return refreshes > 0;
- }
- public void destroy()
- {
- System.out.println(value+".destroy()");
- }
- public Object getValue()
- {
- return value;
- }
- }
-
- /**
- * @param args the command line arguments
- */
- public static void main(String args[])
- {
- TimedCachePolicy cache = new TimedCachePolicy(20, false, 1);
- cache.create();
- cache.start();
- cache.insert("1", new Refreshable(5, "value1", 4));
- cache.insert("2", new Refreshable(3, "value2", 10));
- cache.insert("3", "value3");
- long start = System.currentTimeMillis();
- // Loop until the longest lived value is gone
- while( cache.peek("2") != null )
- {
- long now = System.currentTimeMillis();
- System.out.println("Elapsed: "+(now - start) / 1000);
- System.out.println("get(1) -> "+cache.get("1"));
- System.out.println("get(2) -> "+cache.get("2"));
- System.out.println("get(3) -> "+cache.get("3"));
- try
- {
- Thread.sleep(3*1000);
- }
- catch(InterruptedException e)
- {
- }
- }
- long now = System.currentTimeMillis();
- System.out.println("End, elapsed: "+(now - start) / 1000);
- System.out.println("get(1) -> "+cache.get("1"));
- System.out.println("get(2) -> "+cache.get("2"));
- System.out.println("get(3) -> "+cache.get("3"));
- }
-
-}
Modified: trunk/security-jboss-sx/parent/pom.xml
===================================================================
--- trunk/security-jboss-sx/parent/pom.xml 2011-08-25 02:23:39 UTC (rev 253)
+++ trunk/security-jboss-sx/parent/pom.xml 2011-09-20 20:39:20 UTC (rev 254)
@@ -99,9 +99,9 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.jboss.javaee</groupId>
- <artifactId>jboss-jacc-api</artifactId>
- <version>1.1.0.${org.jboss.javaee.version}</version>
+ <groupId>org.jboss.spec.javax.security.jacc</groupId>
+ <artifactId>jboss-jacc-api_1.4_spec</artifactId>
+ <version>1.0.1.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
More information about the jboss-cvs-commits
mailing list