You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/06/05 13:11:56 UTC
svn commit: r1600601 -
/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy
Author: chetanm
Date: Thu Jun 5 11:11:56 2014
New Revision: 1600601
URL: http://svn.apache.org/r1600601
Log:
OAK-1522 - Provide PojoSR based RepositoryFactory implementation
Updated logic which copies the created token in commit
Modified:
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy
Modified: jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy?rev=1600601&r1=1600600&r2=1600601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy (original)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy Thu Jun 5 11:11:56 2014
@@ -51,14 +51,14 @@ class TokenAuthenticationTest extends Ab
registry.registerService(LoginModuleFactory.class.name, new PreAuthLoginModuleFactory(), [
'jaas.controlFlag' : 'sufficient',
'jaas.realmName' : 'jackrabbit.oak',
- 'jaas.ranking' : '250',
+ 'jaas.ranking' : '150',
] as Hashtable)
MyCredential myCred = new MyCredential("admin")
Session session = repository.login(myCred)
// assert session.getAttribute(".token")
- assert myCred.credentials.getAttribute(".token")
+ assert myCred.getAttribute(".token")
}
private static class PreAuthLoginModuleFactory implements LoginModuleFactory {
@@ -70,7 +70,7 @@ class TokenAuthenticationTest extends Ab
@Slf4j
private static class PreAuthLoginModule extends AbstractLoginModule {
-
+ private MyCredential credential
@Override
protected Set<Class> getSupportedCredentials() {
return Sets.newHashSet(MyCredential.class)
@@ -80,19 +80,19 @@ class TokenAuthenticationTest extends Ab
boolean login() throws LoginException {
Credentials credentials = getCredentials();
if (credentials instanceof MyCredential) {
- String userId = ((MyCredential) credentials).userID;
+ credential = ((MyCredential) credentials)
+ String userId = credential.userID;
if (userId == null) {
log.debug("Could not extract userId/credentials");
} else {
SimpleCredentials sc = new SimpleCredentials(userId, new char[0])
sc.setAttribute(".token","")
+
// we just set the login name and rely on the following login modules to populate the subject
sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin(userId));
sharedState.put(SHARED_KEY_CREDENTIALS, sc);
sharedState.put(SHARED_KEY_LOGIN_NAME, userId);
log.debug("login succeeded with trusted user: {}", userId);
-
- ((MyCredential) credentials).credentials = sc
}
}
return false;
@@ -100,18 +100,44 @@ class TokenAuthenticationTest extends Ab
@Override
boolean commit() throws LoginException {
+ Credentials sharedCreds = getSharedCredentials()
+ if(sharedCreds instanceof SimpleCredentials) {
+ credential.setAttribute(".token", ((SimpleCredentials)sharedCreds).getAttribute(".token"))
+ }
return false
}
}
private static class MyCredential implements Credentials {
final String userID
- def SimpleCredentials credentials
+ private final HashMap attributes = new HashMap();
MyCredential(String userID) {
this.userID = userID
}
+ public void setAttribute(String name, Object value) {
+ // name cannot be null
+ if (name == null) {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+
+ // null value is the same as removeAttribute()
+ if (value == null) {
+ removeAttribute(name);
+ return;
+ }
+
+ synchronized (attributes) {
+ attributes.put(name, value);
+ }
+ }
+
+ public Object getAttribute(String name) {
+ synchronized (attributes) {
+ return (attributes.get(name));
+ }
+ }
}
}