Example usage for javax.servlet.http HttpServletRequest getHeader

List of usage examples for javax.servlet.http HttpServletRequest getHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getHeader.

Prototype

public String getHeader(String name);

Source Link

Document

Returns the value of the specified request header as a String.

Usage

From source file:info.magnolia.cms.security.auth.login.BasicLogin.java

@Override
public LoginResult handle(HttpServletRequest request, HttpServletResponse response) {
    String credentials = request.getHeader("Authorization");
    if (StringUtils.isNotEmpty(credentials) && !credentials.startsWith("NTLM ")
            && !credentials.startsWith("Negotiate ") && !credentials.startsWith("Digest ")
            && !credentials.startsWith("Passport ")) {
        // its a basic authentication request
        CredentialsCallbackHandler callbackHandler = new Base64CallbackHandler(credentials);
        return authenticate(callbackHandler, null);
    }/* w w w .ja v  a  2 s.  c o m*/
    return LoginResult.NOT_HANDLED;
}

From source file:org.trustedanalytics.metadata.security.authorization.PlatformAuthorization.java

private String getToken(HttpServletRequest request) throws OauthTokenMissingException {
    String authHeader = request.getHeader("Authorization");
    if (authHeader == null) {
        throw new OauthTokenMissingException("Cannot find 'Authorization' header.");
    } else {/*from   w  w w  .j  a  v  a2  s .co  m*/
        return authHeader.replaceAll("(?i)bearer ", "");
    }
}

From source file:se.vgregion.portal.loginlink.controller.LoginLinkViewController.java

private boolean internalAccessRule(HttpServletRequest request) {
    String header = request.getHeader("x-forwarded-for");
    String[] ipsForExternalAccess = ipForExternalAccess.replaceAll(" ", "").split(",");
    boolean internal = true;
    if (header != null) {
        // Iterate over the ip:s. We'll find a match if the user is located externally.
        for (String ip : ipsForExternalAccess) {
            if (header.contains(ip)) { // String.contains(...) since the header value may be a comma-separated list.
                return false;
            }//from  w  ww  .j a  v  a2 s.  c om
        }
    }
    return true;
}

From source file:com.thoughtworks.go.server.newsecurity.filters.helpers.ServerUnavailabilityResponse.java

private boolean requestIsOfType(String type, HttpServletRequest request) {
    String header = request.getHeader("Accept");
    String contentType = request.getContentType();
    String url = request.getRequestURI();
    return header != null && header.contains(type) || url != null && url.endsWith(type)
            || contentType != null && contentType.contains(type);
}

From source file:it.geosolutions.geostore.services.rest.security.GeoStoreRequestHeadersAuthenticationFilter.java

@Override
protected void authenticate(HttpServletRequest req) {
    String userName = req.getHeader(userNameHeader);
    if (userName != null) {
        String credentials = null;
        if (credentialsHeader != null) {
            credentials = req.getHeader(credentialsHeader);
            if (credentials.trim().isEmpty()) {
                credentials = null;//from   ww w .  j  a va  2 s .c om
            }
        }
        // create auth object with given user / credentials / attributes
        SecurityContextHolder.getContext()
                .setAuthentication(createAuthenticationForUser(userName, credentials, getHeadersMap(req)));
    }
}

From source file:com.thoughtworks.go.server.security.DenyGoCDAccessForArtifactsFilter.java

private boolean isRequestFromArtifact(HttpServletRequest request) throws MalformedURLException {
    final String referer = request.getHeader("Referer");

    if (isBlank(referer)) {
        return false;
    }//from   ww  w  .j  a va2s . co  m

    return new URL(referer).getPath().startsWith("/go/files");
}

From source file:com.esd.vs.interceptor.LoginInterceptor.java

public String getRemoteAddress(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("Proxy-Client-IP");
    }/*www .  j  a  v a  2s .  com*/
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getRemoteAddr();
    }
    return ip;
}

From source file:org.biokoframework.http.response.impl.AbstractHttpResponseBuilder.java

protected List<String> getAccept(HttpServletRequest request) {
    String accept = request.getHeader(ACCEPT);
    if (!StringUtils.isEmpty(accept)) {
        return Arrays.asList(accept.split(","));
    }//from  w w w .java2  s  .c  o m
    return null;
}

From source file:ru.codemine.ccms.api.security.ApiAuthenticationFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse responce = (HttpServletResponse) resp;
    HttpServletRequest request = (HttpServletRequest) req;

    String authToken = request.getHeader("X-Auth-Token");
    String username = apiTokenUtils.getUsernameFromToken(authToken);

    if (username != null) {
        Employee employee = employeeService.getByUsername(username);
        if (apiTokenUtils.validateToken(authToken, employee)) {
            UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
                    employee, null, employee.getAuthorities());
            authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }//w  w  w . j a  va2 s  .  c o  m
    }

    chain.doFilter(req, resp);
}

From source file:sample.session.SessionDetailsFilter.java

private String getRemoteAddress(HttpServletRequest request) {
    String remoteAddr = request.getHeader("X-FORWARDED-FOR");
    if (remoteAddr == null) {
        remoteAddr = request.getRemoteAddr();
    } else if (remoteAddr.contains(",")) {
        remoteAddr = remoteAddr.split(",")[0];
    }//from ww  w. ja  v a 2s  .co m
    return remoteAddr;
}