11/*
2- * (C) Copyright IBM Corp. 2020, 2023 .
2+ * (C) Copyright IBM Corp. 2020, 2025 .
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55 * the License. You may obtain a copy of the License at
@@ -51,22 +51,22 @@ public class IamIdentityExamples {
5151 protected IamIdentityExamples () {
5252 }
5353
54- private static String apiKeyName = "Example-ApiKey" ;
55- private static String serviceIdName = "Example-ServiceId" ;
56- private static String profileName = "Example-Profile" ;
54+ private static long now = System .currentTimeMillis () / 1000 ;
55+ private static String apiKeyName = "JavaSDK-Example-ApiKey-" + now ;
56+ private static String serviceIdName = "JavaSDK-Example-ServiceId-" + now ;
57+ private static String profileName = "JavaSDK-Example-Profile-" + now ;
5758 private static String claimRuleType = "Profile-SAML" ;
5859 private static String realmName = "https://my.test.realm/1234/saml20" ;
59- private static String profileTemplateName = "Example-Profile-Template" ;
60- private static String profileTemplateProfileName = "Profile-From-Example-Template" ;
61- private static String accountSettingsTemplateName = "Example-Account-Settings-Template" ;
60+ private static String profileTemplateName = "JavaSDK- Example-Profile-Template-" + now ;
61+ private static String profileTemplateProfileName = "Profile-From-JavaSDK- Example-Template-" + now ;
62+ private static String accountSettingsTemplateName = "JavaSDK- Example-Account-Settings-Template-" + now ;
6263 private static String service = "console" ;
6364 private static String valueString = "/billing" ;
6465 private static String preferenceId1 = "landing_page" ;
6566
6667 //values to be read from the env file
6768 private static String accountId ;
6869 private static String iamId ;
69- private static String iamIdMember ;
7070 private static String iamApiKey ;
7171 private static String enterpriseAccountId ;
7272 private static String enterpriseSubAccountId ;
@@ -111,10 +111,8 @@ public static void main(String[] args) throws Exception {
111111 accountId = config .get ("ACCOUNT_ID" );
112112 iamApiKey = config .get ("APIKEY" );
113113 iamId = config .get ("IAM_ID" );
114- iamIdMember = config .get ("IAM_ID_MEMBER" );
115114 enterpriseAccountId = config .get ("ENTERPRISE_ACCOUNT_ID" );
116115 enterpriseSubAccountId = config .get ("ENTERPRISE_SUBACCOUNT_ID" );
117- trustedProfileForPreferences = "iam-" + config .get ("PROFILEID1" );
118116
119117 try {
120118 System .out .println ("createApiKey() result:" );
@@ -592,6 +590,7 @@ public static void main(String[] args) throws Exception {
592590 Response <TrustedProfile > response = identityservice .createProfile (createProfileOptions ).execute ();
593591 TrustedProfile profile = response .getResult ();
594592 profileId = profile .getId ();
593+ trustedProfileForPreferences = profile .getIamId ();
595594
596595 System .out .println (profile );
597596
@@ -1011,7 +1010,7 @@ public static void main(String[] args) throws Exception {
10111010 SetProfileIdentityOptions setProfileIdentityOptions = new SetProfileIdentityOptions .Builder ()
10121011 .profileId (profileId )
10131012 .identityType (type )
1014- .identifier (iamIdMember )
1013+ .identifier (iamId )
10151014 .type ("user" )
10161015 .accounts (accounts )
10171016 .description (description )
@@ -1035,7 +1034,7 @@ public static void main(String[] args) throws Exception {
10351034 GetProfileIdentityOptions getProfileIdentityOptions = new GetProfileIdentityOptions .Builder ()
10361035 .profileId (profileId )
10371036 .identityType ("user" )
1038- .identifierId (iamIdMember )
1037+ .identifierId (iamId )
10391038 .build ();
10401039 Response <ProfileIdentityResponse > response = identityservice .getProfileIdentity (getProfileIdentityOptions ).execute ();
10411040
@@ -1056,7 +1055,7 @@ public static void main(String[] args) throws Exception {
10561055 DeleteProfileIdentityOptions deleteProfileIdentityOptions = new DeleteProfileIdentityOptions .Builder ()
10571056 .profileId (profileId )
10581057 .identityType ("user" )
1059- .identifierId (iamIdMember )
1058+ .identifierId (iamId )
10601059 .build ();
10611060 Response <Void > response = identityservice .deleteProfileIdentity (deleteProfileIdentityOptions ).execute ();
10621061
@@ -1070,27 +1069,6 @@ public static void main(String[] args) throws Exception {
10701069 e .getMessage (), e .getDebuggingInfo ()), e );
10711070 }
10721071
1073-
1074- try {
1075- System .out .println ("deleteProfile() result:" );
1076-
1077- // begin-delete_profile
1078-
1079- DeleteProfileOptions deleteProfileOptions = new DeleteProfileOptions .Builder ()
1080- .profileId (profileId )
1081- .build ();
1082-
1083- Response <Void > response = identityservice .deleteProfile (deleteProfileOptions ).execute ();
1084-
1085- // end-delete_profile
1086-
1087- System .out .printf ("deleteProfile() response status code: %d%n" , response .getStatusCode ());
1088-
1089- } catch (ServiceResponseException e ) {
1090- logger .error (String .format ("Service returned status code %s: %s\n Error details: %s" ,
1091- e .getStatusCode (), e .getMessage (), e .getDebuggingInfo ()), e );
1092- }
1093-
10941072 try {
10951073 System .out .println ("getAccountSettings() result:" );
10961074
@@ -1119,21 +1097,31 @@ public static void main(String[] args) throws Exception {
11191097
11201098 // begin-updateAccountSettings
11211099
1122- AccountSettingsUserMFA userMFA = new AccountSettingsUserMFA .Builder ()
1123- .iamId (iamIdMember )
1100+ UserMfa userMFA = new UserMfa .Builder ()
1101+ .iamId (iamId )
11241102 .mfa ("NONE" )
11251103 .build ();
11261104
1127- List <AccountSettingsUserMFA > userMFAExpList = new ArrayList <>();
1105+ List <UserMfa > userMFAExpList = new ArrayList <>();
11281106 userMFAExpList .add (userMFA );
11291107
1108+ AccountSettingsUserDomainRestriction domain = new AccountSettingsUserDomainRestriction .Builder ("IBMid" )
1109+ .addInvitationEmailAllowPatterns ("*.*@company.com" )
1110+ .restrictInvitation (Boolean .FALSE )
1111+ .build ();
1112+
1113+ List <AccountSettingsUserDomainRestriction > userDomainRestrictions = new ArrayList <>();
1114+ userDomainRestrictions .add (domain );
1115+
11301116 UpdateAccountSettingsOptions updateAccountSettingsOptions = new UpdateAccountSettingsOptions .Builder ()
11311117 .ifMatch (accountSettingsEtag )
11321118 .accountId (accountId )
11331119 .sessionExpirationInSeconds ("86400" )
11341120 .sessionInvalidationInSeconds ("7200" )
11351121 .restrictCreatePlatformApikey ("NOT_RESTRICTED" )
11361122 .restrictCreateServiceId ("NOT_RESTRICTED" )
1123+ .restrictUserListVisibility ("NOT_RESTRICTED" )
1124+ .restrictUserDomains (userDomainRestrictions )
11371125 .mfa ("NONE" )
11381126 .userMfa (userMFAExpList )
11391127 .systemAccessTokenExpirationInSeconds ("3600" )
@@ -1626,13 +1614,13 @@ public static void main(String[] args) throws Exception {
16261614 Response <TemplateAssignmentResponse > updateResponse = identityservice .updateTrustedProfileAssignment (updateOptions ).execute ();
16271615 TemplateAssignmentResponse updateResult = updateResponse .getResult ();
16281616
1629- // Grab the Etag value from the response for use in the update operation.
1630- profileTemplateAssignmentEtag = updateResponse .getHeaders ().values ("Etag" ).get (0 );
1631-
16321617 System .out .println (updateResult );
16331618
16341619 // end-update_trusted_profile_assignment
16351620
1621+ // Grab the Etag value from the response for use in the update operation.
1622+ profileTemplateAssignmentEtag = updateResponse .getHeaders ().values ("Etag" ).get (0 );
1623+
16361624 } catch (ServiceResponseException e ) {
16371625 logger .error (String .format ("Service returned status code %s: %s\n Error details: %s" ,
16381626 e .getStatusCode (), e .getMessage (), e .getDebuggingInfo ()), e );
@@ -2180,6 +2168,26 @@ public static void main(String[] args) throws Exception {
21802168 logger .error (String .format ("Service returned status code %s: %s\n Error details: %s" ,
21812169 e .getStatusCode (), e .getMessage (), e .getDebuggingInfo ()), e );
21822170 }
2171+
2172+ try {
2173+ System .out .println ("deleteProfile() result:" );
2174+
2175+ // begin-delete_profile
2176+
2177+ DeleteProfileOptions deleteProfileOptions = new DeleteProfileOptions .Builder ()
2178+ .profileId (profileId )
2179+ .build ();
2180+
2181+ Response <Void > response = identityservice .deleteProfile (deleteProfileOptions ).execute ();
2182+
2183+ // end-delete_profile
2184+
2185+ System .out .printf ("deleteProfile() response status code: %d%n" , response .getStatusCode ());
2186+
2187+ } catch (ServiceResponseException e ) {
2188+ logger .error (String .format ("Service returned status code %s: %s\n Error details: %s" ,
2189+ e .getStatusCode (), e .getMessage (), e .getDebuggingInfo ()), e );
2190+ }
21832191 }
21842192
21852193 private static void sleep (int numSecs ) {
0 commit comments