Пример #1
0
  public User saveDefault(User user) {
    System.out.println(SecurityContextHolder.getContext().getAuthentication());
    String password = this.passwordEncoder.encode(user.getPassword());
    user.setPassword(password);

    return this.accountRepository.save(user);
  }
Пример #2
0
  /**
   * @param user
   * @return
   */
  public User registerNewUser(User user) {
    String password = this.passwordEncoder.encode(user.getPassword());
    user.setPassword(password);

    user.setProfile(this.findProfileByName("Usuário externo registrado"));

    return this.accountRepository.save(user);
  }
Пример #3
0
  /**
   * @param user
   * @return
   */
  @PreAuthorize("hasPermission(#principal,'" + SystemPermissions.USUARIOS_INSERT + "')")
  public User save(User user) {
    System.out.println(SecurityContextHolder.getContext().getAuthentication());
    String password = this.passwordEncoder.encode(user.getPassword());
    user.setPassword(password);

    return this.accountRepository.save(user);
  }
Пример #4
0
  /**
   * @param permission
   * @return
   * @throws AccessDeniedException
   */
  public boolean hasPermission(String permission) throws AccessDeniedException {
    final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (!(authentication.getPrincipal() instanceof User)) {
      return false;
    }

    final User user = (User) authentication.getPrincipal();

    for (Permissao systemRole : user.getProfile().getPermissaos()) {
      if (systemRole.getName().equals(permission)) {
        return true;
      }
    }
    return false;
  }