Search in sources :

Example 6 with BasePersistenceException

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

the class UpdateUmaScopeAction method searchAvailableAuthorizationPolicies.

public void searchAvailableAuthorizationPolicies() {
    if (this.availableAuthorizationPolicies != null) {
        selectAddedAuthorizationPolicies();
        return;
    }
    try {
        List<CustomScript> availableScripts = customScriptService.findCustomScripts(Arrays.asList(CustomScriptType.UMA_RPT_POLICY), CUSTOM_SCRIPT_RETURN_ATTRIBUTES);
        List<SelectableEntity<CustomScript>> tmpAvailableAuthorizationPolicies = new ArrayList<SelectableEntity<CustomScript>>();
        for (CustomScript authorizationPolicy : availableScripts) {
            tmpAvailableAuthorizationPolicies.add(new SelectableEntity<CustomScript>(authorizationPolicy));
        }
        this.availableAuthorizationPolicies = tmpAvailableAuthorizationPolicies;
        selectAddedAuthorizationPolicies();
    } catch (BasePersistenceException ex) {
        log.error("Failed to find available authorization policies", ex);
    }
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) SelectableEntity(org.gluu.model.SelectableEntity) ArrayList(java.util.ArrayList)

Example 7 with BasePersistenceException

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

the class UpdateUmaScopeAction method save.

public String save() throws Exception {
    this.umaScope.setDisplayName(this.umaScope.getDisplayName().trim());
    this.umaScope.setScopeType(ScopeType.UMA);
    updateAuthorizationPolicies();
    saveAttributesJson();
    if (this.update) {
        if (scopeWithSameNameExistInUpdate()) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "A scope with same name already exist");
            return OxTrustConstants.RESULT_FAILURE;
        }
        try {
            scopeDescriptionService.updateUmaScope(this.umaScope);
        } catch (BasePersistenceException ex) {
            log.error("Failed to update scope description '{}'", this.umaScope.getId(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update UMA resource '#{updateScopeDescriptionAction.scopeDescription.displayName}'");
            return OxTrustConstants.RESULT_FAILURE;
        }
        log.debug("Scope description were updated successfully");
        facesMessages.add(FacesMessage.SEVERITY_INFO, "UMA resource '#{updateScopeDescriptionAction.scopeDescription.displayName}' updated successfully");
        return OxTrustConstants.RESULT_UPDATE;
    } else {
        if (scopeWithSameNameExist()) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "A scope with same name already exist");
            return OxTrustConstants.RESULT_FAILURE;
        }
        Scope exampleScopeDescription = new Scope();
        exampleScopeDescription.setDn(scopeDescriptionService.getDnForScope(null));
        exampleScopeDescription.setId(umaScope.getId());
        String inum = scopeDescriptionService.generateInumForNewScope();
        String scopeDescriptionDn = scopeDescriptionService.getDnForScope(inum);
        this.umaScope.setInum(inum);
        this.umaScope.setDn(scopeDescriptionDn);
        this.umaScope.setId(umaScope.getId());
        try {
            scopeDescriptionService.addUmaScope(this.umaScope);
        } catch (BasePersistenceException ex) {
            log.error("Failed to add new UMA resource '{}'", this.umaScope.getId(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new UMA resource");
            return OxTrustConstants.RESULT_FAILURE;
        }
        log.debug("Scope description were add successfully");
        facesMessages.add(FacesMessage.SEVERITY_INFO, "New UMA resource '#{updateScopeDescriptionAction.scopeDescription.displayName}' added successfully");
        conversationService.endConversation();
        this.update = true;
        this.scopeInum = inum;
        return OxTrustConstants.RESULT_SUCCESS;
    }
}
Also used : BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) Scope(org.oxauth.persistence.model.Scope)

Example 8 with BasePersistenceException

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

the class UpdateUmaScopeAction method update.

public String update() {
    this.update = true;
    if (this.umaScope != null) {
        this.oxAttributesJson = getScopeAttributesJson();
        return OxTrustConstants.RESULT_SUCCESS;
    }
    try {
        String scopeDn = scopeDescriptionService.getDnForScope(this.scopeInum);
        this.umaScope = scopeDescriptionService.getUmaScopeByDn(scopeDn);
        this.oxAttributesJson = getScopeAttributesJson();
        this.authorizationPolicies = getInitialAuthorizationPolicies();
        List<UmaResource> umaResourceList = resourceSetService.findResourcesByScope(scopeDn);
        if (umaResourceList != null) {
            for (UmaResource umaResource : umaResourceList) {
                List<String> list = umaResource.getClients();
                if (list != null) {
                    clientList = new ArrayList<OxAuthClient>();
                    for (String clientDn : list) {
                        OxAuthClient oxAuthClient = clientService.getClientByDn(clientDn);
                        if (oxAuthClient != null) {
                            clientList.add(oxAuthClient);
                        }
                    }
                }
            }
        }
    } catch (BasePersistenceException ex) {
        log.error("Failed to find scope description '{}'", this.scopeInum, ex);
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    if (this.umaScope == null) {
        log.error("Scope description is null");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource)

Example 9 with BasePersistenceException

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

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    Date runDate = new Date(this.lastFinishedTime);
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    List<String> result1 = new ArrayList<String>();
    List<String> result2 = new ArrayList<String>();
    for (GluuSimplePerson removedPerson : removedPersons) {
        String inum = removedPerson.getAttribute(OxTrustConstants.inum);
        // Update GluuInumMap if it exist
        GluuInumMap currentInumMap = inumInumMap.get(inum);
        if (currentInumMap == null) {
            log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
        } else {
            GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, ldapEntryManager.encodeTime(removedPerson.getDn(), runDate));
            try {
                inumDbPersistenceEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BasePersistenceException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BasePersistenceException ex) {
            log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
            continue;
        }
        log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
    }
    return new Pair<List<String>, List<String>>(result1, result2);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.gluu.util.Pair)

Example 10 with BasePersistenceException

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

the class UpdateResourceAction method update.

private String update() {
    log.debug("Loading UMA resource set '{}'", this.oxId);
    try {
        String resourceDn = umaResourcesService.getDnForResource(this.oxId);
        this.resource = umaResourcesService.getResourceByDn(resourceDn);
    } catch (BasePersistenceException ex) {
        log.error("Failed to find resource set '{}'", this.oxId, ex);
        return OxTrustConstants.RESULT_FAILURE;
    }
    if (this.resource == null) {
        log.error("Resource set is null");
        return OxTrustConstants.RESULT_FAILURE;
    }
    this.scopes = getScopesDisplayNameEntries();
    this.clients = getClientDisplayNameEntries();
    this.clientList = new ArrayList<OxAuthClient>();
    List<String> list = this.resource.getClients();
    if (list != null) {
        for (String clientDn : list) {
            OxAuthClient oxAuthClient = clientService.getClientByDn(clientDn);
            if (oxAuthClient != null) {
                clientList.add(oxAuthClient);
            }
        }
    }
    if (this.resource.getResources() == null) {
        this.resources = new ArrayList<String>();
    } else {
        this.resources = new ArrayList<String>(this.resource.getResources());
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient)

Aggregations

BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)22 ArrayList (java.util.ArrayList)4 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)4 GluuConfiguration (org.gluu.oxtrust.model.GluuConfiguration)3 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)3 LdapOxAuthConfiguration (org.gluu.config.oxtrust.LdapOxAuthConfiguration)2 SelectableEntity (org.gluu.model.SelectableEntity)2 CustomScript (org.gluu.model.custom.script.model.CustomScript)2 Scope (org.oxauth.persistence.model.Scope)2 IOException (java.io.IOException)1 Date (java.util.Date)1 WebKeysSettings (org.gluu.config.oxauth.WebKeysSettings)1 DbApplicationConfiguration (org.gluu.config.oxtrust.DbApplicationConfiguration)1 LdapOxTrustConfiguration (org.gluu.config.oxtrust.LdapOxTrustConfiguration)1 DisplayNameEntry (org.gluu.model.DisplayNameEntry)1 UmaResource (org.gluu.oxauth.model.uma.persistence.UmaResource)1 DuplicateEmailException (org.gluu.oxtrust.exception.DuplicateEmailException)1 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)1 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)1 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)1