本文整理汇总了Java中javax.servlet.http.HttpSession.getId方法的典型用法代码示例。如果您正苦于以下问题:Java HttpSession.getId方法的具体用法?Java HttpSession.getId怎么用?Java HttpSession.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpSession
的用法示例。
在下文中一共展示了HttpSession.getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCallbackWithOriginallyRequestedUrl
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Test
public void testCallbackWithOriginallyRequestedUrl() throws Exception {
HttpSession session = request.getSession();
final String originalSessionId = session.getId();
session.setAttribute(Pac4jConstants.REQUESTED_URL, PAC4J_URL);
request.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
final CommonProfile profile = new CommonProfile();
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
config.setClients(new Clients(CALLBACK_URL, indirectClient));
call();
session = request.getSession();
final String newSessionId = session.getId();
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
assertTrue(profiles.containsValue(profile));
assertEquals(1, profiles.size());
assertNotEquals(newSessionId, originalSessionId);
assertEquals(302, response.getStatus());
assertEquals(PAC4J_URL, response.getRedirectedUrl());
}
示例2: valueUnbound
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public void valueUnbound(HttpSessionBindingEvent event) {
try {
Engine.logContext.debug("HTTP session stopping...");
HttpSession httpSession = event.getSession();
String httpSessionID = httpSession.getId();
if (Engine.theApp != null) Engine.theApp.contextManager.removeAll(httpSessionID);
removeSession(httpSessionID);
Engine.logContext.debug("HTTP session stopped [" + httpSessionID + "]");
} catch(Exception e) {
Engine.logContext.error("Exception during unbinding HTTP session listener", e);
}
}
示例3: testCallback
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Test
public void testCallback() throws Exception {
final String originalSessionId = request.getSession().getId();
request.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
final CommonProfile profile = new CommonProfile();
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
config.setClients(new Clients(CALLBACK_URL, indirectClient));
call();
final HttpSession session = request.getSession();
final String newSessionId = session.getId();
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
assertTrue(profiles.containsValue(profile));
assertEquals(1, profiles.size());
assertNotEquals(newSessionId, originalSessionId);
assertEquals(302, response.getStatus());
assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
示例4: testCallbackNoRenew
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Test
public void testCallbackNoRenew() throws Exception {
final String originalSessionId = request.getSession().getId();
request.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
final CommonProfile profile = new CommonProfile();
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
config.setClients(new Clients(CALLBACK_URL, indirectClient));
renewSession = false;
call();
final HttpSession session = request.getSession();
final String newSessionId = session.getId();
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
assertTrue(profiles.containsValue(profile));
assertEquals(1, profiles.size());
assertEquals(newSessionId, originalSessionId);
assertEquals(302, response.getStatus());
assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
示例5: authorize
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@RequestMapping(value = "/authenticate", method = { RequestMethod.POST })
@ResponseBody
public String authorize(
@RequestBody AuthenticationRequest authenticationRequest,
HttpServletRequest request) {
final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
authenticationRequest.getUsername(), authenticationRequest.getPassword());
final Authentication authentication = this.authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
final HttpSession session = request.getSession(true);
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
SecurityContextHolder.getContext());
return session.getId();
}
示例6: initializeTupasIdentification
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
private void initializeTupasIdentification(HttpServletRequest request, HttpServletResponse response) throws ExternalAuthenticationException, IOException {
String convKey = ExternalAuthentication.startExternalAuthentication(request);
/* The above method enriches the servlet request with Shibboleth IdP related
* data such as the relying party value which is fetched in the code below.
* Note that this data is not fetched from browser generated request but directly
* from Shibboleth through internal class method call
*/
HttpSession session = request.getSession();
if (session == null) {
response.sendRedirect(createErrorURL(errorParamIdpExt));
return;
}
String sessionId = session.getId();
String relyingParty = String.valueOf(request.getAttribute(ExternalAuthentication.RELYING_PARTY_PARAM));
// Relying party parameter must match the allowed entity ID format
if (!UrlParamService.isValidEntityId(relyingParty)) {
logger.warn("<<{}>> Received invalid relying party");
response.sendRedirect(createErrorURL(errorParamInvalidEID));
return;
} else {
ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(convKey, request);
AuthenticationContext ac = prc.getSubcontext(AuthenticationContext.class);
if ( ac == null ) {
logger.info("No AuthenticationContext");
response.sendRedirect(createErrorURL(errorParamIdpExt));
return;
}
MultivaluedMap<String, String> requestParams = new MultivaluedHashMap<>();
requestParams.putSingle("declRef", resolveDeclarationRef(prc));
requestParams.putSingle("lang", resolveLanguage(prc));
requestParams.putSingle("ckey", convKey);
requestParams.putSingle("sessionId", sessionId);
String initResult = authenticationHandlerService.initializeSession(requestParams);
response.getWriter().println(initResult);
return;
}
}
示例7: validateFile
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@GetMapping(value = "/validate/{filename:.+}")
public ModelAndView validateFile(@PathVariable String filename, @QueryParam(
"version") ValidationService.MzTabVersion version, @QueryParam(
"maxErrors") int maxErrors, HttpServletRequest request,
HttpSession session) {
if (session == null) {
UriComponents uri = ServletUriComponentsBuilder
.fromServletMapping(request).
build();
return new ModelAndView(
"redirect:" + uri.toUriString());
}
ModelAndView modelAndView = new ModelAndView("validationResult");
modelAndView.
addObject("page", new Page("mzTabValidator", versionNumber, gaId));
modelAndView.addObject("validationFile", filename);
ValidationService.MzTabVersion validationVersion = version;
if (validationVersion != null) {
modelAndView.addObject("validationVersion", validationVersion);
} else {
validationVersion = ValidationService.MzTabVersion.MZTAB_1_1;
modelAndView.addObject("validationVersion", validationVersion);
}
if (maxErrors > 0) {
modelAndView.addObject("validationMaxErrors", maxErrors);
} else {
modelAndView.addObject("validationMaxErrors", 100);
}
UserSessionFile usf = new UserSessionFile(filename, session.getId());
modelAndView.addObject("validationResults", validationService.
asValidationResults(validationService.validate(
validationVersion, usf, maxErrors)));
return modelAndView;
}
示例8: destroySessionBack
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void destroySessionBack(final J2EContext context, final String ticket) {
final HttpSession session = this.sessionMappingStorage.removeSessionByMappingId(ticket);
if (session != null) {
String sessionID = session.getId();
logger.debug("Invalidating session [{}] for ticket [{}]", sessionID, ticket);
try {
session.invalidate();
} catch (final IllegalStateException e) {
logger.debug("Error invalidating session", e);
}
}
}
示例9: doGet
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
boolean createSession = !Boolean.parseBoolean(req
.getParameter("no_create_session"));
HttpSession session = req.getSession(createSession);
if (session == null) {
resp.getWriter().print("NO_SESSION");
} else {
String id = session.getId();
resp.getWriter().print(id);
}
}
示例10: getContext
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public Context getContext() throws Exception {
HttpServletRequest request = (HttpServletRequest) inputData;
initInternalVariables();
HttpSession httpSession = request.getSession();
String sessionID = httpSession.getId();
context = Engine.isEngineMode() ?
Engine.theApp.contextManager.get(this, contextName, sessionID, poolName, projectName, connectorName, sequenceName) :
Engine.theApp.contextManager.get(this, connectorName, sessionID, poolName, projectName, connectorName, sequenceName);
return context;
}
示例11: sessionDestroyed
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void sessionDestroyed(HttpSessionEvent event)
{
final HttpSession session = event.getSession();
final String sessionId = session.getId();
if( LOGGER.isDebugEnabled() )
{
LOGGER.debug(sessionId + " session destroyed");
}
try
{
for( final Institution institution : institutionService.getAvailableMap().values() )
{
runAs.executeAsSystem(institution, new Runnable()
{
@Override
public void run()
{
UserState userState = sessionService.getAttributeFromSession(session, institution,
WebConstants.KEY_USERSTATE);
if( userState != null )
{
if( LOGGER.isDebugEnabled() )
{
LOGGER.debug(sessionId + " firing logout event");
}
eventService.publishApplicationEvent(new UserSessionLogoutEvent(userState, true));
}
}
});
}
}
finally
{
CurrentInstitution.remove();
}
}
示例12: getRequestInfo
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public String getRequestInfo(HttpServletRequest request) {
StringBuffer buffer = new StringBuffer();
try {
String currentURL = request.getRequestURI();
if (request.getQueryString() != null) {
currentURL = currentURL + "?" + request.getQueryString();
}
if (currentURL != null) {
String contextPath = request.getContextPath();
currentURL = currentURL.replaceFirst(contextPath, "");
}
String sessionid = null;
String oprCode = null;
HttpSession session = request.getSession();
if (session != null) {
sessionid = session.getId();
oprCode = getOprCode(request);
}
buffer.append(oprCode).append("|").append(sessionid)
.append("|").append(SecurityUtils.getIpAddr(request)).append("|")
.append(currentURL);
} catch (Throwable e1) {
SecurityLoggerUtils.catching(e1);
}
return buffer.toString();
}
示例13: startSession
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* Stores session in current thread and mapping so other modules can refer to it.
*/
public static void startSession(HttpServletRequest request) {
HttpSession session = request.getSession();
String sessionId = session.getId();
SessionManager.sessionIdMapping.put(sessionId, session);
SessionManager.sessionManager.currentSessionIdContainer.set(sessionId);
}
示例14: convert
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public String convert(ILoggingEvent event) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession httpSession = request.getSession(false);
if (httpSession != null) {
return httpSession.getId();
}
return NO_SESSION;
}
示例15: getServletResponse
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* Returns the final response from the servlet. Note that this method should
* only be invoked after all processing has been done to the servlet response.
**/
public WebResponse getServletResponse() throws IOException {
if (_webResponse == null) {
HttpSession session = _request.getSession( /* create */ false );
if (session != null && session.isNew()) {
Cookie cookie = new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() );
cookie.setPath( _application.getContextPath() );
_response.addCookie( cookie );
}
_webResponse = new ServletUnitWebResponse( _client, _target, _requestURL, _response, _client.getExceptionsThrownOnErrorStatus() );
}
return _webResponse;
}