I'm in a project and will use Basic Auth of Spring Security , I'd like to know how I can configure it to use users created with my Repository .
Entity:
@Entity
public class User extends SuperEntity {
private String name;
private Date birth;
private String email;
private Integer xp;
private Integer xpForNextLevel;
private Integer level;
private Integer punctuation;
private String password;
private String image;
private boolean authenticated;
public User() {
this.xp = 0;
this.punctuation = 0;
this.authenticated = false;
this.xpForNextLevel = 40;
this.level = 0;
}
}
Repository:
@Repository
public interface UserRepository extends SuperRepository<User> {
User findByEmail(String email);
List<User> findAllByDeadIsFalseOrderByPunctuationDesc();
List<User> findAllByDeadIsFalseOrderByLevelDesc();
}
Security Configuration:
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.httpBasic()
.and()
.csrf()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.antMatchers("/**").permitAll();
}
}
Application:
@SpringBootApplication
@Import(value = { SecurityConfiguration.class })
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}