Update OAuth2 sample following breaking API change in Spring Security

See gh-8714 and 9480e09c21
pull/4041/merge
Andy Wilkinson 8 years ago
parent 918a11ea28
commit 771343e31b

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

Loading…
Cancel
Save