List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:fr.gael.dhus.spring.security.handler.LogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String ip = ProxyWebAuthenticationDetails.getRemoteIp(request); String name = authentication == null ? "unknown" : authentication.getName(); LOGGER.info("Connection closed by '" + name + "' from " + ip); SecurityContextProvider.logout((String) request.getSession().getAttribute("integrity")); request.getSession().invalidate();//from w w w . j a v a 2 s . com }
From source file:com.alehuo.wepas2016projekti.controller.DefaultController.java
/** * Uloskirjautumissivu (Jos JavaScript on pois plt) * * @param a Autentikointi//from w w w .j a v a2s.co m * @param m Malli * @param l * @return */ @RequestMapping(value = "/logout/confirm", method = RequestMethod.GET) public String logout(Authentication a, Model m, Locale l) { UserAccount u = userService.getUserByUsername(a.getName()); m.addAttribute("user", u); return "logoutconfirm"; }
From source file:com.mycompany.doctorapp.services.PatientService.java
public void addSickness(Sickness sickness) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String username = auth.getName(); System.out.println(username); Patient authpatient = patientRepository.findByUsername(username); if (authpatient == null) { System.out.println("patient not found"); }/*from ww w .ja v a 2 s.c o m*/ Doctor doctor = authpatient.getOwnDoctor(); if (doctor == null) { System.out.println("No medic found"); } //if no list of treated sicknesses exists for the patient already, create one if (authpatient.getSickness() == null) { List<Sickness> lista = new ArrayList<>(); lista.add(sickness); authpatient.setSickness(lista); } else { authpatient.getSickness().add(sickness); } sickness.setTreatmentStatus(false); //if no list of treated sicknesses exists for the doctor already, create one if (doctor.getTreatedSicknesses() == null) { List<Sickness> lista = new ArrayList<>(); lista.add(sickness); doctor.setTreatedSicknesses(lista); } else { doctor.getTreatedSicknesses().add(sickness); } sicknessRepository.save(sickness); patientRepository.save(authpatient); sickness.setPatient(authpatient); sickness.setDoctor((doctor)); sicknessRepository.save(sickness); }
From source file:org.unidle.repository.AuditorAwareImpl.java
@Override public User getCurrentAuditor() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return null; }// www. ja va 2 s. com final String uuid = authentication.getName(); return "".equals(uuid) ? null : userRepository.findOne(UUID.fromString(uuid)); }
From source file:com.netflix.genie.web.controllers.UIControllerUnitTests.java
/** * Make sure the getIndex endpoint returns the right template name. */// w w w .j a v a 2s . c om @Test public void canGetIndex() { final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final ArgumentCaptor<Cookie> cookieArgumentCaptor = ArgumentCaptor.forClass(Cookie.class); Assert.assertThat(this.controller.getIndex(response, null), Matchers.is("index.html")); Mockito.verify(response, Mockito.times(1)).addCookie(cookieArgumentCaptor.capture()); Assert.assertThat(cookieArgumentCaptor.getValue().getName(), Matchers.is("genie.user")); Assert.assertThat(cookieArgumentCaptor.getValue().getValue(), Matchers.is("user@genie")); final Authentication authentication = Mockito.mock(Authentication.class); final String name = UUID.randomUUID().toString(); Mockito.when(authentication.getName()).thenReturn(name); Assert.assertThat(this.controller.getIndex(response, authentication), Matchers.is("index.html")); Mockito.verify(response, Mockito.times(2)).addCookie(cookieArgumentCaptor.capture()); Assert.assertThat(cookieArgumentCaptor.getValue().getName(), Matchers.is("genie.user")); Assert.assertThat(cookieArgumentCaptor.getValue().getValue(), Matchers.is(name)); }
From source file:co.com.carpco.altablero.spring.web.controller.MainBoardController.java
@RequestMapping(value = { "/", "/admin/general" }, method = RequestMethod.GET) public ModelAndView generalPage() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (!(auth instanceof AnonymousAuthenticationToken)) { ModelAndView model = roleUtils.createModelWithUserDetails(auth.getName()); model.setViewName("admin/general"); return model; } else {/* ww w . j a va 2s . c o m*/ return new ModelAndView("redirect:/login"); } }
From source file:com.gs.config.ItemBasedLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication a) throws IOException, ServletException { //Se enva a refrescar la ventana de todos los clientes para que cierre la sessin requestNodeJS.sendRequestWithUsernameAndMethod(a.getName(), "/session-close"); System.out.println("-----------------------------CERRANDO SESIN-----------------------------"); response.sendRedirect("login?out=1"); //request.getRequestDispatcher("login?out=1").forward(request, response); }
From source file:com.pokerweb.servlets.holdem.GetTableInfo.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*w w w . j a va2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuilder jb = new StringBuilder(); String line = null; BufferedReader reader = request.getReader(); DBManager DBM = DBManager.GetInstance(); while ((line = reader.readLine()) != null) jb.append(line); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String jsMessage = TableStatus.GetInstance().GetDataTable(jb.toString(), auth.getName()); response.setContentType("application/json; charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write(jsMessage); }
From source file:com.rockagen.gnext.service.spring.aspect.OpLogAspect.java
/** * Get username/*from w w w . j av a2s . co m*/ * @return username */ private String getUsername() { String username = "unknown"; Authentication auth = getAuthentication(); if (auth != null) { return auth.getName(); } return username; }
From source file:org.socialsignin.springsocial.security.signin.SpringSocialSecurityAuthenticationFactory.java
public Authentication updateAuthenticationForNewConnection(Authentication existingAuthentication, Connection<?> connection) { return createNewAuthentication(existingAuthentication.getName(), existingAuthentication.getCredentials() == null ? null : existingAuthentication.getCredentials().toString(), addAuthority(existingAuthentication, userAuthoritiesService.getProviderAuthority(connection.getKey()))); }