Merge pull request #6566 from kivicko/BAEL-2762

Bael-2762 Fix tests in spring-boot-security module
This commit is contained in:
Loredana Crusoveanu 2019-03-24 16:29:54 +02:00 committed by GitHub
commit d84dedbb95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 12 deletions

View File

@ -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>

View File

@ -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");
} }

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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");
} }

View File

@ -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

View File

@ -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

View File

@ -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"));
} }
} }

View File

@ -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;