Commit 771343e3 authored by Andy Wilkinson's avatar Andy Wilkinson

Update OAuth2 sample following breaking API change in Spring Security

See gh-8714 and 9480e09c
parent 918a11ea
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package sample.secure.oauth2; package sample.secure.oauth2;
import java.util.Base64;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -29,7 +30,6 @@ import org.springframework.boot.test.context.SpringBootTest; ...@@ -29,7 +30,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.MediaTypes;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
...@@ -85,7 +85,8 @@ public class SampleSecureOAuth2ApplicationTests { ...@@ -85,7 +85,8 @@ public class SampleSecureOAuth2ApplicationTests {
@Test @Test
@Ignore @Ignore
public void accessingRootUriPossibleWithUserAccount() throws Exception { public void accessingRootUriPossibleWithUserAccount() throws Exception {
String header = "Basic " + new String(Base64.encode("greg:turnquist".getBytes())); String header = "Basic "
+ new String(Base64.getEncoder().encode("greg:turnquist".getBytes()));
this.mvc.perform( this.mvc.perform(
get("/").accept(MediaTypes.HAL_JSON).header("Authorization", header)) get("/").accept(MediaTypes.HAL_JSON).header("Authorization", header))
.andExpect( .andExpect(
...@@ -95,7 +96,8 @@ public class SampleSecureOAuth2ApplicationTests { ...@@ -95,7 +96,8 @@ public class SampleSecureOAuth2ApplicationTests {
@Test @Test
public void useAppSecretsPlusUserAccountToGetBearerToken() throws Exception { public void useAppSecretsPlusUserAccountToGetBearerToken() throws Exception {
String header = "Basic " + new String(Base64.encode("foo:bar".getBytes())); String header = "Basic "
+ new String(Base64.getEncoder().encode("foo:bar".getBytes()));
MvcResult result = this.mvc MvcResult result = this.mvc
.perform(post("/oauth/token").header("Authorization", header) .perform(post("/oauth/token").header("Authorization", header)
.param("grant_type", "password").param("scope", "read") .param("grant_type", "password").param("scope", "read")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment