// 3 = Current users credentials
// 4 = Guest
// 5 = Prompt
int type = 0;
DAVAuthenticationRequiredException dave = null;
PasswordCredentials credentials = null;
boolean hasCachedCredentials = false;
if (log.isDebugEnabled())
log.debug("Trying all available credentials for " + getMountString() + path);
while (true) {
// If no credentials are currently set, try those in the cache
// first
if (type == 0) {
credentials = getStore().getRepository().getCredentialsCache().getDAVCredentials(getStore().getName(),
getMountString());
if (credentials == null) {
type++;
} else {
if (log.isDebugEnabled())
log.debug("Trying cached credentials for " + getMountString() + path);
hasCachedCredentials = true;
}
}
// User info from URI
if (type == 1) {
URI uri = getRootVFSURI(store.getEncoding());
String userInfo = uri.getUserinfo();
if (userInfo == null || userInfo.equals("")) {
type++;
} else {
String username = null;
char[] pw = null;
userInfo = Util.urlDecode(userInfo);
int idx = userInfo.indexOf(":");
username = userInfo;
if (idx != -1) {
username = userInfo.substring(0, idx);
pw = userInfo.substring(idx + 1).toCharArray();
}
credentials = new PasswordCredentials(username, pw);
if (log.isDebugEnabled()) {
log.debug("Trying URI credentials for " + getMountString() + path);
}
}
}
// HTTP authentication response
if (type == 2) {
credentials = requestCredentials;
if (credentials == null) {
type++;
} else if (log.isDebugEnabled()) {
log.debug("Trying Request credentials for " + getMountString() + path);
}
}
// Current user creds
if (type == 3) {
if (!tryCurrentUser) {
type++;
} else {
SessionInfo inf = getStore().getRepository().getSession();
char[] pw = LogonControllerFactory.getInstance()
.getPasswordFromCredentials((AuthenticationScheme) inf.getHttpSession()
.getAttribute(Constants.AUTH_SESSION));
if (pw == null) {
if (log.isDebugEnabled())
log.debug("No password available from current session");
type++;
} else {
credentials = new PasswordCredentials(inf.getUser().getPrincipalName(), pw);
if (log.isDebugEnabled()) {
log.debug("Trying current session credentials for " + "/" + getMountString() + path);
}
}
}
}
// Guest creds
if (type == 4) {
if (!tryGuest) {
type++;
} else {
String guestAccount = getStore().getGuestUsername();
if (guestAccount == null) {
type++;
} else {
credentials = new PasswordCredentials(guestAccount, getStore().getGuestPassword());
if (log.isDebugEnabled()) {
log.debug("Trying guest credentials for " + getMountString() + path);
}
}