Merge branch 'master' into 'master'

Add user created date and modified date

See merge request entgra/carbon-device-mgt!124
revert-70aa11f8
Dharmakeerthi Lasantha 6 years ago
commit c20d0ae542

@ -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;
}
}

@ -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<String, String> defaultUserClaims =
this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(),
userInfo.getEmailAddress());
userInfo.getEmailAddress(), true);
// calling addUser method of carbon user api
List<String> tmpRoles = new ArrayList<>();
String[] userInfoRoles = userInfo.getRoles();
@ -279,7 +280,7 @@ public class UserManagementServiceImpl implements UserManagementService {
Map<String, String> 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<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<>();
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;
}

@ -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";

Loading…
Cancel
Save