本文整理汇总了Java中javax.naming.directory.Attributes类的典型用法代码示例。如果您正苦于以下问题:Java Attributes类的具体用法?Java Attributes怎么用?Java Attributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attributes类属于javax.naming.directory包,在下文中一共展示了Attributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDnsAttributes
import javax.naming.directory.Attributes; //导入依赖的package包/类
String getDnsAttributes(String ip) {
try {
Hashtable<String, String> env = new Hashtable<>();
env.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
// TODO don't specify ws1, instead use ns servers for s.maxmind.com
env.put("java.naming.provider.url", "dns://ws1.maxmind.com/");
DirContext ictx = new InitialDirContext(env);
Attributes attrs = ictx.getAttributes(licenseKey + "." + ip
+ ".s.maxmind.com", new String[] { "txt" });
// System.out.println(attrs.get("txt").get());
String str = attrs.get("txt").get().toString();
return str;
} catch (NamingException e) {
// TODO fix this to handle exceptions
System.out.println("DNS error");
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: defineTriggerExecutionSpecificPoint
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* 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 );
}
}
示例4: getServerAddress
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Returns a server's address and port for the specified hostname, looking up the SRV record if possible
*/
private static String[] getServerAddress(String p_78863_0_)
{
try
{
String s = "com.sun.jndi.dns.DnsContextFactory";
Class.forName("com.sun.jndi.dns.DnsContextFactory");
Hashtable<String, String> hashtable = new Hashtable();
hashtable.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
hashtable.put("java.naming.provider.url", "dns:");
hashtable.put("com.sun.jndi.dns.timeout.retries", "1");
DirContext dircontext = new InitialDirContext(hashtable);
Attributes attributes = dircontext.getAttributes("_minecraft._tcp." + p_78863_0_, new String[] {"SRV"});
String[] astring = attributes.get("srv").get().toString().split(" ", 4);
return new String[] {astring[3], astring[2]};
}
catch (Throwable var6)
{
return new String[] {p_78863_0_, Integer.toString(25565)};
}
}
示例5: getAttributeValue
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Return a String representing the value of the specified attribute.
*
* @param attrId Attribute name
* @param attrs Attributes containing the required value
*
* @exception NamingException if a directory server error occurs
*/
private String getAttributeValue(String attrId, Attributes attrs)
throws NamingException {
if (debug >= 3)
log(" retrieving attribute " + attrId);
if (attrId == null || attrs == null)
return null;
Attribute attr = attrs.get(attrId);
if (attr == null)
return (null);
Object value = attr.get();
if (value == null)
return (null);
String valueString = null;
if (value instanceof byte[])
valueString = new String((byte[]) value);
else
valueString = value.toString();
return valueString;
}
示例6: decodeSearchResult
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Converts a JNDI SearchResult into our LdapEntry object.
*/
private LdapEntry decodeSearchResult(
SearchResult sr,
String contextBase,
String[] attrNames)
throws LdapException
{
// print dn == distinguished name
String dn;
if (sr.getName() == null || sr.getName().length() == 0)
dn = contextBase;
else dn = sr.getName() + "," + contextBase;
Attributes attrraw = sr.getAttributes();
return decodeAttributes( dn, attrNames, attrraw);
}
示例7: getAttributes
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Retrieves all of the attributes associated with a named object.
*
* @return the set of attributes associated with name.
* Returns an empty attribute set if name has no attributes; never null.
* @param name the name of the object from which to retrieve attributes
* @exception NamingException if a naming exception is encountered
*/
public Attributes getAttributes(Name name, String[] attrIds)
throws NamingException {
Entry entry = null;
if (name.isEmpty())
entry = entries;
else
entry = treeLookup(name);
if (entry == null)
throw new NamingException
(sm.getString("resources.notFound", name));
ZipEntry zipEntry = entry.getEntry();
ResourceAttributes attrs = new ResourceAttributes();
attrs.setCreationDate(new Date(zipEntry.getTime()));
attrs.setName(entry.getName());
if (!zipEntry.isDirectory())
attrs.setResourceType("");
attrs.setContentLength(zipEntry.getSize());
attrs.setLastModified(zipEntry.getTime());
return attrs;
}
示例8: 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);
}
示例9: 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 );
}
}
示例10: getJndiAttributesFromLdif
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Convert a LDIF String to a JNDI attributes.
*
* @param ldif The LDIF string containing an attribute value
* @return An Attributes instance
* @exception LdapLdifException If the LDIF String cannot be converted to an Attributes
*/
public static Attributes getJndiAttributesFromLdif( String ldif ) throws LdapLdifException
{
try ( LdifAttributesReader reader = new LdifAttributesReader() )
{
return AttributeUtils.toAttributes( reader.parseEntry( ldif ) );
}
catch ( IOException ioe )
{
throw new LdapLdifException( ioe.getMessage(), ioe );
}
}
示例11: testConvertToLdifEncoding
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Tests that unsafe characters are encoded using UTF-8 charset.
* @throws LdapException
*
* @throws NamingException
*/
@Test
public void testConvertToLdifEncoding() throws LdapException
{
Attributes attributes = new BasicAttributes( "cn", "Saarbr\u00FCcken" );
String ldif = LdifUtils.convertToLdif( attributes );
assertEquals( "cn:: U2FhcmJyw7xja2Vu\n", ldif );
}
示例12: testConvertToLdifAttrWithNullValues
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Tests that null values are correctly encoded
*
* @throws NamingException
*/
@Test
public void testConvertToLdifAttrWithNullValues() throws LdapException
{
Attributes attributes = new BasicAttributes( "cn", null );
String ldif = LdifUtils.convertToLdif( attributes );
assertEquals( "cn:\n", ldif );
}
示例13: getGroupsFromNames
import javax.naming.directory.Attributes; //导入依赖的package包/类
public List<GroupBean> getGroupsFromNames(DirContext ctx, Collection<Name> ldapgroupnames)
{
List<GroupBean> alist = new ArrayList<GroupBean>();
for( Name groupname : ldapgroupnames )
{
Attributes gattr = ldap.getAttributes(ctx, groupname, ldap.getGroupAttributes());
GroupBean gbean = ldap.getGroupBeanFromResult(new LDAPResult(groupname, gattr));
if( gbean != null )
{
alist.add(gbean);
}
}
return alist;
}
示例14: addAttributeValues
import javax.naming.directory.Attributes; //导入依赖的package包/类
/**
* Add values of a specified attribute to a list
*
* @param attrId
* Attribute name
* @param attrs
* Attributes containing the new values
* @param values
* ArrayList containing values found so far
*
* @exception NamingException
* if a directory server error occurs
*/
private ArrayList<String> addAttributeValues(String attrId, Attributes attrs, ArrayList<String> values)
throws NamingException {
if (containerLog.isTraceEnabled())
containerLog.trace(" retrieving values for attribute " + attrId);
if (attrId == null || attrs == null)
return values;
if (values == null)
values = new ArrayList<String>();
Attribute attr = attrs.get(attrId);
if (attr == null)
return values;
NamingEnumeration<?> e = attr.getAll();
try {
while (e.hasMore()) {
String value = (String) e.next();
values.add(value);
}
} catch (PartialResultException ex) {
if (!adCompat)
throw ex;
} finally {
e.close();
}
return values;
}
示例15: getURLContext
import javax.naming.directory.Attributes; //导入依赖的package包/类
public static Context getURLContext(
String scheme, Hashtable<?,?> environment)
throws NamingException {
return new InitialDirContext() {
public Attributes getAttributes(String name, String[] attrIds)
throws NamingException {
return new BasicAttributes() {
public Attribute get(String attrID) {
BasicAttribute ba = new BasicAttribute(attrID);
ba.add("1 1 99 b.com.");
ba.add("0 0 88 a.com."); // 2nd has higher priority
return ba;
}
};
}
};
}