List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:hu.unideb.studentSupportInterface.backing.ManageProfile.java
@PostConstruct public void initBean() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); user = (User) userDao.loadUserByUsername(auth.getName()); selectedLanguages = oldSelectedLanguages = languageDao.getLanguagesByUser(user); languages = languageDao.getAllLanguage(); }
From source file:com.siriusit.spezg.multilib.jsf.login.UserPopulatorFilter.java
private String getUsernameFromAuthentication() { SecurityContext securityContext = SecurityContextHolder.getContext(); if (securityContext instanceof SecurityContext) { Authentication authentication = securityContext.getAuthentication(); if (authentication instanceof Authentication) { return authentication.getName(); }// ww w.j a v a 2s.co m } return null; }
From source file:de.dominikschadow.duke.encounters.services.UserService.java
public String getUsername() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = authentication.getName(); if (authentication instanceof UserDetails) { UserDetails userDetails = (UserDetails) authentication; username = userDetails.getUsername(); }/*from w w w .j a va 2 s . c om*/ return username; }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManagerTests.java
@Test public void testAuthenticate() throws Exception { responseHeaders.setLocation(new URI("https://uaa.cloudfoundry.com/")); Map<String, String> response = new HashMap<String, String>(); response.put("username", "marissa"); @SuppressWarnings("rawtypes") ResponseEntity<Map> expectedResponse = new ResponseEntity<Map>(response, responseHeaders, HttpStatus.OK); when(restTemplate.exchange(endsWith("/authenticate"), eq(HttpMethod.POST), any(HttpEntity.class), eq(Map.class))).thenReturn(expectedResponse); Authentication result = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken("marissa", "foo")); assertEquals("marissa", result.getName()); assertTrue(result.isAuthenticated()); }
From source file:org.unitedinternet.cosmo.security.CosmoSecurityManager.java
public String getUsername() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = context.getAuthentication(); if (authentication == null) { throw new RuntimeException("no Authentication found in SecurityContext"); }/*from w w w. j av a 2 s . c om*/ return authentication.getName(); }
From source file:no.dusken.aranea.admin.control.MenuController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Person p = null;/* www . ja v a2s . c o m*/ if (authentication != null) { String username = authentication.getName(); p = personService.getPersonByUsername(username); } if (p != null) { map.put("loggedInUser", p); } return new ModelAndView("no/dusken/aranea/base/admin/common/menu", map); }
From source file:com.alehuo.wepas2016projekti.controller.CommentController.java
/** * Kommentin lismissivu//from ww w. ja v a2 s . c om * * @param a Autentikointi * @param m Model * @param uuid Kuvan UUID * @param l * @return Nkym "addcomment" */ @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) public String addComment(Authentication a, Model m, @PathVariable String uuid, Locale l) { UserAccount u = userService.getUserByUsername(a.getName()); m.addAttribute("user", u); m.addAttribute("imageUuid", uuid); return "addcomment"; }
From source file:hsa.awp.usergui.NavigationLoginPanel.java
public NavigationLoginPanel(String id) { super(id);/*from w w w.j av a 2 s.c o m*/ SingleUser singleUser = SingleUser.getInstance(); singleUser.setName(""); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { singleUser = controller.getUserById(auth.getName()); } Form<Object> loginForm = new Form<Object>("loginForm"); add(loginForm); MarkupContainer loggedInContainer = new WebMarkupContainer("loggedIn"); loggedInContainer.add(new Label("loginName", singleUser.getName())); add(loggedInContainer); if (auth == null) { loggedInContainer.setVisible(false); loginForm.setVisible(true); } else { loggedInContainer.setVisible(true); loginForm.setVisible(false); } }
From source file:jp.xet.uncommons.web.UsernameLogFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { SecurityContext ctx = SecurityContextHolder.getContext(); Authentication auth = ctx.getAuthentication(); boolean successfulRegistration = false; if (auth != null) { String username = auth.getName(); successfulRegistration = registerUsername(username); }//w w w.j a v a 2 s . c o m try { filterChain.doFilter(request, response); } finally { if (successfulRegistration) { MDC.remove(USER_KEY); } } }
From source file:org.duracloud.account.app.controller.AmaTestBase.java
protected void intializeAuthManager() { Authentication auth = createMock(Authentication.class); EasyMock.expect(auth.getName()).andReturn(TEST_USERNAME).anyTimes(); authenticationManager = createMock(AuthenticationManager.class); SecurityContext ctx = new SecurityContextImpl(); ctx.setAuthentication(auth);/*from w w w.j av a2 s. c om*/ EasyMock.expect(auth.getPrincipal()).andReturn(createUser()).anyTimes(); SecurityContextHolder.setContext(ctx); }