Example usage for org.apache.wicket.request.http WebRequest getHeader

List of usage examples for org.apache.wicket.request.http WebRequest getHeader

Introduction

In this page you can find the example usage for org.apache.wicket.request.http WebRequest getHeader.

Prototype

public abstract String getHeader(String name);

Source Link

Document

Returns the value of the specified request header as a String

Usage

From source file:de.alpharogroup.wicket.base.application.seo.DisableJSessionIDinUrlApplication.java

License:Apache License

/**
 * Disable sessionId in the url if it comes from a robot.
 * /*from w ww  .  jav  a  2 s  .  c o m*/
 * @param webRequest
 *            the web request
 * @param httpServletResponse
 *            the http servlet response
 * @return the web response
 */
@Override
protected WebResponse newWebResponse(final WebRequest webRequest,
        final HttpServletResponse httpServletResponse) {
    return new ServletWebResponse((ServletWebRequest) webRequest, httpServletResponse) {

        @Override
        public String encodeRedirectURL(final CharSequence url) {
            return isRobot(webRequest) ? url.toString() : super.encodeRedirectURL(url);
        }

        @Override
        public String encodeURL(final CharSequence url) {
            return isRobot(webRequest) ? url.toString() : super.encodeURL(url);
        }

        private boolean isRobot(final WebRequest request) {
            final String agent = webRequest.getHeader("User-Agent");
            return BotAgentInspector.isAgent(agent);
        }
    };
}

From source file:org.hippoecm.frontend.util.RequestUtils.java

License:Apache License

/**
 * Returns the remote host addresses related to this request.
 * If there's any proxy server between the client and the server,
 * then the proxy addresses are contained in the returned array.
 * The lowest indexed element is the farthest downstream client and
 * each successive proxy addresses are the next elements.
 * @param request wicket request/*from   w w w.j a  v a2 s .co m*/
 * @return remote host addresses as non-null string array
 */
public static String[] getRemoteAddrs(final Request request) {
    if (request instanceof WebRequest) {
        WebRequest webRequest = (WebRequest) request;

        String headerName = getForwardedForHeaderName(webRequest);
        String headerValue = webRequest.getHeader(headerName);

        if (headerValue != null && headerValue.length() > 0) {
            String[] addrs = headerValue.split(",");
            for (int i = 0; i < addrs.length; i++) {
                addrs[i] = addrs[i].trim();
            }
            return addrs;
        } else if (webRequest.getContainerRequest() instanceof ServletRequest) {
            final ServletRequest servletRequest = (ServletRequest) webRequest.getContainerRequest();
            return new String[] { servletRequest.getRemoteAddr() };
        }
    }

    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.jaulp.wicket.base.application.seo.DisableJSessionIDinUrlApplication.java

License:Apache License

/**
 * Disable sessionId in the url if it comes from a robot.
 * //  ww  w  .  ja va 2s  .c  om
 * @param webRequest
 *            the web request
 * @param httpServletResponse
 *            the http servlet response
 * @return the web response
 */
@Override
protected WebResponse newWebResponse(final WebRequest webRequest,
        final HttpServletResponse httpServletResponse) {
    return new ServletWebResponse((ServletWebRequest) webRequest, httpServletResponse) {

        @Override
        public String encodeURL(CharSequence url) {
            return isRobot(webRequest) ? url.toString() : super.encodeURL(url);
        }

        @Override
        public String encodeRedirectURL(CharSequence url) {
            return isRobot(webRequest) ? url.toString() : super.encodeRedirectURL(url);
        }

        private boolean isRobot(WebRequest request) {
            final String agent = webRequest.getHeader("User-Agent");
            return BotAgentInspector.isAgent(agent);
        }
    };
}

From source file:org.rest.annotations.security.HttpBasicAuthRoleCheckingStrategy.java

License:Apache License

@Override
public boolean hasAnyRole(Roles roles) {
    WebRequest currentWebRequest = AbstractRestResource.getCurrentWebRequest();
    String authorization = currentWebRequest.getHeader("Authorization");

    if (!Strings.isEmpty(authorization) && authorization.startsWith("Basic")) {
        String base64Credentials = authorization.substring("Basic".length()).trim();
        String credentials = new String(Base64.decodeBase64(base64Credentials));

        final String[] values = credentials.split(":", 2);

        return username.equals(values[0]) && password.equals(values[1]);
    }// w ww.  j a v  a 2s.c om

    return false;
}

From source file:org.wicketstuff.rest.utils.reflection.MethodParameter.java

License:Apache License

/**
 * Extract method parameter value from request header.
 *
 * @param headerParam the {@link HeaderParam} annotation used for the current method parameter.
 * @return the extracted value converted to argClass.
 *//* ww  w . ja  va  2s  .c om*/
private Object extractParameterFromHeader(HeaderParam headerParam) {
    String value = headerParam.value();
    WebRequest webRequest = AbstractRestResource.getCurrentWebRequest();

    return AbstractRestResource.toObject(parameterClass, webRequest.getHeader(value));
}

From source file:org.wicketstuff.security.login.http.HttpAuthenticationLoginPage.java

License:Apache License

@Override
protected void configureResponse(final WebResponse response) {
    super.configureResponse(response);
    if (doAuthentication) {
        WebRequest request = (WebRequest) RequestCycle.get().getRequest();
        String auth = request.getHeader("Authorization");
        if (Strings.isEmpty(auth))
            requestAuthentication(request, response);
        else {//from w w w  . jav a  2 s  . com
            int index = auth.indexOf(' ');
            if (index < 1)
                requestAuthentication(request, response);
            String type = auth.substring(0, index);
            try {
                handleAuthentication(request, response, type, auth.substring(index + 1));
            } catch (LoginException e) {
                log.error(type + " Http authentication failed", e);
                error(e);
                requestAuthentication(request, response);
            }
        }
    }
}

From source file:org.xaloon.wicket.component.security.AuthenticatedWebApplication.java

License:Apache License

@Override
protected org.apache.wicket.request.http.WebResponse newWebResponse(
        final org.apache.wicket.request.http.WebRequest webRequest,
        javax.servlet.http.HttpServletResponse httpServletResponse) {
    return new ServletWebResponse((ServletWebRequest) webRequest, httpServletResponse) {
        @Override/*from w  w  w . j av a  2  s.co m*/
        public String encodeURL(CharSequence url) {
            final String agent = webRequest.getHeader("User-Agent");
            return isAgent(agent) ? url.toString() : super.encodeURL(url).toString();
        }
    };
}

From source file:sf.wicklet.gwt.server.ajax.impl.GwtAjaxWickletTarget.java

License:Apache License

/**
 * @return the markup id of the focused element in the browser
 *//*  w  w w  .  j  a va2 s.  c o m*/
@Override
public String getFocus() {
    final WebRequest request = (WebRequest) page.getRequest();
    final String id = request.getHeader("Wicket-FocusedElementId");
    return Strings.isEmpty(id) ? null : id;
}