List of usage examples for org.springframework.web.context.request RequestContextHolder currentRequestAttributes
public static RequestAttributes currentRequestAttributes() throws IllegalStateException
From source file:org.jbr.commons.rest.RestEndpointAspect.java
private Date startTimer() { final RequestAttributes attrs = RequestContextHolder.currentRequestAttributes(); final int scope = RequestAttributes.SCOPE_REQUEST; Date startTime = (Date) attrs.getAttribute(HEADER_START_TIME, scope); if (startTime == null) { startTime = new Date(); attrs.setAttribute(HEADER_START_TIME, startTime, scope); }/*from w ww .ja v a2 s . c o m*/ return startTime; }
From source file:com.centeractive.ws.server.endpoint.GenericContextDomEndpoint.java
private HttpServletRequest getHttpServletRequest() { return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); }
From source file:com.cws.us.pws.controllers.AboutController.java
@RequestMapping(value = "/default", method = RequestMethod.GET) public final ModelAndView showDefaultPage() { final String methodName = AboutController.CNAME + "#showDefaultPage()"; if (DEBUG) {/*from w ww . j a v a2 s. c om*/ DEBUGGER.debug(methodName); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } try { CareerRequest request = new CareerRequest(); request.setLang( (StringUtils.isBlank(hRequest.getParameter("lang"))) ? "en" : hRequest.getParameter("lang")); if (DEBUG) { DEBUGGER.debug("CareerRequest: {}", request); } CareerResponse response = this.careerRefSvc.getCareerList(request); if (DEBUG) { DEBUGGER.debug("CareerResponse: {}", response); } if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) { mView.addObject("doCareersExist", Boolean.TRUE); } } catch (CareerRequestException crx) { ERROR_RECORDER.error(crx.getMessage(), crx); } mView.setViewName(this.aboutUsPage); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:de.metas.ui.web.login.LoginRestController.java
private static MSession createMSession(final Login loginService) { final HttpServletRequest httpRequest = ((ServletRequestAttributes) RequestContextHolder .currentRequestAttributes()).getRequest(); final HttpSession httpSess = httpRequest.getSession(); final String webSessionId = httpSess.getId(); //// w ww. j a va2s. c o m // final WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); String remoteAddr = httpRequest.getRemoteAddr(); String remoteHost = httpRequest.getRemoteHost(); // // Check if we are behind proxy and if yes, get the actual client IP address // NOTE: when configuring apache, don't forget to activate reverse-proxy mode // see http://www.xinotes.org/notes/note/770/ final String forwardedFor = httpRequest.getHeader("X-Forwarded-For"); if (!Check.isEmpty(forwardedFor)) { remoteAddr = forwardedFor; remoteHost = forwardedFor; } final LoginContext ctx = loginService.getCtx(); final MSession sessionPO = MSession.get(ctx.getSessionContext(), remoteAddr, remoteHost, webSessionId); // Set HostKey // FIXME: commented out because this one is not working when running over websockets (i.e. HttpServletResponse does not exists) // see https://dev.vaadin.com/ticket/11808 // @formatter:off // final I_AD_Session session = InterfaceWrapperHelper.create(sessionPO, I_AD_Session.class); // HttpCookieHostKeyStorage.createUpdateHostKey(); // final String hostKey = hostKeyBL.getHostKey(); // session.setHostKey(hostKey); // InterfaceWrapperHelper.save(session); // @formatter:on // Update Login helper loginService.setRemoteAddr(remoteAddr); loginService.setRemoteHost(remoteHost); loginService.setWebSession(webSessionId); return sessionPO; }
From source file:net.groupbuy.controller.admin.BaseController.java
/** * /*from w ww . j a v a2 s. c om*/ * * @param content * */ protected void addLog(String content) { if (content != null) { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); requestAttributes.setAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME, content, RequestAttributes.SCOPE_REQUEST); } }
From source file:com.jaspersoft.jasperserver.war.model.impl.AwsDataSourceTreeDataProvider.java
private AWSCredentials retrieveCredentialsFromRequest() { ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); HttpServletRequest request = attr.getRequest(); String accessKey = request.getParameter("awsAccessKey"); String secretKey = request.getParameter("awsSecretKey"); if (secretKey != null && secretKey.equals( messageSource.getMessage("input.password.substitution", null, LocaleContextHolder.getLocale()))) { String uri = request.getParameter("datasourceUri"); AwsReportDataSource existingDs = (AwsReportDataSource) getRepositoryService().getResource(null, uri); if (existingDs != null) { secretKey = existingDs.getAWSSecretKey(); }//from w w w.ja v a 2s. com } String arn = request.getParameter("arn"); arn = !isBlank(arn) ? arn : null; return AwsCredentialUtil.getAWSCredentials(accessKey, secretKey, arn); }
From source file:org.springjutsu.validation.util.RequestUtils.java
public static HttpServletRequest getCurrentRequest() { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); if (attributes == null) { return null; }/*from w ww . ja v a2 s .c om*/ return ((ServletRequestAttributes) attributes).getRequest(); }
From source file:org.opentides.persistence.user.AuthenticationDaoJdbcImpl.java
@Override public void onApplicationEvent(ApplicationEvent event) { if (enableUserLockCheck) { if (event instanceof AuthenticationSuccessEvent) { userService.unlockUser(((AbstractAuthenticationEvent) event).getAuthentication().getName()); } else if (event instanceof AbstractAuthenticationFailureEvent) { String username = ((AbstractAuthenticationEvent) event).getAuthentication().getName(); String origin = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) .getRequest().getRemoteAddr(); String cause = ((AbstractAuthenticationFailureEvent) event).getException().toString(); logger.info("Failed authentication for user '" + username + "' from ip " + origin + " caused by " + cause);// w ww . j a v a 2 s. c o m if (event instanceof AuthenticationFailureBadCredentialsEvent) { if (!userService.isUserLockedOut(username, maxAttempts, lockoutSeconds)) userService.updateFailedLogin(username, event.getTimestamp()); } } } }
From source file:com.sammyun.service.impl.MemberServiceImpl.java
/** * ?// w ww . j a v a2 s. c om * * @return ? */ @Transactional(readOnly = true) public boolean isAuthenticated() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return true; } } return false; }
From source file:net.groupbuy.service.impl.MemberServiceImpl.java
@Transactional(readOnly = true) public boolean isAuthenticated() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return true; }// w w w. ja v a 2s. c om } return false; }