Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1.  
  2. package com.oblivionsoftware.raid.security;
  3.  
  4. /**
  5.  * Imports
  6.  */
  7. import com.oblivionsoftware.raid.security.encoder.PasswordEncoder;
  8. import com.oblivionsoftware.raid.entity.User;
  9. import com.oblivionsoftware.raid.entity.UserManagerBean;
  10. import javax.ejb.EJB;
  11. import javax.ejb.Stateless;
  12. import javax.persistence.EntityNotFoundException;
  13.  
  14. /**
  15.  * SecurityServiceBean.
  16.  *
  17.  * @author Dustin Dobervich <ddobervich@gmail.com>
  18.  */
  19. @Stateless
  20. public class SecurityManagerBean
  21. {
  22.     @EJB
  23.     private UserManagerBean userManager;
  24.    
  25.     /**
  26.      * Validates a users credentials.
  27.      *
  28.      * @param username The username
  29.      * @param password The password
  30.      * @return True if valid, false otherwise
  31.      */
  32.     public boolean validateCredentials(String username, String password)
  33.     {
  34.         User user = this.userManager.findUserByUsername(username);
  35.         if (user == null) {
  36.             throw new EntityNotFoundException("Unable to find user with username: " + username);
  37.         }
  38.        
  39.         PasswordEncoder encoder = new PasswordEncoder();
  40.         String encodedPassword = encoder.encodePassword(password, user.getSalt());
  41.        
  42.         return encodedPassword.equals(password);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement