Example usage for javax.servlet.http HttpServletRequest getRemoteUser

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

Introduction

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

Prototype

public String getRemoteUser();

Source Link

Document

Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

Usage

From source file:org.openhab.io.rest.internal.resources.ContextResource.java

/***************************************************************************************
 * /*from   ww w .j a  v a  2s  .  c o  m*/
 * PUT request on /rest/context/<scriptFile>/<arg1>/<arg2>
 *
 *       will execute scriptFile.PUT.bat (Windows OS) OR scriptFile.PUT.sh (*NIX OS)
 *       located at openhab runtime folder /contexts
 * 
 *     Arguments passed on to the script are (no spaces allowed): 
 *          a) Cookie Parameter "uid" value ("0" if missing)
 *          b) Path Parameters "arg1" & "arg2" (required)
 *          c) PayLoad of Request (in PLAIN TEXT, spaces allowed)
 *       
 *       Results printed to stdout are returned as PLAIN TEXT in response body.
 * 
 *************************************************************************************/
@PUT
@Path("/{scriptfile: [a-zA-Z_0-9]*}/{arg1: [a-zA-Z_0-9]*}/{arg2: [a-zA-Z_0-9]*}")
@Consumes({ MediaType.TEXT_PLAIN })
@Produces({ MediaType.TEXT_PLAIN })
public Response callShellScriptWithDataAndSendReturnValue(@PathParam("scriptfile") String scriptFile,
        @PathParam("arg1") @DefaultValue("0") String Arg1, @PathParam("arg2") @DefaultValue("0") String Arg2,
        @QueryParam("que1") @DefaultValue("0") String Que1, @QueryParam("que2") @DefaultValue("0") String Que2,
        @QueryParam("type") @DefaultValue("0") String Type, @CookieParam("uid") @DefaultValue("0") String UID,
        @HeaderParam("If-None-Match") @DefaultValue("0") String INM,
        @HeaderParam("Timeout") @DefaultValue("10000") Integer TimeOut, @Context HttpServletRequest request,
        String value) {

    if (Type.equals(""))
        Type = "0";
    //         final String responseType = getResponseMediaType(Type);

    String uid = "0";
    if (request.getRemoteUser() != null)
        uid = request.getRemoteUser();
    else
        uid = UID;

    if (INM.equals("0"))
        INM = "0";

    if (Arg1.equals(""))
        Arg1 = "0";
    if (Arg2.equals(""))
        Arg2 = "0";

    if (Que1.equals(""))
        Que1 = "0";
    if (Que2.equals(""))
        Que2 = "0";

    if (TimeOut.equals(""))
        TimeOut = 10000;
    else
        TimeOut = TimeOut - 500;

    //file extention according to Op.Sys.
    String ext = "sh";
    if (SystemUtils.IS_OS_WINDOWS)
        ext = "bat";

    if (scriptFile.equals(""))
        scriptFile = "0";
    String fileName = scriptFile + ".PUT." + ext;
    File f = new File("contexts/" + fileName);

    //check if scriptfile exists
    if (f.exists() && !f.isDirectory()) {

        String result = Exec.executeCommandLine(
                "contexts/" + fileName + " " + uid + " " + Arg1 + " " + Arg2 + " " + value, TimeOut);

        if (result != null) {
            if (Type != "0")
                return Response.ok(result).build();
            else
                return Response.status(201).build();
        } else {
            logger.info("HTTP PUT request at '{}' for scriptFile '{}' returned null", uriInfo.getPath(),
                    scriptFile);
            return Response.status(404).build();
        }
    } else
        return Response.status(404).build();
}

From source file:org.kuali.rice.ken.web.spring.NotificationController.java

/**
 * This method handles displaying the search screen.
 * @param request/*from   www.j ava2 s.  com*/
 * @param response
 * @return ModelAndView
 * @throws ServletException
 * @throws IOException
 */
public ModelAndView displaySearch(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String view = "Search";
    LOG.debug("remoteUser: " + request.getRemoteUser());
    Map<String, Object> model = new HashMap<String, Object>();
    return new ModelAndView(view, model);
}

From source file:org.kuali.rice.ken.web.spring.NotificationController.java

/**
 * Handles the display of the main home page in the system.
 * @param request : a servlet request/*from  w w  w  .ja  v a2 s.  c  o  m*/
 * @param response : a servlet response
 * @throws ServletException : an exception
 * @throws IOException : an exception
 * @return a ModelAndView object
 */
public ModelAndView displayHome(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String view = "HomePage";
    LOG.debug("remoteUser: " + request.getRemoteUser());
    Map<String, Object> model = new HashMap<String, Object>();
    return new ModelAndView(view, model);
}

From source file:org.kuali.rice.ken.web.spring.NotificationController.java

/**
 * This method displays the user lookup screen.
 * @param request/*  ww w.j a v  a  2 s. c  o  m*/
 * @param response
 * @return
 * @throws ServletException
 * @throws IOException
 */
public ModelAndView displayLookupUsers(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String view = "LookupUsers";
    LOG.debug("remoteUser: " + request.getRemoteUser());
    Map<String, Object> model = new HashMap<String, Object>();
    return new ModelAndView(view, model);
}

From source file:alpha.portal.webapp.controller.DashBoardController.java

/**
 * Accept request.// ww  w  .j  a v a2  s . c om
 * 
 * @param contributorRequest
 *            the contributor request
 * @param errors
 *            the errors
 * @param request
 *            the request
 * @return the string
 * @throws Exception
 *             the exception
 */
@RequestMapping(method = RequestMethod.POST, params = { "acceptRequest" })
public String acceptRequest(final ContributorRequest contributorRequest, final BindingResult errors,
        final HttpServletRequest request) throws Exception {

    // get the current user
    final String reqId = request.getParameter("sel");

    final ContributorRequest contrReq = this.contrReqManager.get(Long.parseLong(reqId));
    if (contrReq == null) {
        // TODO Error
    }

    final User currentUser = this.userManager.getUserByUsername(request.getRemoteUser());

    final AlphaCard aCard = contrReq.getAlphaCard();

    aCard.getAlphaCase().addParticipant(currentUser);
    this.caseManager.save(aCard.getAlphaCase());
    aCard.getAlphaCardDescriptor().setAdornment(AdornmentType.Contributor.getName(),
            currentUser.getId().toString());
    this.alphaCardManager.save(aCard);

    this.contrReqManager.remove(Long.parseLong(reqId));

    return "redirect:/dashBoard";
}

From source file:org.kuali.rice.ken.web.spring.NotificationController.java

/**
 * This method displays the workgroup lookup screen.
 * @param request//  w  w  w  .  ja v  a  2  s .  c o  m
 * @param response
 * @return
 * @throws ServletException
 * @throws IOException
 */
public ModelAndView displayLookupWorkgroups(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String view = "LookupWorkgroups";
    LOG.debug("remoteUser: " + request.getRemoteUser());
    Map<String, Object> model = new HashMap<String, Object>();
    return new ModelAndView(view, model);
}

From source file:org.kuali.mobility.academics.controllers.AcademicsAuthControllerImpl.java

@SuppressWarnings("unchecked")
@RequestMapping(value = "/gradeAlerts", method = RequestMethod.GET)
public String gradeAlerts(HttpServletRequest request, Model uiModel) {
    if ("3".equalsIgnoreCase(getKmeProperties().getProperty("kme.uiVersion", "classic"))) {
        return "ui3/academics/gradeAlerts";
    }// www.  j  a  va  2  s  .  c o m

    LOG.debug("REMOTE_USER is " + request.getRemoteUser());
    HttpSession session = request.getSession();
    if (session == null) {
        LOG.error("HttpSession is NULL!");
    } else {
        User user = (User) session.getAttribute(AuthenticationConstants.KME_USER_KEY);
        if (user != null) {
            LOG.debug("gradeAlerts: User is [" + user.getLoginName() + "] and should be ["
                    + request.getRemoteUser() + "]");
            LOG.debug("gradeAlerts: User's opt-in status is:"
                    + user.getAttribute(AcademicsConstants.USER_ATTR_GRADEALERT));
        } else {
            LOG.debug("gradeAlerts: User is null.");
        }
        String optInStatus;
        List<UserAttribute> attributes = user.getAttribute(AcademicsConstants.USER_ATTR_GRADEALERT);
        if (attributes == null || attributes.isEmpty()) {
            optInStatus = "off";
        } else if (attributes.size() == 1) {
            optInStatus = attributes.get(0).getAttributeValue();
        } else {
            // This case shouldn't ever happen.  There should never be more than one
            // attribute for this particular key.
            optInStatus = attributes.get(0).getAttributeValue();
            user.clearAttribute(AcademicsConstants.USER_ATTR_GRADEALERT);
            getUserDao().saveUser(user);
            user.addAttribute(AcademicsConstants.USER_ATTR_GRADEALERT, optInStatus);
            getUserDao().saveUser(user);
        }
        uiModel.addAttribute("gradeAlertOpt", optInStatus);
        uiModel.addAttribute("toolContext", "myAcademics");
        uiModel.addAttribute(AcademicsConstants.BACKBUTTON_URL, request.getContextPath() + "/academics");

        // for test push notification
        //NativeCookieInterceptor.SESSION_PLATFORM
        LOG.debug("platform = " + session.getAttribute("session_platform"));
        LOG.debug("native = " + session.getAttribute("session_native"));
        uiModel.addAttribute("platform", session.getAttribute("session_platform"));
        uiModel.addAttribute("native", session.getAttribute("session_native"));

    }
    if (request != null) {
        updateDeviceLinking(request);
    }

    return "academics/gradeAlerts";
}

From source file:org.kuali.rice.ken.web.spring.NotificationController.java

/**
 * This method handles displaying the notifications that an individual sent.
 * @param request/*from   w w  w  .  ja v  a2s .  c o  m*/
 * @param response
 * @return ModelAndView
 * @throws ServletException
 * @throws IOException
 */
public ModelAndView displayNotificationsSent(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String view = "NotificationsSent";
    LOG.debug("remoteUser: " + request.getRemoteUser());
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("userId", request.getRemoteUser());
    return new ModelAndView(view, model);
}

From source file:com.openkm.servlet.admin.LogCatServlet.java

/**
 * List logs// w w  w .  ja v  a  2  s  . c o m
 */
private void list(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("list({}, {})", request, response);
    ServletContext sc = getServletContext();
    sc.setAttribute("files", FileUtils.listFiles(logFolder, null, false));
    sc.getRequestDispatcher("/admin/logcat.jsp").forward(request, response);

    // Activity log
    UserActivity.log(request.getRemoteUser(), "ADMIN_LOGCAT_LIST", null, null, logFolder.getPath());

    log.debug("list: void");
}