Skip to content

Commit

Permalink
Enable Spotless on Identity (#42596)
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft authored Oct 25, 2024
1 parent b801348 commit 50af1d0
Show file tree
Hide file tree
Showing 148 changed files with 3,375 additions and 3,032 deletions.
1 change: 1 addition & 0 deletions sdk/identity/azure-identity-broker-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<javaModulesSurefireArgLine>
--add-opens java.xml/jdk.xml.internal=ALL-UNNAMED
</javaModulesSurefireArgLine>
<spotless.skip>false</spotless.skip>
</properties>

<parent>
Expand Down
1 change: 1 addition & 0 deletions sdk/identity/azure-identity-broker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
--add-exports com.azure.core/com.azure.core.implementation=com.azure.identity.broker
</javaModulesSurefireArgLine>
<doclintMissingInclusion>-</doclintMissingInclusion>
<spotless.skip>false</spotless.skip>
</properties>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.azure.identity.broker;


import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.ProxyOptions;
Expand Down Expand Up @@ -121,7 +120,8 @@ public InteractiveBrowserBrokerCredentialBuilder authenticationRecord(Authentica
* {@inheritDoc}
*/
@Override
public InteractiveBrowserBrokerCredentialBuilder browserCustomizationOptions(BrowserCustomizationOptions browserCustomizationOptions) {
public InteractiveBrowserBrokerCredentialBuilder
browserCustomizationOptions(BrowserCustomizationOptions browserCustomizationOptions) {
super.browserCustomizationOptions(browserCustomizationOptions);
return this;
}
Expand Down Expand Up @@ -256,7 +256,8 @@ public InteractiveBrowserBrokerCredentialBuilder redirectUrl(String redirectUrl)
* {@inheritDoc}
*/
@Override
public InteractiveBrowserBrokerCredentialBuilder additionallyAllowedTenants(List<String> additionallyAllowedTenants) {
public InteractiveBrowserBrokerCredentialBuilder
additionallyAllowedTenants(List<String> additionallyAllowedTenants) {
super.additionallyAllowedTenants(additionallyAllowedTenants);
return this;
}
Expand Down Expand Up @@ -301,7 +302,8 @@ public InteractiveBrowserBrokerCredentialBuilder retryTimeout(Function<Duration,
* {@inheritDoc}
*/
@Override
public InteractiveBrowserBrokerCredentialBuilder tokenCachePersistenceOptions(TokenCachePersistenceOptions tokenCachePersistenceOptions) {
public InteractiveBrowserBrokerCredentialBuilder
tokenCachePersistenceOptions(TokenCachePersistenceOptions tokenCachePersistenceOptions) {
super.tokenCachePersistenceOptions(tokenCachePersistenceOptions);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
requires transitive com.azure.identity;
requires msal4j.brokers;
requires com.microsoft.aad.msal4j;

opens com.azure.identity.broker.implementation to com.azure.identity;

exports com.azure.identity.broker;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;


class InteractiveBrowserBrokerCredentialBuilderTest {

@Test
Expand All @@ -24,15 +23,17 @@ public void canEnableLegacyMsa() {
}

@Test
public void canSetWindowHandle() {} {
public void canSetWindowHandle() {
}

{
assertDoesNotThrow(() -> {
InteractiveBrowserBrokerCredentialBuilder builder = new InteractiveBrowserBrokerCredentialBuilder();
builder.setWindowHandle(1L);
InteractiveBrowserCredential credential = builder.build();
});
}


@Test
void clientOptions() {
assertDoesNotThrow(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void canLoadMsalRuntime() {
}

@Test
@EnabledOnOs({OS.MAC, OS.LINUX})
@EnabledOnOs({ OS.MAC, OS.LINUX })
public void msalRuntimeErrorThrown() {
Assertions.assertThrows(ExceptionInInitializerError.class, () -> {
IBroker broker = InteractiveBrowserBroker.getMsalRuntimeBroker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private static Map<String, String> parseChallengeParameters(String challenge) {
return parameters;
}


// Method to extract the nonce parameter from the challenge response
public static String extractNonce(String challenge) {
// Split the challenge by commas to separate key-value pairs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ private Mono<Void> setAuthorizationHeaderHelper(HttpPipelineCallContext context,
}

TokenRequestContext popTokenRequestContext = new TokenRequestContext().setScopes(this.scopes)
.setProofOfPossessionOptions(new ProofOfPossessionOptions()
.setProofOfPossessionNonce(popNonce)
.setProofOfPossessionOptions(new ProofOfPossessionOptions().setProofOfPossessionNonce(popNonce)
.setRequestMethod(context.getHttpRequest().getHttpMethod())
.setRequestUrl(context.getHttpRequest().getUrl()));

Expand All @@ -196,8 +195,7 @@ private void setAuthorizationHeaderHelperSync(HttpPipelineCallContext context, b
"Proof of possession token authentication is not permitted for non TLS-protected (HTTPS) endpoints."));
}
TokenRequestContext popTokenRequestContext = new TokenRequestContext().setScopes(this.scopes)
.setProofOfPossessionOptions(new ProofOfPossessionOptions()
.setProofOfPossessionNonce(popNonce)
.setProofOfPossessionOptions(new ProofOfPossessionOptions().setProofOfPossessionNonce(popNonce)
.setRequestMethod(context.getHttpRequest().getHttpMethod())
.setRequestUrl(context.getHttpRequest().getUrl()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public void testPopTokenAuth() {
WinDef.HWND hwnd = User32.INSTANCE.GetForegroundWindow();
long hwndValue = com.sun.jna.Pointer.nativeValue(hwnd.getPointer());

InteractiveBrowserCredential interactiveBrowserCredential = new InteractiveBrowserBrokerCredentialBuilder().setWindowHandle(hwndValue).build();
InteractiveBrowserCredential interactiveBrowserCredential
= new InteractiveBrowserBrokerCredentialBuilder().setWindowHandle(hwndValue).build();

PopTokenAuthenticationPolicy policy = new PopTokenAuthenticationPolicy(interactiveBrowserCredential, "https://graph.microsoft.com/.default");
PopTokenAuthenticationPolicy policy = new PopTokenAuthenticationPolicy(interactiveBrowserCredential,
"https://graph.microsoft.com/.default");
HttpPipeline pipeline = new HttpPipelineBuilder().policies(policy).build();
HttpRequest request = new HttpRequest(HttpMethod.GET, "https://graph.microsoft.com/v1.0/me");
HttpResponse httpResponse = pipeline.sendSync(request, Context.NONE);
Expand Down
4 changes: 4 additions & 0 deletions sdk/identity/azure-identity-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<description>This package provides the ability of authenticating with Azure AD and returning a token as a password.</description>
<url>https://github.com/azure/azure-sdk-for-java</url>

<properties>
<spotless.skip>false</spotless.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.mysql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ private TokenCredential resolveTokenCredential(TokenCredentialProviderOptions op
String clientSecret = options.getClientSecret();
if (isClientIdSet && hasText(clientSecret)) {
return new ClientSecretCredentialBuilder().clientId(clientId)
.authorityHost(authorityHost)
.clientSecret(clientSecret)
.tenantId(tenantId)
.build();
.authorityHost(authorityHost)
.clientSecret(clientSecret)
.tenantId(tenantId)
.build();
}

String clientCertificatePath = options.getClientCertificatePath();
if (isClientIdSet && hasText(clientCertificatePath)) {
ClientCertificateCredentialBuilder builder = new ClientCertificateCredentialBuilder()
.authorityHost(authorityHost)
ClientCertificateCredentialBuilder builder
= new ClientCertificateCredentialBuilder().authorityHost(authorityHost)
.tenantId(tenantId)
.clientId(clientId);

Expand All @@ -76,14 +76,13 @@ private TokenCredential resolveTokenCredential(TokenCredentialProviderOptions op
}
}

if (isClientIdSet && hasText(options.getUsername())
&& hasText(options.getPassword())) {
if (isClientIdSet && hasText(options.getUsername()) && hasText(options.getPassword())) {
return new UsernamePasswordCredentialBuilder().username(options.getUsername())
.authorityHost(authorityHost)
.password(options.getPassword())
.clientId(clientId)
.tenantId(tenantId)
.build();
.authorityHost(authorityHost)
.password(options.getPassword())
.clientId(clientId)
.tenantId(tenantId)
.build();
}

if (options.isManagedIdentityEnabled()) {
Expand All @@ -94,11 +93,10 @@ && hasText(options.getPassword())) {
return builder.build();
}

return new DefaultAzureCredentialBuilder()
.authorityHost(authorityHost)
.tenantId(tenantId)
.managedIdentityClientId(clientId)
.build();
return new DefaultAzureCredentialBuilder().authorityHost(authorityHost)
.tenantId(tenantId)
.managedIdentityClientId(clientId)
.build();
}

private boolean hasText(@Nullable String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ public enum AuthProperty {
/**
* Client ID to use when performing service principal authentication with Azure.
*/
CLIENT_ID("azure.clientId",
"Client ID to use when performing service principal authentication with Azure.",
false),
CLIENT_ID("azure.clientId", "Client ID to use when performing service principal authentication with Azure.", false),
/**
* Client secret to use when performing service principal authentication with Azure.
*/
CLIENT_SECRET("azure.clientSecret",
"Client secret to use when performing service principal authentication with Azure.",
false),
"Client secret to use when performing service principal authentication with Azure.", false),
/**
* Path of a PEM/PFX certificate file to use when performing service principal authentication with Azure.
*/
Expand All @@ -36,71 +33,51 @@ public enum AuthProperty {
/**
* Password of the certificate file.
*/
CLIENT_CERTIFICATE_PASSWORD("azure.clientCertificatePassword",
"Password of the certificate file.",
false),
CLIENT_CERTIFICATE_PASSWORD("azure.clientCertificatePassword", "Password of the certificate file.", false),
/**
* Username to use when performing username/password authentication with Azure.
*/
USERNAME("azure.username",
"Username to use when performing username/password authentication with Azure.",
false),
USERNAME("azure.username", "Username to use when performing username/password authentication with Azure.", false),
/**
* Password to use when performing username/password authentication with Azure.
*/
PASSWORD("azure.password",
"Password to use when performing username/password authentication with Azure.",
false),
PASSWORD("azure.password", "Password to use when performing username/password authentication with Azure.", false),
/**
* Whether to enable managed identity to authenticate with Azure.
*/
MANAGED_IDENTITY_ENABLED("azure.managedIdentityEnabled",
"Whether to enable managed identity to authenticate with Azure.",
false),
"Whether to enable managed identity to authenticate with Azure.", false),
/**
* The well known authority hosts for the Azure Public Cloud and sovereign clouds.
*/
AUTHORITY_HOST("azure.authorityHost",
AzureAuthorityHosts.AZURE_PUBLIC_CLOUD,
"The well known authority hosts for the Azure Public Cloud and sovereign clouds.",
true),
AUTHORITY_HOST("azure.authorityHost", AzureAuthorityHosts.AZURE_PUBLIC_CLOUD,
"The well known authority hosts for the Azure Public Cloud and sovereign clouds.", true),
/**
* Tenant ID for Azure resources.
*/
TENANT_ID("azure.tenantId",
"Tenant ID for Azure resources.",
true),
TENANT_ID("azure.tenantId", "Tenant ID for Azure resources.", true),
/**
* Claims for Azure resources.
*/
CLAIMS("azure.claims",
"Claims for Azure resources.",
false),
CLAIMS("azure.claims", "Claims for Azure resources.", false),
/**
* Scopes for Azure resources.
*/
SCOPES("azure.scopes",
"Scopes for Azure resources.",
false),
SCOPES("azure.scopes", "Scopes for Azure resources.", false),
/**
* Max time to get an access token.
*/
GET_TOKEN_TIMEOUT("azure.accessTokenTimeoutInSeconds",
"Max time to get an access token.",
false),
GET_TOKEN_TIMEOUT("azure.accessTokenTimeoutInSeconds", "Max time to get an access token.", false),
/**
* The canonical class name of a class that implements 'TokenCredentialProvider'.
*/
TOKEN_CREDENTIAL_PROVIDER_CLASS_NAME("azure.tokenCredentialProviderClassName",
"The canonical class name of a class that implements 'TokenCredentialProvider'.",
false),
"The canonical class name of a class that implements 'TokenCredentialProvider'.", false),
/**
* The given bean name of a TokenCredential bean in the Spring context.
*/
TOKEN_CREDENTIAL_BEAN_NAME("azure.tokenCredentialBeanName",
"springCloudAzureDefaultCredential",
"The given bean name of a TokenCredential bean in the Spring context.",
false);
TOKEN_CREDENTIAL_BEAN_NAME("azure.tokenCredentialBeanName", "springCloudAzureDefaultCredential",
"The given bean name of a TokenCredential bean in the Spring context.", false);

String propertyKey;
String defaultValue;
Expand Down Expand Up @@ -190,17 +167,18 @@ public void setProperty(Map<String, String> map, String value) {

static class AuthPropertyConfigurationProperty {
private static Configuration configuration = Configuration.getGlobalConfiguration();
static Map<AuthProperty, String> authPropertyKeyAndConfigurationPropertyKey = new HashMap<AuthProperty, String>() {
{
put(AuthProperty.CLIENT_ID, Configuration.PROPERTY_AZURE_CLIENT_ID);
put(AuthProperty.CLIENT_SECRET, Configuration.PROPERTY_AZURE_CLIENT_SECRET);
put(AuthProperty.CLIENT_CERTIFICATE_PATH, Configuration.PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH);
put(AuthProperty.USERNAME, Configuration.PROPERTY_AZURE_USERNAME);
put(AuthProperty.PASSWORD, Configuration.PROPERTY_AZURE_PASSWORD);
put(AuthProperty.AUTHORITY_HOST, Configuration.PROPERTY_AZURE_AUTHORITY_HOST);
put(AuthProperty.TENANT_ID, Configuration.PROPERTY_AZURE_TENANT_ID);
}
};
static Map<AuthProperty, String> authPropertyKeyAndConfigurationPropertyKey
= new HashMap<AuthProperty, String>() {
{
put(AuthProperty.CLIENT_ID, Configuration.PROPERTY_AZURE_CLIENT_ID);
put(AuthProperty.CLIENT_SECRET, Configuration.PROPERTY_AZURE_CLIENT_SECRET);
put(AuthProperty.CLIENT_CERTIFICATE_PATH, Configuration.PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH);
put(AuthProperty.USERNAME, Configuration.PROPERTY_AZURE_USERNAME);
put(AuthProperty.PASSWORD, Configuration.PROPERTY_AZURE_PASSWORD);
put(AuthProperty.AUTHORITY_HOST, Configuration.PROPERTY_AZURE_AUTHORITY_HOST);
put(AuthProperty.TENANT_ID, Configuration.PROPERTY_AZURE_TENANT_ID);
}
};

static String getConfigurationPropertyValue(AuthProperty authProperty) {
String key = authPropertyKeyAndConfigurationPropertyKey.get(authProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class AzureAuthenticationTemplate {

private AccessTokenResolver accessTokenResolver;


/**
* Default constructor for AzureAuthenticationTemplate
*/
Expand All @@ -43,7 +42,7 @@ public AzureAuthenticationTemplate() {
* @param accessTokenResolver An AccessTokenResolver class instance.
*/
public AzureAuthenticationTemplate(TokenCredentialProvider tokenCredentialProvider,
AccessTokenResolver accessTokenResolver) {
AccessTokenResolver accessTokenResolver) {
this.tokenCredentialProvider = tokenCredentialProvider;
this.accessTokenResolver = accessTokenResolver;
}
Expand All @@ -58,13 +57,13 @@ public void init(Properties properties) {
LOGGER.verbose("Initializing AzureAuthenticationTemplate.");

if (getTokenCredentialProvider() == null) {
this.tokenCredentialProvider = TokenCredentialProvider.createDefault(
new TokenCredentialProviderOptions(properties));
this.tokenCredentialProvider
= TokenCredentialProvider.createDefault(new TokenCredentialProviderOptions(properties));
}

if (getAccessTokenResolver() == null) {
this.accessTokenResolver = AccessTokenResolver.createDefault(
new AccessTokenResolverOptions(properties));
this.accessTokenResolver
= AccessTokenResolver.createDefault(new AccessTokenResolverOptions(properties));
}

LOGGER.verbose("Initialized AzureAuthenticationTemplate.");
Expand All @@ -83,9 +82,9 @@ public Mono<String> getTokenAsPasswordAsync() {
throw LOGGER.logExceptionAsError(new IllegalStateException("must call init() first"));
}
return Mono.fromSupplier(getTokenCredentialProvider())
.flatMap(getAccessTokenResolver())
.filter(token -> !token.isExpired())
.map(AccessToken::getToken);
.flatMap(getAccessTokenResolver())
.filter(token -> !token.isExpired())
.map(AccessToken::getToken);
}

/**
Expand Down
Loading

0 comments on commit 50af1d0

Please sign in to comment.