use of javax.jcr.Credentials in project jackrabbit by apache.
the class GroupAdministratorTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// create a first user
Principal p = getTestPrincipal();
UserImpl pUser = (UserImpl) userMgr.createUser(p.getName(), buildPassword(p));
save(superuser);
otherUID = pUser.getID();
// create a second user and make it group-admin
p = getTestPrincipal();
String pw = buildPassword(p);
Credentials creds = buildCredentials(p.getName(), pw);
User user = userMgr.createUser(p.getName(), pw);
save(superuser);
uID = user.getID();
// make other user a group-administrator:
Authorizable grAdmin = userMgr.getAuthorizable(UserConstants.GROUP_ADMIN_GROUP_NAME);
if (grAdmin == null || !grAdmin.isGroup()) {
throw new NotExecutableException("Cannot execute test. No group-administrator group found.");
}
groupAdmin = (Group) grAdmin;
groupAdmin.addMember(user);
save(superuser);
grID = groupAdmin.getID();
// create a session for the group-admin user.
uSession = getHelper().getRepository().login(creds);
groupsPath = (userMgr instanceof UserManagerImpl) ? ((UserManagerImpl) userMgr).getGroupsPath() : UserConstants.GROUPS_PATH;
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class BasicCredentialsProviderTest method testEmptyDefaultHeader.
public void testEmptyDefaultHeader() throws ServletException, LoginException {
CredentialsProvider cb = new BasicCredentialsProvider(BasicCredentialsProvider.EMPTY_DEFAULT_HEADER_VALUE);
Credentials creds = cb.getCredentials(new RequestImpl(null));
assertNull(creds);
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class BasicCredentialsProviderTest method testGuestCredentialsDefaultHeader.
public void testGuestCredentialsDefaultHeader() throws ServletException, LoginException {
CredentialsProvider cb = new BasicCredentialsProvider(BasicCredentialsProvider.GUEST_DEFAULT_HEADER_VALUE);
Credentials creds = cb.getCredentials(new RequestImpl(null));
assertTrue(creds instanceof GuestCredentials);
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class TokenLoginModule method commit.
@Override
public boolean commit() throws LoginException {
if (tokenCredentials != null && userId != null) {
Set<? extends Principal> principals = (principal != null) ? getPrincipals(principal) : getPrincipals(userId);
updateSubject(tokenCredentials, getAuthInfo(tokenInfo, principals), principals);
return true;
}
try {
if (tokenProvider != null && sharedState.containsKey(SHARED_KEY_CREDENTIALS)) {
Credentials shared = getSharedCredentials();
if (shared != null && tokenProvider.doCreateToken(shared)) {
Root r = getRoot();
if (r != null) {
// refresh root, in case the external login module created users
r.refresh();
}
TokenInfo ti = tokenProvider.createToken(shared);
if (ti != null) {
TokenCredentials tc = new TokenCredentials(ti.getToken());
Map<String, String> attributes = ti.getPrivateAttributes();
for (String name : attributes.keySet()) {
tc.setAttribute(name, attributes.get(name));
}
attributes = ti.getPublicAttributes();
for (String name : attributes.keySet()) {
tc.setAttribute(name, attributes.get(name));
}
sharedState.put(SHARED_KEY_ATTRIBUTES, attributes);
updateSubject(tc, null, null);
} else {
// failed to create token -> fail commit()
Object logId = (userId != null) ? userId : sharedState.get(SHARED_KEY_LOGIN_NAME);
log.debug("TokenProvider failed to create a login token for user " + logId);
throw new LoginException("Failed to create login token for user " + logId);
}
}
}
} finally {
// the login attempt on this module did not succeed: clear state
clearState();
}
return false;
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class LoginModuleImpl method getLoginId.
//--------------------------------------------------------------------------
@CheckForNull
private String getLoginId(@CheckForNull PreAuthenticatedLogin preAuthenticatedLogin) {
if (preAuthenticatedLogin != null) {
return preAuthenticatedLogin.getUserId();
}
String uid = null;
if (credentials != null) {
if (credentials instanceof SimpleCredentials) {
uid = ((SimpleCredentials) credentials).getUserID();
} else if (credentials instanceof GuestCredentials) {
uid = getAnonymousId();
} else if (credentials instanceof ImpersonationCredentials) {
Credentials bc = ((ImpersonationCredentials) credentials).getBaseCredentials();
if (bc instanceof SimpleCredentials) {
uid = ((SimpleCredentials) bc).getUserID();
}
} else {
try {
NameCallback callback = new NameCallback("User-ID: ");
callbackHandler.handle(new Callback[] { callback });
uid = callback.getName();
} catch (UnsupportedCallbackException e) {
log.warn("Credentials- or NameCallback must be supported");
} catch (IOException e) {
log.error("Name-Callback failed: " + e.getMessage());
}
}
}
if (uid == null) {
uid = getSharedLoginName();
}
return uid;
}
Aggregations