Search in sources :

Example 36 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class Scim2FidoDeviceService method updateFidoDevice.

public FidoDevice updateFidoDevice(String id, FidoDevice fidoDevice) throws Exception {
    GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(fidoDevice.getUserId(), id);
    if (gluuCustomFidoDevice == null) {
        throw new EntryPersistenceException("Scim2FidoDeviceService.updateFidoDevice(): Resource " + id + " not found");
    }
    GluuCustomFidoDevice updatedGluuCustomFidoDevice = copyUtils2.updateGluuCustomFidoDevice(fidoDevice, gluuCustomFidoDevice);
    log.info(" Setting meta: update device ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuCustomFidoDevice.setMetaLastModified(dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuCustomFidoDevice.getMetaLocation() == null || (updatedGluuCustomFidoDevice.getMetaLocation() != null && updatedGluuCustomFidoDevice.getMetaLocation().isEmpty())) {
        String relativeLocation = "/scim/v2/FidoDevices/" + id;
        updatedGluuCustomFidoDevice.setMetaLocation(relativeLocation);
    }
    fidoDeviceService.updateGluuCustomFidoDevice(gluuCustomFidoDevice);
    FidoDevice updatedFidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
    return updatedFidoDevice;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 37 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class Scim2FidoDeviceService method deleteFidoDevice.

public void deleteFidoDevice(String id) throws Exception {
    GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(null, id);
    if (gluuCustomFidoDevice == null) {
        throw new EntryPersistenceException("Scim2FidoDeviceService.deleteFidoDevice(): Resource " + id + " not found");
    }
    fidoDeviceService.removeGluuCustomFidoDevice(gluuCustomFidoDevice);
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Example 38 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class Scim2GroupService method updateGroup.

public Group updateGroup(String id, Group group) throws Exception {
    GluuGroup gluuGroup = groupService.getGroupByInum(id);
    if (gluuGroup == null) {
        throw new EntryPersistenceException("Scim2GroupService.updateGroup(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update displayName of a different id
        if (gluuGroup.getDisplayName() != null) {
            GluuGroup groupToFind = new GluuGroup();
            groupToFind.setDisplayName(group.getDisplayName());
            List<GluuGroup> foundGroups = groupService.findGroups(groupToFind, 2);
            if (foundGroups != null && foundGroups.size() > 0) {
                for (GluuGroup foundGroup : foundGroups) {
                    if (foundGroup != null && !foundGroup.getInum().equalsIgnoreCase(gluuGroup.getInum())) {
                        throw new DuplicateEntryException("Cannot update displayName of a different id: " + group.getDisplayName());
                    }
                }
            }
        }
    }
    GluuGroup updatedGluuGroup = copyUtils2.copy(group, gluuGroup, true);
    if (group.getMembers().size() > 0) {
        serviceUtil.personMembersAdder(updatedGluuGroup, groupService.getDnForGroup(id));
    }
    log.info(" Setting meta: update group ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuGroup.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuGroup.getAttribute("oxTrustMetaLocation") == null || (updatedGluuGroup.getAttribute("oxTrustMetaLocation") != null && updatedGluuGroup.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Groups/" + id;
        updatedGluuGroup.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // For custom script: update group
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateGroupMethods(updatedGluuGroup);
    }
    groupService.updateGroup(updatedGluuGroup);
    log.debug(" group updated ");
    Group updatedGroup = copyUtils2.copy(updatedGluuGroup, null);
    return updatedGroup;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) GluuGroup(org.gluu.oxtrust.model.GluuGroup) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 39 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class Scim2GroupService method deleteGroup.

public void deleteGroup(String id) throws Exception {
    log.info(" Checking if the group exists ");
    log.info(" id : " + id);
    GluuGroup gluuGroup = groupService.getGroupByInum(id);
    if (gluuGroup == null) {
        log.info(" the group is null ");
        throw new EntryPersistenceException("Scim2GroupService.deleteGroup(): " + "Resource " + id + " not found");
    } else {
        // For custom script: delete group
        if (externalScimService.isEnabled()) {
            externalScimService.executeScimDeleteGroupMethods(gluuGroup);
        }
        log.info(" getting started to delete members from groups ");
        if (gluuGroup.getMembers() != null) {
            if (gluuGroup.getMembers().size() > 0) {
                log.info(" getting dn for group ");
                String dn = groupService.getDnForGroup(id);
                log.info(" DN : " + dn);
                serviceUtil.deleteGroupFromPerson(gluuGroup, dn);
            }
        }
        log.info(" removing the group ");
        groupService.removeGroup(gluuGroup);
    }
}
Also used : EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 40 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class AuthenticationService method updateLastLogonUserTime.

private void updateLastLogonUserTime(User user) {
    if (!appConfiguration.getUpdateUserLastLogonTime()) {
        return;
    }
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(user.getDn());
    customEntry.setCustomObjectClasses(UserService.USER_OBJECT_CLASSES);
    CustomAttribute customAttribute = new CustomAttribute("oxLastLogonTime", new Date());
    customEntry.getCustomAttributes().add(customAttribute);
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastLoginTime of user '{}'", user.getUserId());
    }
}
Also used : CustomEntry(org.xdi.ldap.model.CustomEntry) CustomAttribute(org.xdi.ldap.model.CustomAttribute) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Aggregations

EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)51 Response (javax.ws.rs.core.Response)20 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)20 Path (javax.ws.rs.Path)19 Produces (javax.ws.rs.Produces)19 URI (java.net.URI)17 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)15 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)12 EmptyEntryPersistenceException (org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 DefaultValue (javax.ws.rs.DefaultValue)9 HeaderParam (javax.ws.rs.HeaderParam)9 GluuGroup (org.gluu.oxtrust.model.GluuGroup)9 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)9 MappingException (org.gluu.site.ldap.persistence.exception.MappingException)9 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)8 ParseException (java.text.ParseException)8 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)8 ConnectionException (org.gluu.site.ldap.exception.ConnectionException)8 AuthenticationException (org.gluu.site.ldap.persistence.exception.AuthenticationException)8