-
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.
Move active directory related logic from main branch to 4.0 branch (#…
…25282) * 1. Move active directory related code from main branch to 4.0 branch. 2. Change package name. 3. Resolve the errors reported by "mvn clean install". * Delete package-info.java in this package and is sub packages: com.azure.spring.cloud.autoconfigure.active.directory.implementation. * Create 2 starters: spring-cloud-azure-starter-active-directory and spring-cloud-azure-starter-active-directory-b2c. * Delete unnecessary contents in the 2 starters: spring-cloud-azure-starter-active-directory and spring-cloud-azure-starter-active-directory-b2c.
- Loading branch information
Rujun Chen
authored
Nov 11, 2021
1 parent
37c7c01
commit 7ef326f
Showing
121 changed files
with
10,317 additions
and
9 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
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
74 changes: 74 additions & 0 deletions
74
...re/spring/cloud/autoconfigure/active/directory/implementation/aad/AADApplicationType.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,74 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.cloud.autoconfigure.active.directory.implementation.aad; | ||
|
||
import org.springframework.util.ClassUtils; | ||
|
||
/** | ||
* AAD application type. | ||
* <p>The value can be inferred by dependencies, only 'web_application_and_resource_server' must be configured manually.</p> | ||
* <pre> | ||
* | Has dependency: spring-security-oauth2-client | Has dependency: spring-security-oauth2-resource-server | Valid values of application type | Default value | | ||
* |-----------------------------------------------|--------------------------------------------------------|--------------------------------------------------------------------------------------------------------|-----------------------------| | ||
* | Yes | No | 'web_application' | 'web_application' | | ||
* | No | Yes | 'resource_server' | 'resource_server' | | ||
* | Yes | Yes | 'web_application','resource_server','resource_server_with_obo', 'web_application_and_resource_server' | 'resource_server_with_obo' | | ||
* </pre> | ||
*/ | ||
public enum AADApplicationType { | ||
|
||
WEB_APPLICATION("web_application"), | ||
RESOURCE_SERVER("resource_server"), | ||
RESOURCE_SERVER_WITH_OBO("resource_server_with_obo"), | ||
WEB_APPLICATION_AND_RESOURCE_SERVER("web_application_and_resource_server"); | ||
|
||
private final String applicationType; | ||
|
||
AADApplicationType(String applicationType) { | ||
this.applicationType = applicationType; | ||
} | ||
|
||
public String getValue() { | ||
return applicationType; | ||
} | ||
|
||
public static final String SPRING_SECURITY_OAUTH2_CLIENT_CLASS_NAME = | ||
"org.springframework.security.oauth2.client.registration.ClientRegistration"; | ||
public static final String SPRING_SECURITY_OAUTH2_RESOURCE_SERVER_CLASS_NAME = | ||
"org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"; | ||
|
||
/** | ||
* Infer application type by dependencies | ||
* | ||
* @return AADApplicationType | ||
*/ | ||
public static AADApplicationType inferApplicationTypeByDependencies() { | ||
AADApplicationType type; | ||
if (isOAuth2ClientAvailable()) { | ||
if (isResourceServerAvailable()) { | ||
type = AADApplicationType.RESOURCE_SERVER_WITH_OBO; | ||
} else { | ||
type = AADApplicationType.WEB_APPLICATION; | ||
} | ||
} else { | ||
if (isResourceServerAvailable()) { | ||
type = AADApplicationType.RESOURCE_SERVER; | ||
} else { | ||
type = null; | ||
} | ||
} | ||
return type; | ||
} | ||
|
||
private static boolean isOAuth2ClientAvailable() { | ||
return isPresent(SPRING_SECURITY_OAUTH2_CLIENT_CLASS_NAME); | ||
} | ||
|
||
private static boolean isResourceServerAvailable() { | ||
return isPresent(SPRING_SECURITY_OAUTH2_RESOURCE_SERVER_CLASS_NAME); | ||
} | ||
|
||
private static boolean isPresent(String className) { | ||
return ClassUtils.isPresent(className, ClassUtils.getDefaultClassLoader()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ng/cloud/autoconfigure/active/directory/implementation/aad/AADAuthorizationGrantType.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,35 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.cloud.autoconfigure.active.directory.implementation.aad; | ||
|
||
import org.springframework.security.oauth2.core.AuthorizationGrantType; | ||
|
||
/** | ||
* Defines grant types: client_credentials, authorization_code, on_behalf_of, azure_delegated. | ||
*/ | ||
public enum AADAuthorizationGrantType { | ||
|
||
CLIENT_CREDENTIALS("client_credentials"), | ||
AUTHORIZATION_CODE("authorization_code"), | ||
ON_BEHALF_OF("on_behalf_of"), | ||
AZURE_DELEGATED("azure_delegated"); | ||
|
||
private final String authorizationGrantType; | ||
|
||
AADAuthorizationGrantType(String authorizationGrantType) { | ||
// For backward compatibility, we support 'on-behalf-of'. | ||
if ("on-behalf-of".equals(authorizationGrantType)) { | ||
this.authorizationGrantType = "on_behalf_of"; | ||
} else { | ||
this.authorizationGrantType = authorizationGrantType; | ||
} | ||
} | ||
|
||
public String getValue() { | ||
return authorizationGrantType; | ||
} | ||
|
||
public boolean isSameGrantType(AuthorizationGrantType grantType) { | ||
return this.authorizationGrantType.equals(grantType.getValue()); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ud/autoconfigure/active/directory/implementation/aad/AADAuthorizationServerEndpoints.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,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.cloud.autoconfigure.active.directory.implementation.aad; | ||
|
||
import com.nimbusds.oauth2.sdk.util.StringUtils; | ||
|
||
/** | ||
* Used to get endpoints for Microsoft Identity authorization server. | ||
*/ | ||
public class AADAuthorizationServerEndpoints { | ||
|
||
private static final String DEFAULT_BASE_URI = "https://login.microsoftonline.com/"; | ||
|
||
private static final String AUTHORIZATION_ENDPOINT = "/oauth2/v2.0/authorize"; | ||
private static final String TOKEN_ENDPOINT = "/oauth2/v2.0/token"; | ||
private static final String JWK_SET_ENDPOINT = "/discovery/v2.0/keys"; | ||
private static final String END_SESSION_ENDPOINT = "/oauth2/v2.0/logout"; | ||
|
||
private final String baseUri; | ||
private final String tenantId; | ||
|
||
public AADAuthorizationServerEndpoints(String baseUri, String tenantId) { | ||
if (StringUtils.isBlank(baseUri)) { | ||
baseUri = DEFAULT_BASE_URI; | ||
} | ||
this.baseUri = addSlash(baseUri); | ||
this.tenantId = tenantId; | ||
} | ||
|
||
public String getBaseUri() { | ||
return this.baseUri; | ||
} | ||
|
||
private String addSlash(String uri) { | ||
return uri.endsWith("/") ? uri : uri + "/"; | ||
} | ||
|
||
public String authorizationEndpoint() { | ||
return baseUri + tenantId + AUTHORIZATION_ENDPOINT; | ||
} | ||
|
||
public String tokenEndpoint() { | ||
return baseUri + tenantId + TOKEN_ENDPOINT; | ||
} | ||
|
||
public String jwkSetEndpoint() { | ||
return baseUri + tenantId + JWK_SET_ENDPOINT; | ||
} | ||
|
||
public String endSessionEndpoint() { | ||
return baseUri + tenantId + END_SESSION_ENDPOINT; | ||
} | ||
} |
Oops, something went wrong.