Search in sources :

Example 6 with DuplicateEntryException

use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.

the class PersonService method addPerson.

// TODO: Review this methods. We need to check if uid is unique in outside method
public void addPerson(GluuCustomPerson person) throws Exception {
    try {
        List<GluuCustomPerson> persons = getPersonsByUid(person.getUid());
        if (persons == null || persons.size() == 0) {
            person.setCreationDate(new Date());
            attributeService.applyMetaData(person.getCustomAttributes());
            persistenceEntryManager.persist(person);
        } else {
            throw new DuplicateEntryException("Duplicate UID value: " + person.getUid());
        }
    } catch (Exception e) {
        if (e.getCause().getMessage().contains("unique attribute conflict was detected for attribute mail")) {
            throw new DuplicateEmailException("Email Already Registered");
        } else {
            throw new Exception("Duplicate UID value: " + person.getUid());
        }
    }
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) DuplicateEmailException(io.jans.scim.exception.DuplicateEmailException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) Date(java.util.Date) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) DuplicateEmailException(io.jans.scim.exception.DuplicateEmailException)

Example 7 with DuplicateEntryException

use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.

the class NativePersistenceCacheProvider method putImpl.

private void putImpl(String key, Object object, Date creationDate, int expirationInSeconds) {
    Calendar expirationDate = Calendar.getInstance();
    expirationDate.setTime(creationDate);
    expirationDate.add(Calendar.SECOND, expirationInSeconds);
    String originalKey = key;
    key = hashKey(key);
    NativePersistenceCacheEntity entity = new NativePersistenceCacheEntity();
    entity.setTtl(expirationInSeconds);
    entity.setData(asString(object));
    entity.setId(key);
    entity.setDn(createDn(key));
    entity.setCreationDate(creationDate);
    entity.setExpirationDate(expirationDate.getTime());
    entity.setDeletable(true);
    try {
        if (attemptUpdateBeforeInsert) {
            entryManager.merge(entity);
        } else {
            if (!skipRemoveBeforePut) {
                silentlyRemoveEntityIfExists(entity.getDn());
            }
            entryManager.persist(entity);
        }
    } catch (EntryPersistenceException e) {
        if (e.getCause() instanceof DuplicateEntryException) {
            // on duplicate, remove entry and try to persist again
            try {
                silentlyRemoveEntityIfExists(entity.getDn());
                entryManager.persist(entity);
                return;
            } catch (Exception ex) {
                log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
            }
        }
        if (attemptUpdateBeforeInsert) {
            try {
                entryManager.persist(entity);
                return;
            } catch (Exception ex) {
                log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
            }
        }
        log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
    } catch (Exception e) {
        // log as trace since it is perfectly valid that entry is removed by timer for example
        log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
    }
}
Also used : Calendar(java.util.Calendar) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Example 8 with DuplicateEntryException

use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.

the class GroupWebService method checkDisplayNameExistence.

private void checkDisplayNameExistence(String displayName, String id) throws DuplicateEntryException {
    // Validate if there is an attempt to supply a displayName already in use by a
    // group other than current
    GluuGroup groupToFind = new GluuGroup();
    groupToFind.setDisplayName(displayName);
    List<GluuGroup> list = groupService.findGroups(groupToFind, 2);
    if (list != null && list.stream().anyMatch(g -> !g.getInum().equals(id))) {
        throw new DuplicateEntryException("Duplicate group displayName value: " + displayName);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Produces(javax.ws.rs.Produces) QUERY_PARAM_FILTER(io.jans.scim.model.scim2.Constants.QUERY_PARAM_FILTER) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) QUERY_PARAM_SORT_ORDER(io.jans.scim.model.scim2.Constants.QUERY_PARAM_SORT_ORDER) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) MediaType(javax.ws.rs.core.MediaType) SCIMException(io.jans.scim.model.exception.SCIMException) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) GluuGroup(io.jans.scim.model.GluuGroup) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) SortOrder(io.jans.orm.model.SortOrder) Predicate(java.util.function.Predicate) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) QUERY_PARAM_EXCLUDED_ATTRS(io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS) GroupResource(io.jans.scim.model.scim2.group.GroupResource) List(java.util.List) Response(javax.ws.rs.core.Response) ErrorScimType(io.jans.scim.model.scim2.ErrorScimType) Scim2PatchService(io.jans.scim.service.scim2.Scim2PatchService) PostConstruct(javax.annotation.PostConstruct) QUERY_PARAM_START_INDEX(io.jans.scim.model.scim2.Constants.QUERY_PARAM_START_INDEX) QUERY_PARAM_SORT_BY(io.jans.scim.model.scim2.Constants.QUERY_PARAM_SORT_BY) GroupService(io.jans.scim.service.GroupService) PathParam(javax.ws.rs.PathParam) QUERY_PARAM_COUNT(io.jans.scim.model.scim2.Constants.QUERY_PARAM_COUNT) GET(javax.ws.rs.GET) QUERY_PARAM_ATTRIBUTES(io.jans.scim.model.scim2.Constants.QUERY_PARAM_ATTRIBUTES) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) DateUtil(io.jans.scim.model.scim2.util.DateUtil) HttpMethod(javax.ws.rs.HttpMethod) ScimResourceUtil(io.jans.scim.model.scim2.util.ScimResourceUtil) Inject(javax.inject.Inject) Named(javax.inject.Named) POST(javax.ws.rs.POST) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) UTF8_CHARSET_FRAGMENT(io.jans.scim.model.scim2.Constants.UTF8_CHARSET_FRAGMENT) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) GROUP_OVERHEAD_BYPASS_PARAM(io.jans.scim.model.scim2.Constants.GROUP_OVERHEAD_BYPASS_PARAM) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) SearchRequest(io.jans.scim.model.scim2.SearchRequest) PagedResult(io.jans.orm.model.PagedResult) MEDIA_TYPE_SCIM_JSON(io.jans.scim.model.scim2.Constants.MEDIA_TYPE_SCIM_JSON) Scim2GroupService(io.jans.scim.service.scim2.Scim2GroupService) PUT(javax.ws.rs.PUT) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) GluuGroup(io.jans.scim.model.GluuGroup)

Example 9 with DuplicateEntryException

use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.

the class GroupService method addGroup.

public void addGroup(GluuGroup group) throws Exception {
    GluuGroup displayNameGroup = new GluuGroup();
    displayNameGroup.setDisplayName(group.getDisplayName());
    List<GluuGroup> groups = findGroups(displayNameGroup, 1);
    if (groups == null || groups.size() == 0) {
        persistenceEntryManager.persist(group);
    } else {
        throw new DuplicateEntryException("Duplicate displayName: " + group.getDisplayName());
    }
}
Also used : DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) GluuGroup(io.jans.scim.model.GluuGroup)

Aggregations

DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)9 SCIMException (io.jans.scim.model.exception.SCIMException)6 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)6 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)6 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 Consumes (javax.ws.rs.Consumes)6 GluuGroup (io.jans.scim.model.GluuGroup)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5 Produces (javax.ws.rs.Produces)5 Response (javax.ws.rs.core.Response)5 GroupResource (io.jans.scim.model.scim2.group.GroupResource)3 POST (javax.ws.rs.POST)3 PUT (javax.ws.rs.PUT)3 Path (javax.ws.rs.Path)3 PagedResult (io.jans.orm.model.PagedResult)2 SortOrder (io.jans.orm.model.SortOrder)2 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)2