javax.naming.ldap.LdapContext#modifyAttributes ( )源码实例Demo

下面列出了javax.naming.ldap.LdapContext#modifyAttributes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: directory-ldap-api   文件: TriggerUtils.java
/**
 * Defines the Administration point and administrative role for the TriggerExecution specific point
 * @param apCtx The administrative point context
 * @throws NamingException If the operation failed
 */
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException
{
    Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } );
    Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT );
    
    if ( administrativeRole == null
        || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) )
    {
        Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT,
            SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true );
        apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
    }
}
 
源代码2 项目: directory-ldap-api   文件: TriggerUtils.java
/**
 * Load an prescriptive trigger specification
 * 
 * @param apCtx The administrative point context
 * @param subentryCN The subentry CN
 * @param triggerSpec The trigger specification
 * @throws NamingException If the operation failed
 */
public static void loadPrescriptiveTriggerSpecification(
    LdapContext apCtx,
    String subentryCN,
    String triggerSpec ) throws NamingException
{
    Attributes changes = new BasicAttributes( SchemaConstants.PRESCRIPTIVE_TRIGGER_SPECIFICATION_AT, triggerSpec, true );
    apCtx.modifyAttributes( "cn=" + subentryCN, DirContext.ADD_ATTRIBUTE, changes );
}
 
源代码3 项目: directory-ldap-api   文件: TriggerUtils.java
/**
     * Load the trigger specification entry
     * 
     * @param ctx The context
     * @param triggerSpec The trigger specification
     * @throws NamingException If the operation failed
     */
public static void loadEntryTriggerSpecification(
        LdapContext ctx,
        String triggerSpec ) throws NamingException
    {
        Attributes changes = new BasicAttributes( SchemaConstants.ENTRY_TRIGGER_SPECIFICATION_AT, triggerSpec, true );
        ctx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
    }
 
源代码4 项目: ldapchai   文件: JNDIProviderImpl.java
@LdapOperation
@ModifyOperation
public final void deleteStringAttributeValue( final String entryDN, final String attributeName, final String attributeValue )
        throws ChaiUnavailableException, ChaiOperationException
{
    activityPreCheck();
    getInputValidator().deleteStringAttributeValue( entryDN, attributeName, attributeValue );

    // Create a BasicAttribute for the object.
    final BasicAttribute attributeToReplace = new BasicAttribute( attributeName, attributeValue );

    // Create the ModificationItem
    final ModificationItem[] modificationItem = new ModificationItem[1];

    // Populate the ModificationItem object with the flag & the attribute to replace.
    modificationItem[0] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attributeToReplace );

    // Modify the Attributes.
    final LdapContext ldapConnection = getLdapConnection();
    try
    {
        ldapConnection.modifyAttributes( addJndiEscape( entryDN ), modificationItem );
    }
    catch ( NamingException e )
    {
        convertNamingException( e );
    }
}
 
源代码5 项目: ldapchai   文件: JNDIProviderImpl.java
@LdapOperation
@ModifyOperation
public final void replaceStringAttribute( final String entryDN, final String attributeName, final String oldValue, final String newValue )
        throws ChaiUnavailableException, ChaiOperationException
{
    activityPreCheck();
    getInputValidator().replaceStringAttribute( entryDN, attributeName, oldValue, newValue );

    // Create the ModificationItem
    final ModificationItem[] mods = new ModificationItem[2];

    // Mark the flag to remover the existing attribute.
    mods[0] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( attributeName, oldValue ) );

    // Mark the flag to add the new attribute
    mods[1] = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute( attributeName, newValue ) );

    // get ldap connection
    final LdapContext ldapConnection = getLdapConnection();

    // Modify the Attributes.
    try
    {
        ldapConnection.modifyAttributes( addJndiEscape( entryDN ), mods );
    }
    catch ( NamingException e )
    {
        convertNamingException( e );
    }
}
 
源代码6 项目: ldapchai   文件: JNDIProviderImpl.java
@LdapOperation
@ModifyOperation
public final void writeStringAttribute( final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite )
        throws ChaiUnavailableException, ChaiOperationException
{
    activityPreCheck();
    getInputValidator().writeStringAttribute( entryDN, attributeName, values, overwrite );


    // Create the ModificationItem
    final ModificationItem[] modificationItem = new ModificationItem[values.size()];

    int loopCounter = 0;
    for ( final String value : values )
    {
        // Create a BasicAttribute for the object.
        final BasicAttribute attributeToReplace = new BasicAttribute( attributeName, value );

        // Determine the modification type, if replace, only replace on the first attribute, the rest just get added.
        final int modType = ( loopCounter == 0 && overwrite ) ? DirContext.REPLACE_ATTRIBUTE : DirContext.ADD_ATTRIBUTE;

        // Populate the ModificationItem object with the flag & the attribute to replace.
        modificationItem[loopCounter] = new ModificationItem( modType, attributeToReplace );
        loopCounter++;
    }

    // get ldap connection
    final LdapContext ldapConnection = getLdapConnection();

    // Modify the Attributes.
    try
    {
        ldapConnection.modifyAttributes( addJndiEscape( entryDN ), modificationItem );
    }
    catch ( NamingException e )
    {
        LOGGER.trace( "error during write of attribute '" + attributeName + "', error: " + e.getMessage() );
        convertNamingException( e );
    }
}
 
源代码7 项目: cukes   文件: EntityService.java
public void modifyByDn(String dn, List<ModificationItem> modificationItems) {
    try {
        LdapContext context = connectionService.getContext();
        context.modifyAttributes(dn, modificationItems.toArray(new ModificationItem[modificationItems.size()]));
    } catch (NamingException e) {
        throw new CukesRuntimeException("Cannot modify entity by dn " + dn, e);
    } finally {
        connectionService.close();
    }
}
 
源代码8 项目: ldapchai   文件: JNDIProviderImpl.java
public final void writeStringAttributes(
        final String entryDN,
        final Map<String, String> attributeValueProps,
        final boolean overwrite,
        final BasicControl[] controls
)
        throws ChaiUnavailableException, ChaiOperationException
{
    activityPreCheck();
    getInputValidator().writeStringAttributes( entryDN, attributeValueProps, overwrite );

    // Determine the modification type, if replace, only replace on the first attribute, the rest just get added.
    final int modType = overwrite ? DirContext.REPLACE_ATTRIBUTE : DirContext.ADD_ATTRIBUTE;

    // Create the ModificationItem
    final List<ModificationItem> modificationItems = new ArrayList<>();
    for ( final Map.Entry<String, String> entry : attributeValueProps.entrySet() )
    {
        // Create a BasicAttribute for the object.
        final BasicAttribute attributeToReplace = new BasicAttribute( entry.getKey(), entry.getValue() );

        // Populate the ModificationItem object with the flag & the attribute to replace.
        modificationItems.add( new ModificationItem( modType, attributeToReplace ) );
    }

    // convert to array
    final ModificationItem[] modificationItemArray = modificationItems.toArray( new ModificationItem[modificationItems.size()] );

    // get ldap connection
    final LdapContext ldapConnection = getLdapConnection();

    // Modify the Attributes.
    try
    {
        ldapConnection.modifyAttributes( addJndiEscape( entryDN ), modificationItemArray );
    }
    catch ( NamingException e )
    {
        convertNamingException( e );
    }
}