use of javax.jcr.GuestCredentials in project sling by apache.
the class AbstractSlingRepository2 method login.
/**
* Logs into the repository at the given {@code workspace} with the given
* {@code credentials} and returns the session returned from
* the repository.
* <p>
* This method logs in as a guest if {@code null} credentials are provided.
* The method may be overwritten to implement a different behaviour as
* indicated by the JCR specification for this method to use external
* mechanisms to login instead of leveraging provided credentials.
* <p>
* This method may be overwritten.
*
* @param credentials The {@code Credentials} to use to login. If this is
* {@code null} JCR {@code GuestCredentials} are used to login.
* @param workspace The workspace to access or {@code null} to access the
* {@link #getDefaultWorkspace() default workspace}
* @throws LoginException If login is not possible
* @throws NoSuchWorkspaceException if the desired workspace is not
* available
* @throws RepositoryException If another error occurrs during login
* @see #getNamespaceAwareSession(Session)
*/
@Override
public Session login(Credentials credentials, String workspace) throws LoginException, NoSuchWorkspaceException, RepositoryException {
if (credentials == null) {
credentials = new GuestCredentials();
}
// check the workspace
if (workspace == null) {
workspace = this.getDefaultWorkspace();
}
try {
logger.debug("login: Logging in to workspace '" + workspace + "'");
final Repository repository = this.getRepository();
if (this.getRepository() == null) {
throw new RepositoryException("Sling Repository not ready");
}
final Session session = repository.login(credentials, workspace);
return session;
} catch (final RuntimeException re) {
// repository has already been shut down ...
throw new RepositoryException(re.getMessage(), re);
}
}
use of javax.jcr.GuestCredentials 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.GuestCredentials 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;
}
use of javax.jcr.GuestCredentials in project jackrabbit-oak by apache.
the class GuestLoginModule method login.
@Override
public boolean login() {
if (callbackHandler != null) {
CredentialsCallback ccb = new CredentialsCallback();
try {
callbackHandler.handle(new Callback[] { ccb });
Credentials credentials = ccb.getCredentials();
if (credentials == null) {
guestCredentials = new GuestCredentials();
sharedState.put(AbstractLoginModule.SHARED_KEY_CREDENTIALS, guestCredentials);
return true;
}
} catch (IOException e) {
log.debug("Login: Failed to retrieve Credentials from CallbackHandler", e);
} catch (UnsupportedCallbackException e) {
log.debug("Login: Failed to retrieve Credentials from CallbackHandler", e);
}
}
// ignore this login module
return false;
}
use of javax.jcr.GuestCredentials in project jackrabbit-oak by apache.
the class CugOakTest method beforeSuite.
@Override
protected void beforeSuite() throws Exception {
super.beforeSuite();
Credentials creds = (runAsAdmin) ? getCredentials() : new GuestCredentials();
cs = contentRepository.login(creds, null);
subject = new Subject(true, cs.getAuthInfo().getPrincipals(), Collections.emptySet(), Collections.emptySet());
}
Aggregations