當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。