iRequest.databaseName = urlParts[1];
final List<String> authenticationParts = iRequest.authorization != null ? OStringSerializerHelper.split(iRequest.authorization,
':') : null;
OHttpSession currentSession;
if (iRequest.sessionId != null && iRequest.sessionId.length() > 1) {
currentSession = OHttpSessionManager.getInstance().getSession(iRequest.sessionId);
if (currentSession != null && authenticationParts != null) {
if (!currentSession.getUserName().equals(authenticationParts.get(0))) {
// CHANGED USER, INVALIDATE THE SESSION
currentSession = null;
}
}
} else
currentSession = null;
if (currentSession == null) {
// NO SESSION
if (iRequest.authorization == null || SESSIONID_LOGOUT.equals(iRequest.sessionId)) {
iResponse.setSessionId(SESSIONID_UNAUTHORIZED);
sendAuthorizationRequest(iRequest, iResponse, iRequest.databaseName);
return false;
} else
return authenticate(iRequest, iResponse, authenticationParts, iRequest.databaseName);
} else {
// CHECK THE SESSION VALIDITY
if (!currentSession.getDatabaseName().equals(iRequest.databaseName)) {
// SECURITY PROBLEM: CROSS DATABASE REQUEST!
OLogManager.instance().warn(this,
"Session %s is trying to access to the database '%s', but has been authenticated against the database '%s'",
iRequest.sessionId, iRequest.databaseName, currentSession.getDatabaseName());
OHttpSessionManager.getInstance().removeSession(iRequest.sessionId);
sendAuthorizationRequest(iRequest, iResponse, iRequest.databaseName);
return false;
} else if (authenticationParts != null && !currentSession.getUserName().equals(authenticationParts.get(0))) {
// SECURITY PROBLEM: CROSS DATABASE REQUEST!
OLogManager.instance().warn(this,
"Session %s is trying to access to the database '%s' with user '%s', but has been authenticated with user '%s'",
iRequest.sessionId, iRequest.databaseName, authenticationParts.get(0), currentSession.getUserName());
OHttpSessionManager.getInstance().removeSession(iRequest.sessionId);
sendAuthorizationRequest(iRequest, iResponse, iRequest.databaseName);
return false;
}