use of javax.jcr.Credentials in project sling by apache.
the class AuthenticationInfoTest method testGetCredentials.
@Test
public void testGetCredentials() {
final AuthenticationInfo info = new AuthenticationInfo("test");
assertNull(info.get(CREDENTIALS));
assertFalse(info.containsKey(CREDENTIALS));
final Credentials creds = new SimpleCredentials("user", new char[0]);
info.put(CREDENTIALS, creds);
assertSame(creds, info.get(CREDENTIALS));
final String user = "user";
final char[] pwd = new char[5];
final AuthenticationInfo infoCred = new AuthenticationInfo("TEST", user, pwd);
// credentials not stored in the object
assertFalse(infoCred.containsKey(CREDENTIALS));
}
use of javax.jcr.Credentials in project sling by apache.
the class AuthenticationInfoTest method testSetCredentials.
@Test
public void testSetCredentials() {
final Credentials creds = new SimpleCredentials("user", new char[0]);
final AuthenticationInfo info = new AuthenticationInfo("test");
info.put(CREDENTIALS, creds);
Assert.assertSame(creds, info.get(CREDENTIALS));
}
use of javax.jcr.Credentials in project sling by apache.
the class SystemUsersTest method assertSystemUser.
private void assertSystemUser(String name) throws RepositoryException {
final SlingRepository repo = teleporter.getService(SlingRepository.class);
final Session s = repo.loginAdministrative(null);
try {
final Credentials creds = new SimpleCredentials(name, new char[] {});
try {
s.impersonate(creds);
} catch (RepositoryException rex) {
fail("Impersonation as " + name + " failed: " + rex.toString());
}
} finally {
s.logout();
}
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class DefaultLoginModule method commit.
//--------------------------------------------------------< LoginModule >---
/**
* @see javax.security.auth.spi.LoginModule#commit()
*/
@Override
public boolean commit() throws LoginException {
boolean success = super.commit();
if (success && !disableTokenAuth) {
if (TokenBasedAuthentication.doCreateToken(credentials)) {
Session s = null;
try {
/*
use a different session instance to create the token
node in order to prevent concurrent modifications with
the shared system session.
*/
s = session.createSession(session.getWorkspace().getName());
Credentials tc = TokenBasedAuthentication.createToken(user, credentials, tokenExpiration, s);
if (tc != null) {
subject.getPublicCredentials().add(tc);
}
} catch (RepositoryException e) {
LoginException le = new LoginException("Failed to commit: " + e.getMessage());
le.initCause(e);
throw le;
} finally {
if (s != null) {
s.logout();
}
}
} else if (tokenCredentials != null) {
subject.getPublicCredentials().add(tokenCredentials);
}
}
return success;
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class GarbageCollectorTest method testTransientObjects.
public void testTransientObjects() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
deleteMyNodes();
Credentials cred = getHelper().getSuperuserCredentials();
Session s2 = getHelper().getRepository().login(cred);
root = s2.getRootNode();
Node node2 = root.addNode("node3");
Node n = node2.addNode("nodeWithBlob");
ValueFactory vf = session.getValueFactory();
n.setProperty("test", vf.createBinary(new RandomInputStream(10, 1000)));
runGC(session, false);
s2.save();
InputStream in = n.getProperty("test").getBinary().getStream();
InputStream in2 = new RandomInputStream(10, 1000);
verifyInputStream(in, in2);
deleteMyNodes();
s2.logout();
}
Aggregations