[BAEL-12731] - Fixed tests in spring-boot-security module
This commit is contained in:
parent
6ad4766776
commit
1ff8710842
|
@ -12,7 +12,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
.withUser("spring")
|
.withUser("spring")
|
||||||
.password("secret")
|
.password("{noop}secret")
|
||||||
.roles("USER");
|
.roles("USER");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.baeldung.springbootsecurity.oauth2server.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Profile("authz")
|
||||||
|
public class AuthenticationMananagerConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Override
|
||||||
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||||
|
return super.authenticationManagerBean();
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,13 +25,13 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
||||||
clients
|
clients
|
||||||
.inMemory()
|
.inMemory()
|
||||||
.withClient("baeldung")
|
.withClient("baeldung")
|
||||||
.secret("baeldung")
|
.secret("{noop}baeldung")
|
||||||
.authorizedGrantTypes("client_credentials", "password", "authorization_code")
|
.authorizedGrantTypes("client_credentials", "password", "authorization_code")
|
||||||
.scopes("openid", "read")
|
.scopes("openid", "read")
|
||||||
.autoApprove(true)
|
.autoApprove(true)
|
||||||
.and()
|
.and()
|
||||||
.withClient("baeldung-admin")
|
.withClient("baeldung-admin")
|
||||||
.secret("baeldung")
|
.secret("{noop}baeldung")
|
||||||
.authorizedGrantTypes("authorization_code", "client_credentials", "refresh_token")
|
.authorizedGrantTypes("authorization_code", "client_credentials", "refresh_token")
|
||||||
.scopes("read", "write")
|
.scopes("read", "write")
|
||||||
.autoApprove(true);
|
.autoApprove(true);
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class SpringBootSecurityTagLibsConfig extends WebSecurityConfigurerAdapte
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
.withUser("testUser")
|
.withUser("testUser")
|
||||||
.password("password")
|
.password("{noop}password")
|
||||||
.roles("ADMIN");
|
.roles("ADMIN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
|
@ -48,8 +49,6 @@ public class BasicAuthConfigurationIntegrationTest {
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(base.toString(), String.class);
|
ResponseEntity<String> response = restTemplate.getForEntity(base.toString(), String.class);
|
||||||
|
|
||||||
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
|
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
|
||||||
assertTrue(response
|
assertNull(response.getBody());
|
||||||
.getBody()
|
|
||||||
.contains("Unauthorized"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue