javax.naming.directory.InvalidAttributeValueException#org.apache.directory.api.ldap.model.entry.Entry源码实例Demo

下面列出了javax.naming.directory.InvalidAttributeValueException#org.apache.directory.api.ldap.model.entry.Entry 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyVirtualDirectory   文件: SchemaInterceptor.java
/**
 * Checks to see if an attribute is required by as determined from an entry's
 * set of objectClass attribute values.
 *
 * @return true if the objectClass values require the attribute, false otherwise
 * @throws Exception if the attribute is not recognized
 */
private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException
{
    // Never check the attributes if the extensibleObject objectClass is
    // declared for this entry
    Attribute objectClass = entry.get( OBJECT_CLASS_AT );

    if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) )
    {
        return;
    }

    for ( Attribute attribute : entry )
    {
        String attrOid = attribute.getAttributeType().getOid();

        AttributeType attributeType = attribute.getAttributeType();

        if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
            && !allowed.contains( attrOid ) )
        {
            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277,
                attribute.getUpId(), dn.getName() ) );
        }
    }
}
 
源代码2 项目: directory-ldap-api   文件: SchemaAwareEntryTest.java
/**
 * Helper method which creates an entry with 4 attributes.
 */
private Entry createEntry()
{
    try
    {
        Entry entry = new DefaultEntry( exampleDn );

        Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
        Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
        Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
        Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );

        entry.put( attrOC, attrCN, attrSN, attrPWD );

        return entry;
    }
    catch ( LdapException ne )
    {
        // Do nothing
        return null;
    }
}
 
源代码3 项目: directory-ldap-api   文件: SchemaAwareEntryTest.java
/**
 * Test method for DefaultEntry()
 */
@Test
public void testDefaultClientEntryLdif() throws Exception
{
    Entry entry = new DefaultEntry(
        "ou=example, dc=com",
        "ObjectClass: top",
        "ObjectClass: person",
        "cn: test",
        "sn: test" );

    assertNotNull( entry );
    assertEquals( "ou=example, dc=com", entry.getDn().toString() );
    assertEquals( 3, entry.size() );
    assertTrue( entry.contains( "objectClass", "top", "person" ) );
    assertTrue( entry.contains( "cn", "test" ) );
    assertTrue( entry.contains( "sn", "test" ) );
}
 
源代码4 项目: directory-ldap-api   文件: SchemaAwareEntryTest.java
/**
 * Test method for clear()
 */
@Test
public void testClear() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    assertEquals( 0, entry.size() );
    assertNull( entry.get( "ObjectClass" ) );
    entry.clear();
    assertEquals( 0, entry.size() );
    assertNull( entry.get( "ObjectClass" ) );

    entry.add( "ObjectClass", "top", "person" );
    assertEquals( 1, entry.size() );
    assertNotNull( entry.get( "ObjectClass" ) );

    entry.clear();
    assertEquals( 0, entry.size() );
    assertNull( entry.get( "ObjectClass" ) );
}
 
源代码5 项目: directory-ldap-api   文件: SchemaEntityFactory.java
/**
 * Process the FQCN attribute
 * 
 * @param entry The entry to read
 * @param objectType The type of schema object
 * @return The schema object FQCN
 * @throws LdapInvalidAttributeValueException If the attribute does not contain a valid value
 */
private String getFqcn( Entry entry, String objectType ) throws LdapInvalidAttributeValueException
{
    // The FQCN
    Attribute mFqcn = entry.get( MetaSchemaConstants.M_FQCN_AT );

    if ( mFqcn == null )
    {
        String msg = I18n.err( I18n.ERR_16034_ENTRY_WITHOUT_VALID_AT, objectType, MetaSchemaConstants.M_FQCN_AT );
        
        if ( LOG.isWarnEnabled() )
        {
            LOG.warn( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    return mFqcn.getString();
}
 
源代码6 项目: directory-ldap-api   文件: SchemaAwareEntryTest.java
/**
 * Test method for contains( EntryAttribute... )
 */
@Test
public void testContainsEntryAttributeArray() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
    Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
    Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
    Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );

    assertFalse( entry.contains( attrOC, attrCN ) );

    entry.add( attrOC, attrCN );

    assertTrue( entry.contains( attrOC, attrCN ) );
    assertFalse( entry.contains( attrOC, attrCN, attrSN ) );

    entry.add( attrSN, attrPWD );

    assertTrue( entry.contains( attrSN, attrPWD ) );
}
 
/**
 * {@inheritDoc}
 */
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    // Special case : if we don't have any modification to apply, just return
    if ( modifyContext.getModItems().size() == 0 )
    {
        return;
    }

    Partition partition = getPartition( modifyContext.getDn() );

    partition.modify( modifyContext );

    if ( modifyContext.isPushToEvtInterceptor() )
    {
        directoryService.getInterceptor( InterceptorEnum.EVENT_INTERCEPTOR.getName() ).modify( modifyContext );
    }

    Entry alteredEntry = modifyContext.getAlteredEntry();

    if ( alteredEntry != null )
    {
        // MyVD doesn't care about csn
    	// directoryService.setContextCsn( alteredEntry.get( ENTRY_CSN_AT ).getString() );
    }
}
 
源代码8 项目: ldapchai   文件: ApacheLdapProviderImpl.java
public String readStringAttribute( final String entryDN, final String attribute )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    activityPreCheck();
    getInputValidator().readStringAttribute( entryDN, attribute );

    try
    {
        final EntryCursor entries = connection.search(
                entryDN,
                ChaiConstant.FILTER_OBJECTCLASS_ANY,
                org.apache.directory.api.ldap.model.message.SearchScope.OBJECT,
                attribute
        );
        final Entry entry = entries.iterator().next();
        final Attribute attr = entry.get( attribute );
        return attr == null ? null : attr.getString();

    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
/**
 * {@inheritDoc}
 */
@Override
public AddFuture addAsync( Entry entry ) throws LdapException
{
    if ( entry == null )
    {
        String msg = I18n.err( I18n.ERR_04125_CANNOT_ADD_NULL_ENTRY );
        
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    AddRequest addRequest = new AddRequestImpl();
    addRequest.setEntry( entry );

    return addAsync( addRequest );
}
 
源代码10 项目: directory-fortress-core   文件: UserDAO.java
/**
 * Given a collection of ARBAC roles, {@link UserAdminRole}, convert to raw data format and load into ldap
 * attribute set in preparation for ldap add.
 *
 * @param list  contains List of type {@link UserAdminRole} targeted for adding to ldap.
 * @param entry collection of ldap attributes containing ARBAC role assignments in raw ldap format.
 * @throws LdapException
 */
private void loadUserAdminRoles( List<UserAdminRole> list, Entry entry ) throws LdapException
{
    if ( list != null )
    {
        Attribute userAdminRoleData = new DefaultAttribute( GlobalIds.USER_ADMINROLE_DATA );
        Attribute userAdminRoleAssign = new DefaultAttribute( GlobalIds.USER_ADMINROLE_ASSIGN );

        for ( UserAdminRole userRole : list )
        {
            userAdminRoleData.add( userRole.getRawData() );
            userAdminRoleAssign.add( userRole.getName() );
        }

        if ( userAdminRoleData.size() != 0 )
        {
            entry.add( userAdminRoleData );
            entry.add( userAdminRoleAssign );
        }
    }
}
 
源代码11 项目: directory-ldap-api   文件: SchemaAwareEntryTest.java
/**
 * Test method for userCertificate;binary AT
 */
@Test
public void testUserCertificateBinary() throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );
    entry.add( "objectClass", "top", "person", "inetorgPerson" );
    entry.add( "cn", "test1", "test2" );
    entry.add( "sn", "Test1", "Test2" );
    entry.add( "userPassword", BYTES1, BYTES2 );

    entry.add( "userCertificate;binary", Strings.getBytesUtf8( "secret" ) );
    assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
    assertTrue( entry.containsAttribute( "userCertificate" ) );

    entry.removeAttributes( "userCertificate;binary" );
    assertFalse( entry.containsAttribute( "userCertificate;binary" ) );
    assertFalse( entry.containsAttribute( "userCertificate" ) );

    entry.add( "userCertificate", Strings.getBytesUtf8( "secret" ) );
    assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
    assertTrue( entry.containsAttribute( "userCertificate" ) );
}
 
源代码12 项目: directory-fortress-core   文件: AuditDAO.java
private Mod getModEntityFromLdapEntry( Entry le, long sequence ) throws LdapInvalidAttributeValueException
{
    Mod mod = new ObjectFactory().createMod();
    mod.setSequenceId( sequence );
    mod.setObjectClass( getAttribute( le, OBJECTCLASS ) );
    mod.setReqAuthzID( getAttribute( le, REQUAUTHZID ) );
    mod.setReqDN( getAttribute( le, REQDN ) );
    mod.setReqEnd( getAttribute( le, REQEND ) );
    mod.setReqResult( getAttribute( le, REQRESULT ) );
    mod.setReqSession( getAttribute( le, REQSESSION ) );
    mod.setReqStart( getAttribute( le, REQSTART ) );
    mod.setReqType( getAttribute( le, REQTYPE ) );
    mod.setReqMod( getAttributes( le, REQMOD ) );

    return mod;
}
 
源代码13 项目: mamute   文件: LDAPApi.java
private void updateAvatarImage(LDAPResource ldap, Entry entry, User user) {
	try {
		byte[] jpegBytes = getAvatarImage(ldap, entry);
		if (jpegBytes != null) {
			String fileName = user.getEmail() + ".jpg";
			DefaultUploadedFile avatar = new DefaultUploadedFile(new ByteArrayInputStream(jpegBytes), fileName, "image/jpeg", jpegBytes.length);
			Attachment attachment = imageStore.processAndStore(avatar, user, clientIp);
			Attachment old = user.getAvatar();
			if (old != null) {
				imageStore.delete(old);
			}
			user.setAvatar(attachment);
		}
	} catch (LdapException | IOException e) {
		// problems with avatar processing are non-fatal
		logger.warn("Error updating user avatar from LDAP: " + user.getName(), e);
	}
}
 
源代码14 项目: directory-ldap-api   文件: SchemaElementImpl.java
/**
 * Return the extensions formated as Ldif lines
 *
 * @param id The attributeId : can be m-objectClassExtension or
 * m-attributeTypeExtension
 * @return The extensions formated as ldif lines
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
protected String extensionsToLdif( String id ) throws LdapException
{
    StringBuilder sb = new StringBuilder();

    Entry entry = new DefaultEntry();
    Attribute attribute = new DefaultAttribute( id );

    for ( String extension : extensions.keySet() )
    {
        attribute.add( extension );
    }

    sb.append( LdifUtils.convertAttributesToLdif( entry ) );

    return sb.toString();
}
 
源代码15 项目: directory-fortress-core   文件: AdminRoleDAO.java
/**
 * @param le
 * @return
 * @throws LdapInvalidAttributeValueException 
 * @throws LdapException
 */
private AdminRole unloadLdapEntry( Entry le, long sequence, String contextId )
    throws LdapInvalidAttributeValueException
{
    AdminRole entity = new ObjectFactory().createAdminRole();
    entity.setSequenceId( sequence );
    entity.setId( getAttribute( le, GlobalIds.FT_IID ) );
    entity.setDescription( getAttribute( le, SchemaConstants.DESCRIPTION_AT ) );
    entity.setOccupants( getAttributes( le, ROLE_OCCUPANT ) );
    entity.setOsPSet( getAttributeSet( le, ROLE_OSP ) );
    entity.setOsUSet( getAttributeSet( le, ROLE_OSU ) );
    entity.setName( getAttribute( le, SchemaConstants.CN_AT ) );
    unloadTemporal( le, entity );
    entity.setRoleRangeRaw( getAttribute( le, ROLE_RANGE ) );
    entity.setParents( getAttributeSet( le, GlobalIds.PARENT_NODES ) );
    entity.setChildren( AdminRoleUtil.getChildren( entity.getName().toUpperCase(), contextId ) );
    return entity;
}
 
源代码16 项目: directory-fortress-core   文件: LdapDataProvider.java
/**
 * Method wraps ldap client to return multivalued attribute by name within a given entry and returns
 * as a set of strings.
 *
 * @param entry         contains the target ldap entry.
 * @param attributeName name of ldap attribute to retrieve.
 * @return List of type string containing attribute values.
 */
protected Set<String> getAttributeSet( Entry entry, String attributeName )
{
    // create Set with case insensitive comparator:
    Set<String> attrValues = new TreeSet<>( String.CASE_INSENSITIVE_ORDER );

    if ( entry != null && entry.containsAttribute( attributeName ) )
    {
        for ( Value<?> value : entry.get( attributeName ) )
        {
            attrValues.add( value.getString() );
        }
    }

    return attrValues;
}
 
源代码17 项目: guacamole-client   文件: UserService.java
/**
 * Returns all Guacamole users accessible to the user currently bound under
 * the given LDAP connection.
 *
 * @param ldapConnection
 *     The current connection to the LDAP server, associated with the
 *     current user.
 *
 * @return
 *     All users accessible to the user currently bound under the given
 *     LDAP connection, as a map of connection identifier to corresponding
 *     user object.
 *
 * @throws GuacamoleException
 *     If an error occurs preventing retrieval of users.
 */
public Map<String, User> getUsers(LdapNetworkConnection ldapConnection)
        throws GuacamoleException {

    // Retrieve all visible user objects
    Collection<String> attributes = confService.getUsernameAttributes();
    List<Entry> results = queryService.search(ldapConnection,
            confService.getUserBaseDN(),
            confService.getUserSearchFilter(),
            attributes,
            null);

    // Convert retrieved users to map of identifier to Guacamole user object
    return queryService.asMap(results, entry -> {

        // Get username from record
        try {
            String username = queryService.getIdentifier(entry, attributes);
            if (username == null) {
                logger.warn("User \"{}\" is missing a username attribute "
                        + "and will be ignored.", entry.getDn().toString());
                return null;
            }
            
            return new SimpleUser(username);
        }
        catch (LdapInvalidAttributeValueException e) {
            
            return null;
        }

    });

}
 
@Test
public void testLdifEmpty() throws LdapLdifException, IOException
{
    String ldif = "";

    LdifAttributesReader reader = new LdifAttributesReader();
    Entry entry = reader.parseEntry( ldif );

    assertEquals( 0, entry.size() );
    reader.close();
}
 
private LdapReferralException buildReferralException( Entry parentEntry, Dn childDn ) throws LdapException
{
    // Get the Ref attributeType
    Attribute refs = parentEntry.get( SchemaConstants.REF_AT );

    List<String> urls = new ArrayList<String>();

    try
    {
        // manage each Referral, building the correct URL for each of them
        for ( Value<?> url : refs )
        {
            // we have to replace the parent by the referral
            LdapUrl ldapUrl = new LdapUrl( url.getString() );

            // We have a problem with the Dn : we can't use the UpName,
            // as we may have some spaces around the ',' and '+'.
            // So we have to take the Rdn one by one, and create a
            // new Dn with the type and value UP form

            Dn urlDn = ldapUrl.getDn().add( childDn );

            ldapUrl.setDn( urlDn );
            urls.add( ldapUrl.toString() );
        }
    }
    catch ( LdapURLEncodingException luee )
    {
        throw new LdapOperationErrorException( luee.getMessage(), luee );
    }

    // Return with an exception
    LdapReferralException lre = new LdapReferralException( urls );
    lre.setRemainingDn( childDn );
    lre.setResolvedDn( parentEntry.getDn() );
    lre.setResolvedObject( parentEntry );

    return lre;
}
 
源代码20 项目: MyVirtualDirectory   文件: DefaultPartitionNexus.java
/**
 * Creates the root nexus singleton of the entire system.  The root DSE has
 * several attributes that are injected into it besides those that may
 * already exist.  As partitions are added to the system more namingContexts
 * attributes are added to the rootDSE.
 *
 * @see <a href="http://www.faqs.org/rfcs/rfc3045.html">Vendor Information</a>
 * @param rootDse the root entry for the DSA
 * @throws javax.naming.Exception on failure to initialize
 */
public DefaultPartitionNexus( Entry rootDse ) throws Exception
{
    id = ID;
    suffixDn = null;

    // setup that root DSE
    this.rootDse = rootDse;

    // Add the basic informations
    rootDse.put( SchemaConstants.SUBSCHEMA_SUBENTRY_AT, ServerDNConstants.CN_SCHEMA_DN );
    rootDse.put( SchemaConstants.SUPPORTED_LDAP_VERSION_AT, "3" );
    rootDse.put( SchemaConstants.SUPPORTED_FEATURES_AT, SchemaConstants.FEATURE_ALL_OPERATIONAL_ATTRIBUTES );
    rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, NoticeOfDisconnect.EXTENSION_OID );

    // Add the objectClasses
    rootDse.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );

    // Add the 'vendor' name and version infos
    rootDse.put( SchemaConstants.VENDOR_NAME_AT, ASF );

    Properties props = new Properties();

    try
    {
        props.load( getClass().getResourceAsStream( "version.properties" ) );
    }
    catch ( IOException e )
    {
        LOG.error( I18n.err( I18n.ERR_33 ) );
    }

    rootDse.put( SchemaConstants.VENDOR_VERSION_AT, props.getProperty( "apacheds.version", "UNKNOWN" ) );

    // The rootDSE uuid has been randomly created
    rootDse.put( SchemaConstants.ENTRY_UUID_AT, "f290425c-8272-4e62-8a67-92b06f38dbf5" );
}
 
源代码21 项目: directory-ldap-api   文件: DefaultSchemaLoader.java
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> nameFormEntries = new ArrayList<>();

    if ( schemas == null )
    {
        return nameFormEntries;
    }

    AttributesFactory factory = new AttributesFactory();

    for ( Schema schema : schemas )
    {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();

        for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
        {
            SchemaObject schemaObject = schemaObjectWrapper.get();

            if ( schemaObject instanceof NameForm )
            {
                NameForm nameForm = ( NameForm ) schemaObject;

                Entry nameFormEntry = factory.convert( nameForm, schema, null );

                nameFormEntries.add( nameFormEntry );
            }
        }
    }

    return nameFormEntries;
}
 
源代码22 项目: ldapchai   文件: ApacheLdapProviderImpl.java
private List<Value> readMultiAttribute( final String entryDN, final String attribute )
        throws ChaiOperationException
{
    try
    {
        final EntryCursor entries = connection.search(
                entryDN,
                ChaiConstant.FILTER_OBJECTCLASS_ANY,
                org.apache.directory.api.ldap.model.message.SearchScope.OBJECT,
                attribute
        );
        final Entry entry = entries.iterator().next();
        final List<Value> returnSet = new ArrayList<>();
        final Attribute attr = entry.get( attribute );
        if ( attr == null )
        {
            return null;
        }
        for ( final Value value : attr )
        {
            if ( value != null )
            {
                returnSet.add( value );
            }
        }
        return Collections.unmodifiableList( returnSet );

    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }

}
 
源代码23 项目: MyVirtualDirectory   文件: MyVDBaseCursor.java
/**
 * {@inheritDoc}
 */
public Entry get() throws InvalidCursorPositionException
{
    if ( available() )
    {
        return prefetched;
    }

    throw new InvalidCursorPositionException();
}
 
源代码24 项目: mamute   文件: LDAPApi.java
private byte[] getByteAttribute(Entry entry, String attribute) throws LdapException, InvalidAttributeValueException {
	Attribute value = entry.get(attribute);
	if (value != null) {
		return value.getBytes();
	}
	return null;
}
 
源代码25 项目: guacamole-client   文件: ObjectQueryService.java
/**
 * Converts a given list of LDAP entries to a {@link Map} of Guacamole
 * objects stored by their identifiers.
 *
 * @param <ObjectType>
 *     The type of object to store within the {@link Map}.
 *
 * @param entries
 *     A list of LDAP entries to convert to Guacamole objects.
 *
 * @param mapper
 *     A mapping function which converts a given LDAP entry to its
 *     corresponding Guacamole object. If the LDAP entry cannot be
 *     converted, null should be returned.
 *
 * @return
 *     A new {@link Map} containing Guacamole object versions of each of
 *     the given LDAP entries, where each object is stored within the
 *     {@link Map} under its corresponding identifier.
 */
public <ObjectType extends Identifiable> Map<String, ObjectType>
    asMap(List<Entry> entries, Function<Entry, ObjectType> mapper) {

    // Convert each entry to the corresponding Guacamole API object
    Map<String, ObjectType> objects = new HashMap<>(entries.size());
    for (Entry entry : entries) {

        ObjectType object = mapper.apply(entry);
        if (object == null) {
            logger.debug("Ignoring object \"{}\".", entry.getDn().toString());
            continue;
        }

        // Attempt to add object to map, warning if the object appears
        // to be a duplicate
        String identifier = object.getIdentifier();
        if (objects.putIfAbsent(identifier, object) != null)
            logger.warn("Multiple objects ambiguously map to the "
                    + "same identifier (\"{}\"). Ignoring \"{}\" as "
                    + "a duplicate.", identifier, entry.getDn().toString());

    }

    return objects;

}
 
源代码26 项目: MyVirtualDirectory   文件: DefaultCoreSession.java
/**
 * {@inheritDoc}
 */
public Entry lookup( Dn dn, String... attrIds ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();
    LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds );

    Entry entry = operationManager.lookup( lookupContext );

    return entry;
}
 
源代码27 项目: directory-ldap-api   文件: AddRequestTest.java
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_base64_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertFalse( value.isHumanReadable() );
    assertEquals( "DSMLv2.0 rocks!!", value.getString() );
}
 
源代码28 项目: directory-ldap-api   文件: AddRequestTest.java
/**
 * Test parsing of a request with 2 Attr elements with value
 */
@Test
public void testRequestWith2AttrWithValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_2_attr_with_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "person", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
源代码29 项目: guacamole-client   文件: ConnectionService.java
/**
 * Returns an LDAP search filter which queries all connections accessible
 * by the user having the given DN.
 *
 * @param userDN
 *     DN of the user to search for associated guacConfigGroup connections.
 *
 * @param ldapConnection
 *     LDAP connection to use if additional information must be queried to
 *     produce the filter, such as groups driving RBAC.
 *
 * @return
 *     An LDAP search filter which queries all guacConfigGroup objects
 *     accessible by the user having the given DN.
 *
 * @throws LdapException
 *     If an error occurs preventing retrieval of user groups.
 *
 * @throws GuacamoleException
 *     If an error occurs retrieving the group base DN.
 */
private ExprNode getConnectionSearchFilter(Dn userDN,
        LdapNetworkConnection ldapConnection)
        throws LdapException, GuacamoleException {

    AndNode searchFilter = new AndNode();

    // Add the prefix to the search filter, prefix filter searches for guacConfigGroups with the userDN as the member attribute value
    searchFilter.addNode(new EqualityNode("objectClass","guacConfigGroup"));
    
    // Apply group filters
    OrNode groupFilter = new OrNode();
    groupFilter.addNode(new EqualityNode(confService.getMemberAttribute(),
        userDN.toString()));

    // Additionally filter by group membership if the current user is a
    // member of any user groups
    List<Entry> userGroups = userGroupService.getParentUserGroupEntries(ldapConnection, userDN);
    if (!userGroups.isEmpty()) {
        userGroups.forEach(entry ->
            groupFilter.addNode(new EqualityNode("seeAlso",entry.getDn().toString()))
        );
    }

    // Complete the search filter.
    searchFilter.addNode(groupFilter);

    return searchFilter;
}
 
源代码30 项目: directory-ldap-api   文件: SearchResultEntryTest.java
/**
 * Test parsing of a response with 1 Attr 0 Value
 */
@Test
public void testResponseWith1Attr0Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            SearchResultEntryTest.class.getResource( "response_with_1_attr_0_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "dc", attribute.getUpId() );
}