use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.
the class OAuth2ResourceServerConfigurerTests method requestWhenBearerTokenResolverAllowsQueryParameterThenEitherHeaderOrQueryParameterIsAccepted.
@Test
public void requestWhenBearerTokenResolverAllowsQueryParameterThenEitherHeaderOrQueryParameterIsAccepted() throws Exception {
this.spring.register(AllowBearerTokenAsQueryParameterConfig.class, JwtDecoderConfig.class, BasicController.class).autowire();
JwtDecoder decoder = this.spring.getContext().getBean(JwtDecoder.class);
given(decoder.decode(anyString())).willReturn(JWT);
// @formatter:off
this.mvc.perform(get("/authenticated").with(bearerToken(JWT_TOKEN))).andExpect(status().isOk()).andExpect(content().string(JWT_SUBJECT));
this.mvc.perform(get("/authenticated").param("access_token", JWT_TOKEN)).andExpect(status().isOk()).andExpect(content().string(JWT_SUBJECT));
// @formatter:on
}
use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.
the class OAuth2ResourceServerConfigurerTests method requestWhenCustomJwtDecoderExposedAsBeanThenUsed.
@Test
public void requestWhenCustomJwtDecoderExposedAsBeanThenUsed() throws Exception {
this.spring.register(CustomJwtDecoderAsBean.class, BasicController.class).autowire();
JwtDecoder decoder = this.spring.getContext().getBean(JwtDecoder.class);
given(decoder.decode(anyString())).willReturn(JWT);
// @formatter:off
this.mvc.perform(get("/authenticated").with(bearerToken(JWT_TOKEN))).andExpect(status().isOk()).andExpect(content().string(JWT_SUBJECT));
// @formatter:on
}
use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.
the class OAuth2ResourceServerConfigurerTests method requestWhenCustomJwtDecoderInLambdaOnDslThenUsed.
@Test
public void requestWhenCustomJwtDecoderInLambdaOnDslThenUsed() throws Exception {
this.spring.register(CustomJwtDecoderInLambdaOnDsl.class, BasicController.class).autowire();
CustomJwtDecoderInLambdaOnDsl config = this.spring.getContext().getBean(CustomJwtDecoderInLambdaOnDsl.class);
JwtDecoder decoder = config.decoder();
given(decoder.decode(anyString())).willReturn(JWT);
// @formatter:off
this.mvc.perform(get("/authenticated").with(bearerToken(JWT_TOKEN))).andExpect(status().isOk()).andExpect(content().string(JWT_SUBJECT));
// @formatter:on
}
use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.
the class OAuth2ResourceServerConfigurerTests method requestWhenRealmNameConfiguredThenUsesOnAccessDenied.
@Test
public void requestWhenRealmNameConfiguredThenUsesOnAccessDenied() throws Exception {
this.spring.register(RealmNameConfiguredOnAccessDeniedHandler.class, JwtDecoderConfig.class).autowire();
JwtDecoder decoder = this.spring.getContext().getBean(JwtDecoder.class);
given(decoder.decode(anyString())).willReturn(JWT);
// @formatter:off
this.mvc.perform(get("/authenticated").with(bearerToken("insufficiently_scoped"))).andExpect(status().isForbidden()).andExpect(header().string(HttpHeaders.WWW_AUTHENTICATE, startsWith("Bearer realm=\"myRealm\"")));
// @formatter:on
}
use of org.springframework.security.oauth2.jwt.JwtDecoder in project spring-security by spring-projects.
the class OAuth2ResourceServerConfigurerTests method requestWhenBasicAndResourceServerEntryPointsThenMatchedByRequest.
@Test
public void requestWhenBasicAndResourceServerEntryPointsThenMatchedByRequest() throws Exception {
this.spring.register(BasicAndResourceServerConfig.class, JwtDecoderConfig.class).autowire();
JwtDecoder decoder = this.spring.getContext().getBean(JwtDecoder.class);
given(decoder.decode(anyString())).willThrow(BadJwtException.class);
// @formatter:off
this.mvc.perform(get("/authenticated").with(httpBasic("some", "user"))).andExpect(status().isUnauthorized()).andExpect(header().string(HttpHeaders.WWW_AUTHENTICATE, startsWith("Basic")));
this.mvc.perform(get("/authenticated")).andExpect(status().isUnauthorized()).andExpect(header().string(HttpHeaders.WWW_AUTHENTICATE, startsWith("Basic")));
this.mvc.perform(get("/authenticated").with(bearerToken("invalid_token"))).andExpect(status().isUnauthorized()).andExpect(header().string(HttpHeaders.WWW_AUTHENTICATE, startsWith("Bearer")));
// @formatter:on
}
Aggregations