Skip to content

Commit

Permalink
feat(jans-config-api): user mgt plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pujavs committed Apr 18, 2022
1 parent ae132cf commit ccc56f8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
public class UserResource extends BaseResource {

private static final String USER = "user";
private static final String USER_PWD = "userPassword";

@Inject
Logger logger;
Expand Down Expand Up @@ -214,7 +215,7 @@ private void checkMissingAttributes(User user)
private List<User> getUsers(List<User> users) throws EncryptionException {
if (users != null && !users.isEmpty()) {
for (User user : users) {
if (StringHelper.isNotEmpty(user.getAttribute("userPassword"))) {
if (StringHelper.isNotEmpty(user.getAttribute(USER_PWD))) {
decryptUserPassword(user);
}
}
Expand All @@ -223,15 +224,15 @@ private List<User> getUsers(List<User> users) throws EncryptionException {
}

private User encryptUserPassword(User user) throws EncryptionException {
if (StringHelper.isNotEmpty(user.getAttribute("userPassword"))) {
user.setAttribute("userPassword", encryptionService.encrypt(user.getAttribute("userPassword")), false);
if (StringHelper.isNotEmpty(user.getAttribute(USER_PWD))) {
user.setAttribute(USER_PWD, encryptionService.encrypt(user.getAttribute(USER_PWD)), false);
}
return user;
}

private User decryptUserPassword(User user) throws EncryptionException {
if (StringHelper .isNotEmpty(user.getAttribute("userPassword"))) {
user.setAttribute("userPassword", encryptionService.decrypt(user.getAttribute("userPassword")), false);
if (StringHelper .isNotEmpty(user.getAttribute(USER_PWD))) {
user.setAttribute(USER_PWD, encryptionService.decrypt(user.getAttribute(USER_PWD)), false);
}
return user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@ public class Constants {
private Constants() {}

public static final String CONFIG_USER = "/configuser";
public static final String LIMIT = "limit";
public static final String START_INDEX = "startIndex";
public static final String PATTERN = "pattern";
public static final String STATUS = "status";
public static final String INUM = "inum";
public static final String SORT_BY = "sortBy";
public static final String SORT_ORDER = "sortOrder";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,7 @@ public class MgtUtil {
@Inject
UserMgtConfigSource configSource;

public String getProperty(String propertyName) {
logger.error("configSource.getValue(propertyName:{} ",configSource.getValue(propertyName));
return configSource.getValue(propertyName);
}

public String getMaxCount() {
logger.error("default.max.count:{} ",getProperty("default.max.count"));
return getProperty("default.max.count");
}

public String getDefaultListSize() {
logger.error("default.max.count:{} ",getProperty("default.list.size"));
return (StringHelper.isNotEmpty(getProperty("default.list.size")) ? getProperty("default.list.size") : ApiConstants.DEFAULT_LIST_SIZE);
}

public String getDefaultListStartIndex() {
logger.error("default.max.count:{} ",getProperty("default.list.start.index"));
return (StringHelper.isNotEmpty(getProperty("default.list.start.index")) ? getProperty("default.list.start.index") : ApiConstants.DEFAULT_LIST_SIZE);
}


public int getRecordMaxCount() {
logger.trace(" MaxCount details - ApiAppConfiguration.MaxCount():{}, DEFAULT_MAX_COUNT:{} ",
configurationFactory.getApiAppConfiguration().getMaxCount(), ApiConstants.DEFAULT_MAX_COUNT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,39 @@ When method GET
Then status 404
And print response

@CreateUpdateDelete
Scenario: Create new user, patch and delete
Given url mainUrl
And header Authorization = 'Bearer ' + accessToken
And request read('user.json')
When method POST
Then status 201
And print response
Then def result = response
And print result
And assert result != null
And assert result.customAttributes.length != null
Then def inum = funGetCustomAttributes(result.customAttributes,'inum')
And print inum
And assert inum != null
And print result.userId
And print 'Patching user ' + '-' +result.userId + '-' +inum
Given url mainUrl + '/' +inum
And header Authorization = 'Bearer ' + accessToken
And request read('user-patch.json')
When method PATCH
Then status 200
And print response
Then def result = response
And print 'About to delete user ' + '-' +result.userId + '-' +inum
Given url mainUrl + '/' +inum
And header Authorization = 'Bearer ' + accessToken
When method DELETE
Then status 204
And print response
And print 'User successfully deleted'

@ignore
@CreateUpdateDelete
Scenario: Create new user, update and delete
Given url mainUrl
Expand Down

0 comments on commit ccc56f8

Please sign in to comment.