当前位置: 首页>>代码示例>>Java>>正文


Java ModificationItem类代码示例

本文整理汇总了Java中javax.naming.directory.ModificationItem的典型用法代码示例。如果您正苦于以下问题:Java ModificationItem类的具体用法?Java ModificationItem怎么用?Java ModificationItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ModificationItem类属于javax.naming.directory包,在下文中一共展示了ModificationItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lock

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
/**
 * Lock an user :
 * <ul>
 * <li>Clear the password to prevent new authentication</li>
 * <li>Set the disabled flag.</li>
 * </ul>
 * 
 * @param principal
 *            User requesting the lock.
 * @param user
 *            The LDAP user to disable.
 * @param isolate
 *            When <code>true</code>, the user will be isolated in addition.
 */
private void lock(final String principal, final UserOrg user, final boolean isolate) {
	if (user.getLockedBy() == null) {
		// Not yet locked
		final ModificationItem[] mods = new ModificationItem[2];
		final long timeInMillis = DateUtils.newCalendar().getTimeInMillis();
		mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(lockedAttribute,
				String.format("%s|%s|%s|%s|", lockedValue, timeInMillis, principal, isolate ? user.getCompany() : "")));
		mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD_ATTRIBUTE, null));
		template.modifyAttributes(org.springframework.ldap.support.LdapUtils.newLdapName(user.getDn()), mods);

		// Also update the disabled date
		user.setLocked(new Date(timeInMillis));
		user.setLockedBy(principal);
	}
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:30,代码来源:UserLdapRepository.java

示例2: activateNis

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
/**
 * This seems to be required for objectClass posixGroup.
 */
private ApacheDS activateNis() throws Exception {
  Preconditions.checkState(ldapServer.isStarted());

  Attribute disabled = new BasicAttribute("m-disabled", "TRUE");
  Attribute disabled2 = new BasicAttribute("m-disabled", "FALSE");
  ModificationItem[] mods = new ModificationItem[] {
    new ModificationItem(DirContext.REMOVE_ATTRIBUTE, disabled),
    new ModificationItem(DirContext.ADD_ATTRIBUTE, disabled2)
  };

  Hashtable env = new Hashtable();
  env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  env.put(Context.PROVIDER_URL, getUrl());

  DirContext ctx = new InitialDirContext(env);
  ctx.modifyAttributes("cn=nis,ou=schema", mods);

  return this;
}
 
开发者ID:SonarQubeCommunity,项目名称:sonar-activedirectory,代码行数:23,代码来源:ApacheDS.java

示例3: updateLdapZimbra

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
public void updateLdapZimbra(LdapContext ctx ,User user,String name, Employee emp) throws NamingException{
	Modifications mods = Modifications.getInstance();
       for (int i = 0; i < 5;i++){
       	 mods.addItem(zimbraProperty[i][0],zimbraProperty[i][1]);
       }
       mods.addItem("zimbramaildeliveryaddress",user.getEmailAddress());
    
      // mods.addItem("company",user.getEmailAddress());
     //  mods.addItem("street",user.getEmailAddress());
      //.addItem("company",user.getEmailAddress());
      // mods.addItem("company",user.getEmailAddress());
   	//System.out.println("My  " + mods);
       ModificationItem[] modItems = mods.getItems();
       ctx.modifyAttributes(name, modItems);
       //= getContext(serviceContext.getCompanyId());
	
}
 
开发者ID:openegovplatform,项目名称:OEPv2,代码行数:18,代码来源:EmployeeExportToLdap.java

示例4: removeMember

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
/**
 * Remove an "uniqueMember" from given group. Cache is not updated there.
 * 
 * @param uniqueMember
 *            DN of the member to remove.
 * @param group
 *            CN of the group to update. Must be normalized.
 * @return the {@link GroupOrg} where the member has just been removed from.
 */
private GroupOrg removeMember(final ResourceOrg uniqueMember, final String group) {
	final GroupOrg groupLdap = findById(group);
	if (groupLdap.getMembers().contains(uniqueMember.getId()) || groupLdap.getSubGroups().contains(uniqueMember.getId())) {
		// Not useless LDAP operation, avoid LDAP duplicate deletion
		final ModificationItem[] mods = new ModificationItem[1];
		mods[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(UNIQUE_MEMBER, uniqueMember.getDn()));
		try {
			template.modifyAttributes(org.springframework.ldap.support.LdapUtils.newLdapName(groupLdap.getDn()), mods);
		} catch (final org.springframework.ldap.AttributeInUseException aiue) {
			// Even if the membership update failed, the user does not exist anymore. A broken reference can remains
			// in LDAP, but this case is well managed.
			log.info("Unable to remove user {} from the group {} : {}", uniqueMember.getDn(), group, aiue);
		} catch (final org.springframework.ldap.SchemaViolationException sve) { // NOSONAR - Exception is logged
			// Occurs when there is a LDAP schema violation such as as last member removed
			log.warn("Unable to remove user {} from the group {}", uniqueMember.getDn(), group, sve);
			throw new ValidationJsonException("groups", "last-member-of-group", "user", uniqueMember.getId(), "group", group);
		}
	}
	return groupLdap;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:30,代码来源:GroupLdapRepository.java

示例5: addAttributes

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
@Override
public void addAttributes(final String dn, final String attribute, final Collection<String> values) {
	if (values.isEmpty()) {
		// Ignore this call
		return;
	}

	// Build the modification operation
	final ModificationItem[] mods = values.stream().map(v -> new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(attribute, v)))
			.toArray(ModificationItem[]::new);
	try {
		// Perform the addition
		template.modifyAttributes(org.springframework.ldap.support.LdapUtils.newLdapName(dn), mods);
	} catch (final org.springframework.ldap.AttributeInUseException aiue) {
		if (!aiue.getMessage().matches(".*(value #0 already exists|error code 20|ATTRIBUTE_OR_VALUE_EXISTS).*")) {
			throw aiue;
		}
		log.info("{} is already member of {}", values, dn);
	}
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:21,代码来源:GroupLdapRepository.java

示例6: convertToServerModification

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
/**
 * 
 * Convert a list of ModificationItemImpl to a list of 
 *
 * @param modificationImpls
 * @param atRegistry
 * @return
 * @throws LdapException
 */
public static List<Modification> convertToServerModification( List<ModificationItem> modificationItems,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modificationItems != null )
    {
        List<Modification> modifications = new ArrayList<Modification>( modificationItems.size() );

        for ( ModificationItem modificationItem : modificationItems )
        {
            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( modificationItem
                .getAttribute().getID() );
            modifications.add( toServerModification( modificationItem, attributeType ) );
        }

        return modifications;
    }
    else
    {
        return null;
    }
}
 
开发者ID:TremoloSecurity,项目名称:MyVirtualDirectory,代码行数:31,代码来源:ServerEntryUtils.java

示例7: changePassord

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
public void changePassord(ServiceContext serviceContext, User user, String password) throws Exception{
	long companyId = serviceContext.getCompanyId();
	Properties userMappings = getUserMappings(serviceContext.getCompanyId());
	Binding binding = getUser(companyId, user.getScreenName());
	System.out.println("bingging " + binding);
	System.out.println("Pass " + user.getPassword());
    String name = StringPool.BLANK;
	StringBuilder sb = new StringBuilder();
	LdapContext ctx = getContext(serviceContext.getCompanyId());
       sb = new StringBuilder();
	sb.append(userMappings.getProperty("screenName"));
	sb.append(StringPool.EQUAL);
	sb.append(user.getScreenName());
	sb.append(StringPool.COMMA);
	sb.append(getUsersDN(companyId));
	name = sb.toString();
	Modifications mods = Modifications.getInstance();  
	
	mods.addItem(userMappings.getProperty(UserConverterKeys.PASSWORD),password);
	ModificationItem[] modItems = mods.getItems();
	if (binding != null) {
		ctx.modifyAttributes(name, modItems);
	}
	
}
 
开发者ID:openegovplatform,项目名称:OEPv2,代码行数:26,代码来源:ManagerLdap.java

示例8: resetUserPassword

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
/**
 * Function for instance_admin to reset user password 
 */
public boolean resetUserPassword(String usrDn, String pw) {
    DirContext context = null;
    
    try {
        context = getContext();
        Attribute userPassword = new BasicAttribute(LdapManager.PERSON_PASSWORD, hash256(pw));
        ModificationItem[] mods = new ModificationItem[1];
        mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, userPassword);
        context.modifyAttributes(usrDn, mods);
        logger.info("LdapManager info: User '"+usrDn+"' password reseted by instance_admin.");
        context.close();
        
    } catch (NamingException e) {
        logger.error("LdapManager error: Error reseting user password, "+e);
        return false;
    }
    
    return true;
}
 
开发者ID:mikkeliamk,项目名称:osa,代码行数:23,代码来源:LdapManager.java

示例9: testUpdate

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
@Test public void testUpdate() throws Exception {
      String input = "exec native('update;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one', 2, 3.0)"; 

      TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
      Command command = util.parseCommand(input);
      ExecutionContext ec = Mockito.mock(ExecutionContext.class);
      RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
      LdapContext connection = Mockito.mock(LdapContext.class);
      LdapContext ctx = Mockito.mock(LdapContext.class);
      Mockito.stub(connection.lookup("")).toReturn(ctx);
      
      LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution)TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();

ArgumentCaptor<String> nameArgument = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ModificationItem[]> modificationItemArgument = ArgumentCaptor.forClass(ModificationItem[].class);
Mockito.verify(ctx).modifyAttributes(nameArgument.capture(),modificationItemArgument.capture());

assertEquals("uid=doe,ou=people,o=teiid.org", nameArgument.getValue());
assertEquals("one", modificationItemArgument.getValue()[0].getAttribute().getID());
assertEquals("one", modificationItemArgument.getValue()[0].getAttribute().get());
assertEquals("two", modificationItemArgument.getValue()[1].getAttribute().getID());
assertEquals("2", modificationItemArgument.getValue()[1].getAttribute().get());
assertEquals("three", modificationItemArgument.getValue()[2].getAttribute().getID());
assertEquals("3.0", modificationItemArgument.getValue()[2].getAttribute().get());
  }
 
开发者ID:kenweezy,项目名称:teiid,代码行数:27,代码来源:TestLDAPDirectQueryExecution.java

示例10: testUpdateNull

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
@Test public void testUpdateNull() throws Exception {
      String sql = "update LdapModel.People set userid = 1, name = null where dn = 'x'"; //$NON-NLS-1$

      QueryMetadataInterface metadata = exampleLdap();
      
      Update query = (Update)getCommand(sql, metadata);
      
      LDAPExecutionFactory config = new LDAPExecutionFactory();
  	
      LdapContext context = Mockito.mock(LdapContext.class);
      
      Mockito.stub(context.lookup("")).toReturn(context);
      
LDAPUpdateExecution lue = new LDAPUpdateExecution(query, context);
      
      lue.execute();
      ArgumentCaptor<ModificationItem[]> captor = ArgumentCaptor.forClass(ModificationItem[].class);
      Mockito.verify(context).modifyAttributes(ArgumentCaptor.forClass(String.class).capture(), captor.capture());
      ModificationItem[] modifications = captor.getValue();
      assertEquals(2, modifications.length);
      assertEquals("uid: 1", modifications[0].getAttribute().toString());
      assertEquals("cn: null", modifications[1].getAttribute().toString());
  }
 
开发者ID:kenweezy,项目名称:teiid,代码行数:24,代码来源:TestIQueryToLdapSearchParser.java

示例11: testUpdateArray

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
@Test public void testUpdateArray() throws Exception {
      String sql = "update LdapModel.People set userid = 1, vals = ('a','b') where dn = 'x'"; //$NON-NLS-1$

      QueryMetadataInterface metadata = exampleLdap();
      
      Update query = (Update)getCommand(sql, metadata);
      
      LDAPExecutionFactory config = new LDAPExecutionFactory();
  	
      LdapContext context = Mockito.mock(LdapContext.class);
      
      Mockito.stub(context.lookup("")).toReturn(context);
      
LDAPUpdateExecution lue = new LDAPUpdateExecution(query, context);
      
      lue.execute();
      ArgumentCaptor<ModificationItem[]> captor = ArgumentCaptor.forClass(ModificationItem[].class);
      Mockito.verify(context).modifyAttributes(ArgumentCaptor.forClass(String.class).capture(), captor.capture());
      ModificationItem[] modifications = captor.getValue();
      assertEquals(2, modifications.length);
      assertEquals("uid: 1", modifications[0].getAttribute().toString());
      assertEquals("vals: a, b", modifications[1].getAttribute().toString());
  }
 
开发者ID:kenweezy,项目名称:teiid,代码行数:24,代码来源:TestIQueryToLdapSearchParser.java

示例12: enableKerberoseSchema

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
private void enableKerberoseSchema() throws DirectoryServerException {
    // check if krb5kdc is disabled
    Attributes krb5kdcAttrs;
    try {
        krb5kdcAttrs = schemaRoot.getAttributes("cn=Krb5kdc");

        boolean isKrb5KdcDisabled = false;
        if (krb5kdcAttrs.get("m-disabled") != null) {
            isKrb5KdcDisabled = "TRUE".equalsIgnoreCase((String) krb5kdcAttrs.get("m-disabled").get());
        }

        // if krb5kdc is disabled then enable it
        if (isKrb5KdcDisabled) {
            Attribute disabled = new BasicAttribute("m-disabled");
            ModificationItem[] mods =
                    new ModificationItem[]{new ModificationItem(
                            DirContext.REMOVE_ATTRIBUTE, disabled)};
            schemaRoot.modifyAttributes("cn=Krb5kdc", mods);
        }
    } catch (NamingException e) {
        String msg = "An error occurred while enabling Kerberos schema.";
        logger.error(msg, e);
        throw new DirectoryServerException(msg, e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:26,代码来源:ApacheKDCServer.java

示例13: setupModifications

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
/**
 * setupModifications, Setup Bulk Modificationitem from incoming Attributes Object.
 *
 * @param _modtype    Modifcation Type.
 * @param _entryattrs Incoming attributes to be placed into Modificationitem Queue.
 * @throws idxIRRException for any specific IRR unrecoverable errors during function.
 * @throws Exception       for any unrecoverable errors during function.
 */
private void setupModifications(int _modtype, Attributes _entryattrs)
        throws Exception, idxIRRException {

    // **********************************************
    // Check incoming Parameters.
    if (_entryattrs == null) {
        return;
    }

    // **********************************************************
    // Process the incoming Attributes into the Modification Set.
    for (NamingEnumeration ea = _entryattrs.getAll(); ea.hasMore(); ) {
        Attribute attr = (Attribute) ea.next();
        CURRENT_MODLIST.addLast(new ModificationItem(_modtype, attr));
    } // End of For Loop.

    // **********************************************
    // Return
    return;
}
 
开发者ID:jaschenk,项目名称:jeffaschenk-commons,代码行数:29,代码来源:IRRChangeLogRestoreServiceReaderThread.java

示例14: modifyAttributes

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
public void modifyAttributes(Name name, ModificationItem[] modificationItems)
        throws NamingException {
    if (!(name instanceof CompositeName)) {
        // jndi.26=URL context can't accept non-composite name: {0}
        throw new InvalidNameException(Messages.getString("jndi.26", name)); //$NON-NLS-1$
    }

    if (name.size() == 1) {
        modifyAttributes(name.get(0), modificationItems);
        return;
    }
    DirContext context = getContinuationContext(name);

    try {
        context.modifyAttributes(name.getSuffix(1), modificationItems);
        return;
    } finally {
        context.close();
    }

}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:ldapURLContext.java

示例15: testToString

import javax.naming.directory.ModificationItem; //导入依赖的package包/类
public void testToString() {
	log.setMethod("testToString()");
	String str;

	AttributeModificationException ex = new AttributeModificationException(
			"sample message");
	str = ex.toString();
	assertTrue(str.indexOf("sample message") >= 0);
	assertFalse(str.indexOf("sample id") >= 0);
	assertFalse(str.indexOf("sample value") >= 0);

	ModificationItem items[] = new ModificationItem[] { new ModificationItem(
			DirContext.ADD_ATTRIBUTE, new BasicAttribute("sample id",
					"sample value")), };

	ex.setUnexecutedModifications(items);
	str = ex.toString();
	assertTrue(str.indexOf("sample message") >= 0);
	assertTrue(str.indexOf("sample id") >= 0);
	assertTrue(str.indexOf("sample value") >= 0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:AttributeModificationExceptionTest.java


注:本文中的javax.naming.directory.ModificationItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。