List of usage examples for org.springframework.security.crypto.bcrypt BCryptPasswordEncoder BCryptPasswordEncoder
public BCryptPasswordEncoder()
From source file:com.cami.persistence.service.impl.RoleService.java
/** * on ne doit pas supprimer un utilisateur car on doit garder son historique * aussi cette mthode va juste crypter le username de faon ce que * l'utilisateur que l'on veut supprimer ne puisse plus avoir accs son * compte (puisqu'il ne connaitra plus son username car celui est encrypt) * moins qu'un administrateur ne modifie son compte pour cela * * @param id: the id of the user to delete *///ww w .j a va2 s. c om @Override public void deleteRole(final long id) { Role roleToDelete = roleDao.findOne(id); BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); roleToDelete.getUser().setUsername(passwordEncoder.encode(roleToDelete.getUser().getUsername())); roleDao.save(roleToDelete); }
From source file:au.aurin.org.controller.RestController.java
@RequestMapping(method = RequestMethod.GET, value = "/getUserOne", produces = "application/json") @ResponseStatus(HttpStatus.OK)/*from w ww. ja v a 2s. c o m*/ public @ResponseBody userDataOne getUserOne(@RequestHeader("X-AURIN-USER-ID") final String roleId, @RequestHeader("user") final String user, @RequestHeader("password") final String password, final HttpServletRequest request) { if (!roleId.equals(adminUser.getAdminUsername())) { logger.info("Incorrect X-AURIN-USER-ID passed: {}.", roleId); return null; } logger.info("*******>> Rest-getUser for Project user ={} and pass={} ", user, password); final userDataOne myuser = new userDataOne(); try { final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); if (geodataFinder.getUser(user) != null) { myuser.setUser_id(geodataFinder.getUser(user).getUser_id()); myuser.setPassword(geodataFinder.getUser(user).getPassword()); myuser.setEmail(geodataFinder.getUser(user).getEmail()); final boolean isMatch = passwordEncoder.matches(password, myuser.getPassword()); if (isMatch == true) { // final HttpSession session = request.getSession(true); // session.setAttribute("user_id", "1"); // session.setAttribute("user_name", "Alireza Shamakhy"); // session.setAttribute("user_org", "Maroondah"); myuser.setPassword(""); return myuser; } else { return null; } } else { return null; } } catch (final Exception e) { logger.info(e.toString()); logger.info("*******>> Error in Rest-getUser for Project user ={} and pass={} ", user, password); } return null; }
From source file:com.restfiddle.controller.rest.UserController.java
@RequestMapping(value = "/api/users/change-password", method = RequestMethod.POST, headers = "Accept=application/json") public @ResponseBody void changePassword(@RequestBody PasswordResetDTO passwordResetDTO) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Object principal = authentication.getPrincipal(); if (principal != null && principal instanceof User) { User loggedInUser = (User) principal; User user = userRepository.findOne(loggedInUser.getId()); PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); user.setPassword(passwordEncoder.encode(passwordResetDTO.getRetypedPassword())); userRepository.save(user);//from ww w . ja v a2 s.c om } }
From source file:com.abixen.platform.core.application.service.LayoutManagementService.java
@PreAuthorize("hasPermission(#id, '" + AclClassName.Values.LAYOUT + "', '" + PermissionName.Values.LAYOUT_EDIT + "')")/*from ww w . j av a2s.co m*/ public LayoutDto changeLayoutIcon(final Long id, final MultipartFile iconFile) throws IOException { log.debug("changeLayoutIcon() - id: {}, iconFile: {}", id, iconFile); final Layout layout = layoutService.find(id); //FIXME - rename to thumbnail final File currentThumbnailFile = new File( platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + layout.getIconFileName()); if (currentThumbnailFile.exists()) { if (!currentThumbnailFile.delete()) { throw new FileExistsException(); } } final PasswordEncoder encoder = new BCryptPasswordEncoder(); final String newIconFileName = encoder.encode(iconFile.getName() + new Date().getTime()) .replaceAll("\"", "s").replaceAll("/", "a").replace(".", "sde"); final File newIconFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + newIconFileName); final FileOutputStream out = new FileOutputStream(newIconFile); out.write(iconFile.getBytes()); out.close(); layout.changeIconFileName(newIconFileName); final Layout updatedLayout = layoutService.update(layout); return layoutToLayoutDtoConverter.convert(updatedLayout); }
From source file:com.abixen.platform.core.service.impl.UserServiceImpl.java
@Override public UserChangePasswordForm changeUserPassword(User user, UserChangePasswordForm userChangePasswordForm) { log.info("changeUserPassword()"); PasswordEncoder encoder = new BCryptPasswordEncoder(); String password = userChangePasswordForm.getCurrentPassword(); if (!encoder.matches(password, user.getPassword())) { throw new UsernameNotFoundException("Wrong username and / or password."); }/*from w w w. j av a 2 s.c om*/ user.setPassword(encoder.encode(userChangePasswordForm.getNewPassword())); updateUser(user); return userChangePasswordForm; }
From source file:resources.RedSocialColaborativaRESTFUL.java
/** * * @param _newPasswordDTO//from w w w. j a v a2 s .c om * @return * @throws NoSuchAlgorithmException */ @RequestMapping(value = "/perfil/password", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json") public ResponseEntity<String> cambioPasswordUsuario(@RequestBody NewPasswordDTO _newPasswordDTO) throws NoSuchAlgorithmException { String usernameConectado = null; Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { usernameConectado = ((UserDetails) principal).getUsername(); BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); if (_newPasswordDTO.getPasswordActual() == null) { return new ResponseEntity<>(HttpStatus.CONFLICT); } if (!encoder.matches(_newPasswordDTO.getPasswordActual(), ((UserDetails) principal).getPassword())) { return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } } if (!_newPasswordDTO.getNewPassword().equals(_newPasswordDTO.getConfPassword())) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } red.setUsername(usernameConectado); red.cambiarPassword(_newPasswordDTO.getNewPassword()); return new ResponseEntity<>(HttpStatus.OK); }
From source file:org.ng200.openolympus.Application.java
@Bean public PasswordEncoder passwordEncoder() { Application.logger.info("Creating password encoder"); return new BCryptPasswordEncoder(); }
From source file:io.dacopancm.jfee.managedController.SociosBean.java
public String addSocioAction() { try {/*from ww w . j av a 2 s. co m*/ socioService.addSocio(selectedSocio); planList = null; FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Afiliacin", "Afiliacin exitosa!")); return "/views/s/adminSocios/facturaAfiliacion.xhtml?faces-redirect=true&socCi=" + selectedSocio.getUsuario().getUsrCi() + "&h=" + UriUtils.encode(new BCryptPasswordEncoder().encode(selectedSocio.getUsuario().getUsrCi()), "UTF-8") + "&r=" + returnPage; } catch (JfeeCustomException fex) { log.error("jfee: " + fex, fex); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", fex.getMessage())); } catch (UnsupportedEncodingException ex) { log.error("jfee: " + ex, ex); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "No se pudo Afiliar.")); } return null; }
From source file:com.abixen.platform.core.service.impl.UserServiceImpl.java
@Override public User changeUserAvatar(Long userId, MultipartFile avatarFile) throws IOException { User user = findUser(userId);/*from w w w . j a va 2 s. c o m*/ File currentAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/user-avatar/" + user.getAvatarFileName()); if (currentAvatarFile.exists()) { if (!currentAvatarFile.delete()) { throw new FileExistsException(); } } PasswordEncoder encoder = new BCryptPasswordEncoder(); String newAvatarFileName = encoder.encode(avatarFile.getName() + new Date().getTime()).replaceAll("\"", "s") .replaceAll("/", "a").replace(".", "sde"); File newAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/user-avatar/" + newAvatarFileName); FileOutputStream out = new FileOutputStream(newAvatarFile); out.write(avatarFile.getBytes()); out.close(); user.setAvatarFileName(newAvatarFileName); updateUser(user); return findUser(userId); }