本文整理匯總了Java中javax.naming.directory.BasicAttribute類的典型用法代碼示例。如果您正苦於以下問題:Java BasicAttribute類的具體用法?Java BasicAttribute怎麽用?Java BasicAttribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BasicAttribute類屬於javax.naming.directory包,在下文中一共展示了BasicAttribute類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: activateNis
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例2: lock
import javax.naming.directory.BasicAttribute; //導入依賴的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);
}
}
示例3: removeMember
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例4: addAttributes
import javax.naming.directory.BasicAttribute; //導入依賴的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);
}
}
示例5: toJndiAttribute
import javax.naming.directory.BasicAttribute; //導入依賴的package包/類
/**
* Converts an {@link Attribute} to a JNDI Attribute.
*
* @param attribute the {@link Attribute} to convert
* @return the equivalent JNDI Attribute
*/
public static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute )
{
if ( attribute != null )
{
javax.naming.directory.Attribute jndiAttribute = new BasicAttribute( attribute.getUpId() );
// Looping on values
for ( Iterator<Value> valueIterator = attribute.iterator(); valueIterator.hasNext(); )
{
Value value = valueIterator.next();
jndiAttribute.add( value.getValue() );
}
return jndiAttribute;
}
return null;
}
示例6: testConvertAttributesfromLdif
import javax.naming.directory.BasicAttribute; //導入依賴的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 );
}
示例7: createTriggerExecutionSubentry
import javax.naming.directory.BasicAttribute; //導入依賴的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 );
}
示例8: getMockedLDAPSearchResult
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例9: getURLContext
import javax.naming.directory.BasicAttribute; //導入依賴的package包/類
public static Context getURLContext(
String scheme, Hashtable<?,?> environment)
throws NamingException {
return new DnsContext("", null, new Hashtable<String,String>()) {
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;
}
};
}
};
}
示例10: getURLContext
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
};
}
};
}
示例11: getUserAttributes
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例12: getBasicAttributes
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例13: resetUserPassword
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例14: toAttributes
import javax.naming.directory.BasicAttribute; //導入依賴的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;
}
示例15: enableKerberoseSchema
import javax.naming.directory.BasicAttribute; //導入依賴的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);
}
}