// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. package com.microsoft.aad.msal4j; import org.slf4j.LoggerFactory; import java.net.MalformedURLException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; import static com.microsoft.aad.msal4j.ParameterValidationUtils.validateNotBlank; import static com.microsoft.aad.msal4j.ParameterValidationUtils.validateNotNull; /** * Class to be used to acquire tokens for public client applications (Desktop, Mobile). * For details see {@link IPublicClientApplication} *
* Conditionally thread-safe
*/
public class PublicClientApplication extends AbstractClientApplicationBase implements IPublicClientApplication {
private IBroker broker;
private boolean brokerEnabled;
@Override
public CompletableFuture
* Setting this will cause MSAL Java to use the given broker implementation to retrieve tokens from a broker (such as WAM/MSALRuntime) in flows that support it
*/
public PublicClientApplication.Builder broker(IBroker val) {
this.broker = val;
this.brokerEnabled = this.broker.isBrokerAvailable();
return self();
}
@Override
public PublicClientApplication build() {
return new PublicClientApplication(this);
}
@Override
protected Builder self() {
return this;
}
}
/**
* Used to determine whether to call into an IBroker instance instead of standard MSAL Java's normal interactive flow,
* and may throw exceptions or log messages if broker-only parameters are used when a broker is not enabled/available
*/
private boolean validateBrokerUsage(InteractiveRequestParameters parameters) {
//Check if broker-only parameters are being used when a broker is not enabled. If they are, either throw an
// exception saying a broker is required, or provide a clear log message saying the parameter will be ignored
if (!brokerEnabled) {
if (parameters.proofOfPossession() != null) {
throw new MsalClientException(
"InteractiveRequestParameters.proofOfPossession should not be used when broker is not available, see https://aka.ms/msal4j-pop for more information",
AuthenticationErrorCode.MSALJAVA_BROKERS_ERROR );
}
}
return brokerEnabled;
}
/**
* Used to determine whether to call into an IBroker instance instead of standard MSAL Java's normal username/password flow,
* and may throw exceptions or log messages if broker-only parameters are used when a broker is not enabled/available
*/
private boolean validateBrokerUsage(UserNamePasswordParameters parameters) {
//Check if broker-only parameters are being used when a broker is not enabled. If they are, either throw an
// exception saying a broker is required, or provide a clear log message saying the parameter will be ignored
if (!brokerEnabled) {
if (parameters.proofOfPossession() != null) {
throw new MsalClientException(
"UserNamePasswordParameters.proofOfPossession should not be used when broker is not available, see https://aka.ms/msal4j-pop for more information",
AuthenticationErrorCode.MSALJAVA_BROKERS_ERROR );
}
}
return brokerEnabled;
}
/**
* Used to determine whether to call into an IBroker instance instead of standard MSAL Java's normal silent flow,
* and may throw exceptions or log messages if broker-only parameters are used when a broker is not enabled/available
*/
private boolean validateBrokerUsage(SilentParameters parameters) {
//Check if broker-only parameters are being used when a broker is not enabled. If they are, either throw an
// exception saying a broker is required, or provide a clear log message saying the parameter will be ignored
if (!brokerEnabled) {
if (parameters.proofOfPossession() != null) {
throw new MsalClientException(
"UserNamePasswordParameters.proofOfPossession should not be used when broker is not available, see https://aka.ms/msal4j-pop for more information",
AuthenticationErrorCode.MSALJAVA_BROKERS_ERROR );
}
}
return brokerEnabled;
}
}