Add user created date and modified date

4.x.x
Milan Perera 6 years ago
parent 5a6789e336
commit 650f02bf03

@ -32,6 +32,10 @@ public class BasicUserInfo {
private String lastname; private String lastname;
@ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true ) @ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true )
private String emailAddress; 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() { public String getUsername() {
return username; return username;
@ -65,4 +69,20 @@ public class BasicUserInfo {
this.emailAddress = emailAddress; 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;
}
} }

@ -94,6 +94,7 @@ import java.net.URISyntaxException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -152,7 +153,7 @@ public class UserManagementServiceImpl implements UserManagementService {
Map<String, String> defaultUserClaims = Map<String, String> defaultUserClaims =
this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(),
userInfo.getEmailAddress()); userInfo.getEmailAddress(), true);
// calling addUser method of carbon user api // calling addUser method of carbon user api
List<String> tmpRoles = new ArrayList<>(); List<String> tmpRoles = new ArrayList<>();
String[] userInfoRoles = userInfo.getRoles(); String[] userInfoRoles = userInfo.getRoles();
@ -279,7 +280,7 @@ public class UserManagementServiceImpl implements UserManagementService {
Map<String, String> defaultUserClaims = Map<String, String> defaultUserClaims =
this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(),
userInfo.getEmailAddress()); userInfo.getEmailAddress(), false);
if (StringUtils.isNotEmpty(userInfo.getPassword())) { if (StringUtils.isNotEmpty(userInfo.getPassword())) {
// Decoding Base64 encoded password // Decoding Base64 encoded password
userStoreManager.updateCredentialByAdmin(username, userStoreManager.updateCredentialByAdmin(username,
@ -427,11 +428,7 @@ public class UserManagementServiceImpl implements UserManagementService {
userList = new ArrayList<>(users.length); userList = new ArrayList<>(users.length);
BasicUserInfo user; BasicUserInfo user;
for (String username : users) { for (String username : users) {
user = new BasicUserInfo(); user = getBasicUserInfo(username);
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));
userList.add(user); userList.add(user);
} }
@ -899,11 +896,17 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
} }
private Map<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress) { private Map<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress,
boolean isFresh) {
Map<String, String> defaultUserClaims = new HashMap<>(); Map<String, String> defaultUserClaims = new HashMap<>();
defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstName); defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstName);
defaultUserClaims.put(Constants.USER_CLAIM_LAST_NAME, lastName); defaultUserClaims.put(Constants.USER_CLAIM_LAST_NAME, lastName);
defaultUserClaims.put(Constants.USER_CLAIM_EMAIL_ADDRESS, emailAddress); 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()) { if (log.isDebugEnabled()) {
log.debug("Default claim map is created for new user: " + defaultUserClaims.toString()); 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.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
userInfo.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); userInfo.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
userInfo.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_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; return userInfo;
} }

@ -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_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_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_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 PRIMARY_USER_STORE = "PRIMARY";
public static final String DEFAULT_STREAM_VERSION = "1.0.0"; public static final String DEFAULT_STREAM_VERSION = "1.0.0";
public static final String SCOPE = "scope"; public static final String SCOPE = "scope";

Loading…
Cancel
Save