lundi 13 avril 2015

Authentication with Spring Security + Spring data + MongoDB

I want to use Spring security with MongoDB (using Spring data).


This is my UserService class:



public class UserService {
private ApplicationContext applicationContext;
private MongoOperations mongoOperations;

public UserService() {
applicationContext = new AnnotationConfigApplicationContext(MongoConfig.class);
mongoOperations = (MongoOperations) applicationContext.getBean("mongoTemplate");
}

public User find(String username) {
return mongoOperations.findOne(Query.query(Criteria.where("username").is(username)), User.class);
}
}


And my SecurityConfig class:



@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserService userService;

@Autowired
public void configAuthBuilder(AuthenticationManagerBuilder builder) throws Exception {
builder.userDetailsService(userService); //THIS DOES NOT WORK
builder.inMemoryAuthentication().withUser("username").password("password").roles("USER");
}

}


The line I commented says:



The inferred type UserService is not a valid substitute for the bounded parameter <T extends UserDetailsService>.


How can I fix it so I can use MongoDB with Spring Security?


Aucun commentaire:

Enregistrer un commentaire