diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasicUserInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasicUserInfo.java index d7c82a9edcc..07e58252ca2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasicUserInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasicUserInfo.java @@ -32,6 +32,10 @@ public class BasicUserInfo { private String lastname; @ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true ) private String emailAddress; + @ApiModelProperty(name = "createdDate", value = "User creation date." ) + private String createdDate; + @ApiModelProperty(name = "modifiedDate", value = "User modifiedDate date." ) + private String modifiedDate; public String getUsername() { return username; @@ -65,4 +69,20 @@ public class BasicUserInfo { this.emailAddress = emailAddress; } + public String getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(String createdDate) { + this.createdDate = createdDate; + } + + public String getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(String modifiedDate) { + this.modifiedDate = modifiedDate; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 8bcb3d934b9..090563af7b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -94,6 +94,7 @@ import java.net.URISyntaxException; import java.security.SecureRandom; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -152,7 +153,7 @@ public class UserManagementServiceImpl implements UserManagementService { Map defaultUserClaims = this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), - userInfo.getEmailAddress()); + userInfo.getEmailAddress(), true); // calling addUser method of carbon user api List tmpRoles = new ArrayList<>(); String[] userInfoRoles = userInfo.getRoles(); @@ -279,7 +280,7 @@ public class UserManagementServiceImpl implements UserManagementService { Map defaultUserClaims = this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), - userInfo.getEmailAddress()); + userInfo.getEmailAddress(), false); if (StringUtils.isNotEmpty(userInfo.getPassword())) { // Decoding Base64 encoded password userStoreManager.updateCredentialByAdmin(username, @@ -427,11 +428,7 @@ public class UserManagementServiceImpl implements UserManagementService { userList = new ArrayList<>(users.length); BasicUserInfo user; for (String username : users) { - user = new BasicUserInfo(); - user.setUsername(username); - user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); - user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); - user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); + user = getBasicUserInfo(username); userList.add(user); } @@ -899,11 +896,17 @@ public class UserManagementServiceImpl implements UserManagementService { } } - private Map buildDefaultUserClaims(String firstName, String lastName, String emailAddress) { + private Map buildDefaultUserClaims(String firstName, String lastName, String emailAddress, + boolean isFresh) { Map defaultUserClaims = new HashMap<>(); defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstName); defaultUserClaims.put(Constants.USER_CLAIM_LAST_NAME, lastName); defaultUserClaims.put(Constants.USER_CLAIM_EMAIL_ADDRESS, emailAddress); + if (isFresh) { + defaultUserClaims.put(Constants.USER_CLAIM_CREATED, String.valueOf(Instant.now().getEpochSecond())); + } else { + defaultUserClaims.put(Constants.USER_CLAIM_MODIFIED, String.valueOf(Instant.now().getEpochSecond())); + } if (log.isDebugEnabled()) { log.debug("Default claim map is created for new user: " + defaultUserClaims.toString()); } @@ -936,6 +939,8 @@ public class UserManagementServiceImpl implements UserManagementService { userInfo.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); userInfo.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); userInfo.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); + userInfo.setCreatedDate(getClaimValue(username, Constants.USER_CLAIM_CREATED)); + userInfo.setModifiedDate(getClaimValue(username, Constants.USER_CLAIM_MODIFIED)); return userInfo; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java index 4525cdd38dd..29a9e5da257 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java @@ -26,6 +26,8 @@ public class Constants { public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress"; public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname"; public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname"; + public static final String USER_CLAIM_CREATED = "http://wso2.org/claims/created"; + public static final String USER_CLAIM_MODIFIED = "http://wso2.org/claims/modified"; public static final String PRIMARY_USER_STORE = "PRIMARY"; public static final String DEFAULT_STREAM_VERSION = "1.0.0"; public static final String SCOPE = "scope";