⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldapgroupstore.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    if (subkeys[o].equals(interkeys[n])){                      // found a match, so far the intersection for this key is valid                      remove=false;                      break;                    }                  }                  if (remove){                    interkeys[n] = null;                  }                }              }            }            for (int p=0; p< interkeys.length; p++){              if (interkeys[p] != null){                keys.add(interkeys[p]);              }            }          }          break;        case DIFFERENCE:          if (subsets.length > 0){            ArrayList discardKeys = new ArrayList();            subkeys = subsets[0].getPersonKeys();            // load initial keys from first entity set            for(int q=0; q<subkeys.length; q++){              keys.add(subkeys[q]);            }            for (int r=1; r<subsets.length; r++){              subkeys = subsets[r].getPersonKeys();              for (int s=0; s<subkeys.length; s++){                String ky = subkeys[s];                if (keys.contains(ky)){                  keys.remove(ky);                  discardKeys.add(ky);                }                else{                  if (!discardKeys.contains(ky)){                    keys.add(ky);                  }                }              }            }          }          break;        case SUBTRACT:          if (subsets.length>0){            subkeys = subsets[0].getPersonKeys();            // load initial keys from first entity set            for(int t=0; t<subkeys.length; t++){              keys.add(subkeys[t]);            }            for(int u=1; u<subsets.length; u++){              subkeys = subsets[u].getPersonKeys();              for(int v=0; v<subkeys.length; v++){                String kyy = subkeys[v];                if(keys.contains(kyy)){                  keys.remove(kyy);                }              }            }          }          break;      }      return (String[]) keys.toArray(new String[0]);    }  }  protected void processLdapResults(NamingEnumeration results, ArrayList keys){    //long time1 = System.currentTimeMillis();    //long casting=0;    //long getting=0;    //long setting=0;    //long looping=0;    //long loop1=System.currentTimeMillis();    try{      while(results.hasMore()){        //long loop2 = System.currentTimeMillis();        //long cast1=System.currentTimeMillis();        //looping=looping+loop2-loop1;        SearchResult result = (SearchResult) results.next();        //long cast2 = System.currentTimeMillis();        //long get1 = System.currentTimeMillis();        Attributes ldapattribs = result.getAttributes();        //long get2 = System.currentTimeMillis();        //long set1 = System.currentTimeMillis();        Attribute attrib = ldapattribs.get(keyfield);        if (attrib != null) {            keys.add(String.valueOf(attrib.get()).toLowerCase());        }        //long set2 = System.currentTimeMillis();        //loop1=System.currentTimeMillis();        //casting=casting+cast2-cast1;        //setting=setting+set2-set1;        //getting=getting+get2-get1;      }    }    catch(NamingException nex){        log.error("LDAPGroupStore: error processing results", nex);    }    finally{      try{results.close();}catch(Exception e){}    }    //long time5 = System.currentTimeMillis();    //System.out.println("Result processing took "+(time5-time1)+": "+getting+" for getting, "    //  +setting+" for setting, "+casting+" for casting, "+looping+" for looping,"    //  +(time5-loop1)+" for closing");  }  protected DirContext getConnection(){     //JNDI boilerplate to connect to an initial context    DirContext context = (DirContext) contexts.get("context");    if (context==null){      Hashtable jndienv = new Hashtable();      jndienv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");      jndienv.put(Context.SECURITY_AUTHENTICATION,"simple");      if (url.startsWith("ldaps")) { // Handle SSL connections        String newurl = url.substring(0,4) + url.substring(5);        jndienv.put(Context.SECURITY_PROTOCOL, "ssl");        jndienv.put(Context.PROVIDER_URL, newurl);      }      else {        jndienv.put(Context.PROVIDER_URL, url);      }      if (logonid!=null)        jndienv.put(Context.SECURITY_PRINCIPAL,logonid);      if (logonpassword!=null)        jndienv.put(Context.SECURITY_CREDENTIALS,logonpassword);      try {        context = new InitialDirContext(jndienv);      } catch (NamingException nex) {        log.error("LDAPGroupStore: unable to get context", nex);      }      contexts.put("context",context);    }    return context;  }  protected IEntityGroup makeGroup(GroupShadow shadow) throws GroupsException{    IEntityGroup group = null;    if ( shadow != null )    {        group = new EntityGroupImpl(shadow.key,iperson);         group.setDescription(shadow.description);        group.setName(shadow.name);    }    return group;  }  protected GroupShadow getShadow(IEntityGroup group){    return (GroupShadow) groups.get(group.getLocalKey());  }  public void delete(IEntityGroup group) throws GroupsException {    throw new java.lang.UnsupportedOperationException("LDAPGroupStore: Method delete() not supported.");  }  public IEntityGroup find(String key) throws GroupsException {    return makeGroup((GroupShadow)this.groups.get(key));  }  public Iterator findContainingGroups(IGroupMember gm) throws GroupsException {     ArrayList al = new ArrayList();     String key;     GroupShadow[] shadows = getGroupShadows();     if (gm.isEntity()){       key = gm.getKey();       for (int i=0; i < shadows.length; i++){        String[] keys = getPersonKeys(shadows[i].key);        for (int j=0; j< keys.length; j++){          if (keys[j].equals(key)){            al.add(makeGroup(shadows[i]));            break;          }        }       }     }     if (gm.isGroup()){        key = ((IEntityGroup)gm).getLocalKey();        for (int i=0; i < shadows.length; i++){          for (int j=0; j< shadows[i].subgroups.length; j++){            if (shadows[i].subgroups[j].key.equals(key)){              al.add(makeGroup(shadows[i]));              break;            }          }        }     }     return al.iterator();  }  public String[] findMemberGroupKeys(IEntityGroup group) throws GroupsException  {    List keys = new ArrayList();    for ( Iterator itr=findMemberGroups(group); itr.hasNext(); )    {        IEntityGroup eg = (IEntityGroup) itr.next();        keys.add(eg.getKey());    }    return (String[]) keys.toArray(new String[keys.size()]);  }  public Iterator findMemberGroups(IEntityGroup group) throws GroupsException {    ArrayList al = new ArrayList();    GroupShadow shadow = getShadow(group);    for(int i=0; i < shadow.subgroups.length; i++){      al.add(makeGroup(shadow.subgroups[i]));    }    return al.iterator();  }  public IEntityGroup newInstance(Class entityType) throws GroupsException {    throw new java.lang.UnsupportedOperationException("LDAPGroupStore: Method newInstance() not supported");  }  public void update(IEntityGroup group) throws GroupsException {    throw new java.lang.UnsupportedOperationException("LDAPGroupStore: Method update() not supported");  }  public void updateMembers(IEntityGroup group) throws GroupsException {    throw new java.lang.UnsupportedOperationException("LDAPGroupStore: Method updateMembers() not supported");  }  public ILockableEntityGroup findLockable(String key) throws GroupsException {    throw new java.lang.UnsupportedOperationException("LDAPGroupStore: Method findLockable() not supported");  }  protected GroupShadow[] getGroupShadows(){     return (GroupShadow[]) groups.values().toArray(new GroupShadow[0]);  }  public EntityIdentifier[] searchForGroups(String query, int method, Class leaftype) throws GroupsException {    ArrayList ids = new ArrayList();    GroupShadow[] g = getGroupShadows();    int i;    switch (method){      case IS:        for (i=0; i<g.length;i++){          if(g[i].name.equals(query)){            ids.add(new EntityIdentifier(g[i].key,group));          }        }        break;      case STARTS_WITH:        for (i=0; i<g.length;i++){          if(g[i].name.startsWith(query)){            ids.add(new EntityIdentifier(g[i].key,group));          }        }        break;      case ENDS_WITH:        for (i=0; i<g.length;i++){          if(g[i].name.endsWith(query)){            ids.add(new EntityIdentifier(g[i].key,group));          }        }        break;      case CONTAINS:        for (i=0; i<g.length;i++){          if(g[i].name.indexOf(query) > -1){            ids.add(new EntityIdentifier(g[i].key,group));          }        }        break;    }    return (EntityIdentifier[]) ids.toArray(new EntityIdentifier[0]);  }  public Iterator findEntitiesForGroup(IEntityGroup group) throws GroupsException {    GroupShadow shadow = getShadow(group);    ArrayList al = new ArrayList();    String[] keys = getPersonKeys(shadow.key);    for (int i=0; i < keys.length; i++){      al.add(new EntityImpl(keys[i],iperson));    }    return al.iterator();  }  public IEntity newInstance(String key) throws GroupsException {    return new EntityImpl(key, null);  }  public IEntity newInstance(String key, Class type) throws GroupsException {    if ( org.jasig.portal.EntityTypes.getEntityTypeID(type) == null )        { throw new GroupsException("Invalid group type: " + type); }    return new EntityImpl(key, type);  }  public EntityIdentifier[] searchForEntities(String query, int method, Class type)  throws GroupsException {    if (type != group && type != iperson)      return new EntityIdentifier[0];    ArrayList ids = new ArrayList();    switch (method){      case STARTS_WITH:          query = query+"*";        break;      case ENDS_WITH:          query="*"+query;        break;      case CONTAINS:          query="*"+query+"*";        break;    }    query = namefield+"="+query;    DirContext context = getConnection();    NamingEnumeration userlist = null;    SearchControls sc = new SearchControls();    sc.setSearchScope(SearchControls.SUBTREE_SCOPE);    sc.setReturningAttributes(new String[] {keyfield});    try {      userlist = context.search(usercontext,query,sc);    } catch (NamingException nex) {      log.error("LDAPGroupStore: Unable to perform filter "+query, nex);    }    ArrayList keys = new ArrayList();    processLdapResults(userlist,keys);    String[] k = (String[]) keys.toArray(new String[0]);    for (int i=0; i<k.length; i++){      ids.add(new EntityIdentifier(k[i],iperson));    }    return (EntityIdentifier[]) ids.toArray(new EntityIdentifier[0]);  }/** * Answers if <code>group</code> contains <code>member</code>. * @return boolean * @param group org.jasig.portal.groups.IEntityGroup * @param member org.jasig.portal.groups.IGroupMember */public boolean contains(IEntityGroup group, IGroupMember member) throws GroupsException {    boolean found = false;    Iterator itr = ( member.isGroup() )      ? findMemberGroups(group)      : findEntitiesForGroup(group);    while ( itr.hasNext() && ! found )        { found = member.equals(itr.next()); }    return found;}/** * Answers if <code>group</code> contains a member group named  * <code>name</code>. * @return boolean * @param group org.jasig.portal.groups.IEntityGroup * @param name java.lang.String */public boolean containsGroupNamed(IEntityGroup group, String name) throws GroupsException {    boolean found = false;    Iterator itr = findMemberGroups(group);    while ( itr.hasNext() && ! found )    {        String otherName = ((IEntityGroup)itr.next()).getName();        found = otherName != null && otherName.equals(name);    }    return found;}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -