From 69eecb2393573c1d5f1706bbb46360456c269ac3 Mon Sep 17 00:00:00 2001 From: Thumimku Date: Thu, 9 Nov 2023 10:15:21 +0530 Subject: [PATCH] add appleAppID --- .../model/ClientAttestationMetaData.java | 29 ++++++++++++++++++ .../util/IdentityApplicationConstants.java | 2 ++ .../mgt/dao/impl/ApplicationDAOImpl.java | 30 +++++++++++++++++++ .../ApplicationManagementServiceImplTest.java | 10 +++++-- .../IdentityApplicationManagementService.wsdl | 1 + 5 files changed, 70 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/ClientAttestationMetaData.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/ClientAttestationMetaData.java index 5dd6a2b1a33c..8d84c534d068 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/ClientAttestationMetaData.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/ClientAttestationMetaData.java @@ -42,6 +42,7 @@ public class ClientAttestationMetaData implements Serializable { private static final String IS_ATTESTATION_ENABLED = "IsAttestationEnabled"; private static final String ANDROID_PACKAGE_NAME = "AndroidPackageName"; private static final String ANDROID_ATTESTATION_SERVICE_CREDENTIALS = "AndroidAttestationServiceCredentials"; + private static final String APPLE_APP_ID = "AppleAppId"; // Field to store whether attestation is enabled. @IgnoreNullElement @@ -58,6 +59,11 @@ public class ClientAttestationMetaData implements Serializable { @XmlElement(name = ANDROID_ATTESTATION_SERVICE_CREDENTIALS) private String androidAttestationServiceCredentials; + // Field to store Apple app ID. + @IgnoreNullElement + @XmlElement(name = APPLE_APP_ID) + private String appleAppId; + /** * Creates an instance of the ClientAttestationMetaData class by parsing an OMElement. * @@ -83,6 +89,9 @@ public static ClientAttestationMetaData build(OMElement metaDataOM) { if (ANDROID_ATTESTATION_SERVICE_CREDENTIALS.equals(elementName)) { metaData.setAndroidAttestationServiceCredentials(element.getText()); } + if (APPLE_APP_ID.equals(elementName)) { + metaData.setAppleAppId(element.getText()); + } } return metaData; } @@ -147,4 +156,24 @@ public void setAndroidAttestationServiceCredentials(String androidAttestationSer this.androidAttestationServiceCredentials = androidAttestationServiceCredentials; } + + /** + * Gets the Apple App ID. + * + * @return The Apple App ID. + */ + public String getAppleAppId() { + + return appleAppId; + } + + /** + * Sets the Apple App ID. + * + * @param appleAppId The Apple App ID to set. + */ + public void setAppleAppId(String appleAppId) { + + this.appleAppId = appleAppId; + } } diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/util/IdentityApplicationConstants.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/util/IdentityApplicationConstants.java index a134978182bf..be89f507ed15 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/util/IdentityApplicationConstants.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/util/IdentityApplicationConstants.java @@ -124,6 +124,8 @@ private IdentityApplicationConstants() { public static final String IS_ATTESTATION_ENABLED_DISPLAY_NAME = "Is Client Attestation Enabled"; public static final String ANDROID_PACKAGE_NAME_PROPERTY_NAME = "androidPackageName"; public static final String ANDROID_PACKAGE_NAME_DISPLAY_NAME = "Android mobile application package name"; + public static final String APPLE_APP_ID_PROPERTY_NAME = "appleAppId"; + public static final String APPLE_APP_ID_DISPLAY_NAME = "Apple application id"; public static final String APPLICATION_SECRET_TYPE_ANDROID_ATTESTATION_CREDENTIALS = "ANDROID_ATTESTATION_CREDENTIALS"; public static final String CLIENT_ATTESTATION = "CLIENT_ATTESTATION"; diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java index 36175fec2d0b..81ff520bcaf4 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java @@ -133,6 +133,8 @@ import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.ANDROID; import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.ANDROID_PACKAGE_NAME_DISPLAY_NAME; import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.ANDROID_PACKAGE_NAME_PROPERTY_NAME; +import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.APPLE_APP_ID_DISPLAY_NAME; +import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.APPLE_APP_ID_PROPERTY_NAME; import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.APPLICATION_SECRET_TYPE_ANDROID_ATTESTATION_CREDENTIALS; import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.CLIENT_ATTESTATION; import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.CLIENT_ID_SP_PROPERTY_NAME; @@ -450,6 +452,10 @@ private ApplicationCreateResult persistBasicApplicationInformation(Connection co buildAndroidPackageNameProperty(application.getClientAttestationMetaData()); serviceProviderProperties.add(androidPackageName); + ServiceProviderProperty appleAppId = + buildAppleAppIdProperty(application.getClientAttestationMetaData()); + serviceProviderProperties.add(appleAppId); + storeAndroidAttestationServiceCredentialAsSecret(application); } @@ -2118,6 +2124,7 @@ public ServiceProvider getApplication(int applicationId) throws IdentityApplicat ClientAttestationMetaData clientAttestationMetaData = new ClientAttestationMetaData(); clientAttestationMetaData.setAttestationEnabled(getIsAttestationEnabled(propertyList)); clientAttestationMetaData.setAndroidPackageName(getAndroidPackageName(propertyList)); + clientAttestationMetaData.setAppleAppId(getAppleAppId(propertyList)); if (StringUtils.isNotEmpty(clientAttestationMetaData.getAndroidPackageName()) && clientAttestationMetaData.isAttestationEnabled()) { clientAttestationMetaData.setAndroidAttestationServiceCredentials @@ -2358,6 +2365,15 @@ private String getAndroidPackageName(List propertyList) .orElse(StringUtils.EMPTY); } + private String getAppleAppId(List propertyList) { + + return propertyList.stream() + .filter(property -> APPLE_APP_ID_PROPERTY_NAME.equals(property.getName())) + .findFirst() + .map(ServiceProviderProperty::getValue) + .orElse(StringUtils.EMPTY); + } + private String getAndroidAttestationServiceCredentials(ServiceProvider serviceProvider) throws IdentityApplicationManagementException { @@ -4973,6 +4989,10 @@ private void updateConfigurationsAsServiceProperties(ServiceProvider sp) buildAndroidPackageNameProperty(sp.getClientAttestationMetaData()); spPropertyMap.put(androidPackageName.getName(), androidPackageName); + ServiceProviderProperty appleAppId = + buildAppleAppIdProperty(sp.getClientAttestationMetaData()); + spPropertyMap.put(appleAppId.getName(), appleAppId); + storeAndroidAttestationServiceCredentialAsSecret(sp); } @@ -5008,6 +5028,16 @@ private ServiceProviderProperty buildIsAPIBasedAuthenticationEnabledProperty(Ser return androidPackageName; } + private ServiceProviderProperty buildAppleAppIdProperty + (ClientAttestationMetaData clientAttestationMetaData) { + + ServiceProviderProperty appleAppId = new ServiceProviderProperty(); + appleAppId.setName(APPLE_APP_ID_PROPERTY_NAME); + appleAppId.setDisplayName(APPLE_APP_ID_DISPLAY_NAME); + appleAppId.setValue(String.valueOf(clientAttestationMetaData.getAppleAppId())); + return appleAppId; + } + private void storeAndroidAttestationServiceCredentialAsSecret(ServiceProvider sp) throws IdentityApplicationManagementException { diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java index ef6e158a5d27..58a6510c2605 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java @@ -828,14 +828,15 @@ public Object[][] testAddApplicationWithAttestationData() { return new Object[][]{ - {true, "com.wso2.sample.mobile.application", "sampleCredentials"} + {true, "com.wso2.sample.mobile.application", "sampleCredentials", "APPLETEAMID.com.wso2.mobile.sample"} }; } @Test(dataProvider = "testAddApplicationWithAttestationData") public void testAddApplicationWithAttestationData(boolean isAttestationEnabled, String androidPackageName, - String androidCredentials) throws Exception { + String androidCredentials, + String appleAppId) throws Exception { ResolvedSecret resolvedSecret = new ResolvedSecret(); resolvedSecret.setResolvedSecretValue(androidCredentials); @@ -850,6 +851,7 @@ public void testAddApplicationWithAttestationData(boolean isAttestationEnabled, ClientAttestationMetaData clientAttestationMetaData = new ClientAttestationMetaData(); clientAttestationMetaData.setAttestationEnabled(isAttestationEnabled); clientAttestationMetaData.setAndroidPackageName(androidPackageName); + clientAttestationMetaData.setAppleAppId(appleAppId); clientAttestationMetaData.setAndroidAttestationServiceCredentials(androidCredentials); inputSP.setClientAttestationMetaData(clientAttestationMetaData); @@ -860,6 +862,8 @@ public void testAddApplicationWithAttestationData(boolean isAttestationEnabled, Assert.assertEquals(addedSP.getClientAttestationMetaData().getAndroidPackageName(), androidPackageName); Assert.assertEquals(addedSP.getClientAttestationMetaData().getAndroidAttestationServiceCredentials(), androidCredentials); + Assert.assertEquals(addedSP.getClientAttestationMetaData().getAppleAppId(), + appleAppId); SecretManager secretManager = mock(SecretManagerImpl.class); when(secretManager.isSecretExist(anyString(), anyString())).thenReturn(true); @@ -870,12 +874,14 @@ public void testAddApplicationWithAttestationData(boolean isAttestationEnabled, (inputSP.getApplicationName(), SUPER_TENANT_DOMAIN_NAME); Assert.assertEquals(retrievedSP.getClientAttestationMetaData().isAttestationEnabled(), isAttestationEnabled); Assert.assertEquals(retrievedSP.getClientAttestationMetaData().getAndroidPackageName(), androidPackageName); + Assert.assertEquals(retrievedSP.getClientAttestationMetaData().getAppleAppId(), appleAppId); Assert.assertEquals(retrievedSP.getClientAttestationMetaData().getAndroidAttestationServiceCredentials(), androidCredentials); // Updating the application by changing the isManagementApplication flag. It should be changed. ClientAttestationMetaData clientAttestationMetaData2 = new ClientAttestationMetaData(); clientAttestationMetaData2.setAttestationEnabled(!isAttestationEnabled); clientAttestationMetaData2.setAndroidPackageName(null); + clientAttestationMetaData2.setAppleAppId(null); clientAttestationMetaData2.setAndroidAttestationServiceCredentials(null); inputSP.setClientAttestationMetaData(clientAttestationMetaData2); applicationManagementService.updateApplication(inputSP, SUPER_TENANT_DOMAIN_NAME, REGISTRY_SYSTEM_USERNAME); diff --git a/service-stubs/identity/org.wso2.carbon.identity.application.mgt.stub/src/main/resources/IdentityApplicationManagementService.wsdl b/service-stubs/identity/org.wso2.carbon.identity.application.mgt.stub/src/main/resources/IdentityApplicationManagementService.wsdl index 48072f99dbec..ead9dd790904 100644 --- a/service-stubs/identity/org.wso2.carbon.identity.application.mgt.stub/src/main/resources/IdentityApplicationManagementService.wsdl +++ b/service-stubs/identity/org.wso2.carbon.identity.application.mgt.stub/src/main/resources/IdentityApplicationManagementService.wsdl @@ -427,6 +427,7 @@ +