Search in sources :

Example 1 with ScopeDescription

use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.

the class ScopeWS method getScopeDescription.

@GET
@Path("{id}")
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
public Response getScopeDescription(@PathParam("id") String id) {
    log.trace("UMA - get scope description: id: {}", id);
    try {
        if (StringUtils.isNotBlank(id)) {
            final ScopeDescription scope = umaScopeService.getInternalScope(id);
            if (scope != null) {
                final org.xdi.oxauth.model.uma.ScopeDescription jsonScope = new org.xdi.oxauth.model.uma.ScopeDescription();
                jsonScope.setIconUri(scope.getIconUrl());
                jsonScope.setName(scope.getDisplayName());
                return Response.status(Response.Status.OK).entity(ServerUtil.asJson(jsonScope)).build();
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.SERVER_ERROR)).build());
    }
    throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.NOT_FOUND)).build());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ScopeDescription

use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.

the class ScopeService method getInternalScope.

public ScopeDescription getInternalScope(String p_scopeId) {
    try {
        final Filter filter = Filter.create(String.format("&(oxType=%s)(oxId=%s)", UmaScopeType.INTERNAL.getValue(), p_scopeId));
        final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
        if (entries != null && !entries.isEmpty()) {
            // if more then one scope then it's problem, non-deterministic behavior, id must be unique
            if (entries.size() > 1) {
                log.error("Found more then one internal uma scope by input id: {}" + p_scopeId);
                for (ScopeDescription s : entries) {
                    log.error("Scope, Id: {}, dn: {}", s.getId(), s.getDn());
                }
            }
            return entries.get(0);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) WebApplicationException(javax.ws.rs.WebApplicationException) LDAPException(com.unboundid.ldap.sdk.LDAPException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 3 with ScopeDescription

use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.

the class ScopeService method handleInternalScopes.

private List<String> handleInternalScopes(List<String> p_scopeUrls, List<String> result) {
    List<String> notProcessedScopeUrls = new ArrayList<String>(p_scopeUrls);
    try {
        final Filter filter = Filter.create(String.format("&(oxType=%s)", InternalExternal.INTERNAL.getValue()));
        final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
        if (entries != null && !entries.isEmpty()) {
            for (String scopeUrl : p_scopeUrls) {
                for (ScopeDescription scopeDescription : entries) {
                    final String internalScopeUrl = getInternalScopeUrl(scopeDescription);
                    if (internalScopeUrl.equals(scopeUrl) && !result.contains(internalScopeUrl)) {
                        result.add(scopeDescription.getDn());
                        notProcessedScopeUrls.remove(scopeUrl);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return notProcessedScopeUrls;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) ArrayList(java.util.ArrayList) WebApplicationException(javax.ws.rs.WebApplicationException) LDAPException(com.unboundid.ldap.sdk.LDAPException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 4 with ScopeDescription

use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.

the class ScopeService method getScopesByUrls.

public List<ScopeDescription> getScopesByUrls(List<String> p_scopeUrls) {
    List<ScopeDescription> scopes = new ArrayList<ScopeDescription>();
    try {
        // external scopes
        Filter filter = createAnyFilterByUrls(p_scopeUrls);
        if (filter != null) {
            final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
            if (entries != null) {
                scopes.addAll(entries);
            }
        }
        // internal scopes
        filter = Filter.create(String.format("&(oxType=%s)", InternalExternal.INTERNAL.getValue()));
        final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
        if (entries != null && !entries.isEmpty()) {
            for (String scopeUrl : p_scopeUrls) {
                for (ScopeDescription scopeDescription : entries) {
                    final String internalScopeUrl = getInternalScopeUrl(scopeDescription);
                    if (internalScopeUrl.equals(scopeUrl) && !scopes.contains(internalScopeUrl)) {
                        scopes.add(scopeDescription);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return scopes;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) ArrayList(java.util.ArrayList) WebApplicationException(javax.ws.rs.WebApplicationException) LDAPException(com.unboundid.ldap.sdk.LDAPException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 5 with ScopeDescription

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

the class ScopeDescriptionDownloadAction method downloadFile.

public void downloadFile() {
    byte[] resultFile = null;
    ScopeDescription scopeDescription = getScopeDescription();
    if (scopeDescription != null) {
        JSONObject jsonObject = new JSONObject();
        try {
            HashMap<String, List<String>> pageParams = new HashMap<String, List<String>>();
            pageParams.put("scope", Arrays.asList(scopeDescription.getId()));
            String umaScope = viewHandlerService.getBookmarkableURL("/uma/scope/scopeDescriptionFile.xhtml", pageParams);
            jsonObject.put("name", scopeDescription.getId());
            jsonObject.put("icon_uri", umaScope);
            resultFile = jsonObject.toString().getBytes("UTF-8");
        } catch (Exception ex) {
            log.error("Failed to generate json response", ex);
        }
    }
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (resultFile == null) {
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        FileDownloader.sendError(response, "Failed to generate json file");
    } else {
        ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
        ResponseHelper.downloadFile(scopeDescription.getId() + ".json", "application/json;charset=UTF-8", resultFile, contentDisposition, facesContext);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) JSONObject(org.codehaus.jettison.json.JSONObject) ContentDisposition(org.xdi.util.io.FileDownloader.ContentDisposition) HashMap(java.util.HashMap) ExternalContext(javax.faces.context.ExternalContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) List(java.util.List) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Aggregations

ScopeDescription (org.xdi.oxauth.model.uma.persistence.ScopeDescription)7 WebApplicationException (javax.ws.rs.WebApplicationException)5 Filter (com.unboundid.ldap.sdk.Filter)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)1 ContentDisposition (org.xdi.util.io.FileDownloader.ContentDisposition)1