### Eclipse Workspace Patch 1.0 #P oak-core Index: src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java (revision 1584342) +++ src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java (working copy) @@ -23,6 +23,11 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + import javax.jcr.AccessDeniedException; import javax.jcr.Credentials; import javax.jcr.GuestCredentials; @@ -30,11 +35,14 @@ import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials; +import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager; import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials; +import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration; import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo; import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider; import org.apache.jackrabbit.oak.util.NodeUtil; @@ -330,4 +338,66 @@ tree.setProperty(tokenTree.getProperty("rep:token.key")); tree.setProperty(tokenTree.getProperty("rep:token.exp")); } + + + @Test + public void testValidTokenCredentialsWithConflict() throws Exception { + ExecutorService pool = Executors.newFixedThreadPool(10); + List sessions = new ArrayList(); + + try { + TokenConfiguration tc = getSecurityProvider().getConfiguration( + TokenConfiguration.class); + SimpleCredentials sc = (SimpleCredentials) getAdminCredentials(); + + List tokenProviders = new ArrayList(); + + for (int i = 0; i < 10; i++) { + ContentSession session = login(getAdminCredentials()); + Root r = session.getLatestRoot(); + tokenProviders.add(tc.getTokenProvider(r)); + sessions.add(session); + } + + ArrayList list = new ArrayList(); + + for (TokenProvider tokenProvider : tokenProviders) { + list.add(createDataFuture(pool, tokenProvider, sc.getUserID(), + Collections. emptyMap())); + } + + for (DataFuture df : list) { + assertNotNull(df.future.get()); + } + } finally { + for (ContentSession session : sessions) { + if (session != null) { + session.close(); + } + } + + if (pool != null) { + pool.shutdown(); + } + } + } + + private static class DataFuture { + public Future future; + + public DataFuture(Future future) { + super(); + this.future = future; + } + } + + private DataFuture createDataFuture(ExecutorService pool , final TokenProvider tp,final String userId, final Map attributes){ + Future future = pool.submit(new Callable() { + @Override + public TokenInfo call() throws Exception { + return tp.createToken(userId, attributes); + } + }); + return new DataFuture(future); + } } \ No newline at end of file