示例#1
0
 public static List<String> getScopeDNs(List<ScopeDescription> p_scopes) {
   final List<String> result = new ArrayList<String>();
   if (p_scopes != null && !p_scopes.isEmpty()) {
     for (ScopeDescription s : p_scopes) {
       result.add(s.getDn());
     }
   }
   return result;
 }
示例#2
0
  public boolean persist(ScopeDescription p_scopeDescription) {
    try {
      if (StringUtils.isBlank(p_scopeDescription.getDn())) {
        p_scopeDescription.setDn(
            String.format("inum=%s,%s", p_scopeDescription.getInum(), baseDn()));
      }

      ldapEntryManager.persist(p_scopeDescription);
      return true;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return false;
    }
  }
示例#3
0
 public static List<String> getScopeUrls(List<ScopeDescription> p_scopes) {
   final List<String> result = new ArrayList<String>();
   if (p_scopes != null && !p_scopes.isEmpty()) {
     for (ScopeDescription s : p_scopes) {
       final InternalExternal type = s.getType();
       if (type != null) {
         switch (type) {
           case EXTERNAL:
           case EXTERNAL_AUTO:
             result.add(s.getUrl());
             break;
           case INTERNAL:
             result.add(getInternalScopeUrl(s));
             break;
         }
       } else {
         result.add(s.getUrl());
       }
     }
   }
   return result;
 }
示例#4
0
  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: {0}" + p_scopeId);
          for (ScopeDescription s : entries) {
            log.error("Scope, Id: {0}, dn: {1}", s.getId(), s.getDn());
          }
        }
        return entries.get(0);
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
    return null;
  }
示例#5
0
  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;
  }
示例#6
0
  private void handleExternalScopes(List<String> p_scopeUrls, List<String> result)
      throws LDAPException {
    for (String scopeUrl : p_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 =
            ConfigurationFactory.instance().getConfiguration().getUmaAddScopesAutomatically();

        if (addAutomatically != null && addAutomatically) {
          final String inum = inumService.generateInum();
          final ScopeDescription newScope = new ScopeDescription();
          newScope.setInum(inum);
          newScope.setUrl(scopeUrl);
          newScope.setDisplayName(
              scopeUrl); // temp solution : need extract info from scope description on resource
                         // server
          newScope.setId(
              UmaScopeType.EXTERNAL_AUTO
                  .getValue()); // dummy id : not sure what to put right now as id is required by
                                // @NotNull annotation
          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());
        }
      }
    }
  }
示例#7
0
 private static String getInternalScopeUrl(ScopeDescription internalScope) {
   if (internalScope != null && internalScope.getType() == InternalExternal.INTERNAL) {
     return getScopeEndpoint() + "/" + internalScope.getId();
   }
   return "";
 }