-
Notifications
You must be signed in to change notification settings - Fork 456
Added support for providing a JWKSCache implementation #804
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,12 +8,11 @@ | |||||||||||||
import static com.microsoft.azure.telemetry.TelemetryData.SERVICE_NAME; | ||||||||||||||
import static com.microsoft.azure.telemetry.TelemetryData.getClassPackageSimpleName; | ||||||||||||||
|
||||||||||||||
import com.microsoft.azure.telemetry.TelemetrySender; | ||||||||||||||
import com.nimbusds.jose.util.DefaultResourceRetriever; | ||||||||||||||
import com.nimbusds.jose.util.ResourceRetriever; | ||||||||||||||
import java.util.HashMap; | ||||||||||||||
import java.util.Map; | ||||||||||||||
|
||||||||||||||
import javax.annotation.PostConstruct; | ||||||||||||||
|
||||||||||||||
import org.slf4j.Logger; | ||||||||||||||
import org.slf4j.LoggerFactory; | ||||||||||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||||||||||||||
|
@@ -27,6 +26,11 @@ | |||||||||||||
import org.springframework.context.annotation.PropertySource; | ||||||||||||||
import org.springframework.util.ClassUtils; | ||||||||||||||
|
||||||||||||||
import com.microsoft.azure.telemetry.TelemetrySender; | ||||||||||||||
import com.nimbusds.jose.jwk.source.JWKSetCache; | ||||||||||||||
import com.nimbusds.jose.util.DefaultResourceRetriever; | ||||||||||||||
import com.nimbusds.jose.util.ResourceRetriever; | ||||||||||||||
|
||||||||||||||
@Configuration | ||||||||||||||
@ConditionalOnWebApplication | ||||||||||||||
@ConditionalOnResource(resources = "classpath:aad.enable.config") | ||||||||||||||
|
@@ -60,7 +64,12 @@ public AADAuthenticationFilterAutoConfiguration(AADAuthenticationProperties aadA | |||||||||||||
@ConditionalOnExpression("${azure.activedirectory.session-stateless:false} == false") | ||||||||||||||
public AADAuthenticationFilter azureADJwtTokenFilter() { | ||||||||||||||
LOG.info("AzureADJwtTokenFilter Constructor."); | ||||||||||||||
return new AADAuthenticationFilter(aadAuthProps, serviceEndpointsProps, getJWTResourceRetriever()); | ||||||||||||||
if (getJWKSetCache() != null) { | ||||||||||||||
LOG.info("Initializing with JWKS cache"); | ||||||||||||||
return new AADAuthenticationFilter(aadAuthProps, serviceEndpointsProps, getJWTResourceRetriever(), getJWKSetCache()); | ||||||||||||||
} else { | ||||||||||||||
return new AADAuthenticationFilter(aadAuthProps, serviceEndpointsProps, getJWTResourceRetriever()); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@Bean | ||||||||||||||
|
@@ -80,6 +89,12 @@ public ResourceRetriever getJWTResourceRetriever() { | |||||||||||||
aadAuthProps.getJwtSizeLimit()); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@Bean | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be something like what we would want to do? We would then define the lifespan within a properties file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sound good! It is a cool way to customize the cache by properties. If users don't set related configuration, it will use 5 min by default. |
||||||||||||||
@ConditionalOnMissingBean(JWKSetCache.class) | ||||||||||||||
public JWKSetCache getJWKSetCache() { | ||||||||||||||
return null; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method will always return null. It makes no sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well with my understanding that @ConditionalOnMissingBean annotation makes it so this method will only get called when JWKSetCache is missing? So in that case just return null. So the check above will create the AADAuthenticationFilter without the cache object. That's what the library currently does, it doesn't include that last argument, it has 2 constructers the old one without jwkSetCache and a new one with it. But I do not understand where the cache is configured if that bean is present... |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@PostConstruct | ||||||||||||||
private void sendTelemetry() { | ||||||||||||||
if (aadAuthProps.isAllowTelemetry()) { | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method will always return null. How can you get the specific JWKSetCache customized by yourself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also wondering about this. Trying to figure this part out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with the below changes I suggested we might not need the null check. We would always add it as the 4th parameter. And we could default the lifespan to 5 minutes. That's what it gets defaulted to if you don't pass it in as per the documentation so that would be the same behavior unless you specify in the properties file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.