List of usage examples for javax.servlet.http HttpServletRequest getUserPrincipal
public java.security.Principal getUserPrincipal();
java.security.Principal
object containing the name of the current authenticated user. From source file:nl.b3p.kaartenbalie.struts.UserAction.java
@Override public ActionForward deleteConfirm(ActionMapping mapping, DynaValidatorForm dynaForm, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("Getting entity manager ......"); EntityManager em = getEntityManager(); User user = getUser(dynaForm, request, false); if (user == null) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, NOTFOUND_ERROR_KEY); return getAlternateForward(mapping, request); }// www. j a v a2s . c o m User sessionUser = (User) request.getUserPrincipal(); if (sessionUser.getId().equals(user.getId())) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, DELETE_ADMIN_ERROR_KEY); return getAlternateForward(mapping, request); } MessageResources messages = getResources(request); Locale locale = getLocale(request); String lastJoinedMessage = messages.getMessage(locale, LAST_JOINED_KEY); Organization org = user.getMainOrganization(); Set userList = null; if (org != null) { userList = org.getUsers(); } if (userList == null || userList.size() <= 1) { addAlternateMessage(mapping, request, null, lastJoinedMessage); } prepareMethod(dynaForm, request, DELETE, EDIT); addDefaultMessage(mapping, request, ACKNOWLEDGE_MESSAGES); return getDefaultForward(mapping, request); }
From source file:org.apache.hadoop.hdfs.server.namenode.DelegationTokenServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final UserGroupInformation ugi; try {//from w w w . jav a2 s. c om ugi = getUGI(req, new Configuration()); } catch (IOException ioe) { LOG.info("Request for token received with no authentication from " + req.getRemoteAddr(), ioe); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Unable to identify or authenticate user"); return; } LOG.info("Sending token: {" + ugi.getUserName() + "," + req.getRemoteAddr() + "}"); final ServletContext context = getServletContext(); final NameNode nn = (NameNode) context.getAttribute("name.node"); DataOutputStream dos = null; try { dos = new DataOutputStream(resp.getOutputStream()); final DataOutputStream dosFinal = dos; // for doAs block ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { Token<DelegationTokenIdentifier> token = nn .getDelegationToken(new Text(req.getUserPrincipal().getName())); String s = nn.rpcAddress.getAddress().getHostAddress() + ":" + nn.rpcAddress.getPort(); token.setService(new Text(s)); TokenStorage ts = new TokenStorage(); ts.addToken(new Text(ugi.getShortUserName()), token); ts.write(dosFinal); dosFinal.close(); return null; } }); } catch (Exception e) { LOG.info("Exception while sending token. Re-throwing. ", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { if (dos != null) dos.close(); } }
From source file:org.apache.geode.tools.pulse.internal.controllers.PulseController.java
@RequestMapping(value = "/dataBrowserExport", method = RequestMethod.GET) public void dataBrowserExport(HttpServletRequest request, HttpServletResponse response) throws IOException { // get query string String query = request.getParameter("query"); String members = request.getParameter("members"); int limit = 0; try {/*from w w w .j a va 2 s .c o m*/ limit = Integer.valueOf(request.getParameter("limit")); } catch (NumberFormatException e) { limit = 0; if (LOGGER.finerEnabled()) { LOGGER.finer(e.getMessage()); } } ObjectNode queryResult = mapper.createObjectNode(); try { if (StringUtils.isNotNullNotEmptyNotWhiteSpace(query)) { // get cluster object Cluster cluster = Repository.get().getCluster(); String userName = request.getUserPrincipal().getName(); // Call execute query method queryResult = cluster.executeQuery(query, members, limit); // Add query in history if query is executed successfully if (!queryResult.has("error")) { // Add html escaped query to history String escapedQuery = StringEscapeUtils.escapeHtml(query); cluster.addQueryInHistory(escapedQuery, userName); } } } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occured : " + e.getMessage()); } } response.setContentType("application/json"); response.setHeader("Content-Disposition", "attachment; filename=results.json"); response.getOutputStream().write(queryResult.toString().getBytes()); }
From source file:org.rti.zcore.dar.struts.action.PatientRecordListAction.java
protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { /*if (SystemStateManager.getCurrentState() != SystemStateManager.STATUS_NORMAL) { return mapping.findForward(LOCKED_FORWARD); }*/// w w w.j av a 2 s . c om HttpSession session = request.getSession(); Locale sessionLocale = (Locale) request.getAttribute("sessionLocale"); String sessionLocaleString = null; if ((sessionLocale.getLanguage() != null) && ((sessionLocale.getCountry() != null) && (!sessionLocale.getCountry().equals("")))) { sessionLocaleString = sessionLocale.getLanguage() + "_" + sessionLocale.getCountry(); } else if (sessionLocale.getLanguage() != null) { sessionLocaleString = sessionLocale.getLanguage(); } Principal user = request.getUserPrincipal(); String username = user.getName(); Connection conn = null; BaseEncounter encounter = null; Map encMap = null; Long formId = null; SessionSubject sessionPatient = null; Long patientId = null; //Long eventId = null; String eventUuid = null; Form encounterForm = null; String formName = null; if (mapping.getParameter() != null && !mapping.getParameter().equals("")) { formName = mapping.getParameter().trim(); formId = (Long) DynaSiteObjects.getFormNameMap().get(formName); } else { if (request.getParameter("formId") != null) { formId = Long.decode(request.getParameter("formId")); } else if (request.getAttribute("formId") != null) { formId = Long.decode(request.getAttribute("formId").toString()); } //formId = request.getAttribute("id").toString(); } if (request.getParameter("patientId") != null) { patientId = Long.decode(request.getParameter("patientId")); } else if (request.getAttribute("patientId") != null) { patientId = Long.decode(request.getAttribute("patientId").toString()); } try { sessionPatient = (SessionSubject) SessionUtil.getInstance(session).getSessionPatient(); //eventId = sessionPatient.getCurrentEventId(); eventUuid = sessionPatient.getCurrentEventUuid(); } catch (SessionUtil.AttributeNotFoundException e) { log.error("Unable to get TimsSessionSubject"); } if (patientId == null) { try { patientId = sessionPatient.getId(); } catch (Exception e) { log.error("Unable to get TimsSessionSubject field"); } } // sometimes the user can click link to create a new event and then click elsewhere. if (eventUuid == null) { String forwardString = "/listEvents.do?patientId=" + patientId; ActionForward forwardForm = new ActionForward(forwardString); forwardForm.setRedirect(true); return forwardForm; } encounterForm = ((Form) DynaSiteObjects.getForms().get(formId)); try { conn = DatabaseUtils.getZEPRSConnection(username); // populate the records for this class List chartItems = new ArrayList(); String classname = StringManipulation.fixClassname(encounterForm.getName()); Class clazz = Class.forName(Constants.getDynasiteFormsPackage() + "." + classname); try { ArrayList moreItems = (ArrayList) EncountersDAO.getAllOrderBy(conn, patientId, eventUuid, "SQL_RETRIEVE_UUID" + formId, clazz, "date_visit DESC"); chartItems.addAll(moreItems); } catch (IOException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } catch (ServletException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } catch (SQLException e) { request.setAttribute("exception", e); return mapping.findForward("error"); } // DAR-specific: if (formName.equals("PatientCondition")) { String bmiCalc = Constants.getProperties("bmi.calculate", Constants.getAPP_PROPERTIES()); if (bmiCalc != null && bmiCalc.equals("true")) { for (int i = 0; i < chartItems.size(); i++) { PatientCondition pc = (PatientCondition) chartItems.get(i); Float weight = pc.getWeight(); Float height = pc.getHeight(); if ((weight != null) && ((height != null) && (height != 0))) { Float bmi = HealthCalcUtils.bmiCalc(weight, height); pc.setBmi_calculated(bmi); } } } } // Attach a map of encounter values that has enumerations already resolved. MessageResources messageResources = getResources(request, encounterForm.getClassname() + "Messages"); String messageKey = encounterForm.getClassname() + "Messages"; ReloadablePropertyMessageResources messages = (ReloadablePropertyMessageResources) request .getAttribute(messageKey); //ZcorePropertyMessageResources sMessages = (ZcorePropertyMessageResources) messages; HashMap messageResourcesMap = messages.getMessages(); HashMap localeMap = messages.getLocales(); if (localeMap.get(sessionLocale.toString()) == null) { messages.loadLocale(sessionLocale.toString()); } // Attach a map of encounter values that has enumerations already resolved. Form encForm = (Form) DynaSiteObjects.getForms().get(encounterForm.getId()); for (int i = 0; i < chartItems.size(); i++) { encounter = (EncounterData) chartItems.get(i); encMap = PatientRecordUtils.getEncounterMap(encForm, encounter, "fieldId"); encounter.setEncounterMap(encMap); if (messageResourcesMap != null) { encounter.setMessageResourcesMap(messageResourcesMap); } } if (chartItems.size() > 0) { request.setAttribute("chartItems", chartItems); request.setAttribute("formId", encounterForm.getId()); // loading of body onload DWRUtil.useLoadingMessage() request.setAttribute("dwr", 1); } // Process the dynamic dropdown lists. HashMap listMap = new HashMap(); Form inlineForm = null; for (Iterator iterator = encounterForm.getPageItems().iterator(); iterator.hasNext();) { PageItem pageItem = (PageItem) iterator.next(); FormField formField = pageItem.getForm_field(); String identifier = formField.getIdentifier(); if (pageItem.getInputType().equals("dropdown") || pageItem.getInputType().equals("dropdown-add-one") || pageItem.getInputType().equals("dropdown_site")) { List list = WidgetUtils.getList(conn, pageItem.getDropdownTable(), pageItem.getDropdownColumn(), pageItem.getDropdownConstraint(), pageItem.getDropdownOrderByClause(), DropdownItem.class, pageItem.getFkIdentifier()); listMap.put(pageItem.getId(), list); if (pageItem.getInputType().equals("dropdown-add-one")) { String classNameString = StringManipulation.fixClassname(pageItem.getDropdownTable()); Long inlineFormId = (Long) DynaSiteObjects.getFormNameMap().get(classNameString); inlineForm = ((Form) DynaSiteObjects.getForms().get(new Long(inlineFormId))); // Create a list of fieldnames for inline forms. ArrayList<String> inlineFields = new ArrayList<String>(); for (Iterator iterator2 = inlineForm.getPageItems().iterator(); iterator2.hasNext();) { PageItem pageItem2 = (PageItem) iterator2.next(); if (pageItem2.getForm_field().isEnabled() == true && !pageItem2.getForm_field().getType().equals("Display")) { inlineFields.add(pageItem2.getForm_field().getIdentifier()); } } request.setAttribute("inlineForm_" + identifier, inlineForm); request.setAttribute("inlineFields_" + identifier, inlineFields); // loading of body onload DWRUtil.useLoadingMessage() request.setAttribute("dwr", 1); } } } request.setAttribute("listMap", listMap); request.setAttribute("encounterForm", encounterForm); // Keep this block at the end - it sets sessionPatient to null in certain circumstances. // Set the tasklist for particular circumstances. First check if the form requires a patient or if "id" is in the reqiest. if ((encounterForm.isRequirePatient() || ((request.getParameter("id") != null)))) { // we don't need the tasklist if we're just editing a form or it's in unassigned flow Long unassigned = new Long("100"); if (request.getParameter("id") == null) { if (!encounterForm.getFlow().getId().equals(unassigned)) { // moved code for form 66 below. } } Boolean status = Boolean.valueOf(true); List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("activeProblems", activeProblems); // now get inactive problems status = Boolean.valueOf(false); List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("inactiveProblems", inactiveProblems); // Display task list if editing form 1. } else if ((encounterForm.getId().intValue() == 1) & (patientId != null)) { Boolean status = Boolean.valueOf(true); List activeProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("activeProblems", activeProblems); // now get inactive problems status = Boolean.valueOf(false); List inactiveProblems = PatientRecordUtils.assembleProblemTaskList(conn, patientId, eventUuid, status, sessionPatient); request.setAttribute("inactiveProblems", inactiveProblems); // otherwise reset sessionPatient } else { SessionUtil.getInstance(session).setSessionPatient(null); } } catch (ServletException e) { log.error(e); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } encounterForm = null; return mapping.findForward("success"); }
From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java
@RequestMapping(value = "/dataBrowserQuery", method = RequestMethod.GET) public void dataBrowserQuery(HttpServletRequest request, HttpServletResponse response) throws IOException { // get query string String query = request.getParameter("query"); String members = request.getParameter("members"); int limit = 0; try {/*from w w w . ja v a 2 s .c o m*/ limit = Integer.valueOf(request.getParameter("limit")); } catch (NumberFormatException e) { limit = 0; if (LOGGER.finerEnabled()) { LOGGER.finer(e.getMessage()); } } ObjectNode queryResult = mapper.createObjectNode(); try { if (StringUtils.isNotNullNotEmptyNotWhiteSpace(query)) { // get cluster object Cluster cluster = Repository.get().getCluster(); String userName = request.getUserPrincipal().getName(); // Call execute query method queryResult = cluster.executeQuery(query, members, limit); // Add query in history if query is executed successfully if (!queryResult.has("error")) { // Add html escaped query to history String escapedQuery = StringEscapeUtils.escapeHtml(query); cluster.addQueryInHistory(escapedQuery, userName); } } } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occured : " + e.getMessage()); } } response.getOutputStream().write(queryResult.toString().getBytes()); }
From source file:org.openanzo.binarystore.server.BinaryStoreServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w ww.j a va 2 s. c o m if (req.getUserPrincipal() == null) { resp.setHeader(AUTH_HEADER, String.valueOf(HttpServletResponse.SC_UNAUTHORIZED)); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } if (servletPath == null) servletPath = req.getScheme() + "://" + req.getHeader("host") + req.getContextPath() + req.getServletPath(); String pathInfo = req.getPathInfo(); if (pathInfo.length() > 0 && pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); if (pathInfo.equals(NOOP)) { // Handle the NO-OP operation which is used to check proper authentication by clients before uploading a big file. // The 100-Continue HTTP dance unfortunately doesn't work too well due to poor support by clients and servers. So // this NOOP operation is an alternative. sendNOOPResponse(req, resp); return; } //a pool of anzoClients RestrictedAnzoClient ac = null; String user = null; try { try { ac = clientPool.getAnzoClient(true, "BinaryStoreOperation"); user = req.getUserPrincipal().getName(); RestrictedAnzoClient rac = ac; rac.setServiceUser(user); String runAsUser = req.getHeader(AUTHRUNAS_HEADER); if (runAsUser != null && runAsUser.length() > 0) { if (ac.getServicePrincipal().isSysadmin()) { rac.setServiceUser(runAsUser); } } } catch (AnzoException ae) { MDC.put(LogUtils.REMOTE_ADDRESS, req.getRemoteAddr()); log.error(LogUtils.BINARY_MARKER, Messages .formatString(ExceptionConstants.BINARYSTORE.BINARYSTORE_ERROR_PROCESSING_REQUEST), ae); MDC.clear(); resp.setContentType(RDFFormat.JSON.getDefaultMIMEType()); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); try { SerializationUtils.writeExceptionJSON(ae, resp.getWriter()); } catch (JSONException jsone) { log.debug(LogUtils.BINARY_MARKER, Messages.formatString(ExceptionConstants.IO.ERROR_SERIALIZING_JSON), jsone); } return; } if (pathInfo.equals(CREATE) || pathInfo.equals(UPDATE)) { try { createUpdate(ac, req, resp, pathInfo.equals(UPDATE)); } catch (AnzoException e) { MDC.put(LogUtils.REMOTE_ADDRESS, req.getRemoteAddr()); MDC.put(LogUtils.USER, user); log.info(LogUtils.BINARY_MARKER, Messages.formatString( ExceptionConstants.BINARYSTORE.BINARYSTORE_ERROR_PROCESSING_REQUEST), e); sendJSONError(req, resp, e); MDC.clear(); return; } } else if (pathInfo.equals(READ)) { String uri = req.getParameter(GRAPH); if (uri == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } RequestDispatcher dispatcher = req.getRequestDispatcher(uri); if (dispatcher != null) { dispatcher.forward(req, resp); return; } } else if (pathInfo.equals(DELETE)) { try { delete(ac, req, resp); } catch (AnzoException e) { MDC.put(LogUtils.REMOTE_ADDRESS, req.getRemoteAddr()); MDC.put(LogUtils.USER, user); log.info(LogUtils.BINARY_MARKER, Messages.formatString( ExceptionConstants.BINARYSTORE.BINARYSTORE_ERROR_PROCESSING_REQUEST), e); sendJSONError(req, resp, e); MDC.clear(); return; } } else { String uri = req.getRequestURL().toString(); int rc = HttpServletResponse.SC_NOT_FOUND; if (uri != null) { try { rc = read(ac, uri, req, resp); } catch (AnzoException e) { MDC.put(LogUtils.REMOTE_ADDRESS, req.getRemoteAddr()); MDC.put(LogUtils.USER, user); log.info(LogUtils.BINARY_MARKER, Messages.formatString( ExceptionConstants.BINARYSTORE.BINARYSTORE_ERROR_PROCESSING_REQUEST), e); sendJSONError(req, resp, e); MDC.clear(); return; } } if (rc != HttpServletResponse.SC_OK) resp.sendError(rc); } } finally { if (ac != null) { clientPool.returnAnzoClient(ac, true); } } } catch (JSONException ae) { MDC.put(LogUtils.REMOTE_ADDRESS, req.getRemoteAddr()); log.error(LogUtils.BINARY_MARKER, Messages.formatString(ExceptionConstants.BINARYSTORE.BINARYSTORE_ERROR_PROCESSING_REQUEST), ae); MDC.clear(); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); resp.getWriter().write(ae.getMessage()); } }
From source file:com.idega.slide.authentication.IWSlideAuthenticator.java
private HttpServletRequest setAsAuthenticatedInSlide(HttpServletRequest request, String loginName, LoggedOnInfo lInfo) throws HttpException, RemoteException, IOException { String slidePrincipal = loginName; //HttpServletRequest returnRequest = request; HttpSession session = request.getSession(); LoginBusinessBean loginBusiness = getLoginBusiness(request); if (loginBusiness.isLoggedOn(request)) { LoginSession loginSession = ELUtil.getInstance().getBean(LoginSession.class); if (loginSession.isSuperAdmin()) { String rootUserName = getAuthenticationBusiness(request).getRootUserCredentials().getUserName(); //iwc.setRequest(new IWSlideAuthenticatedRequest(iwc.getRequest(),rootUserName,Collections.singleton(rootUserName))); request = new IWSlideAuthenticatedRequest(request, rootUserName, Collections.singleton(rootUserName)); slidePrincipal = rootUserName; } else {/*from w w w. j av a2s.c o m*/ if (request.getUserPrincipal() == null && lInfo != null) { //if(iwc.getUserPrincipal()==null && lInfo != null){ //iwc.setRequest(new IWSlideAuthenticatedRequest(iwc.getRequest(),loginName,lInfo.getUserRoles())); request = new IWSlideAuthenticatedRequest(request, loginName, lInfo.getUserRoles()); } updateRolesForUser(request, lInfo); } } else { String rootUserName = getAuthenticationBusiness(request).getRootUserCredentials().getUserName(); if (loginName.equals(rootUserName)) { //iwc.setRequest(new IWSlideAuthenticatedRequest(iwc.getRequest(),loginName,Collections.singleton(rootUserName))); request = new IWSlideAuthenticatedRequest(request, rootUserName, Collections.singleton(rootUserName)); } else { //iwc.setRequest(new IWSlideAuthenticatedRequest(iwc.getRequest(),loginName,lInfo.getUserRoles())); request = new IWSlideAuthenticatedRequest(request, loginName, lInfo.getUserRoles()); updateRolesForUser(request, lInfo); } } //iwc.setSessionAttribute(SLIDE_USER_PRINCIPAL_ATTRIBUTE_NAME,slidePrincipal); session.setAttribute(SLIDE_USER_PRINCIPAL_ATTRIBUTE_NAME, slidePrincipal); return request; }
From source file:com.pivotal.gemfire.tools.pulse.internal.controllers.PulseController.java
@RequestMapping(value = "/dataBrowserQuery", method = RequestMethod.GET) public void dataBrowserQuery(HttpServletRequest request, HttpServletResponse response) throws IOException { // get query string String query = request.getParameter("query"); String members = request.getParameter("members"); int limit = 0; try {//w w w. j av a 2 s.co m limit = Integer.valueOf(request.getParameter("limit")); } catch (NumberFormatException e) { limit = 0; if (LOGGER.finerEnabled()) { LOGGER.finer(e.getMessage()); } } JSONObject queryResult = new JSONObject(); try { if (StringUtils.isNotNullNotEmptyNotWhiteSpace(query)) { // get cluster object Cluster cluster = Repository.get().getCluster(); String userName = request.getUserPrincipal().getName(); // Call execute query method queryResult = cluster.executeQuery(query, members, limit); // Add query in history if query is executed successfully if (!queryResult.has("error")) { // Add query to history cluster.addQueryInHistory(query, userName); } } } catch (JSONException eJSON) { LOGGER.logJSONError(eJSON, new String[] { "queryResult:" + queryResult }); } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occured : " + e.getMessage()); } } response.getOutputStream().write(queryResult.toString().getBytes()); }
From source file:org.j2free.util.ServletUtils.java
/** * /*from w w w .j a va 2 s . c o m*/ * @param req * @return */ public static String describeRequest(HttpServletRequest req) { if (req == null) { return EMPTY; } HttpSession session = null; try { session = req.getSession(); } catch (Exception e) { } StringBuilder body = new StringBuilder(); body.append("Browser: " + req.getHeader("User-Agent")); body.append("\n\nRequest Info"); body.append("\nRequest URI: " + req.getRequestURI()); body.append("\nRequest URL: " + req.getRequestURL().toString()); body.append("\nPath Info: " + req.getPathInfo()); body.append("\nQuery String: " + req.getQueryString()); if (session != null) { body.append("\n\nSession Info"); body.append("\nSession ID: " + session.getId()); body.append("\nSession Created: " + new Date(session.getCreationTime()).toString()); body.append("\nSession Last Accessed: " + new Date(session.getLastAccessedTime()).toString()); } body.append("\n\nUser Info"); body.append("\nRemote User: " + req.getRemoteUser()); body.append("\nUser Principal: " + req.getUserPrincipal()); body.append("\n\nServer Info"); String hostname = "", serverInstance = "", ip = ""; try { hostname = java.net.InetAddress.getLocalHost().getHostName(); serverInstance = System.getProperty("com.sun.aas.instanceName"); ip = java.net.InetAddress.getLocalHost().getHostAddress(); body.append("\nInstance: " + serverInstance + " : " + ip + " : " + hostname); } catch (Exception e) { } return body.toString(); }
From source file:au.edu.uq.cmm.paul.servlet.WebUIController.java
@RequestMapping(value = "/facilityLogout") public String facilityLogout(Model model, HttpServletRequest request, @RequestParam String facilityName) { model.addAttribute("returnTo", inferReturnTo(request)); GenericPrincipal principal = (GenericPrincipal) request.getUserPrincipal(); if (principal == null || !principal.hasRole("ROLE_ACLS_USER")) { model.addAttribute("message", "I don't know your ACLS userName"); return "failed"; }//from w ww . j av a 2s . com String userName = principal.getName(); FacilityStatusManager fsm = getFacilityStatusManager(); FacilitySession session = fsm.getSession(lookupFacilityByName(facilityName), System.currentTimeMillis()); if (session == null || !session.getUserName().equals(userName)) { model.addAttribute("message", "You are not logged in on '" + facilityName + "'"); return "failed"; } try { fsm.logoutSession(session.getSessionUuid()); model.addAttribute("message", "Your session has been logged out"); return "ok"; } catch (AclsAuthenticationException ex) { LOG.error("Session logout failed", ex); model.addAttribute("message", "Session logout failed due to an internal error"); return "failed"; } }