All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.security.xsuaa.tokenflows.XsuaaTokenFlowsUtils Maven / Gradle / Ivy

There is a newer version: 3.5.6
Show newest version
/**
 * SPDX-FileCopyrightText: 2018-2023 SAP SE or an SAP affiliate company and Cloud Security Client Java contributors
 * SPDX-License-Identifier: Apache-2.0
 */
package com.sap.cloud.security.xsuaa.tokenflows;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * A utilities class providing static functions required to build the XSUAA token flow REST requests.
 */
class XsuaaTokenFlowsUtils {

	static final String CLAIM_ADDITIONAL_AZ_ATTR = "az_attr";

	/**
	 * Builds the additional authorities claim 'az_attr' for the JWT.
	 *
	 * @param additionalAuthorities
	 * 		to be added to az_attr claim.
	 * @return the additional authorities az_attr claim as a String or null if additional authorities were null
	 */
	static String buildAdditionalAuthoritiesJson(Map additionalAuthorities) {
		if (additionalAuthorities != null) {
			Map additionalAuthorizationAttributes = new HashMap<>();
			additionalAuthorizationAttributes.put(CLAIM_ADDITIONAL_AZ_ATTR, additionalAuthorities);

			JSONObject additionalAuthorizationAttributesJson = new JSONObject(additionalAuthorizationAttributes);
			return additionalAuthorizationAttributesJson.toString();
		}
		return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy