use of javax.jcr.Credentials in project jackrabbit by apache.
the class SessionProviderImpl method getSession.
/**
* {@inheritDoc }
*/
public Session getSession(HttpServletRequest request, Repository repository, String workspace) throws LoginException, RepositoryException, ServletException {
Session s = null;
// JCR-3222: Check if a custom session provider is available as a
// request attribute. If one is available, ask it first for a session.
Object object = request.getAttribute(SessionProvider.class.getName());
if (object instanceof SessionProvider) {
SessionProvider provider = (SessionProvider) object;
s = provider.getSession(request, repository, workspace);
if (s != null) {
externalSessions.put(s, provider);
}
}
if (s == null) {
Credentials creds = cp.getCredentials(request);
if (creds == null) {
s = repository.login(workspace);
} else {
s = repository.login(creds, workspace);
}
}
return s;
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class Login method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String anon = "anonymous";
String user = (String) ctx.get(this.userKey);
String password = (String) ctx.get(this.passwordKey);
String workspace = (String) ctx.get(this.workspaceKey);
if (user == null) {
user = anon;
}
if (password == null || (password.equals(anon) && !user.equals(anon))) {
ConsoleReader reader = new ConsoleReader();
password = reader.readLine("Password: ", (char) 0);
}
if (log.isDebugEnabled()) {
log.debug("logging in as " + user);
}
Session session = null;
Repository repo = CommandHelper.getRepository(ctx);
Credentials credentials = new SimpleCredentials(user, password.toCharArray());
if (workspace == null) {
session = repo.login(credentials);
} else {
session = repo.login(credentials, workspace);
}
CommandHelper.setSession(ctx, session);
CommandHelper.setCurrentNode(ctx, session.getRootNode());
return false;
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class CustomCredentialsSupportTest method testLoginWithUnsupportedCredentials.
@Test
public void testLoginWithUnsupportedCredentials() throws Exception {
List<Credentials> creds = ImmutableList.of(new SimpleCredentials("testUser", new char[0]), new GuestCredentials());
for (Credentials c : creds) {
try {
login(c).close();
fail("login must fail for credentials " + c);
} catch (LoginException e) {
// success
}
}
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class TokenExternalLoginModuleTest method testTokenCreation.
@Test
public void testTokenCreation() throws Exception {
Credentials creds = createTestCredentials();
assertTrue(credentialsSupport.setAttributes(creds, ImmutableMap.<String, Object>of(".token", "")));
String expectedUserId = credentialsSupport.getUserId(creds);
ContentSession cs = login(creds);
try {
assertEquals(expectedUserId, cs.getAuthInfo().getUserID());
Map<String, ?> attributes = credentialsSupport.getAttributes(creds);
String token = attributes.get(".token").toString();
assertFalse(token.isEmpty());
root.refresh();
User user = getUserManager(root).getAuthorizable(expectedUserId, User.class);
Tree tokenParent = root.getTree(user.getPath()).getChild(".tokens");
assertTrue(tokenParent.exists());
assertEquals(1, tokenParent.getChildrenCount(100));
} finally {
cs.close();
}
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class AbstractRepositoryTest method testLoginWithCredentials.
/**
* Tests the {@link AbstractRepository#login(Credentials)} method.
*
* @throws RepositoryException if an error occurs
*/
public void testLoginWithCredentials() throws RepositoryException {
Credentials credentials = new SimpleCredentials("", "".toCharArray());
Repository repository = (Repository) record(AbstractRepository.class);
repository.login(credentials, null);
replay();
repository.login(credentials);
verify();
}
Aggregations