List of usage examples for javax.servlet.http HttpServletRequest getRemoteUser
public String getRemoteUser();
null
if the user has not been authenticated. From source file:com.jaeksoft.searchlib.renderer.plugin.AuthPluginNtlm.java
@Override public User getUser(Renderer renderer, HttpServletRequest request) throws IOException { String remoteUser = request.getRemoteUser(); if (remoteUser == null) remoteUser = request.getHeader("X-OSS-REMOTE-USER"); ActiveDirectory activeDirectory = null; if (StringUtils.isEmpty(remoteUser)) throw new AuthException("No user"); int i = remoteUser.indexOf('@'); if (i != -1)//from w w w .jav a2 s . com remoteUser = remoteUser.substring(0, i); try { String domain = renderer.getAuthDomain(); User user = AuthUserCache.INSTANCE.get(remoteUser, domain); if (user != null) return user; NtlmPasswordAuthentication ntlmAuth = getNtlmAuth(renderer, null, null); activeDirectory = new ActiveDirectory(ntlmAuth.getUsername(), ntlmAuth.getPassword(), ntlmAuth.getDomain()); NamingEnumeration<SearchResult> result = activeDirectory.findUser(remoteUser); Attributes attrs = ActiveDirectory.getAttributes(result); if (attrs == null) throw new AuthException("No user found: " + remoteUser); String userId = ActiveDirectory.getObjectSID(attrs); List<ADGroup> groups = new ArrayList<ADGroup>(); activeDirectory.findUserGroups(attrs, groups); String dnUser = ActiveDirectory.getStringAttribute(attrs, "DistinguishedName"); activeDirectory.findUserGroup(dnUser, groups); user = new User(userId, remoteUser, null, ActiveDirectory.toArray(groups), ActiveDirectory.getDisplayString(domain, remoteUser)); Logging.info("USER authenticated: " + user + " DN=" + dnUser); AuthUserCache.INSTANCE.add(remoteUser, domain, user); return user; } catch (NamingException e) { Logging.warn(e); throw new AuthException("LDAP error (NamingException) : " + e.getMessage()); } finally { IOUtils.close(activeDirectory); } }
From source file:eu.planets_project.tb.gui.tags.GetUser.java
/** *//* w ww .j a v a 2 s .com*/ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException { //log.debug("in Tag: GetUser!"); FacesContext context = FacesContext.getCurrentInstance(); //Object session = context.getExternalContext().getSession(false); //if (session != null) { UserBean user = (UserBean) JSFUtil.getManagedObject("UserBean"); //UserBean user = (UserBean)(((HttpSession)session).getAttribute("userBean")); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); if (user.getUserid() == null) { String userId = request.getRemoteUser(); // JAAS Login before? if (userId != null) { //user = new UserBean(); user.setUserid(userId); //((HttpSession)session).setAttribute("userBean",user); } } log.debug("user is: '" + user.getUserid() + "'"); //} }
From source file:com.fiveamsolutions.nci.commons.web.filter.UsernameFilter.java
/** * {@inheritDoc}/*ww w . ja v a2 s . co m*/ */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final String previousUsername = UsernameHolder.getUser(); HttpServletRequest httpRequest = (HttpServletRequest) request; String username = httpRequest.getRemoteUser(); if (caseSensitive) { UsernameHolder.setUserCaseSensitive(username); } else { UsernameHolder.setUser(username); } try { chain.doFilter(request, response); } finally { // See PO-6019. Username needs to be cleaned up after the thread is done. UsernameHolder.setUserCaseSensitive(previousUsername); } }
From source file:br.com.joaops.smt.controller.HomeController.java
@RequestMapping(value = "/", method = RequestMethod.GET) public ModelAndView index(HttpServletRequest request, HttpServletResponse response, Pageable p) { ModelAndView mav = new ModelAndView("home/index"); mav.addObject("user", systemUserService.getUserByEmail(request.getRemoteUser())); mav.addObject("empresas", empresaService.searchAllEmpresa(p)); return mav;//from w w w. j a v a2s . c o m }
From source file:org.apache.hadoop.http.HttpServer.java
/** * Does the user sending the HttpServletRequest has the administrator ACLs? If * it isn't the case, response will be modified to send an error to the user. * //from ww w. j av a2s . c om * @param servletContext * @param request * @param response * @return true if admin-authorized, false otherwise * @throws IOException */ public static boolean hasAdministratorAccess(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException { Configuration conf = (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE); // If there is no authorization, anybody has administrator access. if (!conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) { return true; } String remoteUser = request.getRemoteUser(); if (remoteUser == null) { return true; } AccessControlList adminsAcl = (AccessControlList) servletContext.getAttribute(ADMINS_ACL); UserGroupInformation remoteUserUGI = UserGroupInformation.createRemoteUser(remoteUser); if (adminsAcl != null) { if (!adminsAcl.isUserAllowed(remoteUserUGI)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "User " + remoteUser + " is unauthorized to access this page. " + "AccessControlList for accessing this page : " + adminsAcl.toString()); return false; } } return true; }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String remoteUser = req.getRemoteUser(); if (remoteUser == null) { out.println("Welcome!"); } else {/*from w w w .j ava 2 s .c om*/ out.println("Welcome, " + remoteUser + "!"); Date lastAccess = (Date) accesses.get(remoteUser); if (lastAccess == null) { out.println("This is your first visit!"); } else { out.println("Your last visit was " + accesses.get(remoteUser)); } if (remoteUser.equals("YourFirendName")) { out.println("Shall we play a game?"); } accesses.put(remoteUser, new Date()); } }
From source file:PersonalizedServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String remoteUser = req.getRemoteUser(); if (remoteUser == null) { out.println("Welcome!"); } else {/*from w w w .j a v a2 s. c o m*/ out.println("Welcome, " + remoteUser + "!"); Date lastAccess = (Date) accesses.get(remoteUser); if (lastAccess == null) { out.println("This is your first visit!"); } else { out.println("Your last visit was " + accesses.get(remoteUser)); } if (remoteUser.equals("User A")) { out.println("HI."); } accesses.put(remoteUser, new Date()); } }
From source file:org.eclipse.orion.internal.server.servlets.workspace.WorkspaceServlet.java
/** * Obtain and return the user name from the request headers. *///from w w w. j av a2 s .c o m private String getUserId(HttpServletRequest req) { return req.getRemoteUser(); }
From source file:org.eclipse.orion.server.configurator.servlet.AuthorizationFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; try {/* w ww. j a v a 2 s . c o m*/ if (!AuthorizationService.checkRights(httpRequest.getRemoteUser(), httpRequest.getRequestURI().toString(), httpRequest.getMethod())) { httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } catch (JSONException e) { httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } chain.doFilter(request, response); }
From source file:org.jasig.cas.extension.clearpass.ClearPassController.java
@Override public ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final String userName = request.getRemoteUser(); LOGGER.debug("Handling clearPass request for user [{}]", userName); if (StringUtils.isBlank(userName)) { return returnError("No username was provided to clearPass."); }// w ww .ja v a 2 s . co m if (!this.credentialsCache.containsKey(userName)) { return returnError("Password could not be found in cache for user " + userName); } final String password = this.credentialsCache.get(userName); if (StringUtils.isBlank(password)) { return returnError("Password is null or blank"); } LOGGER.debug("Retrieved credentials will be provided to the requesting service."); return new ModelAndView(this.successView, MODEL_CLEARPASS, password); }