use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class OpenAuthenticationConfiguration method getLoginContextProvider.
@Nonnull
@Override
public LoginContextProvider getLoginContextProvider(ContentRepository contentRepository) {
return new LoginContextProvider() {
@Nonnull
@Override
public LoginContext getLoginContext(final Credentials credentials, String workspaceName) {
return new LoginContext() {
@Override
public Subject getSubject() {
Subject subject = new Subject();
if (credentials != null) {
subject.getPrivateCredentials().add(credentials);
}
subject.setReadOnly();
return subject;
}
@Override
public void login() {
// do nothing
}
@Override
public void logout() {
// do nothing
}
};
}
};
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class AbstractLoginModule method getCredentials.
/**
* Tries to retrieve valid (supported) Credentials:
* <ol>
* <li>using a {@link CredentialsCallback},</li>
* <li>looking for a {@link #SHARED_KEY_CREDENTIALS} entry in the
* shared state (see also {@link #getSharedCredentials()} and finally by</li>
* <li>searching for valid credentials in the subject.</li>
* </ol>
*
* @return Valid (supported) credentials or {@code null}.
*/
@CheckForNull
protected Credentials getCredentials() {
Set<Class> supported = getSupportedCredentials();
if (callbackHandler != null) {
log.debug("Login: retrieving Credentials using callback.");
try {
CredentialsCallback callback = new CredentialsCallback();
callbackHandler.handle(new Callback[] { callback });
Credentials creds = callback.getCredentials();
if (creds != null && supported.contains(creds.getClass())) {
log.debug("Login: Credentials '{}' obtained from callback", creds);
return creds;
} else {
log.debug("Login: No supported credentials obtained from callback; trying shared state.");
}
} catch (UnsupportedCallbackException e) {
log.warn(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
}
Credentials creds = getSharedCredentials();
if (creds != null && supported.contains(creds.getClass())) {
log.debug("Login: Credentials obtained from shared state.");
return creds;
} else {
log.debug("Login: No supported credentials found in shared state; looking for credentials in subject.");
for (Class clz : getSupportedCredentials()) {
Set<Credentials> cds = subject.getPublicCredentials(clz);
if (!cds.isEmpty()) {
log.debug("Login: Credentials found in subject.");
return cds.iterator().next();
}
}
}
log.debug("No credentials found.");
return null;
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class ConcurrentLoginTest method testLogin.
/**
* Tests concurrent logins on the Repository.
*/
public void testLogin() throws RepositoryException {
final Exception[] exception = new Exception[1];
List testRunner = new ArrayList();
for (int i = 0; i < NUM_THREADS; i++) {
testRunner.add(new Thread(new Runnable() {
public void run() {
Credentials cred = getHelper().getSuperuserCredentials();
for (int i = 0; i < NUM_LOGINS_PER_THREAD; i++) {
try {
Session s = getHelper().getRepository().login(cred);
// immediately logout
s.logout();
} catch (Exception e) {
exception[0] = e;
break;
}
}
}
}));
}
// start threads
for (Iterator it = testRunner.iterator(); it.hasNext(); ) {
((Thread) it.next()).start();
}
// join threads
for (Iterator it = testRunner.iterator(); it.hasNext(); ) {
try {
((Thread) it.next()).join();
} catch (InterruptedException e) {
fail(e.toString());
}
}
if (exception[0] != null) {
fail(exception[0].toString());
}
}
use of javax.jcr.Credentials in project jackrabbit by apache.
the class UserTest method testUserHasCredentials.
public void testUserHasCredentials() throws RepositoryException, NotExecutableException {
User user = getTestUser(superuser);
Credentials creds = user.getCredentials();
assertTrue(creds != null);
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class LoginModuleImpl method createAuthInfo.
private AuthInfo createAuthInfo(@Nonnull Set<? extends Principal> principals) {
Credentials creds;
if (credentials instanceof ImpersonationCredentials) {
creds = ((ImpersonationCredentials) credentials).getBaseCredentials();
} else {
creds = credentials;
}
Map<String, Object> attributes = new HashMap<String, Object>();
Object shared = sharedState.get(SHARED_KEY_ATTRIBUTES);
if (shared instanceof Map) {
for (Object key : ((Map) shared).keySet()) {
attributes.put(key.toString(), ((Map) shared).get(key));
}
} else if (creds instanceof SimpleCredentials) {
SimpleCredentials sc = (SimpleCredentials) creds;
for (String attrName : sc.getAttributeNames()) {
attributes.put(attrName, sc.getAttribute(attrName));
}
}
return new AuthInfoImpl(userId, attributes, principals);
}
Aggregations