Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component(value = "userService")
- public class UserService implements AuthenticationProvider {
- @Inject
- @Named(value = "dataSource")
- private DataSource dataSource1;
- String name;
- String password;
- int countRow=0;
- public Authentication authenticate(Authentication auth) throws AuthenticationException {
- ResultSet resultSet = null;
- PreparedStatement preparedStatement = null;
- Connection connection = null;
- name= auth.getName();
- password=auth.getCredentials().toString();
- final String select= "select username,password from users where username='"+name+"'and password='"+password+"'";
- try {
- connection = dataSource1.getConnection();
- preparedStatement = connection.prepareStatement(select);
- resultSet = preparedStatement.executeQuery();
- if(resultSet.next()){
- countRow++;
- if(countRow!=0){
- return new UsernamePasswordAuthenticationToken(name, null);}
- }
- return null;
- }
- return new UsernamePasswordAuthenticationToken("", "");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement