Open christolis opened 4 months ago
i tried running a random snippet but results were unexpected,
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// this you get for free when you configure the db connection in application.properties file
@Autowired
private DataSource dataSource;
// this bean is created in the application starter class if you're looking for it
@Autowired
private PasswordEncoder encoder;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll() // For CORS, the preflight request
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll() // will hit the OPTIONS on the route
.antMatchers("/api/**").authenticated() // Requests for our REST API must be authorized.
.anyRequest().permitAll() // All other requests are allowed without authorization.
.and()
.httpBasic(); // Use HTTP Basic Authentication
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
String userQuery = "SELECT username, password, enabled FROM User WHERE username=?";
String authQuery = "SELECT username, role FROM User WHERE username=?";
auth
.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery(userQuery)
.authoritiesByUsernameQuery(authQuery)
.passwordEncoder(encoder);
}
}@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// this you get for free when you configure the db connection in application.properties file
@Autowired
private DataSource dataSource;
// this bean is created in the application starter class if you're looking for it
@Autowired
private PasswordEncod
OUTPUT:
er encoder;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll() // For CORS, the preflight request
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll() // will hit the OPTIONS on the route
.antMatchers("/api/**").authenticated() // Requests for our REST API must be authorized.
.anyRequest().permitAll() // All other requests are allowed without authorization.
.and()
.httpBasic(); // Use HTTP Basic Authentication
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
String userQuery = "SELECT username, password, enabled FROM User WHERE username=?";
String authQuery = "SELECT username, role FROM User WHERE username=?";
auth
.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery(userQuery)
.authoritiesByUsernameQuery(authQuery)
.passwordEncoder(encoder);
}
}
It's not complete output and always same as well, the length is less than 2k this is gpt formatting at work
Closes #813.