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:org.jboss.bpm.console.server.TaskMgmtFacade.java
@POST @Path("{taskId}/assign/{ifRef}") @Produces("application/json") public Response assignTask(@Context HttpServletRequest request, @PathParam("taskId") long taskId, @PathParam("ifRef") String idRef) { log.debug("Assign task " + taskId + " to '" + idRef + "'"); getTaskManagement().assignTask(taskId, idRef, request.getUserPrincipal().getName()); return Response.ok().build(); }
From source file:org.rti.zcore.dar.struts.action.CreateTestPatientAction.java
protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); Principal user = request.getUserPrincipal(); String username = user.getName(); Connection conn = null;//from w w w . ja va 2 s . co m try { conn = DatabaseUtils.getZEPRSConnection(username); ModuleConfig cfg = mapping.getModuleConfig(); String patientType = request.getParameter("patientType"); String number = request.getParameter("number"); EncounterData enc; // setup clock Calendar cal = new GregorianCalendar(); Date starttime = cal.getTime(); long long_starttime = starttime.getTime(); Site site = SessionUtil.getInstance(session).getClientSettings().getSite(); Long siteId = site.getId(); if (patientType != null & number == null) { enc = TestPatientUtils.populate(conn, siteId, patientType, username); request.setAttribute("patientId", enc.getPatientId()); } else if (number != null) { int numberI = new Integer(number); int numTestPatients = numberI * 10; if (patientType != null) { log.debug("Start Time for generating " + numTestPatients + " " + patientType + " patients: " + starttime.toString()); numberI = numberI * 10; for (int i = 0; i < numberI; i++) { TestPatientUtils.populate(conn, siteId, patientType, username); } } else { log.debug("Start Time for generating " + numTestPatients + " test patients: " + starttime.toString()); for (int i = 0; i < numTestPatients; i++) { patientType = "basic"; TestPatientUtils.populate(conn, siteId, patientType, username); /* patientType = "full"; TestPatientUtils.populate(conn, siteId, patientType, username); patientType = "docket"; TestPatientUtils.populate(conn, siteId, patientType, username); patientType = "courtPrep1"; TestPatientUtils.populate(conn, siteId, patientType, username); patientType = "referral1"; TestPatientUtils.populate(conn, siteId, patientType, username); patientType = "consult2"; TestPatientUtils.populate(conn, siteId, patientType, username); patientType = "courtPrep2final"; TestPatientUtils.populate(conn, siteId, patientType, username);*/ } } // Stop clock and calculate time elapsed Calendar cal2 = new GregorianCalendar(); Date endtime = cal2.getTime(); long long_endtime = endtime.getTime(); long difference = (long_endtime - long_starttime); log.debug("Time to generate " + numTestPatients + " test patients: " + difference / 1000 + " seconds"); } else { enc = TestPatientUtils.populate(conn, siteId, "basic", username); request.setAttribute("patientId", enc.getPatientId()); } } catch (ServletException e) { log.error(e); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } return mapping.findForward("home"); }
From source file:org.apache.axis.security.servlet.ServletSecurityProvider.java
/** Authenticate a user from a username/password pair. * * @param username the user name to check * @param password the password to check * @return an AuthenticatedUser or null//from w w w . j a v a2 s. c o m */ public AuthenticatedUser authenticate(MessageContext msgContext) { HttpServletRequest req = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); if (req == null) return null; log.debug(Messages.getMessage("got00", "HttpServletRequest")); Principal principal = req.getUserPrincipal(); if (principal == null) { log.debug(Messages.getMessage("noPrincipal00")); return null; } log.debug(Messages.getMessage("gotPrincipal00", principal.getName())); return new ServletAuthenticatedUser(req); }
From source file:org.nuxeo.ecm.liveconnect.box.BoxBlobUploader.java
private boolean hasServiceAccount(BoxOAuth2ServiceProvider provider) { HttpServletRequest request = getHttpServletRequest(); String username = request.getUserPrincipal().getName(); return provider != null && provider.getServiceUser(username) != null; }
From source file:org.codice.ddf.ui.Query.java
/** * Gets the CAS proxy ticket that will be used by the STS to get a SAML assertion. * * @param request The Http servlet request. * @return Returns the CAS proxy ticket that will be used by the STS to get a SAML assertion. *//* ww w . j a va 2s . c o m*/ private String getProxyTicket(HttpServletRequest request) { AttributePrincipal attributePrincipal = (AttributePrincipal) request.getUserPrincipal(); String proxyTicket = null; if (attributePrincipal != null) { // proxyTicket = attributePrincipal.getProxyTicketFor( // "https://server:8993/ddf/query/sts" ); LOGGER.debug("Getting proxy ticket for {}", STS_SERVICE_URL); proxyTicket = attributePrincipal.getProxyTicketFor(STS_SERVICE_URL); LOGGER.info("proxy ticket: {}", proxyTicket); } else { LOGGER.error("attribute principal is null!"); } return proxyTicket; }
From source file:de.mare.mobile.ui.jsf.pages.LoginPage.java
/** * Perform login of the user/*from ww w . j av a2s . c om*/ * */ public String loginAction() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { request.login(this.username, this.password); String username = request.getUserPrincipal().getName(); User currentUser = userRepository.findUser(username); userSession.setUser(currentUser); LOG.info("username is: " + username); } catch (ServletException e) { if (StringUtils.contains(e.getMessage(), "User already logged in")) { String username = request.getUserPrincipal().getName(); User currentUser = userRepository.findUser(username); userSession.setUser(currentUser); LOG.info("User already loggedn in"); LOG.info("username is: " + username); } else { context.addMessage(null, new FacesMessage("Login failed.")); return "login.error"; } } return "portal.start"; }
From source file:org.jboss.bpm.console.server.TaskMgmtFacade.java
@POST @Path("{taskId}/close/{outcome}") @Produces("application/json") public Response closeTaskWithSignal(@Context HttpServletRequest request, @PathParam("taskId") long taskId, @QueryParam("outcome") String outcome) { log.debug("Close task " + taskId + " outcome " + outcome); getTaskManagement().completeTask(taskId, outcome, null, request.getUserPrincipal().getName()); return Response.ok().build(); }
From source file:org.nuxeo.ecm.platform.wi.filter.WIRequestFilter.java
protected String doFormatLogMessage(HttpServletRequest request, String info) { String remoteHost = RemoteHostGuessExtractor.getRemoteHost(request); Principal principal = request.getUserPrincipal(); String principalName = principal != null ? principal.getName() : "none"; String uri = request.getRequestURI(); String method = request.getMethod(); HttpSession session = request.getSession(false); String sessionId = session != null ? session.getId() : "none"; String threadName = Thread.currentThread().getName(); return "remote=" + remoteHost + ",principal=" + principalName + ",uri=" + uri + ", method=" + method + ",session=" + sessionId + ",thread=" + threadName + ",info=" + info; }
From source file:org.apache.hadoop.hdfs.qjournal.server.GetJournalEditServlet.java
protected boolean isValidRequestor(HttpServletRequest request, Configuration conf) throws IOException { String remotePrincipal = request.getUserPrincipal().getName(); String remoteShortName = request.getRemoteUser(); if (remotePrincipal == null) { // This really shouldn't happen... LOG.warn("Received null remoteUser while authorizing access to " + "GetJournalEditServlet"); return false; }/*from w w w . j ava2 s . c o m*/ if (LOG.isDebugEnabled()) { LOG.debug("Validating request made by " + remotePrincipal + " / " + remoteShortName + ". This user is: " + UserGroupInformation.getLoginUser()); } Set<String> validRequestors = new HashSet<String>(); validRequestors.addAll(DFSUtil.getAllNnPrincipals(conf)); try { validRequestors.add(SecurityUtil.getServerPrincipal( conf.get(DFSConfigKeys.DFS_SECONDARY_NAMENODE_KERBEROS_PRINCIPAL_KEY), SecondaryNameNode.getHttpAddress(conf).getHostName())); } catch (Exception e) { // Don't halt if SecondaryNameNode principal could not be added. LOG.debug("SecondaryNameNode principal could not be added", e); String msg = String.format("SecondaryNameNode principal not considered, %s = %s, %s = %s", DFSConfigKeys.DFS_SECONDARY_NAMENODE_KERBEROS_PRINCIPAL_KEY, conf.get(DFSConfigKeys.DFS_SECONDARY_NAMENODE_KERBEROS_PRINCIPAL_KEY), DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY, conf.get(DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY, DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_DEFAULT)); LOG.warn(msg); } // Check the full principal name of all the configured valid requestors. for (String v : validRequestors) { if (LOG.isDebugEnabled()) LOG.debug("isValidRequestor is comparing to valid requestor: " + v); if (v != null && v.equals(remotePrincipal)) { if (LOG.isDebugEnabled()) LOG.debug("isValidRequestor is allowing: " + remotePrincipal); return true; } } // Additionally, we compare the short name of the requestor to this JN's // username, because we want to allow requests from other JNs during // recovery, but we can't enumerate the full list of JNs. if (remoteShortName.equals(UserGroupInformation.getLoginUser().getShortUserName())) { if (LOG.isDebugEnabled()) LOG.debug("isValidRequestor is allowing other JN principal: " + remotePrincipal); return true; } if (LOG.isDebugEnabled()) LOG.debug("isValidRequestor is rejecting: " + remotePrincipal); return false; }
From source file:io.hops.hopsworks.api.admin.llap.LlapMonitorProxyServlet.java
@Override protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { // Check if the user is logged in if (servletRequest.getUserPrincipal() == null) { servletResponse.sendError(403, "User is not logged in"); return;//w w w.j av a2 s .c o m } // Check that the user is an admin boolean isAdmin = servletRequest.isUserInRole("HOPS_ADMIN"); if (!isAdmin) { servletResponse.sendError(Response.Status.BAD_REQUEST.getStatusCode(), "You don't have the access right for this application"); return; } // The path we will receive is [host]/llapmonitor/llaphost/ // We need to extract the llaphost to redirect the request String[] pathInfoSplits = servletRequest.getPathInfo().split("/"); String llapHost = pathInfoSplits[1]; //Now rewrite the URL StringBuffer urlBuf = new StringBuffer();//note: StringBuilder isn't supported by Matcher Matcher matcher = TEMPLATE_PATTERN.matcher(targetUriTemplate); if (matcher.find()) { matcher.appendReplacement(urlBuf, llapHost); } matcher.appendTail(urlBuf); String newTargetUri = urlBuf.toString(); servletRequest.setAttribute(ATTR_TARGET_URI, newTargetUri); URI targetUriObj; try { targetUriObj = new URI(newTargetUri); } catch (Exception e) { throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e); } servletRequest.setAttribute(ATTR_TARGET_HOST, URIUtils.extractHost(targetUriObj)); super.service(servletRequest, servletResponse); }