List of usage examples for org.eclipse.jgit.util HttpSupport HDR_WWW_AUTHENTICATE
String HDR_WWW_AUTHENTICATE
To view the source code for org.eclipse.jgit.util HttpSupport HDR_WWW_AUTHENTICATE.
Click Source Link
From source file:org.webcat.core.http.BasicAuthenticationFilter.java
License:Open Source License
/** * Gets the session for the user making the request, creating it if it does * not yet exist (for example, if the user is logging in directly through * the Git URL)./*from w ww . j a v a 2 s . c om*/ * * @param info the entity request info */ private Session sessionFromContext(final WOContext context) { final WORequest request = context.request(); final WOResponse response = context.response(); String sessionId = request.headerForKey(SESSION_ID_HEADER); if (sessionId == null) { sessionId = context._requestSessionID(); } Session session = (sessionId != null) ? // Use an existing session if we have one. (Session) Application.wcApplication().restoreSessionWithID(sessionId, request.context()) : null; if (session == null) { String authorization = request.headerForKey(HttpSupport.HDR_AUTHORIZATION); if (authorization == null) { String realm = realmForContext(context); response.setStatus(HttpStatus.SC_UNAUTHORIZED); response.setHeader("Basic realm=\"" + realm + "\"", HttpSupport.HDR_WWW_AUTHENTICATE); } else { authorization = Base64.decode(authorization.substring(6)); String[] parts = authorization.split(":"); final String username = parts[0]; final String password = (parts.length > 1) ? parts[1] : null; final Session oldSession = session; session = call(new ECActionWithResult<Session>() { public Session action() { Session result = oldSession; User user = validateUser(username, password, ec); if (user == null) { Application.wcApplication().saveSessionForContext(context); } else { context._setRequestSessionID(existingSessionId); result = (Session) context.session(); result.setUser(user.localInstance(result.defaultEditingContext())); result._appendCookieToResponse(response); } return result; } }); } } return session; }