-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update AAD auto-config conditional and split OAuth2AuthorizedClientMa…
…nager configuration (#26964)
- Loading branch information
Showing
17 changed files
with
563 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...g/cloud/autoconfigure/aad/implementation/conditions/AbstractApplicationTypeCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.cloud.autoconfigure.aad.implementation.conditions; | ||
|
||
import com.azure.spring.cloud.autoconfigure.aad.properties.AADApplicationType; | ||
import com.azure.spring.cloud.autoconfigure.aad.properties.AADAuthenticationProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionMessage; | ||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; | ||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; | ||
import org.springframework.boot.context.properties.bind.Binder; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Abstract class condition for each application type scenario. | ||
*/ | ||
public abstract class AbstractApplicationTypeCondition extends SpringBootCondition { | ||
|
||
/** | ||
* Check the applicationType satisfies the target application type. | ||
* @param applicationType the target application type. | ||
* @return true if the applicationType satisfies the target type condition. | ||
*/ | ||
abstract boolean isTargetApplicationType(AADApplicationType applicationType); | ||
|
||
private boolean isNotTargetApplicationType(AADApplicationType applicationType) { | ||
return !isTargetApplicationType(applicationType); | ||
} | ||
|
||
/** | ||
* Return the condition title name. | ||
* @return the condition title. | ||
*/ | ||
abstract String getConditionTitle(); | ||
|
||
@Override | ||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
ConditionMessage.Builder message = ConditionMessage.forCondition(getConditionTitle()); | ||
AADAuthenticationProperties properties = | ||
Binder.get(context.getEnvironment()) | ||
.bind("spring.cloud.azure.active-directory", AADAuthenticationProperties.class) | ||
.orElse(null); | ||
if (properties == null) { | ||
return ConditionOutcome.noMatch(message.notAvailable("aad authorization properties")); | ||
} | ||
|
||
// Bind properties will not execute AADAuthenticationProperties#afterPropertiesSet() | ||
AADApplicationType applicationType = Optional.ofNullable(properties.getApplicationType()) | ||
.orElseGet(AADApplicationType::inferApplicationTypeByDependencies); | ||
if (isNotTargetApplicationType(applicationType)) { | ||
return ConditionOutcome.noMatch( | ||
message.because("spring.cloud.azure.active-directory.application-type=" + applicationType)); | ||
} | ||
return ConditionOutcome.match( | ||
message.foundExactly("spring.cloud.azure.active-directory.application-type=" + applicationType)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ing/cloud/autoconfigure/aad/implementation/conditions/ResourceServerWithOBOCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.cloud.autoconfigure.aad.implementation.conditions; | ||
|
||
import com.azure.spring.cloud.autoconfigure.aad.properties.AADApplicationType; | ||
import org.springframework.context.annotation.Condition; | ||
|
||
import static com.azure.spring.cloud.autoconfigure.aad.properties.AADApplicationType.RESOURCE_SERVER_WITH_OBO; | ||
|
||
/** | ||
* {@link Condition} that checks for resource server with OBO scenario. | ||
*/ | ||
public final class ResourceServerWithOBOCondition extends AbstractApplicationTypeCondition { | ||
|
||
@Override | ||
boolean isTargetApplicationType(AADApplicationType applicationType) { | ||
return applicationType == RESOURCE_SERVER_WITH_OBO; | ||
} | ||
|
||
@Override | ||
protected String getConditionTitle() { | ||
return "AAD Resource Server with OBO Condition"; | ||
} | ||
} |
Oops, something went wrong.