// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import java.util.Map;
import java.util.Set;
import static com.microsoft.aad.msal4j.ParameterValidationUtils.validateNotNull;
/**
* Object containing parameters for On-Behalf-Of flow. Can be used as parameter to
* {@link ConfidentialClientApplication#acquireToken(OnBehalfOfParameters)}
*
* For more details, see https://aka.ms/msal4j-on-behalf-of
*/
public class OnBehalfOfParameters implements IAcquireTokenParameters {
private Set scopes;
private boolean skipCache;
private IUserAssertion userAssertion;
private ClaimsRequest claims;
private Map extraHttpHeaders;
private Map extraQueryParameters;
private String tenant;
private OnBehalfOfParameters(Set scopes, Boolean skipCache, IUserAssertion userAssertion, ClaimsRequest claims, Map extraHttpHeaders, Map extraQueryParameters, String tenant) {
this.scopes = scopes;
//Legacy code that made the public parameter take the Boolean class instead of the primitive, so we need a null check
this.skipCache = skipCache != null && skipCache;
this.userAssertion = userAssertion;
this.claims = claims;
this.extraHttpHeaders = extraHttpHeaders;
this.extraQueryParameters = extraQueryParameters;
this.tenant = tenant;
}
private static OnBehalfOfParametersBuilder builder() {
return new OnBehalfOfParametersBuilder();
}
/**
* Builder for {@link OnBehalfOfParameters}
*
* @param scopes scopes application is requesting access to
* @param userAssertion {@link UserAssertion} created from access token received
* @return builder that can be used to construct OnBehalfOfParameters
*/
public static OnBehalfOfParametersBuilder builder(Set scopes, UserAssertion userAssertion) {
validateNotNull("scopes", scopes);
return builder()
.scopes(scopes)
.userAssertion(userAssertion);
}
public Set scopes() {
return this.scopes;
}
public Boolean skipCache() {
return this.skipCache;
}
public IUserAssertion userAssertion() {
return this.userAssertion;
}
public ClaimsRequest claims() {
return this.claims;
}
public Map extraHttpHeaders() {
return this.extraHttpHeaders;
}
public Map extraQueryParameters() {
return this.extraQueryParameters;
}
public String tenant() {
return this.tenant;
}
public static class OnBehalfOfParametersBuilder {
private Set scopes;
private Boolean skipCache;
private IUserAssertion userAssertion;
private ClaimsRequest claims;
private Map extraHttpHeaders;
private Map extraQueryParameters;
private String tenant;
OnBehalfOfParametersBuilder() {
}
public OnBehalfOfParametersBuilder scopes(Set scopes) {
validateNotNull("scopes", scopes);
this.scopes = scopes;
return this;
}
/**
* Indicates whether the request should skip looking into the token cache. Be default it is set to false.
*/
public OnBehalfOfParametersBuilder skipCache(Boolean skipCache) {
this.skipCache = skipCache;
return this;
}
public OnBehalfOfParametersBuilder userAssertion(IUserAssertion userAssertion) {
validateNotNull("userAssertion", userAssertion);
this.userAssertion = userAssertion;
return this;
}
/**
* Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
*/
public OnBehalfOfParametersBuilder claims(ClaimsRequest claims) {
this.claims = claims;
return this;
}
/**
* Adds additional headers to the token request
*/
public OnBehalfOfParametersBuilder extraHttpHeaders(Map extraHttpHeaders) {
this.extraHttpHeaders = extraHttpHeaders;
return this;
}
/**
* Adds additional parameters to the token request
*/
public OnBehalfOfParametersBuilder extraQueryParameters(Map extraQueryParameters) {
this.extraQueryParameters = extraQueryParameters;
return this;
}
/**
* Overrides the tenant value in the authority URL for this request
*/
public OnBehalfOfParametersBuilder tenant(String tenant) {
this.tenant = tenant;
return this;
}
public OnBehalfOfParameters build() {
return new OnBehalfOfParameters(this.scopes, this.skipCache, this.userAssertion, this.claims, this.extraHttpHeaders, this.extraQueryParameters, this.tenant);
}
public String toString() {
return "OnBehalfOfParameters.OnBehalfOfParametersBuilder(scopes=" + this.scopes + ", skipCache$value=" + this.skipCache + ", userAssertion=" + this.userAssertion + ", claims=" + this.claims + ", extraHttpHeaders=" + this.extraHttpHeaders + ", extraQueryParameters=" + this.extraQueryParameters + ", tenant=" + this.tenant + ")";
}
}
}