Example usage for javax.servlet.http HttpServletRequest getAttribute

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

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:de.itsvs.cwtrpc.security.RpcSessionManagementFilter.java

@SuppressWarnings("unchecked")
public static void saveAppliedSessionAuthenticationStrategy(HttpServletRequest request,
        SessionAuthenticationStrategy strategy) {
    List<Class<? extends SessionAuthenticationStrategy>> appliedStrategies;

    appliedStrategies = (List<Class<? extends SessionAuthenticationStrategy>>) request
            .getAttribute(APPLIED_SESSION_AUTHENTICATION_STRATEGIES_ATTR_NAME);
    if (appliedStrategies == null) {
        appliedStrategies = new ArrayList<Class<? extends SessionAuthenticationStrategy>>();
    }//from w w w  .j  av  a 2 s  .  co  m
    appliedStrategies.add(strategy.getClass());
    request.setAttribute(APPLIED_SESSION_AUTHENTICATION_STRATEGIES_ATTR_NAME, appliedStrategies);
}

From source file:de.itsvs.cwtrpc.security.RpcSessionManagementFilter.java

@SuppressWarnings("unchecked")
public static boolean appliedSessionAuthenticationStrategy(HttpServletRequest request,
        SessionAuthenticationStrategy strategy) {
    List<Class<? extends SessionAuthenticationStrategy>> appliedStrategies;

    appliedStrategies = (List<Class<? extends SessionAuthenticationStrategy>>) request
            .getAttribute(APPLIED_SESSION_AUTHENTICATION_STRATEGIES_ATTR_NAME);
    if (appliedStrategies == null) {
        return false;
    }//from w ww .  jav  a 2s  .  c  o  m

    return appliedStrategies.contains(strategy.getClass());
}

From source file:com.us.reflect.ClassFinder.java

private static Object[] getRuntimeArgs(ActionInvocation invocation, String[] paramers) {
    List<Object> runtime = new LinkedList<Object>();
    HttpServletRequest request = ServletActionContext.getRequest();// HttpServletRequest
    for (String param : paramers) {
        char index0 = param.charAt(0);
        String parname = param.substring(1);
        if (index0 == '#') { // Session ??
            runtime.add(request.getSession().getAttribute(parname));
        } else if (index0 == '$') {
            runtime.add(request.getAttribute(parname));
        } else if (index0 == '@' && parname.equals("request")) {
            runtime.add(request);/*from   w  w w .j a v a  2s  .  co m*/
        } else if (index0 == '@' && parname.equals("response")) {
            runtime.add(ServletActionContext.getResponse());
        } else {
            runtime.add(DaoHelper.getBeanById(param));
        }
    }
    return runtime.toArray(new Object[] {});
}

From source file:de.knowwe.core.kdom.rendering.RenderResult.java

private static String createMaskKey(HttpServletRequest request) {
    Object storedMaskKey = request.getAttribute(storeKey);
    if (storedMaskKey != null)
        return (String) storedMaskKey;

    int rnd = Math.abs(new Random().nextInt());
    String maskKey = Integer.toString(rnd, Character.MAX_RADIX);
    request.setAttribute(storeKey, maskKey);
    return maskKey;
}

From source file:com.glaf.base.utils.ParamUtil.java

/**
 * ?attribute//from   w  w  w .  j a v  a  2 s  . c  o  m
 * 
 * @param request
 *            HttpServletRequest request
 * @param param
 *            String ?
 * @param value
 *            String 
 * @return boolean ?true?false
 */
public static boolean getBooleanAttribute(HttpServletRequest request, String param, String value) {
    String temp = (String) request.getAttribute(param);
    if (temp != null && temp.equals(value)) {
        return true;
    } else {
        return false;
    }
}

From source file:org.craftercms.core.util.HttpServletUtils.java

public static Map<String, Object> createRequestAttributesMap(HttpServletRequest request) {
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    for (Enumeration attributeNameEnum = request.getAttributeNames(); attributeNameEnum.hasMoreElements();) {
        String attributeName = (String) attributeNameEnum.nextElement();

        attributesMap.put(attributeName, request.getAttribute(attributeName));
    }/*from w  ww  . j  a v a  2 s .com*/

    return attributesMap;
}

From source file:com.glaf.base.utils.ParamUtil.java

/**
 * ?attribute/*from w  w w. j  a  v  a  2 s. c  om*/
 * 
 * @param request
 *            HttpServletRequest request
 * @param param
 *            String ?
 * @param defaultValue
 *            String ?
 * @return String 
 */
public static String getAttribute(HttpServletRequest request, String param, String defaultValue) {
    String value = (String) request.getAttribute(param);
    if (value == null) {
        if (defaultValue != null)
            value = defaultValue;
        else
            value = "";
    }
    return value;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.ManageShiftDA.java

static List getExecutionCourses(HttpServletRequest request) throws Exception {

    List infoCourseList = new ArrayList();

    // Ler Disciplinas em Execucao
    InfoCurricularYear infoCurricularYear = (InfoCurricularYear) request
            .getAttribute(PresentationConstants.CURRICULAR_YEAR);
    InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) request
            .getAttribute(PresentationConstants.EXECUTION_DEGREE);
    AcademicInterval academicInterval = AcademicInterval.getAcademicIntervalFromResumedString(
            (String) request.getAttribute(PresentationConstants.ACADEMIC_INTERVAL));

    infoCourseList = LerDisciplinasExecucaoDeLicenciaturaExecucaoEAnoCurricular.run(infoExecutionDegree,
            academicInterval, infoCurricularYear.getYear());

    request.setAttribute(PresentationConstants.EXECUTION_COURSE_LIST_KEY, infoCourseList);

    return infoCourseList;

}

From source file:com.ofbizcn.securityext.login.LoginEvents.java

/** Show the password hint for the userLoginId specified in the request object.
 *@param request The HTTPRequest object for the current request
 *@param response The HTTPResponse object for the current request
 *@return String specifying the exit status of this event
 *///w w w . j  a v  a2 s .c o m
public static String showPasswordHint(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");

    String userLoginId = request.getParameter("USERNAME");
    String errMsg = null;

    if ((userLoginId != null) && ("true".equals(
            EntityUtilProperties.getPropertyValue("security.properties", "username.lowercase", delegator)))) {
        userLoginId = userLoginId.toLowerCase();
    }

    if (!UtilValidate.isNotEmpty(userLoginId)) {
        // the password was incomplete
        errMsg = UtilProperties.getMessage(resource, "loginevents.username_was_empty_reenter",
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    GenericValue supposedUserLogin = null;

    try {
        supposedUserLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", userLoginId)
                .queryOne();
    } catch (GenericEntityException gee) {
        Debug.logWarning(gee, "", module);
    }
    if (supposedUserLogin == null) {
        // the Username was not found
        errMsg = UtilProperties.getMessage(resource, "loginevents.username_not_found_reenter",
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    String passwordHint = supposedUserLogin.getString("passwordHint");

    if (!UtilValidate.isNotEmpty(passwordHint)) {
        // the Username was not found
        errMsg = UtilProperties.getMessage(resource,
                "loginevents.no_password_hint_specified_try_password_emailed", UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    Map<String, String> messageMap = UtilMisc.toMap("passwordHint", passwordHint);
    errMsg = UtilProperties.getMessage(resource, "loginevents.password_hint_is", messageMap,
            UtilHttp.getLocale(request));
    request.setAttribute("_EVENT_MESSAGE_", errMsg);
    return "success";
}

From source file:grails.converters.XML.java

/**
 * Parses the give XML (read from the POST Body of the Request)
 *
 * @param request an HttpServletRequest/*from  w w  w .j  av a  2  s.  co m*/
 * @return a groovy.util.XmlSlurper
 * @throws ConverterException
 */
public static Object parse(HttpServletRequest request) throws ConverterException {
    Object xml = request.getAttribute(CACHED_XML);
    if (xml != null)
        return xml;

    String encoding = request.getCharacterEncoding();
    if (encoding == null) {
        encoding = Converter.DEFAULT_REQUEST_ENCODING;
    }
    try {
        if (!request.getMethod().equalsIgnoreCase("GET")) {
            xml = parse(request.getInputStream(), encoding);
            request.setAttribute(CACHED_XML, xml);
        }
        return xml;
    } catch (IOException e) {
        throw new ConverterException("Error parsing XML", e);
    }
}