Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/customer-portal/backend/modules/scim/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ const ORGANIZATION_EXTERNAL = "external";
const DOMAIN_DEFAULT = "DEFAULT";
const ATTRIBUTE_PHONE_NUMBERS = "phoneNumbers";
const ATTRIBUTE_USERNAME = "userName";
const ATTRIBUTE_SCHEMA = "urn:scim:wso2:schema";
public const MOBILE_PHONE_NUMBER_TYPE = "mobile";
2 changes: 1 addition & 1 deletion apps/customer-portal/backend/modules/scim/scim.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public isolated function searchUsers(string email) returns User[]|error {
string organization = isWso2Email(email) ? ORGANIZATION_INTERNAL : ORGANIZATION_EXTERNAL;
UserSearchResult usersResult = check scimOperationsClient->/organizations/[organization]/users/search.post({
domain: DOMAIN_DEFAULT,
attributes: [ATTRIBUTE_PHONE_NUMBERS, ATTRIBUTE_USERNAME],
attributes: [ATTRIBUTE_PHONE_NUMBERS, ATTRIBUTE_USERNAME, ATTRIBUTE_SCHEMA],
filter: string `userName eq ${email}`,
startIndex
});
Expand Down
9 changes: 9 additions & 0 deletions apps/customer-portal/backend/modules/scim/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public type User record {|
string id;
# Phone numbers
PhoneNumber[]? phoneNumbers;
# Schema scope
SchemaScope? urn\:scim\:wso2\:schema;
json...;
|};

# Schema scope.
public type SchemaScope record {|
# Last password update time
string? lastPasswordUpdateTime?;
json...;
|};

Expand Down
9 changes: 9 additions & 0 deletions apps/customer-portal/backend/modules/scim/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ public isolated function processPhoneNumber(User user) returns string? {
}
return mobilePhoneNumber;
}

# Process SCIM user to extract the last password update time.
#
# + user - SCIM user object
# + return - Last password update time if found, else nil
public isolated function processLastPasswordUpdateTime(User user) returns string? {
SchemaScope? schemaScope = user.urn\:scim\:wso2\:schema;
return schemaScope != () ? schemaScope?.lastPasswordUpdateTime : ();
}
2 changes: 2 additions & 0 deletions apps/customer-portal/backend/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public type User record {|
*entity:UserResponse;
# Phone number of the user
string phoneNumber?;
# Last password update time
string? lastPasswordUpdateTime?;
|};

# Payload for updating user information.
Expand Down
5 changes: 4 additions & 1 deletion apps/customer-portal/backend/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
};
}
string? phoneNumber = ();
string? lastPasswordUpdateTime = ();
scim:User[]|error userResults = scim:searchUsers(userInfo.email);
if userResults is error {
// Log the error and return nil
Expand All @@ -144,6 +145,7 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
log:printError(string `No user found while searching phone number for user: ${userInfo.userId}`);
} else {
phoneNumber = scim:processPhoneNumber(userResults[0]);
lastPasswordUpdateTime = scim:processLastPasswordUpdateTime(userResults[0]);
}
}

Expand All @@ -154,7 +156,8 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
lastName: userDetails.lastName,
timeZone: userDetails.timeZone,
roles: userDetails.roles,
phoneNumber
phoneNumber,
lastPasswordUpdateTime
};

error? cacheError = userCache.put(cacheKey, user);
Expand Down