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.eclipse.skalli.view.internal.servlet.AuthenticationServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getUserPrincipal() != null) { // principal provided, go back to calling page String returnUrl = (String) request.getParameter(PARAM_RETURNURL); if (StringUtils.isBlank(returnUrl)) { returnUrl = "/"; //$NON-NLS-1$ }/*from ww w . j av a2 s. c o m*/ response.sendRedirect(returnUrl); } else { ServletContext context = getServletContext(); RequestDispatcher dispatcher = context.getRequestDispatcher(JSP_LOGIN); dispatcher.forward(request, response); } }
From source file:com.deepsky.spring_security.samples.ServletApiController.java
/** * Demonstrates that Spring Security automatically populates {@link javax.servlet.http.HttpServletRequest#getUserPrincipal()} with the * {@link org.springframework.security.core.Authentication} that is present on {@link org.springframework.security.core.context.SecurityContextHolder#getContext()} * @param request/*from w w w . jav a 2 s . c om*/ * @return */ @ModelAttribute("userPrincipal") public Principal userPrincipal(HttpServletRequest request) { return request.getUserPrincipal(); }
From source file:org.eclipse.ecr.web.jaxrs.session.CoreSessionProvider.java
protected CoreSession _createSession(HttpServletRequest request, String repoName) throws Exception { if (request.getUserPrincipal() == null) { throw new java.lang.IllegalStateException("Not authenticated user is trying to get a core session"); }/* ww w . j a v a2 s .co m*/ RepositoryManager rm = Framework.getService(RepositoryManager.class); Repository repo = null; if (repoName == null) { repo = rm.getDefaultRepository(); } else { repo = rm.getRepository(repoName); } if (repo == null) { //TODO use custom exception throw new java.lang.IllegalStateException("Unable to get " + repoName + " repository"); } return repo.open(); }
From source file:hu.fnf.devel.wishbox.gateway.RequestInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("interceptor called: " + request.getUserPrincipal().getName()); return true;/*w ww.j a v a 2s. c om*/ }
From source file:net.sf.gazpachoquest.questionnaires.resource.ResourceProducer.java
@Produces @GazpachoResource/*from w w w. j a v a2 s .co m*/ @RequestScoped public QuestionnaireResource createQuestionnairResource(HttpServletRequest request) { RespondentAccount principal = (RespondentAccount) request.getUserPrincipal(); String apiKey = principal.getApiKey(); String secret = principal.getSecret(); logger.info("Getting QuestionnaireResource using api key {}/{} ", apiKey, secret); JacksonJsonProvider jacksonProvider = new JacksonJsonProvider(); ObjectMapper mapper = new ObjectMapper(); // mapper.findAndRegisterModules(); mapper.registerModule(new JSR310Module()); mapper.setSerializationInclusion(Include.NON_EMPTY); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); jacksonProvider.setMapper(mapper); QuestionnaireResource resource = JAXRSClientFactory.create(BASE_URI, QuestionnaireResource.class, Collections.singletonList(jacksonProvider), null); // proxies // WebClient.client(resource).header("Authorization", "GZQ " + apiKey); Client client = WebClient.client(resource); ClientConfiguration config = WebClient.getConfig(client); config.getOutInterceptors().add(new HmacAuthInterceptor(apiKey, secret)); return resource; }
From source file:org.nuxeo.license.filter.LicenseGuardFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; Principal principal = httpRequest.getUserPrincipal(); HttpSession session = httpRequest.getSession(false); // XXX check config if (session != null && principal != null) { String sid = session.getId(); UserSessionValidity validity = lm.validateUserSession((NuxeoPrincipal) principal, sid); if (UserSessionValidity.BlackListed == validity) { handleDuplicicatedConnection(request, response, principal, sid); return; } else if (UserSessionValidity.NoMoreSessions == validity) { handleNoValidLicense(request, response); return; }/* w w w . j av a 2 s . co m*/ } chain.doFilter(request, response); }
From source file:com.scistor.tab.auth.controller.HomeRestController.java
@RequestMapping(value = "/user", method = RequestMethod.GET) public User getUserInfo(HttpServletRequest request) { System.out.println(SecurityContextHolder.getContext().getAuthentication()); return userRepository.findByUsername(request.getUserPrincipal().getName()); }
From source file:net.triptech.metahive.web.BaseController.java
/** * Load the person from the request.//from w w w .j a v a 2 s . co m * * @param request the request * @return the person */ protected final Person loadUser(final HttpServletRequest request) { Person user = null; if (request.getUserPrincipal() != null && StringUtils.isNotBlank(request.getUserPrincipal().getName())) { List<Person> people = Person.findPeopleByOpenIdIdentifier(request.getUserPrincipal().getName()) .getResultList(); user = people.size() == 0 ? null : people.get(0); } return user; }
From source file:com.deepsky.spring_security.samples.ServletApiController.java
@RequestMapping(value = "/login", method = RequestMethod.GET) public String login(@ModelAttribute LoginForm loginForm, HttpServletRequest request) { Principal principal = request.getUserPrincipal(); if (principal != null) { System.out.println("User principal: " + principal.getName()); } else {/*from w ww . j ava 2 s.c o m*/ System.out.println("Principal is null"); } return "login1"; }
From source file:eu.openanalytics.shinyproxy.controllers.BaseController.java
protected String getUserName(HttpServletRequest request) { Principal principal = request.getUserPrincipal(); String username = (principal == null) ? request.getSession().getId() : principal.getName(); return username; }