예제 #1
0
  @Override
  public boolean isCorrectUsernameAndPassword(String username, String password) {
    User user = userRepository.getUserByUsername(username);
    if (user == null) {
      return false;
    } else {
      // set authorization
      List<GrantedAuthority> authority = new ArrayList<GrantedAuthority>();
      GrantedAuthority grantedAuthority =
          new GrantedAuthority() {

            @Override
            public String getAuthority() {
              // TODO Auto-generated method stub
              return user.getRole().getName();
            }
          };
      authority.add(grantedAuthority);

      Authentication authentication =
          new UsernamePasswordAuthenticationToken(user, user.getPassword(), authority);

      SecurityContextHolder.getContext().setAuthentication(authentication);

      return user.getPassword().equals(password);
    }
  }
예제 #2
0
 @Override
 @PreAuthorize("hasRole('admin')")
 public User updateUser(User user) {
   String username = user.getUsername();
   String password = user.getPassword();
   long id = user.getId();
   return userRepository.update(username, password, id);
 }
예제 #3
0
 @Override
 public void deleteUser(Long userId) {
   userRepository.delete(userId);
 }
예제 #4
0
 @Override
 public List<User> getUserByName(String name) {
   return userRepository.getUserByName(name);
 }
예제 #5
0
 @Override
 public User getUserById(Long userId) {
   return userRepository.findOne(userId);
 }
예제 #6
0
 @Override
 @PreAuthorize("hasRole('admin')")
 public User saveUser(User user) {
   return userRepository.save(user);
 }
예제 #7
0
 public List<User> getAllUsers() {
   return (List<User>) userRepository.findAll();
 }