Skip to content

Commit

Permalink
fix: fido2-plugin throwing error during deployment #1632 (#1633)
Browse files Browse the repository at this point in the history
* fix: fido2-plugin throwing error during deployment #1632

* fix: resolve sonar issues #1632
  • Loading branch information
duttarnab authored Jun 29, 2022
1 parent 04a3a86 commit 90d2c8a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package io.jans.configapi.plugin.fido2.service;

import io.jans.as.common.service.common.UserService;
import io.jans.as.model.config.StaticConfiguration;
import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.model.base.SimpleBranch;
Expand Down Expand Up @@ -35,13 +34,13 @@ public class Fido2RegistrationService {
private StaticConfiguration staticConfiguration;

@Inject
private UserService userService;
private UserFido2Service userFido2Srv;

@Inject
private PersistenceEntryManager persistenceEntryManager;

public List<Fido2RegistrationEntry> findAllByUsername(String username) {
String userInum = userService.getUserInum(username);
String userInum = userFido2Srv.getUserInum(username);
if (userInum == null) {
return Collections.emptyList();
}
Expand All @@ -61,7 +60,7 @@ public List<Fido2RegistrationEntry> findAllByUsername(String username) {
}

public List<Fido2RegistrationEntry> findAllRegisteredByUsername(String username) {
String userInum = userService.getUserInum(username);
String userInum = userFido2Srv.getUserInum(username);
if (userInum == null) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.jans.configapi.plugin.fido2.service;

import com.google.api.client.util.Lists;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;

import java.util.List;

@ApplicationScoped
@Named("userFido2Srv")
public class UserFido2Service extends io.jans.as.common.service.common.UserService {
@Override
public List<String> getPersonCustomObjectClassList() {
return Lists.newArrayList();
}

@Override
public String getPeopleBaseDn() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.jans.configapi.core.rest.ProtectedApi;
import io.jans.configapi.plugin.mgt.model.user.CustomUser;
import io.jans.configapi.plugin.mgt.model.user.UserPatchRequest;
import io.jans.configapi.plugin.mgt.service.UserService;
import io.jans.configapi.plugin.mgt.service.UserMgmtService;
import io.jans.configapi.plugin.mgt.util.Constants;
import io.jans.configapi.plugin.mgt.util.MgtUtil;
import io.jans.configapi.util.ApiAccessConstants;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class UserResource extends BaseResource {
MgtUtil mgtUtil;

@Inject
UserService userSrv;
UserMgmtService userMgmtSrv;

@GET
@ProtectedApi(scopes = {ApiAccessConstants.USER_READ_ACCESS})
Expand All @@ -72,8 +72,8 @@ public Response getUsers(
escapeLog(limit), escapeLog(pattern), escapeLog(startIndex), escapeLog(sortBy),
escapeLog(sortOrder));
}
SearchRequest searchReq = createSearchRequest(userSrv.getPeopleBaseDn(), pattern, sortBy, sortOrder, startIndex,
limit, null, userSrv.getUserExclusionAttributesAsString(), mgtUtil.getRecordMaxCount());
SearchRequest searchReq = createSearchRequest(userMgmtSrv.getPeopleBaseDn(), pattern, sortBy, sortOrder, startIndex,
limit, null, userMgmtSrv.getUserExclusionAttributesAsString(), mgtUtil.getRecordMaxCount());

List<CustomUser> customUsers = this.doSearch(searchReq);
logger.debug("CustomUser search result:{}", customUsers);
Expand All @@ -89,7 +89,7 @@ public Response getUserByInum(@PathParam(ApiConstants.INUM) @NotNull String inum
if (logger.isDebugEnabled()) {
logger.debug("User search by inum:{}", escapeLog(inum));
}
User user = userSrv.getUserBasedOnInum(inum);
User user = userMgmtSrv.getUserBasedOnInum(inum);
checkResourceNotNull(user, USER);
logger.debug("user:{}", user);

Expand All @@ -115,13 +115,13 @@ public Response createUser(@Valid CustomUser customUser)
// get User object
User user = setUserAttributes(customUser);
//parse birthdate if present
userSrv.parseBirthDateAttribute(user);
userMgmtSrv.parseBirthDateAttribute(user);
logger.debug("Create user:{}", user);

// checking mandatory attributes
checkMissingAttributes(user, null);

user = userSrv.addUser(user, true);
user = userMgmtSrv.addUser(user, true);
logger.debug("User created {}", user);

// excludedAttributes
Expand All @@ -145,14 +145,14 @@ public Response updateUser(@Valid CustomUser customUser)
// get User object
User user = setUserAttributes(customUser);
//parse birthdate if present
userSrv.parseBirthDateAttribute(user);
userMgmtSrv.parseBirthDateAttribute(user);
logger.debug("Create user:{}", user);

// checking mandatory attributes
List<String> excludeAttributes = List.of(USER_PWD);
checkMissingAttributes(user, excludeAttributes);

user = userSrv.updateUser(user);
user = userMgmtSrv.updateUser(user);
logger.debug("Updated user:{}", user);

// excludedAttributes
Expand All @@ -175,13 +175,13 @@ public Response patchUser(@PathParam(ApiConstants.INUM) @NotNull String inum,
logger.debug("User:{} to be patched with :{} ", escapeLog(inum), escapeLog(userPatchRequest));
}
// check if user exists
User existingUser = userSrv.getUserBasedOnInum(inum);
User existingUser = userMgmtSrv.getUserBasedOnInum(inum);
//parse birthdate if present
userSrv.parseBirthDateAttribute(existingUser);
userMgmtSrv.parseBirthDateAttribute(existingUser);
checkResourceNotNull(existingUser, USER);

// patch user
existingUser = userSrv.patchUser(inum, userPatchRequest);
existingUser = userMgmtSrv.patchUser(inum, userPatchRequest);
logger.debug("Patched user:{}", existingUser);

// excludedAttributes
Expand All @@ -201,9 +201,9 @@ public Response deleteUser(@PathParam(ApiConstants.INUM) @NotNull String inum) {
if (logger.isDebugEnabled()) {
logger.debug("User to be deleted - inum:{} ", escapeLog(inum));
}
User user = userSrv.getUserBasedOnInum(inum);
User user = userMgmtSrv.getUserBasedOnInum(inum);
checkResourceNotNull(user, USER);
userSrv.removeUser(user);
userMgmtSrv.removeUser(user);
return Response.noContent().build();
}

Expand All @@ -213,7 +213,7 @@ private List<CustomUser> doSearch(SearchRequest searchReq)
logger.debug("User search params - searchReq:{} ", escapeLog(searchReq));
}

PagedResult<User> pagedResult = userSrv.searchUsers(searchReq);
PagedResult<User> pagedResult = userMgmtSrv.searchUsers(searchReq);
if (logger.isTraceEnabled()) {
logger.debug("PagedResult - pagedResult:{}", pagedResult);
}
Expand All @@ -228,23 +228,23 @@ private List<CustomUser> doSearch(SearchRequest searchReq)
}

// excludedAttributes
users = userSrv.excludeAttributes(users, searchReq.getExcludedAttributesStr());
users = userMgmtSrv.excludeAttributes(users, searchReq.getExcludedAttributesStr());
logger.debug("Users fetched - users:{}", users);

//parse birthdate if present
users = users.stream().map(user -> userSrv.parseBirthDateAttribute(user)).collect(Collectors.toList());
users = users.stream().map(user -> userMgmtSrv.parseBirthDateAttribute(user)).collect(Collectors.toList());

// get customUser()
return getCustomUserList(users);
}

private User excludeUserAttributes(User user) throws IllegalAccessException, InvocationTargetException {
return userSrv.excludeAttributes(user, userSrv.getUserExclusionAttributesAsString());
return userMgmtSrv.excludeAttributes(user, userMgmtSrv.getUserExclusionAttributesAsString());
}

private void checkMissingAttributes(User user, List<String> excludeAttributes)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
String missingAttributes = userSrv.checkMandatoryFields(user, excludeAttributes);
String missingAttributes = userMgmtSrv.checkMandatoryFields(user, excludeAttributes);
logger.debug("missingAttributes:{}", missingAttributes);

if (StringHelper.isEmpty(missingAttributes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,34 @@
import io.jans.as.common.util.AttributeConstants;
import io.jans.as.model.config.StaticConfiguration;
import io.jans.as.model.configuration.AppConfiguration;
import io.jans.configapi.core.model.SearchRequest;
import io.jans.configapi.core.util.Jackson;
import io.jans.configapi.plugin.mgt.model.user.UserPatchRequest;
import io.jans.configapi.core.model.SearchRequest;
import io.jans.configapi.plugin.mgt.util.MgtUtil;
import io.jans.configapi.util.AuthUtil;
import io.jans.orm.model.PagedResult;
import io.jans.orm.model.SortOrder;
import io.jans.orm.model.base.CustomObjectAttribute;
import io.jans.orm.search.filter.Filter;
import io.jans.util.StringHelper;

import static io.jans.as.model.util.Util.escapeLog;

import java.lang.reflect.Field;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

import static io.jans.as.model.util.Util.escapeLog;

@ApplicationScoped
@Named("userSrv")
public class UserService extends io.jans.as.common.service.common.UserService {
@Named("userMgmtSrv")
public class UserMgmtService extends io.jans.as.common.service.common.UserService {

@Inject
private Logger logger;
Expand Down

0 comments on commit 90d2c8a

Please sign in to comment.