List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:de.blizzy.documentr.web.account.AccountController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) @PreAuthorize("isAuthenticated()") public String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model, Authentication authentication) throws IOException { if (StringUtils.isNotBlank(form.getNewPassword1()) || StringUtils.isNotBlank(form.getNewPassword2())) { User user = userStore.getUser(authentication.getName()); if (StringUtils.isBlank(form.getPassword())) { bindingResult.rejectValue("password", "user.password.blank"); //$NON-NLS-1$ //$NON-NLS-2$ } else if (!passwordEncoder.matches(form.getPassword(), user.getPassword())) { bindingResult.rejectValue("password", "user.password.wrong"); //$NON-NLS-1$ //$NON-NLS-2$ }// w w w .ja va 2 s .co m if (!StringUtils.equals(form.getNewPassword1(), form.getNewPassword2())) { bindingResult.rejectValue("newPassword1", "user.password.passwordsNotEqual"); //$NON-NLS-1$ //$NON-NLS-2$ } if (!bindingResult.hasErrors()) { String encodedPassword = passwordEncoder.encode(form.getNewPassword1()); User newUser = new User(user.getLoginName(), encodedPassword, user.getEmail(), user.isDisabled()); for (OpenId openId : user.getOpenIds()) { newUser.addOpenId(openId); } userStore.saveUser(newUser, user); } } if (!bindingResult.hasErrors()) { model.addAttribute("messageKey", "dataSaved"); //$NON-NLS-1$ //$NON-NLS-2$ } return "/account/index"; //$NON-NLS-1$ }
From source file:cs545.proj.controller.MemberController.java
@RequestMapping(value = "/selfedit", method = RequestMethod.GET) public String getSelfEditMemberForm(Model model, Principal principal) { if (principal == null) return "redirect:/loginPage"; Authentication authentication = (Authentication) principal; Member member = memberService.getMemberByUsername(authentication.getName()); for (Category category : member.getSelectedCategories()) { member.getCheckedCategoryIDs().add(category.getId()); }//from w w w .j a va 2s .c o m member.getUser().setPassword("88888888"); member.getUser().setConfirmPassword("88888888"); model.addAttribute("editMember", member); return "editMemberTile"; }
From source file:com.realdolmen.rdfleet.webmvc.controllers.rd.OrderCarController.java
@RequestMapping(value = "/freepool/{id}", method = RequestMethod.GET) public String getFreePoolCar(@PathVariable("id") Long id, @ModelAttribute("employeeCar") EmployeeCar employeeCar, Model model) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); try {// w ww . j a va 2s. co m boolean canOrderEmployeeCar = employeeService.employeeCanOrderEmployeeCar(auth.getName(), employeeCar.getId()); if (!canOrderEmployeeCar) return "redirect:/rd/cars/freepool"; EmployeeCar employeeCarFromService = employeeCarService.findById(id); employeeCar.setCarOptions(employeeCarFromService.getCarOptions()); employeeCar.setCarStatus(employeeCarFromService.getCarStatus()); employeeCar.setLicensePlate(employeeCarFromService.getLicensePlate()); employeeCar.setSelectedCar(employeeCarFromService.getSelectedCar()); employeeCar.setMileage(employeeCarFromService.getMileage()); employeeCar.setId(employeeCarFromService.getId()); employeeCar.setVersion(employeeCarFromService.getVersion()); model.addAttribute("employeeCar", employeeCar); model.addAttribute("car", carService.findById(employeeCar.getSelectedCar().getId())); model.addAttribute("canOrderFreePoolCar", canOrderEmployeeCar); } catch (IllegalArgumentException e) { model.addAttribute("error", e.getMessage()); } return "rd/freepool.detail"; }
From source file:org.dspace.rest.authentication.DSpaceAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Context context = null;/*from www . ja v a 2s . com*/ try { context = new Context(); String name = authentication.getName(); String password = authentication.getCredentials().toString(); HttpServletRequest httpServletRequest = new DSpace().getRequestService().getCurrentRequest() .getHttpServletRequest(); List<SimpleGrantedAuthority> grantedAuthorities = new ArrayList<>(); int implicitStatus = authenticationService.authenticateImplicit(context, null, null, null, httpServletRequest); if (implicitStatus == AuthenticationMethod.SUCCESS) { log.info(LogManager.getHeader(context, "login", "type=implicit")); addSpecialGroupsToGrantedAuthorityList(context, httpServletRequest, grantedAuthorities); return createAuthenticationToken(password, context, grantedAuthorities); } else { int authenticateResult = authenticationService.authenticate(context, name, password, null, httpServletRequest); if (AuthenticationMethod.SUCCESS == authenticateResult) { addSpecialGroupsToGrantedAuthorityList(context, httpServletRequest, grantedAuthorities); log.info(LogManager.getHeader(context, "login", "type=explicit")); return createAuthenticationToken(password, context, grantedAuthorities); } else { log.info(LogManager.getHeader(context, "failed_login", "email=" + name + ", result=" + authenticateResult)); throw new BadCredentialsException("Login failed"); } } } catch (BadCredentialsException e) { throw e; } catch (Exception e) { log.error("Error while authenticating in the rest api", e); } finally { if (context != null && context.isValid()) { try { context.complete(); } catch (SQLException e) { log.error(e.getMessage() + " occurred while trying to close", e); } } } return null; }
From source file:com.jiwhiz.JiwhizBlogRestApiTestApplication.java
@Bean public AuditorAware<String> auditorAware() { return new AuditorAware<String>() { public String getCurrentAuditor() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return null; }/* w ww . j a va2 s .com*/ return authentication.getName(); } }; }
From source file:com.epam.training.storefront.security.AcceleratorAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final String username = (authentication.getPrincipal() == null) ? "NONE_PROVIDED" : authentication.getName(); CustomerModel userModel = null;//from www . ja va 2 s . c o m try { userModel = (CustomerModel) getUserService().getUserForUID(StringUtils.lowerCase(username)); } catch (final UnknownIdentifierException e) { LOG.warn("Brute force attack attempt for non existing user name " + username); } if (userModel == null) { throw new BadCredentialsException("Bad credentials"); } if (getBruteForceAttackCounter().isAttack(username)) { userModel.setLoginDisabled(true); userModel.setStatus(Boolean.TRUE); userModel.setAttemptCount(0); getModelService().save(userModel); bruteForceAttackCounter.resetUserCounter(userModel.getUid()); throw new LockedException("Locked account"); } else { userModel.setAttemptCount(bruteForceAttackCounter.getUserFailedLogins(username)); getModelService().save(userModel); } return super.authenticate(authentication); }
From source file:com.t2tierp.controller.T2TiSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { try {/* w w w . java 2 s.c om*/ InitialContext initialContext = new InitialContext(); dao = (UsuarioDAO) initialContext.lookup("java:comp/ejb/usuarioDAO"); Usuario usuario = dao.getUsuario(authentication.getName()); request.getSession().setAttribute("usuarioT2TiERP", usuario); } catch (Exception e) { //e.printStackTrace(); } super.onAuthenticationSuccess(request, response, authentication); }
From source file:cherry.sqlapp.controller.sqltool.clause.SqltoolClauseControllerImpl.java
@Override public SqltoolClauseForm getForm(Integer ref, Authentication auth) { if (ref != null) { SqltoolMetadata md = metadataService.findById(ref, auth.getName()); if (md != null) { SqltoolClause record = clauseService.findById(ref); if (record != null) { return formUtil.getForm(record); }/*from w ww. j a v a 2s . c om*/ } } SqltoolClauseForm form = new SqltoolClauseForm(); form.setDatabaseName(dataSourceDef.getDefaultName()); return form; }
From source file:com.cami.web.controller.UserController.java
@RequestMapping(value = "{id}/edit", method = RequestMethod.GET) public String editAction(@PathVariable("id") final Long id, final ModelMap model) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username final Role userConnected = roleService.retrieveAUser(name); final Role role = roleService.findOne(id); if (userConnected.getId() == role.getId() | userConnected.getRole().equals("ROLE_ADMIN")) { model.addAttribute("fonction_user", userConnected.getRole()); model.addAttribute("user", role); return "user/edit"; } else {/* ww w . jav a 2 s.com*/ return "redirect:/403"; } }
From source file:com.cami.web.controller.UserController.java
@RequestMapping(value = "{id}/editSimpleUser", method = RequestMethod.GET) public String editSimpleUser(@PathVariable("id") final Long id, final ModelMap model) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username final Role userConnected = roleService.retrieveAUser(name); final Role role = roleService.findOne(id); if (userConnected.getId() == role.getId() | userConnected.getRole().equals("ROLE_ADMIN")) { model.addAttribute("fonction_user", userConnected.getRole()); model.addAttribute("user", role); return "user/sedit"; } else {//from ww w . j a v a 2s . c o m return "redirect:/403"; } }