コード例 #1
0
ファイル: ScopeService.java プロジェクト: trintech/oxAuth
 public List<ScopeDescription> getScopes(UmaScopeType p_type) {
   try {
     if (p_type != null) {
       final Filter filter = Filter.create(String.format("&(oxType=%s)", p_type.getValue()));
       return ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
     }
   } catch (Exception e) {
     log.error(e.getMessage(), e);
   }
   return Collections.emptyList();
 }
コード例 #2
0
 public boolean authenticate(String pid, String pwd) throws LDAPException {
   Filter f = Filter.create("(mail=" + pid + ')');
   SearchRequest request = new SearchRequest(BASE_DN, SearchScope.SUB, f);
   SearchResult searchResult = mConnection.search(request);
   if (searchResult.getEntryCount() == 0) return false;
   SearchResultEntry e = searchResult.getSearchEntries().get(0);
   String uid = e.getAttribute("uid").getValue();
   Log.d(LOG_TAG, uid);
   BindRequest bindRequest = new SimpleBindRequest(e.getDN(), pwd);
   BindResult result = mConnection.bind(bindRequest);
   return result.getResultCode() == ResultCode.SUCCESS;
 }
コード例 #3
0
 public ResourceSetPermission getResourceSetPermissionByConfigurationCode(
     String p_configurationCode, String clientDn) {
   try {
     final Filter filter =
         Filter.create(String.format("&(oxConfigurationCode=%s)", p_configurationCode));
     final List<ResourceSetPermission> entries =
         ldapEntryManager.findEntries(clientDn, ResourceSetPermission.class, filter);
     if (entries != null && !entries.isEmpty()) {
       return entries.get(0);
     }
   } catch (Exception e) {
     LOG.trace(e.getMessage(), e);
   }
   return null;
 }
コード例 #4
0
 @Override
 public ResourceSetPermission getResourceSetPermissionByTicket(String p_ticket) {
   try {
     final String baseDn = staticConfiguration.getBaseDn().getClients();
     final Filter filter = Filter.create(String.format("&(oxTicket=%s)", p_ticket));
     final List<ResourceSetPermission> entries =
         ldapEntryManager.findEntries(baseDn, ResourceSetPermission.class, filter);
     if (entries != null && !entries.isEmpty()) {
       return entries.get(0);
     }
   } catch (Exception e) {
     LOG.trace(e.getMessage(), e);
   }
   return null;
 }
コード例 #5
0
ファイル: ScopeService.java プロジェクト: trintech/oxAuth
  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());
        }
      }
    }
  }
コード例 #6
0
ファイル: ScopeService.java プロジェクト: trintech/oxAuth
 private Filter createAnyFilterByUrls(List<String> p_scopeUrls) {
   try {
     if (p_scopeUrls != null && !p_scopeUrls.isEmpty()) {
       final StringBuilder sb = new StringBuilder("(|");
       for (String url : p_scopeUrls) {
         sb.append("(");
         sb.append("oxUrl=");
         sb.append(url);
         sb.append(")");
       }
       sb.append(")");
       final String filterAsString = sb.toString();
       log.trace("Uma scope urls: " + p_scopeUrls + ", ldapFilter: " + filterAsString);
       return Filter.create(filterAsString);
     }
   } catch (LDAPException e) {
     log.error(e.getMessage(), e);
   }
   return null;
 }
コード例 #7
0
ファイル: ScopeService.java プロジェクト: trintech/oxAuth
  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;
  }
コード例 #8
0
ファイル: ScopeService.java プロジェクト: trintech/oxAuth
  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;
  }