[BAEL-12731] - Fixed tests in spring-boot-security module

This commit is contained in:
amit2103 2019-03-16 20:40:14 +05:30
parent 6ad4766776
commit 1ff8710842
5 changed files with 24 additions and 7 deletions

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

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

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

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

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