This is an automated email from the ASF dual-hosted git repository. ilgrosso pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 653e5fe215d0d94e8a2de64f70327580cff7c28b Author: Francesco Chicchiriccò <[email protected]> AuthorDate: Thu Apr 17 14:12:35 2025 +0200 [SYNCOPE-1870] Do not log stacktrace by default for NotFoundException --- .../client/console/rest/RoleRestClient.java | 16 +++++++--- .../client/lib/RestClientExceptionMapper.java | 15 +++++++++- .../org/apache/syncope/core/logic/RoleLogic.java | 2 -- .../core/rest/cxf/RestServiceExceptionMapper.java | 35 +++++++++++++++------- .../provisioning/java/data/UserDataBinderImpl.java | 15 ++-------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/RoleRestClient.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/RoleRestClient.java index db47ae4f41..8136bb15d1 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/RoleRestClient.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/RoleRestClient.java @@ -25,7 +25,9 @@ import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.syncope.client.console.SyncopeConsoleSession; +import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.RoleTO; +import org.apache.syncope.common.lib.types.ClientExceptionType; import org.apache.syncope.common.rest.api.service.RoleService; /** @@ -55,15 +57,21 @@ public class RoleRestClient extends BaseRestClient { return getService(RoleService.class).list(); } - public String readAnyLayout(final String roleKey) { + public String readAnyLayout(final String role) { try { return IOUtils.toString(InputStream.class.cast( - getService(RoleService.class).getAnyLayout(roleKey).getEntity()), + getService(RoleService.class).getAnyLayout(role).getEntity()), StandardCharsets.UTF_8); + } catch (SyncopeClientException e) { + if (e.getType() == ClientExceptionType.NotFound) { + LOG.warn("Could not locate console layout info for role {}", role); + } else { + LOG.error("While retrieving console layout info for role {}", role, e); + } } catch (Exception e) { - LOG.error("Error retrieving console layout info for role {}", roleKey, e); - return StringUtils.EMPTY; + LOG.error(e.getMessage(), e); } + return StringUtils.EMPTY; } public void setAnyLayout(final String roleKey, final String content) { diff --git a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/RestClientExceptionMapper.java b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/RestClientExceptionMapper.java index 9e2bb3b522..8eb11728ad 100644 --- a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/RestClientExceptionMapper.java +++ b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/RestClientExceptionMapper.java @@ -21,6 +21,7 @@ package org.apache.syncope.client.lib; import jakarta.ws.rs.BadRequestException; import jakarta.ws.rs.ForbiddenException; import jakarta.ws.rs.NotAuthorizedException; +import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.core.GenericType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.ext.Provider; @@ -76,7 +77,19 @@ public class RestClientExceptionMapper implements ResponseExceptionMapper<Except ex = new WebServiceException(String.format("Remote exception with status code: %s", Response.Status.fromStatusCode(statusCode).name())); } - LOG.error("Exception thrown", ex); + + if (ex instanceof NotFoundException + || (ex instanceof SyncopeClientException sce && sce.getType() == ClientExceptionType.NotFound)) { + + if (LOG.isDebugEnabled()) { + LOG.debug("Exception thrown", ex); + } else { + LOG.warn("{} thrown: {}", NotFoundException.class.getSimpleName(), ex.getMessage()); + } + } else { + LOG.error("Exception thrown", ex); + } + return ex; } diff --git a/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/RoleLogic.java b/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/RoleLogic.java index 1e948fe5da..1bc3332442 100644 --- a/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/RoleLogic.java +++ b/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/RoleLogic.java @@ -92,8 +92,6 @@ public class RoleLogic extends AbstractTransactionalLogic<RoleTO> { String consoleLayout = role.getAnyLayout(); if (StringUtils.isBlank(consoleLayout)) { - LOG.error("Could not find console layout for Role '{}'", key); - throw new NotFoundException("Console layout for role " + key); } diff --git a/core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java b/core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java index 4c680a322d..6eb45bc7ba 100644 --- a/core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java +++ b/core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java @@ -88,7 +88,15 @@ public class RestServiceExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception ex) { - LOG.error("Exception thrown", ex); + if (ex instanceof NotFoundException) { + if (LOG.isDebugEnabled()) { + LOG.debug("Exception thrown", ex); + } else { + LOG.warn("{} thrown: {}", NotFoundException.class.getSimpleName(), ex.getMessage()); + } + } else { + LOG.error("Exception thrown", ex); + } ResponseBuilder builder; @@ -107,10 +115,9 @@ public class RestServiceExceptionMapper implements ExceptionMapper<Exception> { || ((ex instanceof PersistenceException || ex instanceof DataIntegrityViolationException) && (ex.getCause() instanceof EntityExistsException || ex.getMessage().contains("already exists")))) { - builder = builder(ClientExceptionType.EntityExists, - getPersistenceErrorMessage( - ex instanceof PersistenceException || ex instanceof DataIntegrityViolationException - ? ex.getCause() : ex)); + builder = builder(ClientExceptionType.EntityExists, getPersistenceErrorMessage( + ex instanceof PersistenceException || ex instanceof DataIntegrityViolationException + ? ex.getCause() : ex)); } else if (ex instanceof DataIntegrityViolationException || ex instanceof UncategorizedDataAccessException) { builder = builder(ClientExceptionType.DataIntegrityViolation, getPersistenceErrorMessage(ex)); } else if (ex instanceof ConnectorException) { @@ -256,17 +263,23 @@ public class RestServiceExceptionMapper implements ExceptionMapper<Exception> { if (ex instanceof WorkflowException) { return builder(ClientExceptionType.Workflow, ExceptionUtils.getRootCauseMessage(ex)); - } else if (ex instanceof PersistenceException) { + } + if (ex instanceof PersistenceException) { return builder(ClientExceptionType.GenericPersistence, ExceptionUtils.getRootCauseMessage(ex)); - } else if (ibatisPersistenceException != null && ibatisPersistenceException.isAssignableFrom(ex.getClass())) { + } + if (ibatisPersistenceException != null && ibatisPersistenceException.isAssignableFrom(ex.getClass())) { return builder(ClientExceptionType.Workflow, "Currently unavailable. Please try later."); - } else if (ex instanceof UncategorizedDataAccessException) { + } + if (ex instanceof UncategorizedDataAccessException) { return builder(ClientExceptionType.DataIntegrityViolation, ExceptionUtils.getRootCauseMessage(ex)); - } else if (ex instanceof ConfigurationException) { + } + if (ex instanceof ConfigurationException) { return builder(ClientExceptionType.InvalidConnIdConf, ExceptionUtils.getRootCauseMessage(ex)); - } else if (ex instanceof ParsingValidationException) { + } + if (ex instanceof ParsingValidationException) { return builder(ClientExceptionType.InvalidValues, ExceptionUtils.getRootCauseMessage(ex)); - } else if (ex instanceof MalformedPathException) { + } + if (ex instanceof MalformedPathException) { return builder(ClientExceptionType.InvalidPath, ExceptionUtils.getRootCauseMessage(ex)); } diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java index 9ef36df009..9d3ca8a22d 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java @@ -181,23 +181,12 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat return authUserTO; } - protected RuntimeException aggregateException( - final SyncopeClientCompositeException scce, - final RuntimeException e, - final ClientExceptionType clientExceptionType) { - - SyncopeClientException sce = SyncopeClientException.build(clientExceptionType); - sce.getElements().add(e.getMessage()); - scce.addException(sce); - return scce; - } - protected void setPassword(final User user, final String password, final SyncopeClientCompositeException scce) { try { setCipherAlgorithm(user); user.setPassword(password); } catch (IllegalArgumentException e) { - throw aggregateException(scce, e, ClientExceptionType.NotFound); + throw new NotFoundException(e.getMessage()); } } @@ -209,7 +198,7 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat setCipherAlgorithm(user); user.setSecurityAnswer(securityAnswer); } catch (IllegalArgumentException e) { - throw aggregateException(scce, e, ClientExceptionType.NotFound); + throw new NotFoundException(e.getMessage()); } }
