List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:com.omsalung.service.filter.JWTFilter.java
private String getToken(HttpServletRequest httpRequest) throws ServletException { String token = null;// w w w . j a v a 2 s . c o m final String authorizationHeader = httpRequest.getHeader("authorization"); if (authorizationHeader == null) { throw new ServletException("Unauthorized: No Authorization header was found"); } String[] parts = authorizationHeader.split(" "); if (parts.length != 2) { throw new ServletException("Unauthorized: Format is Authorization: Bearer [token]"); } String scheme = parts[0]; String credentials = parts[1]; Pattern pattern = Pattern.compile("^Bearer$", Pattern.CASE_INSENSITIVE); if (pattern.matcher(scheme).matches()) { token = credentials; } return token; }
From source file:info.magnolia.cms.filters.MultipartRequestFilter.java
/** * @see javax.servlet.Filter#doFilter(ServletRequest, ServletResponse, FilterChain) *///from w ww . ja v a 2s. c om public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String type = null; String type1 = request.getHeader("Content-Type"); //$NON-NLS-1$ String type2 = request.getContentType(); if (type1 == null && type2 != null) { type = type2; } else if (type2 == null && type1 != null) { type = type1; } else if (type1 != null) { type = (type1.length() > type2.length() ? type1 : type2); } if ((type != null) && type.toLowerCase().startsWith("multipart/form-data")) { //$NON-NLS-1$ parseParameters(request); } filterChain.doFilter(req, res); }
From source file:com.create.security.OAuth2LogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String token = request.getHeader(HEADER_AUTHORIZATION); if (token != null && token.startsWith(BEARER_AUTHENTICATION)) { OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(token.split(" ")[0]); if (oAuth2AccessToken != null) { tokenStore.removeAccessToken(oAuth2AccessToken); }//from w w w. ja v a2s. c om } response.setStatus(HttpServletResponse.SC_OK); }
From source file:com.google.gwt.benchmark.dashboard.server.servlets.AddBenchmarkResultServlet.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String auth = req.getHeader("auth"); if (!authController.validateAuth(auth)) { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return;//from w ww .j a va 2 s. c om } BenchmarkRunJson benchmarkRunJSON = null; String json = null; try { json = IOUtils.toString(req.getInputStream(), "UTF-8"); AutoBean<BenchmarkRunJson> bean = AutoBeanCodex.decode(JsonFactory.get(), BenchmarkRunJson.class, json); benchmarkRunJSON = bean.as(); } catch (Exception e) { logger.log(Level.WARNING, "Can not deserialize JSON", e); if (json != null) { logger.warning(json); } resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().write("Can't parse JSON, see App Engine log for details."); return; } try { benchmarkController.addBenchmarkResult(benchmarkRunJSON); resp.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { logger.log(Level.WARNING, "Can not add benchmark results", e); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.jaeksoft.searchlib.renderer.plugin.AuthPluginHttpHeader.java
@Override public User getUser(Renderer renderer, HttpServletRequest request) throws IOException { String remoteUser = request.getRemoteUser(); if (remoteUser == null) remoteUser = request.getHeader("X-OSS-REMOTE-USER"); if (StringUtils.isEmpty(remoteUser)) throw new AuthException("No user"); String[] groups = null;// ww w . j ava 2 s. co m String remoteGroups = request.getHeader("X-OSS-REMOTE-GROUPS"); if (remoteGroups != null) groups = StringUtils.split(remoteGroups, ','); User user = new User(remoteUser, remoteUser, null, groups); Logging.info( "USER authenticated: " + user.userId + " Groups count: " + (groups == null ? 0 : groups.length)); return user; }
From source file:com.centurylink.cloud.sdk.sample.port.adapter.web.filters.InterceptCredentialsFilter.java
private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String username = request.getHeader("X-Clc-Username"); String password = request.getHeader("X-Clc-Password"); if (username != null && password != null) { sdkRegistry.setCredentials(new SdkCredentials(username, password)); }//from w w w.j a v a 2 s . c o m chain.doFilter(request, response); }
From source file:se.inera.certificate.proxy.module.RequestInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { for (String s : Collections.list(request.getHeaderNames())) { log.debug(s + ":" + request.getHeader(s)); }/*www . jav a 2 s.c o m*/ return true; }
From source file:com.seguriboxltv.backing.AdminUserBean.java
private String GetIp() { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();/*from w w w . j a v a 2 s . c om*/ String ipAddress = request.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = request.getRemoteAddr(); } return ipAddress; }
From source file:org.apereo.openlrs.controllers.xapi.XAPIRequestValidationFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String versionHeader = request.getHeader(XApiConstants.XAPI_VERSION_HEADER); if (StringUtils.isNotBlank(versionHeader)) { // for now we are just checking for the header // in the future we'll deal with specific versioning checking filterChain.doFilter(request, response); } else {/*from w ww . ja va2 s . c o m*/ log.warn("Request missing XAPI VERSION HEADER"); response.sendError(400, "Missing " + XApiConstants.XAPI_VERSION_HEADER + " Header"); } }
From source file:org.apereo.openlrs.XAPIRequestValidationFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String versionHeader = request.getHeader(Constants.XAPI_VERSION_HEADER); if (StringUtils.isNotBlank(versionHeader)) { // for now we are just checking for the header // in the future we'll deal with specific versioning checking filterChain.doFilter(request, response); } else {//from w w w. java 2 s . c om log.warn("Request missing XAPI VERSION HEADER"); response.sendError(400, "Missing " + Constants.XAPI_VERSION_HEADER + " Header"); } }