Skip to content

Commit

Permalink
add comments and improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
chamathns committed Jul 12, 2023
1 parent 5550ba4 commit 61ee53c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,32 @@
import java.util.List;
import java.util.Properties;

/**
* This class is a client for the User Registration Admin Service.
* It provides methods to perform operations like adding a new user,
* checking if a user exists, and reading user fields for user registration.
*/
public class UserRegistrationAdminServiceClient {


private UserRegistrationAdminServiceStub stub;
private Properties prop;

/**
* Constructs a new UserRegistrationAdminServiceClient.
* Initializes the service stub with the service URL.
*
* @throws AxisFault if there's an error during stub initialization.
*/
public UserRegistrationAdminServiceClient() throws AxisFault {

StringBuilder builder = new StringBuilder();
String serviceURL = null;

serviceURL = builder.append(TenantDataManager.getPropertyValue(Constants.SERVICES_URL)).append
// Build the service URL for the User Registration admin service.
// Replace any unintended double slashes in the URL with a single slash.
String serviceURL = builder.append(TenantDataManager.getPropertyValue(Constants.SERVICES_URL)).append
(Constants.UserRegistrationConstants.USER_REGISTRATION_SERVICE).toString().replaceAll("(?<!(http:|https:))//", "/");

// Initialize the User Registration Admin Service stub with the service URL.
stub = new UserRegistrationAdminServiceStub(serviceURL);

ServiceClient client = stub._getServiceClient();
Expand All @@ -55,11 +67,12 @@ public UserRegistrationAdminServiceClient() throws AxisFault {

/**
* Add new user.
* @param username Username of the user.
* @param password Password of the user.
*
* @param username Username of the user.
* @param password Password of the user.
* @param userFields User fields to be updated.
* @throws RemoteException
* @throws UserRegistrationAdminServiceException
* @throws RemoteException If a remote or network exception occurs.
* @throws UserRegistrationAdminServiceException If an error occurs while adding the user.
*/
public void addUser(String username, char[] password, List<UserFieldDTO> userFields) throws RemoteException,
UserRegistrationAdminServiceException {
Expand All @@ -74,6 +87,7 @@ public void addUser(String username, char[] password, List<UserFieldDTO> userFie

/**
* Get the user fields for given dialect.
*
* @param dialect Dialect to use.
* @return User fields.
* @throws UserRegistrationAdminServiceIdentityException
Expand All @@ -87,6 +101,7 @@ public UserFieldDTO[] readUserFieldsForUserRegistration(String dialect)

/**
* Check whether the user exists.
*
* @param username Username of the user.
* @return True if user exists.
* @throws RemoteException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ public boolean isValidCallbackURL(String callbackURL, String tenantDomain)

IdentityProvider residentIdP;

// Build the service URL of idp management admin service
StringBuilder builder = new StringBuilder();
/* Build the service URL of the Identity Provider Management Admin service.
Append the user identity management paths to the service URL.
Replace any unintended double slashes in the URL with a single slash. */
String serviceURL = builder.append(IdentityManagementServiceUtil.getInstance().getServiceContextURL())
.append(IdentityManagementEndpointConstants.SERVICE_CONTEXT_PATH)
.append(IdentityManagementEndpointConstants.ServiceEndpoints.IDENTITY_PROVIDER_MANAGEMENT_SERVICE)
.toString().replaceAll("(?<!(http:|https:))//", "/");
try {
// Create a stub for the Identity Provider Management Service.
IdentityProviderMgtServiceStub idPMgtStub = new IdentityProviderMgtServiceStub(serviceURL);
ServiceClient idpClient = idPMgtStub._getServiceClient();
IdentityManagementEndpointUtil.authenticate(idpClient);
Expand All @@ -93,7 +96,7 @@ public boolean isValidCallbackURL(String callbackURL, String tenantDomain)
log.debug("Resident identity provider is not found for the tenant domain: " + tenantDomain);
}
}

// Retrieve the callback URL regex from the IDP properties.
String callbackRegex = null;
if (idpProperties != null) {
for (IdentityProviderProperty property : idpProperties) {
Expand All @@ -107,7 +110,7 @@ public boolean isValidCallbackURL(String callbackURL, String tenantDomain)
}
}
}

// Encode the callback URL.
if (StringUtils.isNotBlank(callbackURL)) {
try {
String encodeURL = URLEncoder.encode(callbackURL, IdentityManagementEndpointConstants.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public UserIdentityManagementAdminServiceClient() throws AxisFault {
StringBuilder builder = new StringBuilder();
String serviceURL = null;

/* Build the service URL of the User Identity Management Admin service.
Append the user identity management paths to the service URL.
Replace any unintended double slashes in the URL with a single slash. */
serviceURL = builder.append(IdentityManagementServiceUtil.getInstance().getServiceContextURL())
.append(IdentityManagementEndpointConstants.SERVICE_CONTEXT_PATH)
.append(IdentityManagementEndpointConstants.ServiceEndpoints.USER_IDENTITY_MANAGEMENT_SERVICE)
.toString().replaceAll("(?<!(http:|https:))//", "/");

// Create a stub for the User Identity Management Admin Service.
stub = new UserIdentityManagementAdminServiceStub(serviceURL);
ServiceClient client = stub._getServiceClient();
IdentityManagementServiceUtil.getInstance().authenticate(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ public UserInformationRecoveryClient() throws AxisFault {
StringBuilder builder = new StringBuilder();
String serviceURL = null;

/* Build the service URL of the User Information Recovery service.
Append the user identity management paths to the service URL.
Replace any unintended double slashes in the URL with a single slash. */
serviceURL = builder.append(IdentityManagementServiceUtil.getInstance().getServiceContextURL())
.append(IdentityManagementEndpointConstants.SERVICE_CONTEXT_PATH)
.append(IdentityManagementEndpointConstants.ServiceEndpoints.USER_INFORMATION_RECOVERY_SERVICE)
.toString().replaceAll("(?<!(http:|https:))//", "/");

// Create a stub for the User Information Recovery Admin Service.
stub = new UserInformationRecoveryServiceStub(serviceURL);
ServiceClient client = stub._getServiceClient();
IdentityManagementServiceUtil.getInstance().authenticate(client);
Expand Down

0 comments on commit 61ee53c

Please sign in to comment.