Java Code Examples for org.apache.catalina.Session#setNote()
The following examples show how to use
org.apache.catalina.Session#setNote() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FederationAuthenticator.java From cxf-fediz with Apache License 2.0 | 6 votes |
protected void saveRequest(Request request, RequestState requestState) throws IOException { String contextId = requestState.getState(); String uri = request.getDecodedRequestURI(); Session session = request.getSessionInternal(true); if (session != null) { LOG.debug("Save request in session '{}'", session.getIdInternal()); } if (session != null && uri != null) { SavedRequest saved; synchronized (session) { super.saveRequest(request, session); saved = (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE); } session.setNote(SESSION_SAVED_REQUEST_PREFIX + uri, saved); StringBuilder sb = new StringBuilder(saved.getRequestURI()); if (saved.getQueryString() != null) { sb.append('?'); sb.append(saved.getQueryString()); } session.setNote(SESSION_SAVED_URI_PREFIX + contextId, sb.toString()); //we set Request State as session attribute for later retrieval in SigninHandler request.getSession().setAttribute( FederationConstants.SESSION_SAVED_REQUEST_STATE_PREFIX + requestState.getState(), requestState); } }
Example 2
Source File: TomcatValve.java From flex-blazeds with Apache License 2.0 | 5 votes |
public Principal login(String username, String password, HttpServletRequest servletRequest) { Realm realm = container.getRealm(); if (realm == null) return null; Principal principal = realm.authenticate(username, password); if (principal == null) return null; if (servletRequestMatches(servletRequest)) { request.setAuthType(AUTH_TYPE); request.setUserPrincipal(principal); Session session = getSession(request, true); // Cache the authentication information in our session. if (session != null) { session.setAuthType(AUTH_TYPE); session.setPrincipal(principal); if (username != null) session.setNote(Constants.SESS_USERNAME_NOTE, username); else session.removeNote(Constants.SESS_USERNAME_NOTE); if (password != null) session.setNote(Constants.SESS_PASSWORD_NOTE, password); else session.removeNote(Constants.SESS_PASSWORD_NOTE); } } return principal; }
Example 3
Source File: TomcatValve4150.java From flex-blazeds with Apache License 2.0 | 5 votes |
public Principal login(String username, String password, HttpServletRequest servletRequest) { Realm realm = container.getRealm(); if (realm == null) return null; Principal principal = realm.authenticate(username, password); if (principal != null) { if (this.request != null && this.request.getRequest() == servletRequest) { request.setAuthType("flexmessaging"); //was "flashgateway" request.setUserPrincipal(principal); Session session = getSession(request, true); // Cache the authentication information in our session, if any if (session != null) { session.setAuthType("flexmessaging"); //was "flashgateway" session.setPrincipal(principal); if (username != null) session.setNote(Constants.SESS_USERNAME_NOTE, username); else session.removeNote(Constants.SESS_USERNAME_NOTE); if (password != null) session.setNote(Constants.SESS_PASSWORD_NOTE, password); else session.removeNote(Constants.SESS_PASSWORD_NOTE); } } } return principal; }
Example 4
Source File: Tomcat7Valve.java From flex-blazeds with Apache License 2.0 | 5 votes |
public Principal login(String username, String password, HttpServletRequest servletRequest) { Realm realm = valve.getContainer().getRealm(); if (realm == null) return null; Principal principal = realm.authenticate(username, password); if (principal == null) return null; if (servletRequestMatches(servletRequest)) { request.setAuthType(AUTH_TYPE); request.setUserPrincipal(principal); Session session = getSession(request, true); // Cache the authentication information in our session. if (session != null) { session.setAuthType(AUTH_TYPE); session.setPrincipal(principal); if (username != null) session.setNote(Constants.SESS_USERNAME_NOTE, username); else session.removeNote(Constants.SESS_USERNAME_NOTE); if (password != null) session.setNote(Constants.SESS_PASSWORD_NOTE, password); else session.removeNote(Constants.SESS_PASSWORD_NOTE); } } return principal; }
Example 5
Source File: FederationAuthenticator.java From cxf-fediz with Apache License 2.0 | 5 votes |
@Override protected boolean matchRequest(Request request) { Session session = request.getSessionInternal(false); String uri = request.getDecodedRequestURI(); if (session != null && uri != null) { SavedRequest saved = (SavedRequest) session.getNote(SESSION_SAVED_REQUEST_PREFIX + uri); if (saved != null) { synchronized (session) { session.setNote(Constants.FORM_REQUEST_NOTE, saved); return super.matchRequest(request); } } } return false; }
Example 6
Source File: FederationAuthenticator.java From cxf-fediz with Apache License 2.0 | 5 votes |
protected boolean restoreRequest(Request request) throws IOException { Session session = request.getSessionInternal(false); String uri = request.getDecodedRequestURI(); if (session != null && uri != null) { SavedRequest saved = (SavedRequest)session.getNote(SESSION_SAVED_REQUEST_PREFIX + uri); if (saved != null) { session.removeNote(SESSION_SAVED_REQUEST_PREFIX + uri); // cleanup session synchronized (session) { session.setNote(Constants.FORM_REQUEST_NOTE, saved); return super.restoreRequest(request, session); } } } return false; }
Example 7
Source File: TomcatSigninHandler.java From cxf-fediz with Apache License 2.0 | 5 votes |
@Override protected FedizPrincipal createPrincipal(HttpServletRequest request, HttpServletResponse response, FedizResponse wfRes) { // Add "Authenticated" role List<String> roles = wfRes.getRoles(); if (roles == null || roles.isEmpty()) { roles = Collections.singletonList("Authenticated"); } else if (getFedizContext().isAddAuthenticatedRole()) { roles = new ArrayList<>(roles); roles.add("Authenticated"); } // proceed creating the JAAS Subject FedizPrincipal principal = new FederationPrincipalImpl(wfRes.getUsername(), roles, wfRes.getClaims(), wfRes.getToken()); Session session = ((Request)request).getSessionInternal(); // Save Federation response in our session session.setNote(FederationAuthenticator.FEDERATION_NOTE, wfRes); // Save Federation response in public session request.getSession(true).setAttribute(FederationAuthenticator.SECURITY_TOKEN, wfRes.getToken()); LOG.debug("UserPrincipal was created successfully for {}", principal); return principal; }
Example 8
Source File: FormAuthenticator.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Save the original request information into our session. * * @param request The request to be saved * @param session The session to contain the saved information * @throws IOException if an IO error occurred during the process */ protected void saveRequest(Request request, Session session) throws IOException { // Create and populate a SavedRequest object for this request SavedRequest saved = new SavedRequest(); Cookie cookies[] = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { saved.addCookie(cookies[i]); } } Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = names.nextElement(); Enumeration<String> values = request.getHeaders(name); while (values.hasMoreElements()) { String value = values.nextElement(); saved.addHeader(name, value); } } Enumeration<Locale> locales = request.getLocales(); while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); saved.addLocale(locale); } // May need to acknowledge a 100-continue expectation request.getResponse().sendAcknowledgement(); int maxSavePostSize = request.getConnector().getMaxSavePostSize(); if (maxSavePostSize != 0) { ByteChunk body = new ByteChunk(); body.setLimit(maxSavePostSize); byte[] buffer = new byte[4096]; int bytesRead; InputStream is = request.getInputStream(); while ( (bytesRead = is.read(buffer) ) >= 0) { body.append(buffer, 0, bytesRead); } // Only save the request body if there is something to save if (body.getLength() > 0) { saved.setContentType(request.getContentType()); saved.setBody(body); } } saved.setMethod(request.getMethod()); saved.setQueryString(request.getQueryString()); saved.setRequestURI(request.getRequestURI()); saved.setDecodedRequestURI(request.getDecodedRequestURI()); // Stash the SavedRequest in our session for later use session.setNote(Constants.FORM_REQUEST_NOTE, saved); }
Example 9
Source File: FormAuthenticator.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Save the original request information into our session. * * @param request The request to be saved * @param session The session to contain the saved information * @throws IOException */ protected void saveRequest(Request request, Session session) throws IOException { // Create and populate a SavedRequest object for this request SavedRequest saved = new SavedRequest(); Cookie cookies[] = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { saved.addCookie(cookies[i]); } } Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = names.nextElement(); Enumeration<String> values = request.getHeaders(name); while (values.hasMoreElements()) { String value = values.nextElement(); saved.addHeader(name, value); } } Enumeration<Locale> locales = request.getLocales(); while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); saved.addLocale(locale); } // May need to acknowledge a 100-continue expectation request.getResponse().sendAcknowledgement(); ByteChunk body = new ByteChunk(); body.setLimit(request.getConnector().getMaxSavePostSize()); byte[] buffer = new byte[4096]; int bytesRead; InputStream is = request.getInputStream(); while ( (bytesRead = is.read(buffer) ) >= 0) { body.append(buffer, 0, bytesRead); } // Only save the request body if there is something to save if (body.getLength() > 0) { saved.setContentType(request.getContentType()); saved.setBody(body); } saved.setMethod(request.getMethod()); saved.setQueryString(request.getQueryString()); saved.setRequestURI(request.getRequestURI()); saved.setDecodedRequestURI(request.getDecodedRequestURI()); // Stash the SavedRequest in our session for later use session.setNote(Constants.FORM_REQUEST_NOTE, saved); }
Example 10
Source File: FormAuthenticator.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Save the original request information into our session. * * @param request The request to be saved * @param session The session to contain the saved information * @throws IOException */ protected void saveRequest(Request request, Session session) throws IOException { // Create and populate a SavedRequest object for this request SavedRequest saved = new SavedRequest(); Cookie cookies[] = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { saved.addCookie(cookies[i]); } } Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = names.nextElement(); Enumeration<String> values = request.getHeaders(name); while (values.hasMoreElements()) { String value = values.nextElement(); saved.addHeader(name, value); } } Enumeration<Locale> locales = request.getLocales(); while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); saved.addLocale(locale); } // May need to acknowledge a 100-continue expectation request.getResponse().sendAcknowledgement(); ByteChunk body = new ByteChunk(); body.setLimit(request.getConnector().getMaxSavePostSize()); byte[] buffer = new byte[4096]; int bytesRead; InputStream is = request.getInputStream(); while ( (bytesRead = is.read(buffer) ) >= 0) { body.append(buffer, 0, bytesRead); } // Only save the request body if there is something to save if (body.getLength() > 0) { saved.setContentType(request.getContentType()); saved.setBody(body); } saved.setMethod(request.getMethod()); saved.setQueryString(request.getQueryString()); saved.setRequestURI(request.getRequestURI()); saved.setDecodedRequestURI(request.getDecodedRequestURI()); // Stash the SavedRequest in our session for later use session.setNote(Constants.FORM_REQUEST_NOTE, saved); }