Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config-api): user attribute validation error handling #8383

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8217,19 +8217,19 @@ components:
$ref: '#/components/schemas/AttributeValidation'
tooltip:
type: string
userCanView:
selected:
type: boolean
adminCanView:
userCanView:
type: boolean
adminCanEdit:
type: boolean
userCanEdit:
type: boolean
userCanAccess:
adminCanView:
type: boolean
adminCanAccess:
type: boolean
selected:
userCanAccess:
type: boolean
whitePagesCanView:
type: boolean
Expand Down
4 changes: 2 additions & 2 deletions jans-config-api/plugins/docs/lock-plugin-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ components:
type: string
policyConsumerType:
type: string
policiesJsonUrisAuthorizationToken:
policiesJsonUrisAccessToken:
type: string
policiesJsonUris:
type: array
items:
type: string
policiesZipUrisAuthorizationToken:
policiesZipUrisAccessToken:
type: string
policiesZipUris:
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import io.jans.model.SearchRequest;
import io.jans.orm.model.PagedResult;
import io.jans.util.StringHelper;
import io.jans.util.exception.InvalidAttributeException;


import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -151,22 +154,22 @@ public Response createUser(@Valid CustomUser customUser,
logger.info("User details to be added - customUser:{}, removeNonLDAPAttributes:{}", escapeLog(customUser),
removeNonLDAPAttributes);
}

try {
// get User object
User user = setUserAttributes(customUser);

// get User object
User user = setUserAttributes(customUser);

// parse birthdate if present
userMgmtSrv.parseBirthDateAttribute(user);
logger.debug("Create user:{}", user);
// parse birthdate if present
userMgmtSrv.parseBirthDateAttribute(user);
logger.debug("Create user:{}", user);

// checking mandatory attributes
checkMissingAttributes(user, null);
ignoreCustomAttributes(user, removeNonLDAPAttributes);
validateAttributes(user);
// checking mandatory attributes
checkMissingAttributes(user, null);
ignoreCustomAttributes(user, removeNonLDAPAttributes);
validateAttributes(user);

logger.info("Service call to create user:{}", user);
logger.info("Service call to create user:{}", user);

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

Expand All @@ -176,14 +179,13 @@ public Response createUser(@Valid CustomUser customUser,
// get custom user
customUser = getCustomUser(user, removeNonLDAPAttributes);
logger.info("newly created customUser:{}", customUser);
}catch(WebApplicationException wex) {
logger.error("ApplicationException while creating user is:{}, cause:{}", wex, wex.getCause());
throwInternalServerException("USER_CREATION_ERROR", wex);
}catch(InvalidAttributeException iae) {
logger.error("InvalidAttributeException while creating user is:{}, cause:{}", iae, iae.getCause());
throwBadRequestException("USER_CREATION_ERROR", iae.getMessage());
}catch(Exception ex) {
logger.error("Exception while creating user is:{}, cause:{}", ex, ex.getCause());
throwInternalServerException(ex);
}

return Response.status(Response.Status.CREATED).entity(customUser).build();
}

Expand All @@ -208,22 +210,22 @@ public Response updateUser(@Valid CustomUser customUser,
removeNonLDAPAttributes);
}


// get User object
User user = setUserAttributes(customUser);
try {
// get User object
User user = setUserAttributes(customUser);

// parse birthdate if present
userMgmtSrv.parseBirthDateAttribute(user);
logger.debug("Create user:{}", user);
// parse birthdate if present
userMgmtSrv.parseBirthDateAttribute(user);
logger.debug("Create user:{}", user);

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

logger.info("Call update user:{}", user);

logger.info("Call update user:{}", user);
try {
user = userMgmtSrv.updateUser(user);
logger.info("Updated user:{}", user);

Expand All @@ -233,9 +235,9 @@ public Response updateUser(@Valid CustomUser customUser,
// get custom user
customUser = getCustomUser(user, removeNonLDAPAttributes);
logger.info("updated customUser:{}", customUser);
} catch (WebApplicationException wex) {
logger.error("ApplicationException while updating user is:{}, cause:{}", wex, wex.getCause());
throwInternalServerException("USER_UPDATE_ERROR", wex.getMessage());
} catch (InvalidAttributeException iae) {
logger.error("InvalidAttributeException while updating user is:{}, cause:{}", iae, iae.getCause());
throwBadRequestException("USER_UPDATE_ERROR", iae.getMessage());
}
catch (Exception ex) {
logger.error("Exception while updating user is:{}, cause:{}", ex, ex.getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import io.jans.orm.model.base.CustomObjectAttribute;
import io.jans.orm.search.filter.Filter;
import io.jans.util.StringHelper;
import io.jans.util.exception.InvalidAttributeException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.WebApplicationException;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -521,7 +522,7 @@ public void validateAttributes(List<CustomObjectAttribute> customAttributes) {

if (StringUtils.isNotBlank(sb.toString())) {
logger.error("Attribute validation failed with error msg:{} \n",sb);
throw new WebApplicationException(sb.toString());
throw new InvalidAttributeException(sb.toString());
}

}
Expand Down