Search in sources :

Example 16 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class ManageCustomScriptAction method save.

public String save() {
    try {
        List<CustomScript> oldCustomScripts = customScriptService.findCustomScripts(Arrays.asList(this.applianceService.getCustomScriptTypes()), "dn", "inum");
        List<String> updatedInums = new ArrayList<String>();
        for (Entry<CustomScriptType, List<CustomScript>> customScriptsByType : this.customScriptsByTypes.entrySet()) {
            List<CustomScript> customScripts = customScriptsByType.getValue();
            for (CustomScript customScript : customScripts) {
                String configId = customScript.getName();
                if (StringHelper.equalsIgnoreCase(configId, OxConstants.SCRIPT_TYPE_INTERNAL_RESERVED_NAME)) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "'{0}' is reserved script name", configId);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                customScript.setRevision(customScript.getRevision() + 1);
                boolean update = true;
                String dn = customScript.getDn();
                String customScriptId = customScript.getInum();
                if (StringHelper.isEmpty(dn)) {
                    String basedInum = organizationService.getOrganizationInum();
                    customScriptId = basedInum + "!" + INumGenerator.generate(2);
                    dn = customScriptService.buildDn(customScriptId);
                    customScript.setDn(dn);
                    customScript.setInum(customScriptId);
                    update = false;
                }
                ;
                customScript.setDn(dn);
                customScript.setInum(customScriptId);
                if (ScriptLocationType.LDAP == customScript.getLocationType()) {
                    customScript.removeModuleProperty(CustomScript.LOCATION_PATH_MODEL_PROPERTY);
                }
                if ((customScript.getConfigurationProperties() != null) && (customScript.getConfigurationProperties().size() == 0)) {
                    customScript.setConfigurationProperties(null);
                }
                if ((customScript.getConfigurationProperties() != null) && (customScript.getModuleProperties().size() == 0)) {
                    customScript.setModuleProperties(null);
                }
                updatedInums.add(customScriptId);
                if (update) {
                    customScriptService.update(customScript);
                } else {
                    customScriptService.add(customScript);
                }
            }
        }
        // Remove removed scripts
        for (CustomScript oldCustomScript : oldCustomScripts) {
            if (!updatedInums.contains(oldCustomScript.getInum())) {
                customScriptService.remove(oldCustomScript);
            }
        }
    } catch (BaseMappingException ex) {
        log.error("Failed to update custom scripts", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update custom script configuration");
        return OxTrustConstants.RESULT_FAILURE;
    }
    facesMessages.add(FacesMessage.SEVERITY_INFO, "Custom script configuration updated successfully");
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) AuthenticationCustomScript(org.xdi.model.custom.script.model.auth.AuthenticationCustomScript) CustomScript(org.xdi.model.custom.script.model.CustomScript) CustomScriptType(org.xdi.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class UpdateGroupAction method add.

public String add() throws Exception {
    if (this.group != null) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    this.update = false;
    this.group = new GluuGroup();
    this.group.setOwner(identity.getUser().getDn());
    this.group.setOrganization(organizationService.getOrganization().getDn());
    try {
        this.members = getMemberDisplayNameEntiries();
    } catch (BaseMappingException ex) {
        log.error("Failed to prepare lists", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new group");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 18 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class UpdateOrganizationAction method initOxAuthSetting.

private void initOxAuthSetting() {
    String configurationDn = configurationFactory.getConfigurationDn();
    try {
        ldapOxAuthConfiguration = organizationService.getOxAuthSetting(configurationDn);
        this.webKeysSettings = ldapOxAuthConfiguration.getOxWebKeysSettings();
        if (webKeysSettings == null) {
            webKeysSettings = new WebKeysSettings();
        }
    } catch (BaseMappingException ex) {
        log.error("Failed to load configuration from LDAP");
    }
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) WebKeysSettings(org.xdi.config.oxauth.WebKeysSettings)

Example 19 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class UpdatePersonAction method save.

/**
 * Saves person to ldap
 *
 * @return String describing success of the operation
 */
public String save() throws Exception {
    if (!organizationService.isAllowPersonModification()) {
        return OxTrustConstants.RESULT_FAILURE;
    }
    if (!update) {
        if (!validatePerson(this.person)) {
            return OxTrustConstants.RESULT_FAILURE;
        }
    }
    updateCustomObjectClasses();
    List<GluuCustomAttribute> removedAttributes = customAttributeAction.detectRemovedAttributes();
    customAttributeAction.updateOriginCustomAttributes();
    List<GluuCustomAttribute> customAttributes = customAttributeAction.getCustomAttributes();
    for (GluuCustomAttribute customAttribute : customAttributes) {
        if (customAttribute.getName().equalsIgnoreCase("gluuStatus")) {
            customAttribute.setValue(gluuStatus.getValue());
        }
    }
    this.person.setCustomAttributes(customAttributeAction.getCustomAttributes());
    this.person.getCustomAttributes().addAll(removedAttributes);
    // Sync email, in reverse ("oxTrustEmail" <- "mail")
    this.person = ServiceUtil.syncEmailReverse(this.person, true);
    boolean runScript = externalUpdateUserService.isEnabled();
    if (update) {
        try {
            if (runScript) {
                externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
            }
            personService.updatePerson(this.person);
            if (runScript) {
                externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
            }
        } catch (BaseMappingException ex) {
            log.error("Failed to update person {}", inum, ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update person '#{updatePersonAction.person.displayName}'");
            return OxTrustConstants.RESULT_FAILURE;
        }
        facesMessages.add(FacesMessage.SEVERITY_INFO, "Person '#{updatePersonAction.person.displayName}' updated successfully");
    } else {
        if (personService.getPersonByUid(this.person.getUid()) != null) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Person with the uid '#{updatePersonAction.person.uid}' already exist'");
            return OxTrustConstants.RESULT_DUPLICATE;
        }
        this.inum = personService.generateInumForNewPerson();
        String iname = personService.generateInameForNewPerson(this.person.getUid());
        String dn = personService.getDnForPerson(this.inum);
        // Save person
        this.person.setDn(dn);
        this.person.setInum(this.inum);
        this.person.setIname(iname);
        this.person.setUserPassword(this.password);
        List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
        if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
            List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
            changedAttributes.addAll(personAttributes);
            changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
            this.person.setCustomAttributes(changedAttributes);
        } else {
            this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
        }
        try {
            if (runScript) {
                externalUpdateUserService.executeExternalAddUserMethods(this.person);
            }
            personService.addPerson(this.person);
            if (runScript) {
                externalUpdateUserService.executeExternalPostAddUserMethods(this.person);
            }
        } catch (Exception ex) {
            log.error("Failed to add new person {}", this.person.getInum(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person'");
            return OxTrustConstants.RESULT_FAILURE;
        }
        facesMessages.add(FacesMessage.SEVERITY_INFO, "New person '#{updatePersonAction.person.displayName}' added successfully");
        conversationService.endConversation();
        this.update = true;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) ArrayList(java.util.ArrayList) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 20 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class UpdateScopeAction method add.

public String add() throws Exception {
    if (this.scope != null) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    this.update = false;
    this.scope = new OxAuthScope();
    try {
        if (this.scope.getOxAuthClaims() != null && this.scope.getOxAuthClaims().size() > 0) {
            this.claims = getClaimDisplayNameEntiries();
        } else {
            this.claims = new ArrayList<DisplayNameEntry>();
        }
    } catch (BaseMappingException ex) {
        log.error("Failed to load scopes", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new scope");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    this.dynamicScripts = getInitialDynamicScripts();
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) OxAuthScope(org.gluu.oxtrust.model.OxAuthScope) DisplayNameEntry(org.xdi.model.DisplayNameEntry)

Aggregations

BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)29 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)5 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)4 Date (java.util.Date)3 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)3 LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)3 CustomScript (org.xdi.model.custom.script.model.CustomScript)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ParseException (java.text.ParseException)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)2 GluuStatus (org.gluu.persist.model.base.GluuStatus)2 AppConfiguration (org.xdi.config.oxtrust.AppConfiguration)2 SelectableEntity (org.xdi.model.SelectableEntity)2 UmaScopeDescription (org.xdi.oxauth.model.uma.persistence.UmaScopeDescription)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1