Example usage for javax.servlet ServletRequest getParameter

List of usage examples for javax.servlet ServletRequest getParameter

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getParameter.

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:org.xwoot.xwootApp.web.XWootSite.java

public Properties updateXWootPropertiesFromRequest(ServletRequest request, String xwootPropertiesPath) {
    Properties p = getProperties(xwootPropertiesPath);
    p.put(XWootSite.XWOOT_WORKING_DIR, request.getParameter(XWootSite.XWOOT_WORKING_DIR));
    p.put(XWootSite.XWOOT_SERVER_NAME, request.getParameter(XWootSite.XWOOT_SERVER_NAME));

    return p;/*from   w w w  . j  a va  2 s  .  com*/
}

From source file:com.parleys.server.frontend.web.ipad.filters.LoginFilter.java

@Override
public void doFilter(final ServletRequest req, final ServletResponse response, final FilterChain chain)
        throws IOException {
    final HttpServletResponse res = (HttpServletResponse) response;
    final PrintWriter writer = res.getWriter();
    res.setStatus(HttpServletResponse.SC_OK);
    res.setHeader("Cache-Control", "must-revalidate");
    res.setHeader("Expires", "Fri, 30 Oct 1998 14:19:41 GMT");
    try {//from   w ww . jav a 2 s.  c  om
        final String username = req.getParameter("username");
        final String password = req.getParameter("password");
        if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
            final ParleysService bean = applicationContext.getBean(ParleysService.class);
            final Long userId = bean.getUserId(username, password);

            final String usernameAndPassword = username + ";" + password;
            final String encrypted = AESEncrypter.INSTANCE.encrypt(usernameAndPassword);
            final Cookie rememberMeCookie = new Cookie(PARLEYS_REMEMBER_ME_IPAD, encrypted);
            rememberMeCookie.setMaxAge(3600 * 24 * 7 * 26); // A half year
            res.addCookie(rememberMeCookie);

            writeUserId(writer, userId);
        } else {
            writeError(writer);
        }
    } catch (Exception e) {
        writeError(writer);
    }
}

From source file:com.stormpath.spring.boot.examples.filter.ReCaptchaFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    if (!(req instanceof HttpServletRequest)
            || !("POST".equalsIgnoreCase(((HttpServletRequest) req).getMethod()))) {
        chain.doFilter(req, res);//from   w ww. j a  v a2 s.c o  m
        return;
    }

    PostMethod method = new PostMethod(RECAPTCHA_URL);
    method.addParameter("secret", RECAPTCHA_SECRET);
    method.addParameter("response", req.getParameter(RECAPTCHA_RESPONSE_PARAM));
    method.addParameter("remoteip", req.getRemoteAddr());

    HttpClient client = new HttpClient();
    client.executeMethod(method);
    BufferedReader br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
    String readLine;
    StringBuffer response = new StringBuffer();
    while (((readLine = br.readLine()) != null)) {
        response.append(readLine);
    }

    JSONObject jsonObject = new JSONObject(response.toString());
    boolean success = jsonObject.getBoolean("success");

    if (success) {
        chain.doFilter(req, res);
    } else {
        ((HttpServletResponse) res).sendError(HttpStatus.BAD_REQUEST.value(), "Bad ReCaptcha");
    }
}

From source file:es.pode.soporte.seguridad.openId.ui.openid.OpenIDAuthenticationProcessingFilter.java

protected String obtainUsername(ServletRequest req) {
    return req.getParameter(claimedIdentityFieldName);

}

From source file:com.threeti.proxy.RequestFilter.java

private String getParams(ServletRequest req) {
    StringBuffer params = new StringBuffer();
    Enumeration<String> keys = req.getParameterNames();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        try {//from   w  w  w  .j av  a  2 s  . c om
            // params.append(key).append("=").append(URLEncoder.encode(req.getParameter(key), "UTF-8")).append("&");
            params.append(key).append("=").append(req.getParameter(key)).append("&");
            //            if("".equals(req.getParameter(key))){
            //               params.append(key);
            //            }else{
            //               
            //            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    System.out.println(params.toString());
    return params.toString();
}

From source file:com.ultrapower.eoms.common.plugin.ecside.filter.ECSideFilter.java

public String getEasyList(ServletRequest servletRequest){
   String easyDataAccess=null;/* w w  w.ja  va2s  . c  om*/
   if (useEasyDataAccess){
      try{
         easyDataAccess=servletRequest.getParameter(ECSideConstants.EASY_DATA_LIST_FLAG);
      }catch(Exception e){
         easyDataAccess=null;
      }
   }
    return StringUtils.isNotBlank(easyDataAccess)?easyDataAccess:null;
}

From source file:edu.harvard.i2b2.fhir.oauth2.ws.PublicClientFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    String url = ((HttpServletRequest) request).getRequestURL().toString();
    logger.info("url:" + url);
    //if(!url.startsWith("/token")) return;

    String msg = "";
    Enumeration<String> kl = request.getParameterNames();
    while (kl.hasMoreElements()) {
        String k = kl.nextElement();
        msg += k + "->" + request.getParameter(k) + "\n";
    }/*from  w ww. j  av  a  2  s  . c o m*/
    logger.info(msg);

    chain.doFilter(new PublicClientWrapper((HttpServletRequest) request), response);
}

From source file:org.egov.lib.rrbac.filter.RuleInterceptorFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    // from action, for which actions rule should be applied expecting parameter with name
    // AUTHRULE_OBJECT_ID and value is id of the
    // product entity. Eg : In case of PTIS BasicPoperty primary key
    if (request.getParameter("AUTHRULE_OBJECT_ID") != null) {
        final HttpServletRequest httpRequest = (HttpServletRequest) request;
        final Action action = this.getAction(httpRequest);
        final List<AuthorizationRule> authRuleList = this.authRuleService
                .findAllByNamedQuery("authRulesByAction", action);
        for (final AuthorizationRule authRule : authRuleList) {
            final Object object = this.getEntity(httpRequest, authRule);
            final List authResList = this.getRuleAuthentication(securityUtils.getCurrentUser(), authRule,
                    object);//from www.j  a va  2  s.  com
            final boolean authorized = Boolean.valueOf(authResList.get(0).toString());
            if (!authorized) {
                // if authorization fails throwing AuthorizationException
                // setting message key to request, from script when authorization failed
                request.setAttribute("AuthRuleErrMsgKey", authResList.get(1).toString());
                throw new AuthorizationException(authResList.get(1).toString());
            }
        }
    }
    chain.doFilter(request, response);
}

From source file:org.infoscoop.admin.web.PreviewImpersonationFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    request.setAttribute(IS_PREVIEW, Boolean.TRUE);

    Subject previewUser = new Subject();

    List<String> principals = new ArrayList<String>();

    String uidParam = request.getParameter(ISPrincipal.UID_PRINCIPAL);
    if (uidParam != null) {
        principals.add(ISPrincipal.UID_PRINCIPAL);
        principals.add(uidParam);/*ww w .j  av a  2  s. co  m*/
        previewUser.getPrincipals().add(new ISPrincipal(ISPrincipal.UID_PRINCIPAL, uidParam));
    }
    for (PrincipalDef def : SessionCreateConfig.getInstance().getPrincipalDefs()) {
        String[] principalValues = request.getParameterValues(def.getType());
        if (principalValues != null) {
            for (int i = 0; i < principalValues.length; i++) {
                if (log.isInfoEnabled())
                    log.info("Set preview principal: PrincipalType=" + def.getType() + ", name="
                            + principalValues[i] + ".");

                principals.add(def.getType());
                principals.add(principalValues[i]);
                previewUser.getPrincipals().add(new ISPrincipal(def.getType(), principalValues[i]));
            }
        }
    }

    // Principal retrieved from AccountManager set AuthenticationService
    AuthenticationService service = AuthenticationService.getInstance();
    IAccountManager manager = null;
    if (service != null)
        manager = service.getAccountManager();
    if (manager != null) {
        for (PrincipalDef def : manager.getPrincipalDefs()) {
            String roleType = def.getType();
            String[] principalValues = request.getParameterValues(roleType);

            for (int i = 0; principalValues != null && i < principalValues.length; i++) {
                if (log.isInfoEnabled())
                    log.info("Set preview principal: PrincipalType=" + roleType + ", name=" + principalValues[i]
                            + ".");
                principals.add(def.getType());
                principals.add(principalValues[i]);
                previewUser.getPrincipals().add(new ISPrincipal(roleType, principalValues[i]));
            }
        }
    }

    request.setAttribute(PRINCIPAL_PARAMS, principals);

    SetPrincipalHttpServletRequest reqwrapper = new SetPrincipalHttpServletRequest((HttpServletRequest) request,
            previewUser);
    filterChain.doFilter(reqwrapper, response);
}

From source file:com.iflytek.edu.cloud.frame.web.filter.ServiceMetricsFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    //HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    StatHttpServletResponseWrapper responseWrapper = new StatHttpServletResponseWrapper(httpResponse);

    final String method = request.getParameter(Constants.SYS_PARAM_KEY_METHOD);
    final String appkey = request.getParameter(Constants.SYS_PARAM_KEY_APPKEY);
    long startNano = System.nanoTime();
    long startMillis = System.currentTimeMillis();

    serviceAppStat.beforeInvoke();/*from www.  j  a  v  a  2s  .c om*/

    ServiceMethodStat methodStat = serviceAppStat.getMethodStat(appkey, method);
    if (methodStat == null) {
        methodStat = serviceAppStat.getMethodStat(appkey, method);
    }

    if (methodStat != null) {
        methodStat.beforeInvoke(startMillis);
    }

    Throwable error = null;
    try {
        chain.doFilter(request, responseWrapper);
    } catch (IOException e) {
        error = e;
        throw e;
    } catch (ServletException e) {
        error = e;
        throw e;
    } catch (RuntimeException e) {
        error = e;
        throw e;
    } catch (Error e) {
        error = e;
        throw e;
    } finally {
        long endNano = System.nanoTime();
        long nanos = endNano - startNano;
        serviceAppStat.afterInvoke(error, nanos);

        if (methodStat != null) {
            methodStat.afterInvoke(error, nanos);
            request.setAttribute(SERVICE_EXEC_TIME, nanos / (1000 * 1000));
        }
    }
}