Merge pull request #6566 from kivicko/BAEL-2762
Bael-2762 Fix tests in spring-boot-security module
This commit is contained in:
commit
d84dedbb95
@ -61,6 +61,12 @@
|
|||||||
<artifactId>spring-security-test</artifactId>
|
<artifactId>spring-security-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
|
<version>2.1.1.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.baeldung.springbootsecurity.oauth2server.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager customAuthenticationManager() throws Exception {
|
||||||
|
return authenticationManager();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.baeldung.springbootsecurity.oauth2sso;
|
package com.baeldung.springbootsecurity.oauth2sso;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
|
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
security.user.password=password
|
spring.security.user.password=password
|
||||||
security.oauth2.client.client-id=client
|
security.oauth2.client.client-id=client
|
||||||
security.oauth2.client.client-secret=secret
|
security.oauth2.client.client-secret=secret
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#jsp config
|
#jsp config
|
||||||
spring.mvc.view.prefix: /WEB-INF/views/
|
spring.mvc.view.prefix= /WEB-INF/views/
|
||||||
spring.mvc.view.suffix: .jsp
|
spring.mvc.view.suffix= .jsp
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package com.baeldung.springbootsecurity.basic_auth;
|
package com.baeldung.springbootsecurity.basic_auth;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.web.server.LocalServerPort;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@ -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
|
Assert.assertNull(response.getBody());
|
||||||
.getBody()
|
|
||||||
.contains("Unauthorized"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringBootSecurityTagLibsApplication.class)
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringBootSecurityTagLibsApplication.class)
|
||||||
public class HomeControllerIntegrationTest {
|
public class HomeControllerUnitTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
Loading…
x
Reference in New Issue
Block a user