Search in sources :

Example 6 with UmaScopeDescription

use of org.xdi.oxauth.model.uma.persistence.UmaScopeDescription in project oxTrust by GluuFederation.

the class ScopeDescriptionDownloadAction method downloadIcon.

public void downloadIcon() {
    byte[] resultFile = null;
    UmaScopeDescription scopeDescription = getScopeDescription();
    if (scopeDescription != null) {
        GluuImage gluuImage = imageService.getGluuImageFromXML(scopeDescription.getFaviconImageAsXml());
        try {
            resultFile = imageService.getThumImageData(gluuImage);
        } catch (Exception ex) {
            log.error("Failed to generate image response", ex);
        }
    }
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (resultFile == null) {
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        FileDownloader.sendError(response, "Failed to prepare icon");
    } else {
        ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
        ResponseHelper.downloadFile(scopeDescription.getId() + ".jpg", "image/jpeg", resultFile, contentDisposition, facesContext);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ContentDisposition(org.xdi.util.io.FileDownloader.ContentDisposition) UmaScopeDescription(org.xdi.oxauth.model.uma.persistence.UmaScopeDescription) ExternalContext(javax.faces.context.ExternalContext) GluuImage(org.xdi.model.GluuImage) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException)

Example 7 with UmaScopeDescription

use of org.xdi.oxauth.model.uma.persistence.UmaScopeDescription in project oxTrust by GluuFederation.

the class UpdateScopeDescriptionAction method save.

public String save() {
    updateAuthorizationPolicies();
    this.scopeDescription.setDisplayName(this.scopeDescription.getDisplayName().trim());
    if (this.update) {
        // Update scope description
        try {
            scopeDescriptionService.updateScopeDescription(this.scopeDescription);
        } catch (BaseMappingException ex) {
            log.error("Failed to update scope description '{}'", this.scopeDescription.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_SUCCESS;
    } else {
        // Check if scope description with this name already exist
        UmaScopeDescription exampleScopeDescription = new UmaScopeDescription();
        exampleScopeDescription.setDn(scopeDescriptionService.getDnForScopeDescription(null));
        exampleScopeDescription.setId(scopeDescription.getId());
        String inum = scopeDescriptionService.generateInumForNewScopeDescription();
        String scopeDescriptionDn = scopeDescriptionService.getDnForScopeDescription(inum);
        this.scopeDescription.setInum(inum);
        this.scopeDescription.setDn(scopeDescriptionDn);
        this.scopeDescription.setOwner(identity.getUser().getDn());
        this.scopeDescription.setId(scopeDescription.getId());
        // Save scope description
        try {
            scopeDescriptionService.addScopeDescription(this.scopeDescription);
        } catch (BaseMappingException ex) {
            log.error("Failed to add new UMA resource '{}'", this.scopeDescription.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_UPDATE;
    }
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) UmaScopeDescription(org.xdi.oxauth.model.uma.persistence.UmaScopeDescription)

Aggregations

UmaScopeDescription (org.xdi.oxauth.model.uma.persistence.UmaScopeDescription)7 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)3 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Filter (org.gluu.search.filter.Filter)1 GluuImage (org.xdi.model.GluuImage)1 ContentDisposition (org.xdi.util.io.FileDownloader.ContentDisposition)1