Search in sources :

Example 16 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel in project CzechIdMng by bcvsolutions.

the class RestErrorAttributes method getErrorAttributes.

@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
    Throwable error = getError(webRequest);
    Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, includeStackTrace);
    // 
    ErrorModel errorModel = null;
    if (error instanceof ResultCodeException) {
        errorModel = ((ResultCodeException) error).getError().getError();
    } else {
        if (errorAttributes.containsKey(ATTRIBUTE_STATUS)) {
            int status = (int) errorAttributes.get(ATTRIBUTE_STATUS);
            switch(status) {
                case 401:
                    {
                        errorModel = new DefaultErrorModel(CoreResultCode.LOG_IN, ImmutableMap.of("path", errorAttributes.get("path")));
                        break;
                    }
                case 403:
                    {
                        errorModel = new DefaultErrorModel(CoreResultCode.FORBIDDEN, ImmutableMap.of("path", errorAttributes.get("path"), "message", errorAttributes.get("message")));
                        break;
                    }
                case 404:
                    {
                        errorModel = new DefaultErrorModel(CoreResultCode.ENDPOINT_NOT_FOUND, ImmutableMap.of("path", errorAttributes.get("path"), "message", errorAttributes.get("message")));
                        break;
                    }
                case 400:
                case 405:
                    {
                        errorModel = new DefaultErrorModel(CoreResultCode.METHOD_NOT_ALLOWED, ImmutableMap.of("path", errorAttributes.get("path"), "message", errorAttributes.get("message")));
                        break;
                    }
                default:
                    {
                        errorModel = null;
                    }
            }
        }
    }
    if (errorModel == null) {
        LOG.error("Error not resolved - errorAttributes needs extension for error attrs [{}]", errorAttributes);
        return errorAttributes;
    }
    errorAttributes.put(ATTRIBUTE_ERROR, errorModel);
    LOG.warn(errorModel.toString());
    // 
    return errorAttributes;
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)

Example 17 with ErrorModel

use of eu.bcvsolutions.idm.core.api.exception.ErrorModel in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordPolicyServiceIntegrationTest method checkMaxHistorySimilarError.

private void checkMaxHistorySimilarError(ResultCodeException exception, int maxHistorySettingOriginal) {
    ErrorModel error = exception.getError().getError();
    assertTrue(error.getMessage().contains("Password does not match password policy"));
    assertEquals(CoreResultCode.PASSWORD_DOES_NOT_MEET_POLICY.getCode(), error.getStatusEnum());
    Map<String, Object> parameters = error.getParameters();
    assertEquals(1, parameters.size());
    assertTrue(parameters.containsKey("maxHistorySimilar"));
    Object parameterAsObject = parameters.get("maxHistorySimilar");
    int maxHistorySetting = Integer.valueOf(parameterAsObject.toString());
    assertEquals(maxHistorySettingOriginal, maxHistorySetting);
}
Also used : ErrorModel(eu.bcvsolutions.idm.core.api.exception.ErrorModel) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Aggregations

ErrorModel (eu.bcvsolutions.idm.core.api.exception.ErrorModel)17 DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)14 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)11 HttpHeaders (org.springframework.http.HttpHeaders)11 ResponseEntity (org.springframework.http.ResponseEntity)11 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)6 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)2 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)2 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 Test (org.junit.Test)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)1 Method (java.lang.reflect.Method)1 AsyncUncaughtExceptionHandler (org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler)1