本文整理汇总了Java中javax.naming.directory.BasicAttributes.put方法的典型用法代码示例。如果您正苦于以下问题:Java BasicAttributes.put方法的具体用法?Java BasicAttributes.put怎么用?Java BasicAttributes.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.BasicAttributes
的用法示例。
在下文中一共展示了BasicAttributes.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMockedLDAPSearchResult
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
private LDAPInitialDirContextFactoryImpl getMockedLDAPSearchResult(boolean withEmail) throws NamingException
{
@SuppressWarnings("unchecked")
NamingEnumeration<SearchResult> mockedNamingEnumeration = mock(NamingEnumeration.class);
when(mockedNamingEnumeration.hasMore()).thenReturn(true).thenReturn(false);
BasicAttributes attributes = new BasicAttributes();
attributes.put(new BasicAttribute("sAMAccountName", "U1"));
attributes.put(new BasicAttribute("givenName", "U1"));
if (withEmail)
{
attributes.put(new BasicAttribute("mail", "[email protected]"));
}
SearchResult mockedSearchResult = new SearchResult("CN:U1", null, attributes);
mockedSearchResult.setNameInNamespace("CN:U1");
when(mockedNamingEnumeration.next()).thenReturn(mockedSearchResult);
InitialDirContext mockedInitialDirContext = mock(InitialDirContext.class);
when(mockedInitialDirContext.search(any(String.class), any(String.class), any(SearchControls.class))).thenReturn(mockedNamingEnumeration);
LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = mock(LDAPInitialDirContextFactoryImpl.class);
when(mockedLdapInitialDirContextFactory.getDefaultIntialDirContext(0)).thenReturn(mockedInitialDirContext);
return mockedLdapInitialDirContextFactory;
}
示例2: getUserAttributes
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* Collect all the value from the table (Arguments), using this create the
* basicAttributes. This will create the Basic Attributes for the User
* defined TestCase for Add Test.
*
* @return the BasicAttributes
*/
private BasicAttributes getUserAttributes() {
BasicAttribute basicattribute = new BasicAttribute("objectclass"); //$NON-NLS-1$
basicattribute.add("top"); //$NON-NLS-1$
basicattribute.add("person"); //$NON-NLS-1$
basicattribute.add("organizationalPerson"); //$NON-NLS-1$
basicattribute.add("inetOrgPerson"); //$NON-NLS-1$
BasicAttributes attrs = new BasicAttributes(true);
attrs.put(basicattribute);
BasicAttribute attr;
for (JMeterProperty jMeterProperty : getArguments()) {
Argument item = (Argument) jMeterProperty.getObjectValue();
attr = getBasicAttribute(item.getName(), item.getValue());
attrs.put(attr);
}
return attrs;
}
示例3: getBasicAttributes
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* This will create the Basic Attributes for the In build TestCase for Add
* Test.
*
* @return the BasicAttributes
*/
private BasicAttributes getBasicAttributes() {
BasicAttributes basicattributes = new BasicAttributes();
BasicAttribute basicattribute = new BasicAttribute("objectclass"); //$NON-NLS-1$
basicattribute.add("top"); //$NON-NLS-1$
basicattribute.add("person"); //$NON-NLS-1$
basicattribute.add("organizationalPerson"); //$NON-NLS-1$
basicattribute.add("inetOrgPerson"); //$NON-NLS-1$
basicattributes.put(basicattribute);
String s1 = "User"; //$NON-NLS-1$
String s3 = "Test"; //$NON-NLS-1$
String s5 = "user"; //$NON-NLS-1$
String s6 = "test"; //$NON-NLS-1$
counter += 1;
basicattributes.put(new BasicAttribute("givenname", s1)); //$NON-NLS-1$
basicattributes.put(new BasicAttribute("sn", s3)); //$NON-NLS-1$
basicattributes.put(new BasicAttribute("cn", "TestUser" + counter)); //$NON-NLS-1$ //$NON-NLS-2$
basicattributes.put(new BasicAttribute("uid", s5)); //$NON-NLS-1$
basicattributes.put(new BasicAttribute("userpassword", s6)); //$NON-NLS-1$
setProperty(new StringProperty(ADD, "cn=TestUser" + counter)); //$NON-NLS-1$
return basicattributes;
}
示例4: toAttributes
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
private static Attributes toAttributes(String strAttributes,String delimiter, String separator) throws PageException {
String[] arrAttr = toStringAttributes(strAttributes,delimiter);
BasicAttributes attributes = new BasicAttributes();
for(int i=0; i<arrAttr.length; i++) {
String strAttr = arrAttr[i];
// Type
int eqIndex=strAttr.indexOf('=');
Attribute attr = new BasicAttribute((eqIndex != -1)?strAttr.substring(0, eqIndex).trim():null);
// Value
String strValue = (eqIndex!=-1)?strAttr.substring( eqIndex+ 1):strAttr;
String[] arrValue=ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(strValue,separator));
// Fill
for(int y=0; y<arrValue.length; y++) {
attr.add(arrValue[y]);
}
attributes.put(attr);
}
return attributes;
}
示例5: MyUser
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
public MyUser(String userId, String surName, String commonName) {
myAttrs = new BasicAttributes(true); // Case ignore
Attribute oc = new BasicAttribute("objectclass");
oc.add("inetOrgPerson");
oc.add("organizationalPerson");
oc.add("person");
oc.add("top");
Attribute sn = new BasicAttribute("sn");
sn.add(surName);
Attribute cn = new BasicAttribute("cn");
cn.add(commonName);
Attribute uid = new BasicAttribute("uid");
uid.add(userId);
myAttrs.put(sn);
myAttrs.put(cn);
myAttrs.put(uid);
myAttrs.put(oc);
}
示例6: getMockedLDAPSearchResult
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
private LDAPInitialDirContextFactoryImpl getMockedLDAPSearchResult(boolean withEmail) throws NamingException
{
@SuppressWarnings("unchecked")
NamingEnumeration<SearchResult> mockedNamingEnumeration = mock(NamingEnumeration.class);
when(mockedNamingEnumeration.hasMore()).thenReturn(true).thenReturn(false);
BasicAttributes attributes = new BasicAttributes();
attributes.put(new BasicAttribute("sAMAccountName", "U1"));
attributes.put(new BasicAttribute("givenName", "U1"));
if (withEmail)
{
attributes.put(new BasicAttribute("mail", "[email protected]m"));
}
SearchResult mockedSearchResult = new SearchResult("CN:U1", null, attributes);
mockedSearchResult.setNameInNamespace("CN:U1");
when(mockedNamingEnumeration.next()).thenReturn(mockedSearchResult);
InitialDirContext mockedInitialDirContext = mock(InitialDirContext.class);
when(mockedInitialDirContext.search(any(String.class), any(String.class), any(SearchControls.class))).thenReturn(mockedNamingEnumeration);
LDAPInitialDirContextFactoryImpl mockedLdapInitialDirContextFactory = mock(LDAPInitialDirContextFactoryImpl.class);
when(mockedLdapInitialDirContextFactory.getDefaultIntialDirContext(0)).thenReturn(mockedInitialDirContext);
return mockedLdapInitialDirContextFactory;
}
示例7: toAttributes
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
public Attributes toAttributes() {
BasicAttributes bas = new BasicAttributes(true);
for (Iterator<Attribute> iter = list.iterator(); iter.hasNext();) {
Attribute attr = iter.next();
BasicAttribute ba = new BasicAttribute(attr.getID(), false);
try {
NamingEnumeration nameEnum = attr.getAll();
while (nameEnum.hasMore()) {
ba.add(nameEnum.next());
}
} catch (NamingException ne) {
}
bas.put(ba);
}
return bas;
}
示例8: addAttribute
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* Adds user attribute.
* @param objectDn the subject dn
* @param attributeName the user attribute will be added.
* @param attributeValue the user attribute value will be added.
* @throws CredentialPolicyException if the credentials are invalid
* @throws IdentityException if a system error occurs preventing the action
* @throws NamingException if an LDAP naming exception occurs
* @throws SQLException if a database communication exception occurs
*/
@Override
public void addAttribute(String objectDn, String attributeName, String attributeValue)
throws CredentialPolicyException, IdentityException, NamingException, SQLException {
LdapClient client = null;
try {
// register the user
client = newServiceConnection();
BasicAttributes ldapAttributes = new BasicAttributes();
BasicAttribute ldapAttribute = new BasicAttribute(attributeName,attributeValue);
ldapAttributes.put(ldapAttribute);
client.getEditFunctions().addAttribute(client.getConnectedContext(), objectDn, ldapAttributes);
} finally {
if (client != null) client.close();
}
}
示例9: removeAttribute
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* Adds user attribute.
* @param objectDn the subject dn
* @param attributeName the user attribute will be removed.
* @param attributeValue the user attribute value will be removed
* @throws CredentialPolicyException if the credentials are invalid
* @throws IdentityException if a system error occurs preventing the action
* @throws NamingException if an LDAP naming exception occurs
* @throws SQLException if a database communication exception occurs
*/
@Override
public void removeAttribute(String objectDn,String attributeName, String attributeValue)
throws CredentialPolicyException, IdentityException, NamingException, SQLException {
LdapClient client = null;
try {
// register the user
client = newServiceConnection();
BasicAttributes ldapAttributes = new BasicAttributes();
BasicAttribute ldapAttribute = new BasicAttribute(attributeName,attributeValue);
ldapAttributes.put(ldapAttribute);
client.getEditFunctions().removeEntry(client.getConnectedContext(), objectDn, ldapAttributes);
} finally {
if (client != null) client.close();
}
}
示例10: mergeAttributes
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* merge two instanceof <code>Attributes</code> to one
*
* @param first
* @param second
* @return
* @throws NamingException
*/
private Attributes mergeAttributes(Attributes first, Attributes second)
throws NamingException {
if (first == null) {
return second;
}
if (second == null) {
return first;
}
BasicAttributes attrs = new BasicAttributes(true);
NamingEnumeration<? extends Attribute> enu = first.getAll();
while (enu.hasMore()) {
attrs.put(enu.next());
}
enu = second.getAll();
while (enu.hasMore()) {
Attribute element = enu.next();
element = mergeAttribute(element, attrs.get(element.getID()));
attrs.put(element);
}
return attrs;
}
示例11: testClone_IgnoreCase
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
public void testClone_IgnoreCase() {
int count = 5;
Attribute[] attributes = new Attribute[count];
for (int i = 0; i < count; i++) {
Person person = Person.getInstance();
attributes[i] = new BasicAttribute(person.getName(), person);
ignoreCaseAttributes.put(attributes[i]);
}
BasicAttributes cloneAttributes = (BasicAttributes) ignoreCaseAttributes
.clone();
assertEquals(cloneAttributes, ignoreCaseAttributes);
for (Attribute element : attributes) {
element.getID();
}
cloneAttributes.put("newID", "new Obj");
assertEquals(ignoreCaseAttributes.size() + 1, cloneAttributes.size());
}
示例12: testClone_CaseSensitive
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
public void testClone_CaseSensitive() {
int count = 5;
Attribute[] attributes = new Attribute[count];
for (int i = 0; i < count; i++) {
Person person = Person.getInstance();
attributes[i] = new BasicAttribute(person.getName(), person);
caseSensitiveAttributes.put(attributes[i]);
}
BasicAttributes cloneAttributes = (BasicAttributes) caseSensitiveAttributes
.clone();
assertEquals(cloneAttributes, caseSensitiveAttributes);
for (Attribute element : attributes) {
element.getID();
}
cloneAttributes.put("newID", "new Obj");
assertEquals(caseSensitiveAttributes.size() + 1, cloneAttributes.size());
}
示例13: testEquals_ignoreCase
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* 1. ignoreCase=true 2. Normal values
*/
public void testEquals_ignoreCase() {
BasicAttributes basicAttributes0 = new BasicAttributes(true);
BasicAttributes basicAttributes1 = new BasicAttributes(true);
int count = 10;
BasicAttribute attribute[] = new BasicAttribute[count];
for (int i = 0; i < count; i++) {
attribute[i] = new BasicAttribute("ID:" + i, "Value: " + i);
basicAttributes0.put(attribute[i]);
basicAttributes1.put(attribute[i]);
}
assertTrue(basicAttributes0.equals(basicAttributes1));
assertTrue(basicAttributes1.equals(basicAttributes0));
assertFalse(basicAttributes0.equals(null));
basicAttributes0.remove("ID:0");
assertFalse(basicAttributes0.equals(basicAttributes1));
assertFalse(basicAttributes1.equals(basicAttributes0));
}
示例14: testEquals_caseSensitive
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* 1. ignoreCase=false 2. Normal values
*/
public void testEquals_caseSensitive() {
BasicAttributes basicAttributes0 = new BasicAttributes(false);
BasicAttributes basicAttributes1 = new BasicAttributes(false);
int count = 10;
BasicAttribute attribute[] = new BasicAttribute[count];
for (int i = 0; i < count; i++) {
attribute[i] = new BasicAttribute("ID:" + i, "Value: " + i);
basicAttributes0.put(attribute[i]);
basicAttributes1.put(attribute[i]);
}
assertTrue(basicAttributes0.equals(basicAttributes1));
assertTrue(basicAttributes1.equals(basicAttributes0));
assertFalse(basicAttributes0.equals(null));
}
示例15: testLdapNameListOfRdn006
import javax.naming.directory.BasicAttributes; //导入方法依赖的package包/类
/**
* <p>
* Test method for 'javax.naming.ldap.LdapName.LdapName(List<Rdn>)'
* </p>
* <p>
* Here we are testing the constructor method of LdapName reciving a list of
* valid names.
* </p>
* <p>
* The expected result is an instance of an object of LdapName, and also
* that the indexing is made like the other way around.
* </p>
*/
public void testLdapNameListOfRdn006() throws Exception {
try {
BasicAttributes bas = new BasicAttributes();
bas.put("test2", "test2");
bas.put("test1", "test1");
bas.put("test3", "test3");
Rdn rdn1 = new Rdn(bas);
LinkedList<Rdn> rdns = new LinkedList<Rdn>();
rdns.add(rdn1);
LdapName ln = new LdapName(rdns);
assertEquals("test1=test1+test2=test2+test3=test3", ln.getAll().nextElement());
} catch (Exception e) {
e.printStackTrace();
}
}