I have configured spring boot security, by adding the dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
And the following class:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers(HttpMethod.GET, "/api").authenticated().and().httpBasic();
http.csrf().disable();
}
}
I have also added These properties in yml:
security:
user: user
Password: user
And am using postman, my URL to secure is:
http://localhost:8080/api
and am adding authorization : type is Basic Auth and username is user and Password is user are also added
But everytime i do Get on this URL, i get 401 unauthorized error.
Please any help is great
Please correct the settings in your application.yml as follows:
spring:
name:
user: user
password: user
BTW, you may see following message in your console output after starting up your application if the configuration hasn't been read correctly:
Using default security password: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Hope this helps to you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With