Changeset 692


Ignore:
Timestamp:
04/15/11 17:41:16 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/pom.xml

    r687 r692  
    160160                <artifactId>spring-orm</artifactId> 
    161161                <version>3.0.2.RELEASE</version> 
     162        </dependency> 
     163 
     164        <dependency> 
     165                <groupId>commons-pool</groupId> 
     166                <artifactId>commons-pool</artifactId> 
     167                <version>1.5.6</version> 
    162168        </dependency> 
    163169    </dependencies> 
  • raptor-client/trunk/src/test/java/uk/ac/cardiff/raptor/event/expansion/AttributeAssociationTest.java

    r687 r692  
    88 
    99import java.util.HashMap; 
     10import java.util.HashSet; 
    1011import java.util.Map; 
    1112 
     
    3536        AttributeResolutionContext context = new AttributeResolutionContext(null); 
    3637 
    37         MockBaseDataConnector connector = new MockBaseDataConnector("foo", (Map<String, Attribute<?>>)null); 
    38         Assert.assertNull(connector.resolve(context)); 
     38        //String id, String ldapUrl, String ldapBaseDn, boolean startTls, int maxIdle, int initIdleCapacity 
     39        LdapDataConnector ldapConnector = new LdapDataConnector("ldap","zidman12.cf.ac.uk","o=people",false,10,10); 
     40        ldapConnector.setPrincipal("cn=srvreg1,o=users"); 
     41        ldapConnector.setPrincipalCredential("1hk27be"); 
     42        ldapConnector.setCacheResults(false); 
     43        Map<String, String> ldapProperties = new HashMap<String, String>(); 
     44        ldapProperties.put("",""); 
     45        ldapConnector.initialize(); 
    3946 
    40         //String id, String ldapUrl, String ldapBaseDn, boolean startTls, int maxIdle, int initIdleCapacity 
    41         LdapDataConnector ldapConnector = new LdapDataConnector("ldap","","",false,100,100); 
     47        HashSet<Attribute<?>> attributes = new HashSet<Attribute<?>>(); 
     48        Attribute<?> attribute = new Attribute<String>("CardiffIDManStatus"); 
     49        attributes.add(attribute); 
     50        context.setRequestedAttributes(attributes); 
     51        //I think the ldap connector should take it form the context, as set above, not as a seperate set of attributes. 
     52        //ldapConnector.setReturnAttributes("CardiffIDManStatus"); 
    4253 
    43         HashMap<String, Attribute<?>> values = new HashMap<String, Attribute<?>>(); 
    44         connector = new MockBaseDataConnector("foo", values); 
    45         Assert.assertNotNull(connector.resolve(context)); 
    46  
    47         Attribute<?> attribute = new Attribute<String>("foo"); 
    48         values.put(attribute.getId(), attribute); 
    49  
    50         connector = new MockBaseDataConnector("foo", values); 
    51         Map<String, Attribute<?>> result = connector.resolve(context); 
     54        Map<String, Attribute<?>> result = ldapConnector.resolve(context); 
    5255        Assert.assertTrue(result.containsKey(attribute.getId())); 
    5356        Assert.assertEquals(result.get(attribute.getId()), attribute); 
  • raptor-client/trunk/src/test/java/uk/ac/cardiff/raptor/event/expansion/LdapDataConnector.java

    r687 r692  
    733733 
    734734        // check for cached data 
    735         if (cacheResults) { 
    736             log.debug("Checking cache for search results"); 
    737             attributes = getCachedAttributes(resolutionContext, searchFilter); 
    738             if (attributes != null && log.isDebugEnabled()) { 
    739                 log.debug("Returning attributes from cache"); 
    740             } 
    741         } 
     735//        if (cacheResults) { 
     736//            log.debug("Checking cache for search results"); 
     737//            attributes = getCachedAttributes(resolutionContext, searchFilter); 
     738//            if (attributes != null && log.isDebugEnabled()) { 
     739//                log.debug("Returning attributes from cache"); 
     740//            } 
     741//        } 
    742742 
    743743        // results not found in the cache 
     
    751751            // build resolved attributes from LDAP attributes 
    752752            attributes = buildBaseAttributes(results); 
    753             if (cacheResults && attributes != null) { 
    754                 setCachedAttributes(resolutionContext, searchFilter, attributes); 
    755                 log.debug("Stored results in the cache"); 
    756             } 
     753//            if (cacheResults && attributes != null) { 
     754//                setCachedAttributes(resolutionContext, searchFilter, attributes); 
     755//                log.debug("Stored results in the cache"); 
     756//            } 
    757757        } 
    758758 
     
    762762 
    763763    //TODO AttributeResolutionException expection was removed 
    764     public void validate() { 
    765         Ldap ldap = null; 
    766         try { 
    767             ldap = (Ldap) ldapPool.borrowObject(); 
    768             if (!ldap.connect()) { 
    769                 throw new NamingException(); 
    770             } 
    771         } catch (NamingException e) { 
    772             log.error("An error occured when attempting to search the LDAP: " + ldapConfig.getEnvironment(), e); 
    773             throw new AttributeResolutionException("An error occurred when attempting to search the LDAP"); 
    774         } catch (Exception e) { 
    775             log.error("Could not retrieve Ldap object from pool", e); 
    776             throw new AttributeResolutionException( 
    777                     "An error occurred when attempting to retrieve a LDAP connection from the pool"); 
    778         } finally { 
    779             if (ldap != null) { 
    780                 try { 
    781                     ((Ldap)ldapPool).returnObject(ldap); 
    782                 } catch (Exception e) { 
    783                     log.error("Could not return Ldap object back to pool", e); 
    784                 } 
    785             } 
    786         } 
    787     } 
     764//    public void validate() throws Exception{ 
     765//        Ldap ldap = null; 
     766//        try { 
     767//            ldap = (Ldap) ldapPool.borrowObject(); 
     768//            if (!ldap.connect()) { 
     769//                throw new NamingException(); 
     770//            } 
     771//        } catch (NamingException e) { 
     772//            log.error("An error occured when attempting to search the LDAP: " + ldapConfig.getEnvironment(), e); 
     773//            throw new Exception("An error occurred when attempting to search the LDAP"); 
     774//        } catch (Exception e) { 
     775//            log.error("Could not retrieve Ldap object from pool", e); 
     776//            throw new Exception( 
     777//                    "An error occurred when attempting to retrieve a LDAP connection from the pool"); 
     778//        } finally { 
     779//            if (ldap != null) { 
     780//                try { 
     781//                    ldapPool.returnObject(ldap); 
     782//                } catch (Exception e) { 
     783//                    log.error("Could not return Ldap object back to pool", e); 
     784//                } 
     785//            } 
     786//        } 
     787//    } 
    788788 
    789789    /** 
     
    827827            throws AttributeResolutionException { 
    828828 
    829         Map<String, BaseAttribute> attributes = new HashMap<String, BaseAttribute>(); 
     829        Map<String, Attribute<?>> attributes = new HashMap<String, Attribute<?>>(); 
    830830 
    831831        if (!results.hasNext()) { 
     
    842842                throw new AttributeResolutionException("Error parsing LDAP attributes"); 
    843843            } 
    844  
     844            log.debug("Found {} attributes",newAttrsMap.size()); 
    845845            for (Map.Entry<String, List<String>> entry : newAttrsMap.entrySet()) { 
    846846                log.debug("Found the following attribute: {}", entry); 
    847                 BaseAttribute<String> attribute = attributes.get(entry.getKey()); 
     847                Attribute<String> attribute = (Attribute<String>) attributes.get(entry.getKey()); 
    848848                if(attribute == null){ 
    849                     attribute = new BasicAttribute<String>(); 
    850                     ((BasicAttribute)attribute).setId(entry.getKey()); 
     849                    attribute = new Attribute<String>(entry.getKey()); 
    851850                    attributes.put(entry.getKey(), attribute); 
    852851                } 
     
    856855                    for(String value : values){ 
    857856                        if(!DatatypeHelper.isEmpty(value)){ 
    858                             attribute.getValues().add(DatatypeHelper.safeTrimOrNullString(value)); 
     857                           attribute.addValue(DatatypeHelper.safeTrimOrNullString(value)); 
    859858                        } 
    860859                    } 
     
    866865    } 
    867866 
    868     /** 
    869      * This stores the supplied attributes in the cache. 
    870      * 
    871      * @param resolutionContext <code>ResolutionContext</code> 
    872      * @param searchFiler the searchFilter that produced the attributes 
    873      * @param attributes <code>Map</code> of attribute ids to attributes 
    874      */ 
    875     protected void setCachedAttributes(AttributeResolutionContext resolutionContext, String searchFiler, 
    876             Map<String, Attribute<?>> attributes) { 
    877         Map<String, Map<String, BaseAttribute>> results = null; 
    878         String principal = resolutionContext.getAttributeRequestContext().getPrincipalName(); 
    879         if (cache.containsKey(principal)) { 
    880             results = cache.get(principal); 
    881         } else { 
    882             results = new HashMap<String, Map<String, BaseAttribute>>(); 
    883             cache.put(principal, results); 
    884         } 
    885         results.put(searchFiler, attributes); 
    886     } 
    887  
    888     /** 
    889      * This retrieves any cached attributes for the supplied resolution context. Returns null if nothing is cached. 
    890      * 
    891      * @param resolutionContext <code>ResolutionContext</code> 
    892      * @param searchFilter the search filter the produced the attributes 
    893      * 
    894      * @return <code>Map</code> of attributes ids to attributes 
    895      */ 
    896     protected Map<String, Attribute<?>> getCachedAttributes(AttributeResolutionContext resolutionContext, 
    897             String searchFilter) { 
    898         Map<String, BaseAttribute> attributes = null; 
    899         if (cacheResults) { 
    900             String principal = resolutionContext.getAttributeRequestContext().getPrincipalName(); 
    901             if (cache.containsKey(principal)) { 
    902                 Map<String, Map<String, BaseAttribute>> results = cache.get(principal); 
    903                 attributes = results.get(searchFilter); 
    904             } 
    905         } 
    906         return attributes; 
    907     } 
     867//    /** 
     868//     * This stores the supplied attributes in the cache. 
     869//     * 
     870//     * @param resolutionContext <code>ResolutionContext</code> 
     871//     * @param searchFiler the searchFilter that produced the attributes 
     872//     * @param attributes <code>Map</code> of attribute ids to attributes 
     873//     */ 
     874//    protected void setCachedAttributes(AttributeResolutionContext resolutionContext, String searchFiler, 
     875//            Map<String, Attribute> attributes) { 
     876//        Map<String, Map<String, Attribute>> results = null; 
     877//        String principal = resolutionContext.getAttributeRequestContext().getPrincipalName(); 
     878//        if (cache.containsKey(principal)) { 
     879//            results = cache.get(principal); 
     880//        } else { 
     881//            results = new HashMap<String, Map<String, Attribute>>(); 
     882//            cache.put(principal, results); 
     883//        } 
     884//        results.put(searchFiler, attributes); 
     885//    } 
     886 
     887//    /** 
     888//     * This retrieves any cached attributes for the supplied resolution context. Returns null if nothing is cached. 
     889//     * 
     890//     * @param resolutionContext <code>ResolutionContext</code> 
     891//     * @param searchFilter the search filter the produced the attributes 
     892//     * 
     893//     * @return <code>Map</code> of attributes ids to attributes 
     894//     */ 
     895//    protected Map<String, Attribute> getCachedAttributes(AttributeResolutionContext resolutionContext, 
     896//            String searchFilter) { 
     897//        Map<String, Attribute> attributes = null; 
     898//        if (cacheResults) { 
     899//            String principal = resolutionContext.getAttributeRequestContext().getPrincipalName(); 
     900//            if (cache.containsKey(principal)) { 
     901//                Map<String, Map<String, Attribute>> results = cache.get(principal); 
     902//                attributes = results.get(searchFilter); 
     903//            } 
     904//        } 
     905//        return attributes; 
     906//    } 
    908907 
    909908 
Note: See TracChangeset for help on using the changeset viewer.