本文整理匯總了Java中javax.naming.directory.Attribute類的典型用法代碼示例。如果您正苦於以下問題:Java Attribute類的具體用法?Java Attribute怎麽用?Java Attribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Attribute類屬於javax.naming.directory包,在下文中一共展示了Attribute類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getReferencedGroupValue
import javax.naming.directory.Attribute; //導入依賴的package包/類
private String getReferencedGroupValue(final DirContextOperations ctx) {
final String referencedGroupValue;
if (StringUtils.isBlank(userGroupReferencedGroupAttribute)) {
referencedGroupValue = ctx.getDn().toString();
} else {
final Attribute attributeName = ctx.getAttributes().get(userGroupReferencedGroupAttribute);
if (attributeName == null) {
throw new AuthorizationAccessException("Referenced group value attribute [" + userGroupReferencedGroupAttribute + "] does not exist.");
}
try {
referencedGroupValue = (String) attributeName.get();
} catch (NamingException e) {
throw new AuthorizationAccessException("Error while retrieving referenced group value attribute [" + userGroupReferencedGroupAttribute + "].");
}
}
return referencedGroupValue;
}
示例2: setupMocks
import javax.naming.directory.Attribute; //導入依賴的package包/類
@Before
public void setupMocks() throws NamingException {
SearchResult mockUserResult = mock(SearchResult.class);
when(mockUserNamingEnum.nextElement()).thenReturn(mockUserResult);
Attribute mockUidNumberAttr = mock(Attribute.class);
Attribute mockGidNumberAttr = mock(Attribute.class);
Attribute mockUidAttr = mock(Attribute.class);
Attributes mockAttrs = mock(Attributes.class);
when(mockUidAttr.get()).thenReturn("some_user");
when(mockUidNumberAttr.get()).thenReturn("700");
when(mockGidNumberAttr.get()).thenReturn("600");
when(mockAttrs.get(eq("uid"))).thenReturn(mockUidAttr);
when(mockAttrs.get(eq("uidNumber"))).thenReturn(mockUidNumberAttr);
when(mockAttrs.get(eq("gidNumber"))).thenReturn(mockGidNumberAttr);
when(mockUserResult.getAttributes()).thenReturn(mockAttrs);
}
示例3: sync
import javax.naming.directory.Attribute; //導入依賴的package包/類
/**
* Performs the actual sync of the specified user.
* @param ctx a DirContext
* @param qm the AlpineQueryManager to use
* @param sc the SearchControls to use
* @param user the LdapUser instance to sync
* @throws NamingException when a problem with the connection with the directory
*/
private void sync(DirContext ctx, AlpineQueryManager qm, SearchControls sc, LdapUser user) throws NamingException {
final String searchFor = LDAP_ATTRIBUTE_NAME + "=" + formatPrincipal(user.getUsername());
LOGGER.debug("Syncing: " + user.getUsername());
final List<SearchResult> results = Collections.list(ctx.search(BASE_DN, searchFor, sc));
if (results.size() > 0) {
// Should only return 1 result, but just in case, get the very first one
final SearchResult result = results.get(0);
user.setDN(result.getNameInNamespace());
final Attribute mail = result.getAttributes().get(ATTRIBUTE_MAIL);
if (mail != null) {
// user.setMail(mail.get()); //todo
}
} else {
// This is an invalid user - a username that exists in the database that does not exist in LDAP
user.setDN("INVALID");
// user.setMail(null); //todo
}
qm.updateLdapUser(user);
}
示例4: testConvertAttributesfromLdif
import javax.naming.directory.Attribute; //導入依賴的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 );
}
示例5: createTriggerExecutionSubentry
import javax.naming.directory.Attribute; //導入依賴的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 );
}
示例6: getRangeRestrictedAttribute
import javax.naming.directory.Attribute; //導入依賴的package包/類
/**
* Gets the values of a repeating attribute that may have range restriction options. If an attribute is range
* restricted, it will appear in the attribute set with a ";range=i-j" option, where i and j indicate the start and
* end index, and j is '*' if it is at the end.
*
* @param attributes
* the attributes
* @param attributeName
* the attribute name
* @return the range restricted attribute
* @throws NamingException
* the naming exception
*/
private Attribute getRangeRestrictedAttribute(Attributes attributes, String attributeName) throws NamingException
{
Attribute unrestricted = attributes.get(attributeName);
if (unrestricted != null)
{
return unrestricted;
}
NamingEnumeration<? extends Attribute> i = attributes.getAll();
String searchString = attributeName.toLowerCase() + ';';
while (i.hasMore())
{
Attribute attribute = i.next();
if (attribute.getID().toLowerCase().startsWith(searchString))
{
return attribute;
}
}
return null;
}
示例7: getAttributeValue
import javax.naming.directory.Attribute; //導入依賴的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 (containerLog.isTraceEnabled())
containerLog.trace(" 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;
}
示例8: getName
import javax.naming.directory.Attribute; //導入依賴的package包/類
/**
* Get name.
*
* @return Name value
*/
public String getName() {
if (name != null)
return name;
if (attributes != null) {
Attribute attribute = attributes.get(NAME);
if (attribute != null) {
try {
name = attribute.get().toString();
} catch (NamingException e) {
// No value for the attribute
}
}
}
return name;
}
示例9: getResourceType
import javax.naming.directory.Attribute; //導入依賴的package包/類
/**
* Get resource type.
*
* @return String resource type
*/
public String getResourceType() {
String result = null;
if (attributes != null) {
Attribute attribute = attributes.get(TYPE);
if (attribute != null) {
try {
result = attribute.get().toString();
} catch (NamingException e) {
// No value for the attribute
}
}
}
if (result == null) {
if (collection)
result = COLLECTION_TYPE;
}
return result;
}
示例10: getValue
import javax.naming.directory.Attribute; //導入依賴的package包/類
private String getValue(Attributes answer, String name)
{
Attribute attr = null;
if( name != null )
{
attr = answer.get(name);
}
if( attr == null )
{
return "";
}
try
{
return (String) attr.get();
}
catch( NamingException ne )
{
return "";
}
}
示例11: getAttributeValue
import javax.naming.directory.Attribute; //導入依賴的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 (containerLog.isTraceEnabled())
containerLog.trace(" 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;
}
示例12: getResourceType
import javax.naming.directory.Attribute; //導入依賴的package包/類
/**
* Get resource type.
*
* @return String resource type
*/
public String getResourceType() {
String result = null;
if (attributes != null) {
Attribute attribute = attributes.get(TYPE);
if (attribute != null) {
try {
result = attribute.get().toString();
} catch (NamingException e) {
; // No value for the attribute
}
}
}
if (result == null) {
if (collection)
result = COLLECTION_TYPE;
else
result = null;
}
return result;
}
示例13: getName
import javax.naming.directory.Attribute; //導入依賴的package包/類
/**
* Get name.
*
* @return Name value
*/
public String getName() {
if (name != null)
return name;
if (attributes != null) {
Attribute attribute = attributes.get(NAME);
if (attribute != null) {
try {
name = attribute.get().toString();
} catch (NamingException e) {
// No value for the attribute
}
}
}
return name;
}
示例14: getUserIdentity
import javax.naming.directory.Attribute; //導入依賴的package包/類
private String getUserIdentity(final DirContextOperations ctx) {
final String identity;
if (useDnForUserIdentity) {
identity = ctx.getDn().toString();
} else {
final Attribute attributeName = ctx.getAttributes().get(userIdentityAttribute);
if (attributeName == null) {
throw new AuthorizationAccessException("User identity attribute [" + userIdentityAttribute + "] does not exist.");
}
try {
identity = (String) attributeName.get();
} catch (NamingException e) {
throw new AuthorizationAccessException("Error while retrieving user name attribute [" + userIdentityAttribute + "].");
}
}
return IdentityMappingUtil.mapIdentity(identity, identityMappings);
}
示例15: getDisabledBoolean
import javax.naming.directory.Attribute; //導入依賴的package包/類
@Override
public boolean getDisabledBoolean(Attributes attrs) {
String ldapDisabledAttrStr = Configuration.get(ConfigurationKeys.LDAP_DISABLED_ATTR);
if (ldapDisabledAttrStr.startsWith("!")) {
ldapDisabledAttrStr = ldapDisabledAttrStr.substring(1);
Attribute ldapDisabledAttr = attrs.get(ldapDisabledAttrStr);
Boolean booleanValue = getAsBoolean(ldapDisabledAttr);
if (booleanValue != null) {
return !booleanValue;
} else {
// if there is no value, assume not disabled
return false;
}
} else {
return getAsBoolean(attrs.get(ldapDisabledAttrStr));
}
}