diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java index 202c97ff..3b128d7f 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java @@ -145,7 +145,7 @@ void acquireTokenInteractive_Ciam() { result = pca.acquireToken(parameters).get(); } catch (Exception e) { - LOG.error("Error acquiring token with authCode: " + e.getMessage()); + LOG.error("Error acquiring token with authCode: {}", e.getMessage()); throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage()); } @@ -236,7 +236,7 @@ private IAuthenticationResult acquireTokenInteractive( result = pca.acquireToken(parameters).get(); } catch (Exception e) { - LOG.error("Error acquiring token with authCode: " + e.getMessage()); + LOG.error("Error acquiring token with authCode: {}", e.getMessage()); throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage()); } return result; @@ -266,7 +266,7 @@ private IAuthenticationResult acquireTokenInteractive_instanceAware( result = pca.acquireToken(parameters).get(); } catch (Exception e) { - LOG.error("Error acquiring token with authCode: " + e.getMessage()); + LOG.error("Error acquiring token with authCode: {}", e.getMessage()); throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage()); } return result; diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java index d43e6710..c0ed99a7 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java @@ -202,7 +202,7 @@ private IAuthenticationResult acquireTokenAuthorizationCodeFlow( .get(); } catch (Exception e) { - LOG.error("Error acquiring token with authCode: " + e.getMessage()); + LOG.error("Error acquiring token with authCode: {}", e.getMessage()); throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage()); } return result; @@ -219,7 +219,7 @@ private IAuthenticationResult acquireTokenInteractiveB2C(ConfidentialClientAppli .build()) .get(); } catch (Exception e) { - LOG.error("Error acquiring token with authCode: " + e.getMessage()); + LOG.error("Error acquiring token with authCode: {}", e.getMessage()); throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage()); } return result; diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java index 3653bfc4..94801e29 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java @@ -152,7 +152,7 @@ private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user) { if (!isRunningLocally) { SeleniumExtensions.takeScreenShot(seleniumDriver); } - LOG.error("Browser automation failed: " + e.getMessage()); + LOG.error("Browser automation failed: {}", e.getMessage()); throw new RuntimeException("Browser automation failed: " + e.getMessage()); } } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java index 62a2eef8..68ec7593 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java @@ -36,7 +36,7 @@ class AadInstanceDiscoveryProvider { static final TreeSet TRUSTED_HOSTS_SET = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); static final TreeSet TRUSTED_SOVEREIGN_HOSTS_SET = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); - private static final Logger log = LoggerFactory.getLogger(AadInstanceDiscoveryProvider.class); + private static final Logger LOG = LoggerFactory.getLogger(AadInstanceDiscoveryProvider.class); //flag to check if instance discovery has failed private static boolean instanceDiscoveryFailed = false; @@ -67,7 +67,7 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl, //If instanceDiscovery flag set to false OR this is a managed identity scenario, cache a basic instance metadata entry to skip this and future lookups if (msalRequest.application() instanceof ManagedIdentityApplication || !((AbstractClientApplicationBase) msalRequest.application()).instanceDiscovery()) { if (cache.get(host) == null) { - log.debug("Instance discovery set to false, caching a default entry."); + LOG.debug("Instance discovery set to false, caching a default entry."); cacheInstanceDiscoveryMetadata(host); } return cache.get(host); @@ -80,10 +80,10 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl, //If there is no cached instance metadata, do instance discovery cache the result if (cache.get(host) == null) { - log.debug("No cached instance metadata, will attempt instance discovery."); + LOG.debug("No cached instance metadata, will attempt instance discovery."); if (shouldUseRegionalEndpoint(msalRequest)) { - log.debug("Region API used, will attempt to discover Azure region."); + LOG.debug("Region API used, will attempt to discover Azure region."); //Server side telemetry requires the result from region discovery when any part of the region API is used String detectedRegion = discoverRegion(msalRequest, serviceBundle); @@ -93,7 +93,7 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl, if (((AbstractClientApplicationBase) msalRequest.application()).azureRegion() == null && ((AbstractClientApplicationBase) msalRequest.application()).autoDetectRegion() && detectedRegion != null) { - log.debug(String.format("Region autodetection found %s, this region will be used for future calls.", detectedRegion)); + LOG.debug("Region autodetection found {}, this region will be used for future calls.", detectedRegion); ((AbstractClientApplicationBase) msalRequest.application()).azureRegion = detectedRegion; host = getRegionalizedHost(authorityUrl.getHost(), ((AbstractClientApplicationBase) msalRequest.application()).azureRegion()); @@ -160,7 +160,7 @@ private static boolean shouldUseRegionalEndpoint(MsalRequest msalRequest){ } else { //Avoid unnecessary warnings when looking for cached tokens by checking if request was a silent call if (msalRequest.getClass() != SilentRequest.class) { - log.warn("Regional endpoints are only available for client credential flow, request will fall back to using the global endpoint. See here for more information about supported scenarios: https://aka.ms/msal4j-azure-regions"); + LOG.warn("Regional endpoints are only available for client credential flow, request will fall back to using the global endpoint. See here for more information about supported scenarios: https://aka.ms/msal4j-azure-regions"); } return false; } @@ -241,7 +241,7 @@ static AadInstanceDiscoveryResponse sendInstanceDiscoveryRequest(URL authorityUr throw MsalServiceExceptionFactory.fromHttpResponse(httpResponse); } // instance discovery failed due to reasons other than an invalid authority, do not perform instance discovery again in this environment. - log.debug("Instance discovery failed due to an unknown error, no more instance discovery attempts will be made."); + LOG.debug("Instance discovery failed due to an unknown error, no more instance discovery attempts will be made."); cacheInstanceDiscoveryMetadata(authorityUrl.getHost()); } @@ -293,7 +293,7 @@ static String discoverRegion(MsalRequest msalRequest, ServiceBundle serviceBundl //Check if the REGION_NAME environment variable has a value for the region if (System.getenv(REGION_NAME) != null) { - log.info(String.format("Region found in environment variable: %s",System.getenv(REGION_NAME))); + LOG.info("Region found in environment variable: {}", System.getenv(REGION_NAME)); currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_ENV_VARIABLE.telemetryValue); return System.getenv(REGION_NAME); @@ -307,23 +307,23 @@ static String discoverRegion(MsalRequest msalRequest, ServiceBundle serviceBundl Future future = executor.submit(() -> executeRequest(IMDS_ENDPOINT, headers, msalRequest, serviceBundle)); try { - log.info("Starting call to IMDS endpoint."); + LOG.info("Starting call to IMDS endpoint."); IHttpResponse httpResponse = future.get(IMDS_TIMEOUT, IMDS_TIMEOUT_UNIT); //If call to IMDS endpoint was successful, return region from response body if (httpResponse.statusCode() == HttpStatus.HTTP_OK && !httpResponse.body().isEmpty()) { - log.info(String.format("Region retrieved from IMDS endpoint: %s", httpResponse.body())); + LOG.info("Region retrieved from IMDS endpoint: {}", httpResponse.body()); currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_IMDS.telemetryValue); return httpResponse.body(); } - log.warn(String.format("Call to local IMDS failed with status code: %s, or response was empty", httpResponse.statusCode())); + LOG.warn("Call to local IMDS failed with status code: {}, or response was empty", httpResponse.statusCode()); currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_FAILED_AUTODETECT.telemetryValue); } catch (Exception ex) { // handle other exceptions //IMDS call failed, cannot find region //The IMDS endpoint is only available from within an Azure environment, so the most common cause of this // exception will likely be java.net.SocketException: Network is unreachable: connect - log.warn(String.format("Exception during call to local IMDS endpoint: %s", ex.getMessage())); + LOG.warn("Exception during call to local IMDS endpoint: {}", ex.getMessage()); currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_FAILED_AUTODETECT.telemetryValue); future.cancel(true); diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractManagedIdentitySource.java index a331eb1d..2593dc41 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractManagedIdentitySource.java @@ -74,9 +74,8 @@ public ManagedIdentityResponse handleResponse( return getSuccessfulResponse(response); } else { message = getMessageFromErrorResponse(response); - LOG.error( - String.format("[Managed Identity] request failed, HttpStatusCode: %s, Error message: %s", - response.statusCode(), message)); + LOG.error("[Managed Identity] request failed, HttpStatusCode: {}, Error message: {}", + response.statusCode(), message); throw new MsalServiceException(message, AuthenticationErrorCode.MANAGED_IDENTITY_REQUEST_FAILED, managedIdentitySourceType); } } catch (Exception e) { diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByClientCredentialSupplier.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByClientCredentialSupplier.java index 98f2d7db..4a376db7 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByClientCredentialSupplier.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByClientCredentialSupplier.java @@ -46,7 +46,7 @@ AuthenticationResult execute() throws Exception { return supplier.execute(); } catch (MsalClientException ex) { - LOG.debug(String.format("Cache lookup failed: %s", ex.getMessage())); + LOG.debug("Cache lookup failed: {}", ex.getMessage()); return acquireTokenByClientCredential(); } } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByInteractiveFlowSupplier.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByInteractiveFlowSupplier.java index 5e01b315..d0924619 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByInteractiveFlowSupplier.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByInteractiveFlowSupplier.java @@ -109,7 +109,7 @@ private void updateRedirectUrl() { try { URI updatedRedirectUrl = new URI("http://localhost:" + httpListener.port()); interactiveRequest.interactiveRequestParameters().redirectUri(updatedRedirectUrl); - LOG.debug("Redirect URI updated to" + updatedRedirectUrl); + LOG.debug("Redirect URI updated to {}", updatedRedirectUrl); } catch (URISyntaxException ex) { throw new MsalClientException("Error updating redirect URI. Not a valid URI format", AuthenticationErrorCode.INVALID_REDIRECT_URI); @@ -204,7 +204,7 @@ private AuthorizationResult getAuthorizationResultFromHttpListener() { long expirationTime; if (timeFromParameters > 0) { - LOG.debug(String.format("Listening for authorization result. Listener will timeout after %S seconds.", timeFromParameters)); + LOG.debug("Listening for authorization result. Listener will timeout after {} seconds.", timeFromParameters); expirationTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + timeFromParameters; } else { LOG.warn("Listening for authorization result. Timeout configured to less than 1 second, listener will use a 1 second timeout instead."); @@ -213,7 +213,7 @@ private AuthorizationResult getAuthorizationResultFromHttpListener() { while (result == null && !interactiveRequest.futureReference().get().isDone()) { if (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) > expirationTime) { - LOG.warn(String.format("Listener timed out after %S seconds, no authorization code was returned from the server during that time.", timeFromParameters)); + LOG.warn("Listener timed out after {} seconds, no authorization code was returned from the server during that time.", timeFromParameters); break; } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByManagedIdentitySupplier.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByManagedIdentitySupplier.java index 15943bf6..41e81b3c 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByManagedIdentitySupplier.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByManagedIdentitySupplier.java @@ -90,15 +90,15 @@ AuthenticationResult execute() throws Exception { return fetchNewAccessTokenAndSaveToCache(tokenRequestExecutor, CacheRefreshReason.CLAIMS); } - LOG.debug(String.format("Refreshing access token. Cache refresh reason: %s", cacheRefreshReason)); + LOG.debug("Refreshing access token. Cache refresh reason: {}", cacheRefreshReason); return fetchNewAccessTokenAndSaveToCache(tokenRequestExecutor, cacheRefreshReason); } } catch (MsalClientException ex) { if (ex.errorCode().equals(AuthenticationErrorCode.CACHE_MISS)) { - LOG.debug(String.format("Cache lookup failed: %s", ex.getMessage())); + LOG.debug("Cache lookup failed: {}", ex.getMessage()); return fetchNewAccessTokenAndSaveToCache(tokenRequestExecutor, cacheRefreshReason); } else { - LOG.error(String.format("Error occurred while cache lookup: %s", ex.getMessage())); + LOG.error("Error occurred while cache lookup: {}", ex.getMessage()); throw ex; } } @@ -108,8 +108,8 @@ private AuthenticationResult fetchNewAccessTokenAndSaveToCache(TokenRequestExecu ManagedIdentityClient managedIdentityClient = new ManagedIdentityClient(msalRequest, tokenRequestExecutor.getServiceBundle()); - LOG.debug(String.format("[Managed Identity] Managed Identity source and ID type identified and set successfully, request will use Managed Identity for %s", - managedIdentityClient.managedIdentitySource.managedIdentitySourceType.name())); + LOG.debug("[Managed Identity] Managed Identity source and ID type identified and set successfully, request will use Managed Identity for {}", + managedIdentityClient.managedIdentitySource.managedIdentitySourceType.name()); ManagedIdentityResponse managedIdentityResponse = managedIdentityClient .getManagedIdentityResponse(managedIdentityParameters); diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByOnBehalfOfSupplier.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByOnBehalfOfSupplier.java index 2d5f27d4..2f438997 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByOnBehalfOfSupplier.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByOnBehalfOfSupplier.java @@ -46,7 +46,7 @@ AuthenticationResult execute() throws Exception { return supplier.execute(); } catch (MsalClientException ex) { - LOG.debug(String.format("Cache lookup failed: %s", ex.getMessage())); + LOG.debug("Cache lookup failed: {}", ex.getMessage()); return acquireTokenOnBehalfOf(); } } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenSilentSupplier.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenSilentSupplier.java index 9fdfc14a..00f97621 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenSilentSupplier.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenSilentSupplier.java @@ -11,7 +11,7 @@ class AcquireTokenSilentSupplier extends AuthenticationResultSupplier { - private static final Logger log = LoggerFactory.getLogger(AcquireTokenSilentSupplier.class); + private static final Logger LOG = LoggerFactory.getLogger(AcquireTokenSilentSupplier.class); private SilentRequest silentRequest; protected static final int ACCESS_TOKEN_EXPIRE_BUFFER_IN_SEC = 5 * 60; @@ -74,7 +74,7 @@ AuthenticationResult execute() throws Exception { throw new MsalClientException(AuthenticationErrorMessage.NO_TOKEN_IN_CACHE, AuthenticationErrorCode.CACHE_MISS); } - log.debug("Returning token from cache"); + LOG.debug("Returning token from cache"); return res; } @@ -99,7 +99,7 @@ private AuthenticationResult makeRefreshRequest(AuthenticationResult cachedResul refreshedResult.metadata().tokenSource(TokenSource.IDENTITY_PROVIDER); refreshedResult.metadata().cacheRefreshReason(refreshReason); - log.info("Access token refreshed successfully."); + LOG.info("Access token refreshed successfully."); return refreshedResult; } catch (MsalServiceException ex) { //If the token refresh attempt threw a MsalServiceException but the refresh attempt was done @@ -117,7 +117,7 @@ private boolean shouldRefresh(SilentParameters parameters, AuthenticationResult //If forceRefresh is true, no reason to check any other option if (parameters.forceRefresh()) { setCacheTelemetry(CacheRefreshReason.FORCE_REFRESH); - log.debug(String.format("Refreshing access token. Cache refresh reason: %s", CacheRefreshReason.FORCE_REFRESH)); + LOG.debug("Refreshing access token. Cache refresh reason: {}", CacheRefreshReason.FORCE_REFRESH); return true; } @@ -125,7 +125,7 @@ private boolean shouldRefresh(SilentParameters parameters, AuthenticationResult // Note: these are the types of claims found in (for example) a claims challenge, and do not include client capabilities if (parameters.claims() != null) { setCacheTelemetry(CacheRefreshReason.CLAIMS); - log.debug(String.format("Refreshing access token. Cache refresh reason: %s", CacheRefreshReason.CLAIMS)); + LOG.debug("Refreshing access token. Cache refresh reason: {}", CacheRefreshReason.CLAIMS); return true; } @@ -134,7 +134,7 @@ private boolean shouldRefresh(SilentParameters parameters, AuthenticationResult //If the access token is expired or within 5 minutes of becoming expired, refresh it if (!StringHelper.isBlank(cachedResult.accessToken()) && cachedResult.expiresOn() < (currTimeStampSec + ACCESS_TOKEN_EXPIRE_BUFFER_IN_SEC)) { setCacheTelemetry(CacheRefreshReason.EXPIRED); - log.debug(String.format("Refreshing access token. Cache refresh reason: %s", CacheRefreshReason.EXPIRED)); + LOG.debug("Refreshing access token. Cache refresh reason: {}", CacheRefreshReason.EXPIRED); return true; } @@ -143,14 +143,14 @@ private boolean shouldRefresh(SilentParameters parameters, AuthenticationResult cachedResult.refreshOn() != null && cachedResult.refreshOn() > 0 && cachedResult.refreshOn() < currTimeStampSec && cachedResult.expiresOn() >= (currTimeStampSec + ACCESS_TOKEN_EXPIRE_BUFFER_IN_SEC)){ setCacheTelemetry(CacheRefreshReason.PROACTIVE_REFRESH); - log.debug(String.format("Refreshing access token. Cache refresh reason: %s", CacheRefreshReason.PROACTIVE_REFRESH)); + LOG.debug("Refreshing access token. Cache refresh reason: {}", CacheRefreshReason.PROACTIVE_REFRESH); return true; } //If there is a refresh token but no access token, we should use the refresh token to get the access token if (StringHelper.isBlank(cachedResult.accessToken()) && !StringHelper.isBlank(cachedResult.refreshToken())) { setCacheTelemetry(CacheRefreshReason.NO_CACHED_ACCESS_TOKEN); - log.debug(String.format("Refreshing access token. Cache refresh reason: %s", CacheRefreshReason.NO_CACHED_ACCESS_TOKEN)); + LOG.debug("Refreshing access token. Cache refresh reason: {}", CacheRefreshReason.NO_CACHED_ACCESS_TOKEN); return true; } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AppServiceManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AppServiceManagedIdentitySource.java index 612e4339..aacee43b 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AppServiceManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AppServiceManagedIdentitySource.java @@ -79,7 +79,7 @@ private static URI validateAndGetUri(String msiEndpoint, String secret) ManagedIdentitySourceType.APP_SERVICE); } - LOG.info("[Managed Identity] Environment variables validation passed for app service managed identity. Endpoint URI: {endpointUri}. Creating App Service managed identity."); + LOG.info("[Managed Identity] Environment variables validation passed for app service managed identity. Endpoint URI: {}. Creating App Service managed identity.", endpointUri); return endpointUri; } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParameters.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParameters.java index 2d6dd0f9..fc2e6c80 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParameters.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParameters.java @@ -37,7 +37,7 @@ public class AuthorizationRequestUrlParameters { Map requestParameters = new HashMap<>(); - Logger log = LoggerFactory.getLogger(AuthorizationRequestUrlParameters.class); + private static final Logger LOG = LoggerFactory.getLogger(AuthorizationRequestUrlParameters.class); public static Builder builder(String redirectUri, Set scopes) { @@ -157,7 +157,7 @@ private AuthorizationRequestUrlParameters(Builder builder) { String key = entry.getKey(); String value = entry.getValue(); if(requestParameters.containsKey(key)){ - log.warn("A query parameter {} has been provided with values multiple times.", key); + LOG.warn("A query parameter {} has been provided with values multiple times.", key); } requestParameters.put(key, value); } @@ -243,7 +243,7 @@ public Map> requestParameters() { } public Logger log() { - return this.log; + return LOG; } public static class Builder { diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationResponseHandler.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationResponseHandler.java index e455e52e..82f98790 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationResponseHandler.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationResponseHandler.java @@ -52,7 +52,7 @@ public void handle(HttpExchange httpExchange) throws IOException { authorizationResultQueue.put(result); } catch (InterruptedException ex) { - LOG.error("Error reading response from socket: " + ex.getMessage()); + LOG.error("Error reading response from socket: {}", ex.getMessage()); throw new MsalClientException(ex); } finally { httpExchange.close(); diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AzureArcManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AzureArcManagedIdentitySource.java index 3e504764..a1ab102d 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AzureArcManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AzureArcManagedIdentitySource.java @@ -57,7 +57,7 @@ private static URI validateAndGetUri(String identityEndpoint, String imdsEndpoin ManagedIdentitySourceType.AZURE_ARC); } - LOG.info(String.format("[Managed Identity] Creating Azure Arc managed identity. Endpoint URI: %s", endpointUri)); + LOG.info("[Managed Identity] Creating Azure Arc managed identity. Endpoint URI: {}", endpointUri); return endpointUri; } @@ -163,14 +163,14 @@ private Optional readChallengeFrom(IHttpResponse response) { private void validateFile(Path path) { String osName = System.getProperty("os.name").toLowerCase(); if (!(osName.contains("windows") || osName.contains("linux"))) { - LOG.error(String.format("[Managed Identity] Unsupported platform: %s", osName)); + LOG.error("[Managed Identity] Unsupported platform: {}", osName); throw new MsalServiceException(MsalErrorMessage.MANAGED_IDENTITY_PLATFORM_NOT_SUPPORTED, MsalError.MANAGED_IDENTITY_FILE_READ_ERROR, ManagedIdentitySourceType.AZURE_ARC); } if (isValidWindowsPath(path) || isValidLinuxPath(path)) { if (path.toFile().length() > MAX_FILE_SIZE_BYTES) { - LOG.error(String.format("[Managed Identity] File is larger than %s bytes.", MAX_FILE_SIZE_BYTES)); + LOG.error("[Managed Identity] File is larger than {} bytes.", MAX_FILE_SIZE_BYTES); throw new MsalServiceException(MsalErrorMessage.MANAGED_IDENTITY_INVALID_FILEPATH, MsalError.MANAGED_IDENTITY_FILE_READ_ERROR, ManagedIdentitySourceType.AZURE_ARC); } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CloudShellManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CloudShellManagedIdentitySource.java index 72a5e367..9b9c7db2 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CloudShellManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CloudShellManagedIdentitySource.java @@ -64,7 +64,7 @@ private static URI validateAndGetUri(String msiEndpoint) try { URI endpointUri = new URI(msiEndpoint); - LOG.info(String.format("[Managed Identity] Environment variables validation passed for cloud shell managed identity. Endpoint URI: %s. Creating cloud shell managed identity.", endpointUri)); + LOG.info("[Managed Identity] Environment variables validation passed for Cloud Shell managed identity. Endpoint URI: {}. Creating Cloud Shell managed identity.", endpointUri); return endpointUri; } catch (URISyntaxException ex) diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultHttpClient.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultHttpClient.java index fb015c31..7a88a2a4 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultHttpClient.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultHttpClient.java @@ -21,7 +21,7 @@ import java.util.Map; class DefaultHttpClient implements IHttpClient { - private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpClient.class); + private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpClient.class); final Proxy proxy; final SSLSocketFactory sslSocketFactory; diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpHelper.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpHelper.java index 028fe67f..2f6da6ae 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpHelper.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpHelper.java @@ -16,7 +16,7 @@ class HttpHelper implements IHttpHelper { - private static final Logger log = LoggerFactory.getLogger(HttpHelper.class); + private static final Logger LOG = LoggerFactory.getLogger(HttpHelper.class); public static final String RETRY_AFTER_HEADER = "Retry-After"; private IHttpClient httpClient; @@ -210,7 +210,7 @@ static Integer getRetryAfterHeader(IHttpResponse httpResponse) { return headerValue; } } catch (NumberFormatException ex) { - log.warn("Failed to parse value of Retry-After header - NumberFormatException"); + LOG.warn("Failed to parse value of Retry-After header - NumberFormatException"); } } } @@ -228,7 +228,7 @@ private void addRequestInfoToTelemetry(final HttpRequest httpRequest, HttpEvent String correlationId = httpRequest.headerValue( HttpHeaders.CORRELATION_ID_HEADER_NAME); - log.warn(LogHelper.createMessage("Setting URL telemetry fields failed: " + + LOG.warn(LogHelper.createMessage("Setting URL telemetry fields failed: " + LogHelper.getPiiScrubbedDetails(ex), correlationId != null ? correlationId : "")); } @@ -281,7 +281,7 @@ private static void verifyReturnedCorrelationId(final HttpRequest httpRequest, returnedCorrelationId), sentCorrelationId); - log.info(msg); + LOG.info(msg); } } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpListener.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpListener.java index 0819748b..1428aa86 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpListener.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpListener.java @@ -28,7 +28,7 @@ void startListener(int port, HttpHandler httpHandler) { server.createContext("/", httpHandler); this.port = server.getAddress().getPort(); server.start(); - LOG.debug("Http listener started. Listening on port: " + port); + LOG.debug("Http listener started. Listening on port: {}", port); } catch (Exception e) { throw new MsalClientException(e.getMessage(), AuthenticationErrorCode.UNABLE_TO_START_HTTP_LISTENER); diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java index 90aeda9b..0efb2426 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java @@ -43,7 +43,7 @@ public IMDSManagedIdentitySource(MsalRequest msalRequest, } if (!StringHelper.isNullOrBlank(environmentVariables.getEnvironmentVariable(Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST))){ - LOG.info(String.format("[Managed Identity] Environment variable AZURE_POD_IDENTITY_AUTHORITY_HOST for IMDS returned endpoint: %s", environmentVariables.getEnvironmentVariable(Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST))); + LOG.info("[Managed Identity] Environment variable AZURE_POD_IDENTITY_AUTHORITY_HOST for IMDS returned endpoint: {}", environmentVariables.getEnvironmentVariable(Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST)); try { imdsEndpoint = new URI(environmentVariables.getEnvironmentVariable(Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST)); } catch (URISyntaxException e) { @@ -68,7 +68,7 @@ public IMDSManagedIdentitySource(MsalRequest msalRequest, imdsEndpoint = DEFAULT_IMDS_ENDPOINT; } - LOG.info(String.format("[Managed Identity] Creating IMDS managed identity source. Endpoint URI: %s", imdsEndpoint)); + LOG.info("[Managed Identity] Creating IMDS managed identity source. Endpoint URI: {}", imdsEndpoint); } @Override @@ -114,7 +114,7 @@ public ManagedIdentityResponse handleResponse( message = message + " " + errorContentMessage; - LOG.error(String.format("Error message: %s Http status code: %s", message, response.statusCode())); + LOG.error("Error message: {} Http status code: {}", message, response.statusCode()); throw new MsalServiceException(message, MsalError.MANAGED_IDENTITY_REQUEST_FAILED, ManagedIdentitySourceType.IMDS); } diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityClient.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityClient.java index 9b118c1e..0ebe7f08 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityClient.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityClient.java @@ -3,14 +3,10 @@ package com.microsoft.aad.msal4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * Class to initialize a managed identity and identify the service. */ class ManagedIdentityClient { - private static final Logger LOG = LoggerFactory.getLogger(ManagedIdentityClient.class); static ManagedIdentitySourceType getManagedIdentitySource() { IEnvironmentVariables environmentVariables = AbstractManagedIdentitySource.getEnvironmentVariables(); diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityResponse.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityResponse.java index 62eba58d..9023d3b3 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityResponse.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityResponse.java @@ -7,15 +7,11 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; class ManagedIdentityResponse implements JsonSerializable { - private static final Logger LOG = LoggerFactory.getLogger(ManagedIdentityResponse.class); - String tokenType; String accessToken; String expiresOn; diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MexParser.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MexParser.java index ea589d8e..6edb6716 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MexParser.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/MexParser.java @@ -23,7 +23,7 @@ class MexParser { - private static final Logger log = LoggerFactory.getLogger(MexParser.class); + private static final Logger LOG = LoggerFactory.getLogger(MexParser.class); private static final String TRANSPORT_BINDING_XPATH = "wsp:ExactlyOne/wsp:All/sp:TransportBinding"; private static final String TRANSPORT_BINDING_2005_XPATH = "wsp:ExactlyOne/wsp:All/sp2005:TransportBinding"; @@ -84,7 +84,7 @@ static BindingPolicy getPolicy(String mexResponse, PolicySelector policySelector Map policies = policySelector.selectPolicies(xmlDocument, xPath, logPii); if (policies.isEmpty()) { - log.debug("No matching policies"); + LOG.debug("No matching policies"); return null; } else { @@ -92,7 +92,7 @@ static BindingPolicy getPolicy(String mexResponse, PolicySelector policySelector xmlDocument, xPath, policies, logPii); if (bindings.isEmpty()) { - log.debug("No matching bindings"); + LOG.debug("No matching bindings"); return null; } else { @@ -132,7 +132,7 @@ private static BindingPolicy selectSingleMatchingPolicy( } if (wstrust13 == null && wstrust2005 == null) { - log.warn("No policies found with the url"); + LOG.warn("No policies found with the url"); return null; } @@ -148,7 +148,7 @@ private static void getPortsForPolicyBindings(Document xmlDocument, xmlDocument, XPathConstants.NODESET); if (portNodes.getLength() == 0) { - log.warn("No ports found"); + LOG.warn("No ports found"); } else { for (int i = 0; i < portNodes.getLength(); i++) { Node portNode = portNodes.item(i); @@ -175,9 +175,9 @@ private static void getPortsForPolicyBindings(Document xmlDocument, bindingPolicy.setUrl(address.trim()); } else { if (logPii) { - log.warn("Skipping insecure endpoint" + ": " + address); + LOG.warn("Skipping insecure endpoint: {}", address); } else { - log.warn("Skipping insecure endpoint"); + LOG.warn("Skipping insecure endpoint"); } } } else { @@ -242,17 +242,17 @@ private static WSTrustVersion checkSoapActionAndTransport(XPath xPath, if (soapAction.equalsIgnoreCase(RST_SOAP_ACTION)) { if (logPii) { - log.debug("Found binding matching Action and Transport: " + bindingName); + LOG.debug("Found binding matching Action and Transport: {}", bindingName); } else { - log.debug("Found binding matching Action and Transport"); + LOG.debug("Found binding matching Action and Transport"); } return WSTrustVersion.WSTRUST13; } else if (soapAction.equalsIgnoreCase(RST_SOAP_ACTION_2005)) { if (logPii) { - log.debug("Binding node did not match soap Action or Transport: " + bindingName); + LOG.debug("Binding node did not match SOAP Action or Transport: {}", bindingName); } else { - log.debug("Binding node did not match soap Action or Transport"); + LOG.debug("Binding node did not match SOAP Action or Transport"); } return WSTrustVersion.WSTRUST2005; @@ -322,9 +322,9 @@ private static String checkPolicy(XPath xPath, Node node, boolean logPii) policyId = id.getNodeValue(); if (logPii) { - log.debug("found matching policy id: " + policyId); + LOG.debug("found matching policy id: {}", policyId); } else { - log.debug("found matching policy"); + LOG.debug("found matching policy"); } } else { String nodeValue = "none"; @@ -333,9 +333,9 @@ private static String checkPolicy(XPath xPath, Node node, boolean logPii) } if (logPii) { - log.debug("potential policy did not match required transport binding: " + nodeValue); + LOG.debug("potential policy did not match required transport binding: {}", nodeValue); } else { - log.debug("potential policy did not match required transport binding"); + LOG.debug("potential policy did not match required transport binding"); } } return policyId; diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServerSideTelemetry.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServerSideTelemetry.java index 8581aae3..aa5ed3bc 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServerSideTelemetry.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServerSideTelemetry.java @@ -77,7 +77,7 @@ private synchronized String buildCurrentRequestHeader() { SCHEMA_PIPE_DELIMITER; if (currentRequestHeader.getBytes(StandardCharsets.UTF_8).length > CURRENT_REQUEST_MAX_SIZE) { - log.warn("Current request telemetry header greater than 100 bytes"); + log.warn("Current request telemetry header greater than {} bytes", CURRENT_REQUEST_MAX_SIZE); } return currentRequestHeader; diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServiceFabricManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServiceFabricManagedIdentitySource.java index e2a4252e..9d363a35 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServiceFabricManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ServiceFabricManagedIdentitySource.java @@ -107,7 +107,7 @@ private static URI validateAndGetUri(String msiEndpoint) try { URI endpointUri = new URI(msiEndpoint); - LOG.info(String.format("[Managed Identity] Environment variables validation passed for Service Fabric Managed Identity. Endpoint URI: %s", endpointUri)); + LOG.info("[Managed Identity] Environment variables validation passed for Service Fabric Managed Identity. Endpoint URI: {}", endpointUri); return endpointUri; } catch (URISyntaxException ex) diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java index 4a90ec10..c6e7ca56 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java @@ -11,7 +11,7 @@ import java.util.*; class TokenRequestExecutor { - Logger log = LoggerFactory.getLogger(TokenRequestExecutor.class); + private static final Logger LOG = LoggerFactory.getLogger(TokenRequestExecutor.class); final Authority requestAuthority; final String tenant; @@ -29,7 +29,7 @@ class TokenRequestExecutor { AuthenticationResult executeTokenRequest() throws IOException { - log.debug("Sending token request to: {}", requestAuthority.canonicalAuthorityUrl()); + LOG.debug("Sending token request to: {}", requestAuthority.canonicalAuthorityUrl()); OAuthHttpRequest oAuthHttpRequest = createOauthHttpRequest(); HttpResponse oauthHttpResponse = oAuthHttpRequest.send(); return createAuthenticationResultFromOauthHttpResponse(oauthHttpResponse); @@ -66,7 +66,7 @@ OAuthHttpRequest createOauthHttpRequest() throws MalformedURLException { if(msalRequest.requestContext().apiParameters().extraQueryParameters() != null ){ for(String key: msalRequest.requestContext().apiParameters().extraQueryParameters().keySet()){ if(params.containsKey(key)){ - log.warn("A query parameter {} has been provided with values multiple times.", key); + LOG.warn("A query parameter {} has been provided with values multiple times.", key); } params.put(key, msalRequest.requestContext().apiParameters().extraQueryParameters().get(key)); } @@ -122,7 +122,7 @@ private void addCredentialToRequest(Map queryParameters, try { authorityToUse = Authority.replaceTenant(authorityToUse, parameters.tenant()); } catch (MalformedURLException e) { - log.warn("Could not create authority with tenant override: {}", e.getMessage()); + LOG.warn("Could not create authority with tenant override: {}", e.getMessage()); } } } @@ -221,7 +221,7 @@ private AuthenticationResult createAuthenticationResultFromOauthHttpResponse(Htt } Logger getLog() { - return this.log; + return LOG; } Authority getRequestAuthority() {