Search in sources :

Example 6 with ScopeDescription

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

the class UpdateResourceSetAction method acceptSelectScopes.

public void acceptSelectScopes() {
    Set<String> addedScopeInums = getAddedScopesInums();
    for (SelectableEntity<ScopeDescription> availableScope : this.availableScopes) {
        ScopeDescription scopeDescription = availableScope.getEntity();
        String scopeDescriptionInum = scopeDescription.getInum();
        if (availableScope.isSelected() && !addedScopeInums.contains(scopeDescriptionInum)) {
            addScope(scopeDescription);
        }
        if (!availableScope.isSelected() && addedScopeInums.contains(scopeDescriptionInum)) {
            removeScope(scopeDescriptionInum);
        }
    }
}
Also used : ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 7 with ScopeDescription

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

the class ScopeService method handleExternalScopes.

private void handleExternalScopes(List<String> scopeUrls, List<String> result) throws LDAPException {
    for (String scopeUrl : scopeUrls) {
        final Filter filter = Filter.create(String.format("&(oxUrl=%s)", scopeUrl));
        final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
        if (entries != null && !entries.isEmpty()) {
            result.add(entries.get(0).getDn());
        } else {
            // scope is not in ldap, add it dynamically
            final Boolean addAutomatically = appConfiguration.getUmaAddScopesAutomatically();
            if (addAutomatically != null && addAutomatically) {
                final String inum = inumService.generateInum();
                final ScopeDescription newScope = new ScopeDescription();
                newScope.setInum(inum);
                newScope.setUrl(scopeUrl);
                // temp solution : need extract info from scope description on resource server
                newScope.setDisplayName(scopeUrl);
                // dummy id : not sure what to put right now as id is required by @NotNull annotation
                newScope.setId(UmaScopeType.EXTERNAL_AUTO.getValue());
                newScope.setType(InternalExternal.EXTERNAL_AUTO);
                final boolean persisted = persist(newScope);
                if (persisted) {
                    result.add(newScope.getDn());
                }
            } else {
                throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.INVALID_RESOURCE_SET_SCOPE)).build());
            }
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Filter(com.unboundid.ldap.sdk.Filter) 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