Last active
December 14, 2015 22:19
-
-
Save sergiomichels/5157749 to your computer and use it in GitHub Desktop.
Class that get's the username and password and try to open a database connection with this information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserDatabaseAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { | |
| def dataSource | |
| @Override | |
| protected void additionalAuthenticationChecks(UserDetails userDetails, | |
| UsernamePasswordAuthenticationToken token) throws AuthenticationException { | |
| } | |
| @Override | |
| protected UserDetails retrieveUser(String username, | |
| UsernamePasswordAuthenticationToken token) throws AuthenticationException { | |
| String password = (String) token.getCredentials(); | |
| if (!StringUtils.hasText(password)) { | |
| throw new BadCredentialsException("Please enter password"); | |
| } | |
| List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); | |
| try { | |
| Connection connection = dataSource.getConnection(username, password) | |
| dataSource.setCredentialsForCurrentThread(username, password) | |
| }catch(SQLException sql) { | |
| throw new BadCredentialsException("Invalid username or password!"); | |
| } | |
| return new User(username, password, true, true, true, true, authorities); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment