本文整理汇总了Java中javax.naming.directory.Attributes.put方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.put方法的具体用法?Java Attributes.put怎么用?Java Attributes.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.Attributes
的用法示例。
在下文中一共展示了Attributes.put方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Converts an {@link Entry} to an {@link Attributes}.
*
* @param entry
* the {@link Entry} to convert
* @return
* the equivalent {@link Attributes}
*/
public static Attributes toAttributes( Entry entry )
{
if ( entry != null )
{
Attributes attributes = new BasicAttributes( true );
// Looping on attributes
for ( Iterator<Attribute> attributeIterator = entry.iterator(); attributeIterator.hasNext(); )
{
Attribute entryAttribute = attributeIterator.next();
attributes.put( toJndiAttribute( entryAttribute ) );
}
return attributes;
}
return null;
}
示例2: testConvertAttributesfromLdif
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Test a conversion of an attributes from a LDIF file
* @throws org.apache.directory.api.ldap.model.ldif.LdapLdifException
*/
@Test
public void testConvertAttributesfromLdif() throws LdapException, LdapLdifException
{
Attributes attributes = new BasicAttributes( true );
Attribute oc = new BasicAttribute( "objectclass" );
oc.add( "top" );
oc.add( "person" );
oc.add( "inetorgPerson" );
attributes.put( oc );
attributes.put( "cn", "Saarbrucken" );
attributes.put( "sn", "test" );
String ldif = LdifUtils.convertToLdif( attributes, ( Dn ) null, 15 );
Attributes result = LdifUtils.getJndiAttributesFromLdif( ldif );
assertEquals( attributes, result );
}
示例3: createTriggerExecutionSubentry
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Create the Trigger execution subentry
*
* @param apCtx The administration point context
* @param subentryCN The CN used by the suentry
* @param subtreeSpec The subtree specification
* @param prescriptiveTriggerSpec The prescriptive trigger specification
* @throws NamingException If the operation failed
*/
public static void createTriggerExecutionSubentry(
LdapContext apCtx,
String subentryCN,
String subtreeSpec,
String prescriptiveTriggerSpec ) throws NamingException
{
Attributes subentry = new BasicAttributes( SchemaConstants.CN_AT, subentryCN, true );
Attribute objectClass = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT );
subentry.put( objectClass );
objectClass.add( SchemaConstants.TOP_OC );
objectClass.add( SchemaConstants.SUBENTRY_OC );
objectClass.add( SchemaConstants.TRIGGER_EXECUTION_SUBENTRY_OC );
subentry.put( SchemaConstants.SUBTREE_SPECIFICATION_AT, subtreeSpec );
subentry.put( SchemaConstants.PRESCRIPTIVE_TRIGGER_SPECIFICATION_AT, prescriptiveTriggerSpec );
apCtx.createSubcontext( "cn=" + subentryCN, subentry );
}
示例4: getUserAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
public static Map<String, String> getUserAttributes(DirContext ctx, String searchBase, String userName,
String principalDomain, String... attributeNames)
throws NamingException {
if (StringUtils.isBlank(userName)) {
throw new IllegalArgumentException("Username and password can not be blank.");
}
if (attributeNames.length == 0) {
return Collections.emptyMap();
}
Attributes matchAttr = new BasicAttributes(true);
BasicAttribute basicAttr = new BasicAttribute("userPrincipalName", userName + principalDomain);
matchAttr.put(basicAttr);
NamingEnumeration<? extends SearchResult> searchResult = ctx.search(searchBase, matchAttr, attributeNames);
if (ctx != null) {
ctx.close();
}
Map<String, String> result = new HashMap<>();
if (searchResult.hasMore()) {
NamingEnumeration<? extends Attribute> attributes = searchResult.next().getAttributes().getAll();
while (attributes.hasMore()) {
Attribute attr = attributes.next();
String attrId = attr.getID();
String attrValue = (String) attr.get();
result.put(attrId, attrValue);
}
}
return result;
}
示例5: setupMocksBase
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
@Before
public void setupMocksBase() throws NamingException {
mockContext = mock(DirContext.class);
doReturn(mockContext).when(mappingSpy).getDirContext();
// We only ever call hasMoreElements once for the user NamingEnum, so
// we can just have one return value
when(mockUserNamingEnum.hasMoreElements()).thenReturn(true);
SearchResult mockGroupResult = mock(SearchResult.class);
// We're going to have to define the loop here. We want two iterations,
// to get both the groups
when(mockGroupNamingEnum.hasMoreElements()).thenReturn(true, true, false);
when(mockGroupNamingEnum.nextElement()).thenReturn(mockGroupResult);
// Define the attribute for the name of the first group
Attribute group1Attr = new BasicAttribute("cn");
group1Attr.add(testGroups[0]);
Attributes group1Attrs = new BasicAttributes();
group1Attrs.put(group1Attr);
// Define the attribute for the name of the second group
Attribute group2Attr = new BasicAttribute("cn");
group2Attr.add(testGroups[1]);
Attributes group2Attrs = new BasicAttributes();
group2Attrs.put(group2Attr);
// This search result gets reused, so return group1, then group2
when(mockGroupResult.getAttributes()).thenReturn(group1Attrs, group2Attrs);
}
示例6: parseAttribute
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Parse an AttributeType/AttributeValue
*
* @param attributes The entry where to store the value
* @param line The line to parse
* @param lowerLine The same line, lowercased
* @throws LdapLdifException If anything goes wrong
*/
private void parseAttribute( Attributes attributes, String line, String lowerLine ) throws LdapLdifException
{
int colonIndex = line.indexOf( ':' );
String attributeType = lowerLine.substring( 0, colonIndex );
// We should *not* have a Dn twice
if ( "dn".equals( attributeType ) )
{
LOG.error( I18n.err( I18n.ERR_12002_ENTRY_WITH_TWO_DNS ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12003_LDIF_ENTRY_WITH_TWO_DNS ) );
}
Object attributeValue = parseValue( attributeType, line, colonIndex );
// Update the entry
javax.naming.directory.Attribute attribute = attributes.get( attributeType );
if ( attribute == null )
{
attributes.put( attributeType, attributeValue );
}
else
{
attribute.add( attributeValue );
}
}
示例7: loadStoredProcedureClass
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Loads a Java class's stream data as a subcontext of an LdapContext given.
*
* @param ctx
* The parent context of the Java class entry to be loaded.
* @param clazz
* Class to be loaded.
* @throws NamingException
* If an error occurs during creating the subcontext.
*/
public static void loadStoredProcedureClass( LdapContext ctx, Class<?> clazz ) throws NamingException
{
byte[] buf = getClassFileAsStream( clazz );
String fullClassName = clazz.getName();
Attributes attributes = new BasicAttributes( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, true );
attributes.get( SchemaConstants.OBJECT_CLASS_AT ).add( "storedProcUnit" );
attributes.get( SchemaConstants.OBJECT_CLASS_AT ).add( "javaStoredProcUnit" );
attributes.put( "storedProcLangId", "Java" );
attributes.put( "storedProcUnitName", fullClassName );
attributes.put( "javaByteCode", buf );
ctx.createSubcontext( "storedProcUnitName=" + fullClassName, attributes );
}
示例8: toAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
Attributes toAttributes() {
Attributes attrs = new BasicAttributes(true);
TypeAndValue tv;
Attribute attr;
for (int i = 0; i < tvs.size(); i++) {
tv = tvs.elementAt(i);
if ((attr = attrs.get(tv.getType())) == null) {
attrs.put(tv.getType(), tv.getUnescapedValue());
} else {
attr.add(tv.getUnescapedValue());
}
}
return attrs;
}
示例9: toAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Retrieves the {@link javax.naming.directory.Attributes Attributes}
* view of the type/value mappings contained in this Rdn.
*
* @return The non-null attributes containing the type/value
* mappings of this Rdn.
*/
public Attributes toAttributes() {
Attributes attrs = new BasicAttributes(true);
for (int i = 0; i < entries.size(); i++) {
RdnEntry entry = entries.get(i);
Attribute attr = attrs.put(entry.getType(), entry.getValue());
if (attr != null) {
attr.add(entry.getValue());
attrs.put(attr);
}
}
return attrs;
}
示例10: setupMocks
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
@Before
public void setupMocks() throws NamingException {
mockContext = mock(DirContext.class);
doReturn(mockContext).when(mappingSpy).getDirContext();
SearchResult mockUserResult = mock(SearchResult.class);
// We only ever call hasMoreElements once for the user NamingEnum, so
// we can just have one return value
when(mockUserNamingEnum.hasMoreElements()).thenReturn(true);
when(mockUserNamingEnum.nextElement()).thenReturn(mockUserResult);
when(mockUserResult.getNameInNamespace()).thenReturn("CN=some_user,DC=test,DC=com");
SearchResult mockGroupResult = mock(SearchResult.class);
// We're going to have to define the loop here. We want two iterations,
// to get both the groups
when(mockGroupNamingEnum.hasMoreElements()).thenReturn(true, true, false);
when(mockGroupNamingEnum.nextElement()).thenReturn(mockGroupResult);
// Define the attribute for the name of the first group
Attribute group1Attr = new BasicAttribute("cn");
group1Attr.add(testGroups[0]);
Attributes group1Attrs = new BasicAttributes();
group1Attrs.put(group1Attr);
// Define the attribute for the name of the second group
Attribute group2Attr = new BasicAttribute("cn");
group2Attr.add(testGroups[1]);
Attributes group2Attrs = new BasicAttributes();
group2Attrs.put(group2Attr);
// This search result gets reused, so return group1, then group2
when(mockGroupResult.getAttributes()).thenReturn(group1Attrs, group2Attrs);
}
示例11: toCaseInsensitive
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Check if the attributes is a BasicAttributes, and if so, switch
* the case sensitivity to false to avoid tricky problems in the server.
* (Ldap attributeTypes are *always* case insensitive)
*
* @param attributes The Attributes to check
* @return The modified Attributes
*/
public static Attributes toCaseInsensitive( Attributes attributes )
{
if ( attributes == null )
{
return attributes;
}
if ( attributes instanceof BasicAttributes )
{
if ( attributes.isCaseIgnored() )
{
// Just do nothing if the Attributes is already case insensitive
return attributes;
}
else
{
// Ok, bad news : we have to create a new BasicAttributes
// which will be case insensitive
Attributes newAttrs = new BasicAttributes( true );
NamingEnumeration<?> attrs = attributes.getAll();
if ( attrs != null )
{
// Iterate through the attributes now
while ( attrs.hasMoreElements() )
{
newAttrs.put( ( javax.naming.directory.Attribute ) attrs.nextElement() );
}
}
return newAttrs;
}
}
else
{
// we can safely return the attributes if it's not a BasicAttributes
return attributes;
}
}