Java Code Examples for org.springframework.security.oauth2.server.resource.web.BearerTokenResolver

The following examples show how to use org.springframework.security.oauth2.server.resource.web.BearerTokenResolver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testUserBeansReturnedUserConfigPresent() {
	this.contextRunner
			.withUserConfiguration(UserConfiguration.class)
			.withPropertyValues("spring.cloud.gcp.security.iap.audience=unused")
			.run((context) -> {
				JwtDecoder jwtDecoder =  context.getBean(JwtDecoder.class);
				assertThat(jwtDecoder).isNotNull();
				assertThat(jwtDecoder).isNotInstanceOf(NimbusJwtDecoderJwkSupport.class);
				assertThat(jwtDecoder.decode("Ceci n'est pas un Jwt")).isSameAs(mockJwt);

				BearerTokenResolver resolver = context.getBean(BearerTokenResolver.class);
				assertThat(resolver).isNotNull();
				assertThat(resolver.resolve(this.mockIapRequest)).isEqualTo(FAKE_USER_TOKEN);
				assertThat(resolver.resolve(this.mockNonIapRequest)).isEqualTo(FAKE_USER_TOKEN);
			});
}
 
Example 2
BearerTokenResolver getTokenBrokerResolver() {
	Cache cache = new CaffeineCache("token",
			Caffeine.newBuilder()
					.expireAfterWrite(15, TimeUnit.MINUTES)
					.maximumSize(100).build(), false);

	return new TokenBrokerResolver(xsuaaServiceConfiguration, cache, AuthenticationMethod.BASIC);
}
 
Example 3
@Test
public void testCustomPropertyOverridesDefault() {
	this.contextRunner
			.withPropertyValues("spring.cloud.gcp.security.iap.header=some-other-header")
			.withPropertyValues("spring.cloud.gcp.security.iap.audience=unused")
			.run((context) -> {
				when(this.mockNonIapRequest.getHeader("some-other-header")).thenReturn("other header jwt");

				BearerTokenResolver resolver = context.getBean(BearerTokenResolver.class);
				assertThat(resolver).isNotNull();
				assertThat(resolver.resolve(this.mockIapRequest)).isEqualTo(null);
				assertThat(resolver.resolve(this.mockNonIapRequest)).isEqualTo("other header jwt");
			});
}
 
Example 4
private void verifyJwtBeans(AssertableApplicationContext context) {
	JwtDecoder jwtDecoder =  context.getBean(JwtDecoder.class);
	assertThat(jwtDecoder).isNotNull();
	assertThat(jwtDecoder).isInstanceOf(NimbusJwtDecoderJwkSupport.class);

	BearerTokenResolver resolver = context.getBean(BearerTokenResolver.class);
	assertThat(resolver).isNotNull();
	assertThat(resolver.resolve(this.mockIapRequest)).isEqualTo("very fake jwt");

	assertThat(resolver.resolve(this.mockNonIapRequest)).isNull();
}
 
Example 5
@Bean
@ConditionalOnMissingBean
public BearerTokenResolver iatTokenResolver(IapAuthenticationProperties properties) {
	return (r) -> r.getHeader(properties.getHeader());
}
 
Example 6
@Bean
public BearerTokenResolver bearerTokenResolver() {
	return (httpServletRequest) -> FAKE_USER_TOKEN;
}