List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:org.callistasoftware.netcare.web.security.MobileAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { log.info("==== Mobile Authentication [DEV MODE] ===="); log.info("User: {}", authentication.getName()); final UserDetails details = getUserDetailsService().loadUserByUsername(authentication.getName()); log.info("User found: {}", details != null); log.info("=========================================="); return new UsernamePasswordAuthenticationToken(details, "", details.getAuthorities()); }
From source file:cz.muni.pa165.carparkapp.web.PersonalInfoController.java
@RequestMapping(value = "/update", method = RequestMethod.POST) public String update(@Valid @ModelAttribute EmployeeDTO employee, BindingResult bindingResult, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder, Locale locale) { log.debug("update(locale={}, customer={})", locale, employee); if (bindingResult.hasErrors()) { log.debug("binding errors"); for (ObjectError ge : bindingResult.getGlobalErrors()) { log.debug("ObjectError: {}", ge); }// w w w. ja v a 2 s. c o m for (FieldError fe : bindingResult.getFieldErrors()) { log.debug("FieldError: {}", fe); } return employee.getId() < 1 ? "employee" : "employee/update"; } Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); EmployeeDTO emp = null; for (EmployeeDTO employee1 : employeeService.getAllEmployees()) { if (employee1.getUserName().equals(name)) emp = employee1; } employee.setUserName(name); employee.setPassword(emp.getPassword()); employeeService.updateEmployee(employee); redirectAttributes.addFlashAttribute("message", messageSource.getMessage("employee.updated", new Object[] { employee.getFirstName(), employee.getLastName(), employee.getId() }, locale)); return "redirect:" + uriBuilder.path("/employee").build(); }
From source file:am.ik.categolj2.domain.AuditAwareBean.java
@Override public String getCurrentAuditor() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return null; } else {//from w w w. j a va 2s. c om return authentication.getName(); } }
From source file:ru.trett.cis.controllers.HomeController.java
@RequestMapping(value = "profile/delete") public String deleteProfile() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); User user = inventoryService.getUserByLoginName(auth.getName()); inventoryService.remove(User.class, user.getId()); return "redirect:/logout"; }
From source file:com.crimelab.controller.AssignmentController.java
@RequestMapping(value = "/assignment", method = RequestMethod.POST) public String assignTask(Model model, @RequestParam("taskName") String taskName, @RequestParam("description") String description, @RequestParam("users") String users, @RequestParam("reportType") String reportType, @RequestParam("division") String division, @RequestParam("priority") int priority) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String username = auth.getName(); //get logged in username String result_id = assignmentService.createResult(reportType, users, division); if (!result_id.isEmpty()) { assignmentService.createTask(taskName, description, username, users, priority, result_id); model.addAttribute("success", true); }// w ww . jav a 2 s .co m return "redirect:/" + division + "/assignment"; }
From source file:com.datapine.aop.LoggingAspect.java
/** * Logs a successful attempt to login by a user. * @param join Method/*from w ww. j a v a 2s . c o m*/ * SimpleUrlAuthenticationSuccessHandler#onAuthenticationSuccess(...). * @checkstyle LineLengthCheck (2 lines) */ @After("execution(* org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler.onAuthenticationSuccess(..))") public final void loginSucceeded(final JoinPoint join) { final Authentication auth = (Authentication) join.getArgs()[2]; Logger.info(this, "Login of the user '%s' succeeds with authorities %s", auth.getName(), auth.getAuthorities()); }
From source file:oauth2.authentication.UserAuthenticationProvider.java
@Override @Transactional(noRollbackFor = AuthenticationException.class) public Authentication authenticate(Authentication authentication) { checkNotNull(authentication);/*from w w w . j av a 2 s . c o m*/ String userId = authentication.getName(); User user = userRepository.findByUserId(userId); if (user == null) { LOGGER.debug("User {} not found", userId); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } try { authenticationStrategy.authenticate(user, authentication.getCredentials()); user.getLoginStatus().loginSuccessful(Instant.now()); Set<GrantedAuthority> authorities = mapAuthorities(user); return createSuccessAuthentication(authentication.getPrincipal(), authentication, authorities); } catch (BadCredentialsException ex) { user.getLoginStatus().loginFailed(Instant.now()); throw ex; } }
From source file:org.xaloon.wicket.security.spring.external.ExternalAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (StringUtils.isEmpty(authentication.getName())) { throw new IllegalArgumentException("Authentication username is not provided!"); }//from w w w .ja v a2 s.c o m UserDetails loadedUser = null; AuthenticationToken initialToken = null; if (authentication instanceof SpringAuthenticationToken) { initialToken = ((SpringAuthenticationToken) authentication).getToken(); } try { loadedUser = userDetailsService.loadUserByUsername(authentication.getName()); } catch (DataAccessException repositoryProblem) { throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); } catch (UsernameNotFoundException e) { } if (loadedUser == null) { return createExternalAuthenticationToken(authentication, initialToken); } else { return createDefaultAuthenticationToken(authentication, loadedUser); } }
From source file:shiver.me.timbers.security.spring.AuthenticatedAuthenticationConverterTest.java
@Test public void Can_convert_an_authentication_into_a_target() { final Authentication authentication = mock(Authentication.class); final String expected = someString(); // Given// w w w .jav a 2 s . co m given(authentication.getName()).willReturn(expected); // When final String actual = authenticationConverter.convert(authentication); // Then assertThat(actual, is(expected)); }
From source file:com.netflix.genie.web.controllers.UIController.java
/** * Return the index.html file for requests to root. * * @param response The servlet response to add cookies to * @param authentication The Spring Security authentication if present * @return getIndex// ww w . j a v a 2 s . c o m */ @GetMapping(value = { "/", "/applications/**", "/clusters/**", "/commands/**", "/jobs/**", "/output/**" }) public String getIndex(@NotNull final HttpServletResponse response, @Nullable final Authentication authentication) { if (authentication != null) { response.addCookie(new Cookie("genie.user", authentication.getName())); } else { response.addCookie(new Cookie("genie.user", "user@genie")); } return "index.html"; }