use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class SessionImplTest method testSessionAttributes.
/**
* JCR-1932: Session.getAttributes( ) call always returns an empty array
*
* @see <a href="https://issues.apache.org/jira/browse/JCR-1932">JCR-1932</a>
*/
public void testSessionAttributes() throws RepositoryException {
SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
credentials.setAttribute("test", "attribute");
Session session = getHelper().getRepository().login(credentials);
try {
String[] names = session.getAttributeNames();
assertEquals(1, names.length);
assertEquals("test", names[0]);
assertEquals("attribute", session.getAttribute("test"));
} finally {
session.logout();
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class SimpleBench method test.
void test(int run) throws Exception {
this.run = run;
new File("target/jcr.log").delete();
FileUtils.deleteQuietly(new File("repository"));
start();
repository = new TransientRepository();
Session session = repository.login(new SimpleCredentials("", "".toCharArray()));
if (session.getRootNode().hasNode("test")) {
session.getRootNode().getNode("test").remove();
session.save();
}
session.getRootNode().addNode("test");
session.save();
end("init");
Node node = session.getRootNode().getNode("test");
Node n = null;
int len = run == 0 ? 100 : 1000;
start();
for (int i = 0; i < len; i++) {
if (i % 100 == 0) {
n = node.addNode("sub" + i);
}
Node x = n.addNode("x" + (i % 100));
x.setProperty("name", "John");
x.setProperty("firstName", "Doe");
session.save();
}
end("addNodes");
session.logout();
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class TokenBasedAuthenticationTest method testDoCreateToken.
public void testDoCreateToken() {
assertFalse(TokenBasedAuthentication.doCreateToken(creds));
assertFalse(TokenBasedAuthentication.doCreateToken(simpleCreds));
assertFalse(TokenBasedAuthentication.doCreateToken(tokenCreds));
SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, null);
assertFalse(TokenBasedAuthentication.doCreateToken(sc));
sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "somevalue");
assertFalse(TokenBasedAuthentication.doCreateToken(sc));
sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
assertTrue(TokenBasedAuthentication.doCreateToken(sc));
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class TokenBasedLoginTest method testConcurrentLoginOfDifferentUsers.
/**
* Tests concurrent login of 3 different users on the Repository including
* token creation.
* Test copied and slightly adjusted from org.apache.jackrabbit.core.ConcurrentLoginTest
*/
public void testConcurrentLoginOfDifferentUsers() throws RepositoryException, NotExecutableException {
final Exception[] exception = new Exception[1];
List<Thread> testRunner = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
testRunner.add(new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 100; i++) {
try {
SimpleCredentials c;
double rand = 3 * Math.random();
int index = (int) Math.floor(rand);
switch(index) {
case 0:
c = new SimpleCredentials(testuser.getID(), testuser.getID().toCharArray());
break;
case 1:
c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_PWD).toCharArray());
break;
default:
c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_PWD).toCharArray());
break;
}
c.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
Session s = getHelper().getRepository().login(c);
try {
Set<TokenCredentials> tcs = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
assertFalse(tcs.isEmpty());
} finally {
s.logout();
}
} catch (Exception e) {
exception[0] = e;
break;
}
}
}
}));
}
// start threads
for (Object aTestRunner : testRunner) {
((Thread) aTestRunner).start();
}
// join threads
for (Object aTestRunner : testRunner) {
try {
((Thread) aTestRunner).join();
} catch (InterruptedException e) {
fail(e.toString());
}
}
if (exception[0] != null) {
fail(exception[0].toString());
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class TokenProviderTest method testCreateTokenIsCaseInsensitive.
public void testCreateTokenIsCaseInsensitive() throws Exception {
String upperCaseUserId = userId.toUpperCase();
TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(upperCaseUserId, new char[0]));
assertTokenInfo(info);
}
Aggregations