无法使用 Java SDK 通过 MS Graph API 在 Azure AD 中添加企业应用程序的 SAML 签名选项
Unable to add SAML signing option of an Enterprise application in Azure AD through MS Graph API using Java SDK
列表定义List = new LinkedList<>();
definitionList.add(
"{ "TokenIssuancePolicy":{"TokenResponseSigningPolicy":"ResponseAndToken","SamlTokenVersion":"2.0","SigningAlgorithm":"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256","版本" :1}}");
TokenIssuancePolicy newPolicy = new TokenIssuancePolicy();
newPolicy.definition = definitionList;
newPolicy.displayName = "sample-app";
newPolicy = serviceClient.policies().tokenIssuancePolicies().buildRequest().post(newPolicy);
System.out.println("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/"+newPolicy.id);
TokenIssuancePolicyCollectionWithReferencesPage policyPage = serviceClient.servicePrincipals(principal.id).tokenIssuancePolicies().buildRequest().get();
List<TokenIssuancePolicy> policyList = policyPage.getCurrentPage();
System.out.println(policyPage.getCount());
if (Objects.isNull(policyList) || policyList.isEmpty()) {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
policyList.forEach(app1 -> System.out.println(app1.displayName + " : " + app1.id));
TokenIssuancePolicy policy = new TokenIssuancePolicy();
policy.additionalDataManager().put("@odata.id", new JsonPrimitivenew JsonPrimitive("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/" + newPolicy.id));
System.out.println(policy.additionalDataManager());
serviceClient.servicePrincipals(principal.id).tokenIssuancePolicies().references().buildRequest().post(policy);
以上是我尝试更新企业应用程序策略但以无效对象标识符结束的代码 'null'。
谁能帮我解决这个问题。
提前致谢。
enter image description here
根据我的测试,我们不能使用代码TokenIssuancePolicy policy = new TokenIssuancePolicy(); policy.additionalDataManager().put("@odata.id", new JsonPrimitivenew JsonPrimitive("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/" + newPolicy.id));
来创建新策略。我们需要更新代码如下
TokenIssuancePolicy policy = new TokenIssuancePolicy(); policy.id=tokenIssuancePolicy.id;
例如
TokenIssuancePolicy tokenIssuancePolicy = new TokenIssuancePolicy();
LinkedList<String> definitionList = new LinkedList<String>();
definitionList.add("{\r\n \"TokenIssuancePolicy\": {\r\n \"Version\": 1,\r\n \"SigningAlgorithm\": \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\",\r\n \"TokenResponseSigningPolicy\": \"ResponseAndToken\",\r\n \"SamlTokenVersion\": \"2.0\"\r\n }\r\n}");
tokenIssuancePolicy.definition = definitionList;
tokenIssuancePolicy.displayName = "mytest";
tokenIssuancePolicy= graphClient.policies().tokenIssuancePolicies()
.buildRequest()
.post(tokenIssuancePolicy);
System.out.println("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/"+tokenIssuancePolicy.id);
TokenIssuancePolicy policy = new TokenIssuancePolicy();
policy.id=tokenIssuancePolicy.id;
policy =graphClient.servicePrincipals("00964c82-a7c2-4675-bbed-54bcf16328b3").tokenIssuancePolicies().references()
.buildRequest()
.post(policy);
System.out.println("-----------"+policy.id);
列表定义List = new LinkedList<>(); definitionList.add( "{ "TokenIssuancePolicy":{"TokenResponseSigningPolicy":"ResponseAndToken","SamlTokenVersion":"2.0","SigningAlgorithm":"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256","版本" :1}}");
TokenIssuancePolicy newPolicy = new TokenIssuancePolicy();
newPolicy.definition = definitionList;
newPolicy.displayName = "sample-app";
newPolicy = serviceClient.policies().tokenIssuancePolicies().buildRequest().post(newPolicy);
System.out.println("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/"+newPolicy.id);
TokenIssuancePolicyCollectionWithReferencesPage policyPage = serviceClient.servicePrincipals(principal.id).tokenIssuancePolicies().buildRequest().get();
List<TokenIssuancePolicy> policyList = policyPage.getCurrentPage();
System.out.println(policyPage.getCount());
if (Objects.isNull(policyList) || policyList.isEmpty()) {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
policyList.forEach(app1 -> System.out.println(app1.displayName + " : " + app1.id));
TokenIssuancePolicy policy = new TokenIssuancePolicy();
policy.additionalDataManager().put("@odata.id", new JsonPrimitivenew JsonPrimitive("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/" + newPolicy.id));
System.out.println(policy.additionalDataManager());
serviceClient.servicePrincipals(principal.id).tokenIssuancePolicies().references().buildRequest().post(policy);
以上是我尝试更新企业应用程序策略但以无效对象标识符结束的代码 'null'。 谁能帮我解决这个问题。 提前致谢。 enter image description here
根据我的测试,我们不能使用代码TokenIssuancePolicy policy = new TokenIssuancePolicy(); policy.additionalDataManager().put("@odata.id", new JsonPrimitivenew JsonPrimitive("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/" + newPolicy.id));
来创建新策略。我们需要更新代码如下
TokenIssuancePolicy policy = new TokenIssuancePolicy(); policy.id=tokenIssuancePolicy.id;
例如
TokenIssuancePolicy tokenIssuancePolicy = new TokenIssuancePolicy();
LinkedList<String> definitionList = new LinkedList<String>();
definitionList.add("{\r\n \"TokenIssuancePolicy\": {\r\n \"Version\": 1,\r\n \"SigningAlgorithm\": \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\",\r\n \"TokenResponseSigningPolicy\": \"ResponseAndToken\",\r\n \"SamlTokenVersion\": \"2.0\"\r\n }\r\n}");
tokenIssuancePolicy.definition = definitionList;
tokenIssuancePolicy.displayName = "mytest";
tokenIssuancePolicy= graphClient.policies().tokenIssuancePolicies()
.buildRequest()
.post(tokenIssuancePolicy);
System.out.println("https://graph.microsoft.com/v1.0/policies/tokenIssuancePolicies/"+tokenIssuancePolicy.id);
TokenIssuancePolicy policy = new TokenIssuancePolicy();
policy.id=tokenIssuancePolicy.id;
policy =graphClient.servicePrincipals("00964c82-a7c2-4675-bbed-54bcf16328b3").tokenIssuancePolicies().references()
.buildRequest()
.post(policy);
System.out.println("-----------"+policy.id);