wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
741 stars 719 forks source link

Support renaming the username #4116

Open malithie opened 5 years ago

malithie commented 5 years ago

At the moment there is no service available to perform username rename. This is to include that support over the capability of identity anonymization tool.

malithie commented 5 years ago

Fixed introducing a REST API endpoint to support updating a username of a user.

API context URL - https://{host}:{port}/t/{tenant-domain}/api/identity/user/v1.0/update-username path.

Sample Request - curl -k -v -X PUT -H "Authorization: Basic " -H "Content-Type: application/json" -d '{ "tenantDomain": "foo.com", "realm": "sales", "existingUsername": "john@abc.com", "newUsername": "john@xyz.com"}' "https://localhost:9443/api/identity/user/v1.0/update-username"

The API is designed to work as below upon a username update request.

  1. Validate the username update request
  2. Disable the account of the user (Applied when user account disabling is enabled [1] for the respective tenant)
  3. Perform username update (Invokes forgetme tool)
  4. Enable the account of the user

Disabling the user account at step (2), will terminate all active sessions of the user.

[1] https://docs.wso2.com/display/IS570/Account+Disabling

Prerequisites

  1. Enable session termination when the user account gets disabled.

Note - Once below steps are applied active sessions of the user will be terminated upon following events

<UserSessionMapping>
    <Enable>true</Enable>
</UserSessionMapping>

(ii) Apply below configuration within tag in /repository/conf/identity/identity.xml file.

<EventListener type="org.wso2.carbon.user.core.listener.UserOperationEventListener"
                       name="org.wso2.carbon.identity.mgt.listener.UserSessionTerminationListener"
                       orderId="85" enable="true"/>
  1. Secure the API resource

Apply below configuration within tag in /repository/conf/identity/identity.xml file.

<Resource context="(.*)/api/identity/user/v1.0/update-username(.*)" secured="true" http-method="PUT">
    <Permissions>/permission/admin/manage/identity/usermgt/update</Permissions>
</Resource>
nilasini commented 5 years ago

Fixed with https://github.com/wso2/product-is/pull/4115 https://github.com/wso2/carbon-identity-framework/pull/2020