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:de.mpg.escidoc.services.aa.web.client.BasicAaClient.java

private boolean testLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String auth = request.getHeader("authorization");
    if (auth == null) {
        response.addHeader("WWW-Authenticate", "Basic realm=\"Validation Service\"");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return false;
    } else {// w  w  w.  j  a v a2s .co  m
        auth = auth.substring(6);
        String cred = new String(Base64.decodeBase64(auth.getBytes()));
        if (cred.contains(":")) {

            String[] userPass = cred.split(":");
            String userName = "admin";
            String password = "nimda";

            if (!userPass[0].equals(userName) || !userPass[1].equals(password)) {
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
                return false;
            } else {
                return true;
            }
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return false;
        }
    }
}

From source file:eionet.cr.web.action.TabularDataServlet.java

/**
 *
 * @param httpRequest//from   w ww . j a v  a 2  s  .  c  om
 * @return
 */
private boolean isRdfXmlPreferred(HttpServletRequest httpRequest) {

    String acceptHeader = httpRequest.getHeader("Accept");
    return acceptHeader != null && acceptHeader.trim().toLowerCase().startsWith("application/rdf+xml");
}

From source file:com.isalnikov.config.auth.UserAuthorizationFilter.java

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException {

    String terminalId = request.getHeader("Authorization");

    terminalId = "1";

    //        if (request.getHeader("Authorization") == null) {
    //            return null; // no header found, continue on to other security filters
    //        }// w  w  w  .ja  v  a 2 s  .  co m
    String userName = obtainUsername(request);
    String password = obtainPassword(request);

    if (terminalId != null) {
        UserAuthorizationToken token = new UserAuthorizationToken(userName, password, terminalId,
                Arrays.asList(UserAuthority.ROLE_USER));

        return super.getAuthenticationManager().authenticate(token);
    }

    throw new BadCredentialsException("Invalid username or password");
}

From source file:eu.trentorise.smartcampus.feedback.controller.FeedbackController.java

private User retrieveUser(HttpServletRequest request, HttpServletResponse response) throws AcServiceException {
    String token = request.getHeader(AcProviderFilter.TOKEN_HEADER);
    return acService.getUserByToken(token);
}

From source file:com.ctc.storefront.security.impl.DefaultGuestCheckoutCartCleanStrategy.java

@Override
public void cleanGuestCart(final HttpServletRequest request) {

    if (isAnonymousCheckout() && StringUtils.isBlank(request.getHeader(AJAX_REQUEST_HEADER_NAME))
            && isGetMethod(request) && !checkWhetherURLContainsCheckoutPattern(request)) {
        final CartModel cartModel = getCartService().getSessionCart();
        cartModel.setDeliveryAddress(null);
        cartModel.setDeliveryMode(null);
        cartModel.setPaymentInfo(null);//from  w  ww . ja  va 2  s  .co  m
        cartModel.setUser(getUserService().getAnonymousUser());
        getCartService().saveOrder(cartModel);
        getSessionService().removeAttribute(WebConstants.ANONYMOUS_CHECKOUT);
        getSessionService().removeAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID);
    }

}

From source file:com.naver.blog.api.AuthenticationUserIdFinder.java

public String getUserId(HttpServletRequest request) {

    if (onOffStatusHolder.on(ZookeeperServiceType.APIGW_AUTH_TYPE)) {
        CloseApiAuthType apiAuthType = CloseApiAuthType.find(request.getHeader(AUTH_TYPE));
        return apiAuthType.getAuthenticationUserIdRule().getUserId(request);
    } else {//from  ww w .  jav a2  s.c  o  m
        return CloseApiAuthType.UNKNOWN.getAuthenticationUserIdRule().getUserId(request);
    }
}

From source file:com.organization.projectname.controller.AuthenticationController.java

@RequestMapping(value = "${jwt.route.authentication.refresh}", method = RequestMethod.GET)
public ResponseEntity<?> refreshAndGetAuthenticationToken(HttpServletRequest request) throws Exception {

    userService.isIPOK();/*  www .jav  a 2s. c  o m*/

    String token = request.getHeader(tokenHeader);
    String username = jwtTokenUtil.getUsernameFromToken(token);
    User user = (User) userService.loadUserByUsername(username);

    if (jwtTokenUtil.canTokenBeRefreshed(token, user.getLastPasswordResetDate())) {
        String refreshedToken = jwtTokenUtil.refreshToken(token);
        return ResponseEntity.ok(new AuthenticationResponse(refreshedToken));
    } else {
        return ResponseEntity.badRequest().body(null);
    }
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.WithAjaxAuthenticationProcessingFilterEntryPoint.java

/**
 * {@inheritDoc}/*  w  ww. ja  v  a2s.  c  om*/
 * @see org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint#determineUrlToUseForThisRequest(
 *    javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
 *    org.springframework.security.AuthenticationException)
 */
@Override
protected String determineUrlToUseForThisRequest(final HttpServletRequest request,
        final HttpServletResponse response, final AuthenticationException exception) {

    if (request.getHeader(ajaxHeader) != null && ajaxLoginFormUrl != null) {
        return ajaxLoginFormUrl;
    }

    return getLoginFormUrl();
}

From source file:com.krawler.svnwebclient.authorization.impl.CredentialsManager.java

protected boolean isBasicAuthentication(HttpServletRequest request) {
    String auth = request.getHeader("Authorization");
    if (auth != null && !auth.equals("") && auth.toLowerCase().startsWith("basic")) {
        return true;
    } else {//ww w .  j a  va 2  s  .  c o m
        return false;
    }
}

From source file:com.wavemaker.spinup.web.SpinupController.java

private boolean isAjaxRequest(HttpServletRequest request) {
    return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
}