本文整理汇总了Java中javax.naming.directory.BasicAttributes类的典型用法代码示例。如果您正苦于以下问题:Java BasicAttributes类的具体用法?Java BasicAttributes怎么用?Java BasicAttributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicAttributes类属于javax.naming.directory包,在下文中一共展示了BasicAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mockSearchResults
import javax.naming.directory.BasicAttributes; //导入依赖的package包/类
private NamingEnumeration<SearchResult> mockSearchResults(String password)
throws NamingException {
@SuppressWarnings("unchecked")
NamingEnumeration<SearchResult> searchResults =
EasyMock.createNiceMock(NamingEnumeration.class);
EasyMock.expect(Boolean.valueOf(searchResults.hasMore()))
.andReturn(Boolean.TRUE)
.andReturn(Boolean.FALSE)
.andReturn(Boolean.TRUE)
.andReturn(Boolean.FALSE);
EasyMock.expect(searchResults.next())
.andReturn(new SearchResult("ANY RESULT", "",
new BasicAttributes(USER_PASSWORD_ATTR, password)))
.times(2);
EasyMock.replay(searchResults);
return searchResults;
}
示例2: toAttributes
import javax.naming.directory.BasicAttributes; //导入依赖的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;
}
示例3: testConvertAttributesfromLdif
import javax.naming.directory.BasicAttributes; //导入依赖的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 );
}
示例4: defineTriggerExecutionSpecificPoint
import javax.naming.directory.BasicAttributes; //导入依赖的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 );
}
}
示例5: createTriggerExecutionSubentry
import javax.naming.directory.BasicAttributes; //导入依赖的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: 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;
}
示例7: compareToSearchResult
import javax.naming.directory.BasicAttributes; //导入依赖的package包/类
boolean compareToSearchResult(String name) {
boolean successful = false;
switch (status) {
case LdapClient.LDAP_COMPARE_TRUE:
status = LdapClient.LDAP_SUCCESS;
entries = new Vector<>(1,1);
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
LdapEntry entry = new LdapEntry( name, attrs );
entries.addElement(entry);
successful = true;
break;
case LdapClient.LDAP_COMPARE_FALSE:
status = LdapClient.LDAP_SUCCESS;
entries = new Vector<>(0);
successful = true;
break;
default:
successful = false;
break;
}
return successful;
}
示例8: getURLContext
import javax.naming.directory.BasicAttributes; //导入依赖的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;
}
};
}
};
}
示例9: getURLContext
import javax.naming.directory.BasicAttributes; //导入依赖的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;
}
};
}
};
}
示例10: authenticate_shouldReturnAuthenticationResponseWithAuthConfigOnSuccessfulAuthentication
import javax.naming.directory.BasicAttributes; //导入依赖的package包/类
@Test
public void authenticate_shouldReturnAuthenticationResponseWithAuthConfigOnSuccessfulAuthentication() throws Exception {
final UserMapper userMapper = mock(UserMapper.class);
final AuthConfig validAuthConfig = mock(AuthConfig.class);
final LdapConfiguration validLdapConfiguration = mock(LdapConfiguration.class);
Attributes attributes = new BasicAttributes();
when(validAuthConfig.getConfiguration()).thenReturn(validLdapConfiguration);
when(ldapFactory.ldapForConfiguration(validAuthConfig.getConfiguration())).thenReturn(ldap);
when(ldap.authenticate(eq(credentials.getUsername()), eq(credentials.getPassword()), any(AbstractMapper.class))).thenThrow(new RuntimeException()).thenReturn(attributes);
when(validLdapConfiguration.getUserMapper(new UsernameResolver(credentials.getUsername()))).thenReturn(userMapper);
when(userMapper.mapFromResult(attributes)).thenReturn(mock(User.class));
final AuthenticationResponse authenticationResponse = ldapAuthenticator.authenticate(credentials, Arrays.asList(this.authConfig, validAuthConfig));
assertThat(authenticationResponse.getConfigUsedForAuthentication(), is(validAuthConfig));
}
示例11: 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;
}
示例12: 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;
}
示例13: getUserAttributes
import javax.naming.directory.BasicAttributes; //导入依赖的package包/类
/***************************************************************************
* Collect all the values from the table (Arguments), using this create the
* Attributes, this will create the Attributes for the User
* defined TestCase for Add Test
*
* @return The Attributes
**************************************************************************/
private Attributes getUserAttributes() {
Attributes attrs = new BasicAttributes(true);
Attribute attr;
for (JMeterProperty jMeterProperty : getArguments()) {
Argument item = (Argument) jMeterProperty.getObjectValue();
attr = attrs.get(item.getName());
if (attr == null) {
attr = getBasicAttribute(item.getName(), item.getValue());
} else {
attr.add(item.getValue());
}
attrs.put(attr);
}
return attrs;
}
示例14: testBind
import javax.naming.directory.BasicAttributes; //导入依赖的package包/类
@Test
public void testBind() throws Exception {
String dnToBind = "some dn to bind";
initializeTest(dnToBind);
Attributes attributes = new BasicAttributes();
attributes.put("some attribute name", "some attribute value");
body.put(SpringLdapProducer.ATTRIBUTES, attributes);
producer.sendBody("spring-ldap:"
+ SpringLdapTestConfiguration.LDAP_MOCK_NAME
+ "?operation=bind", body);
ArgumentCaptor<String> dnCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor
.forClass(Attributes.class);
ArgumentCaptor<Object> objectToBindCaptor = ArgumentCaptor
.forClass(Object.class);
Mockito.verify(ldapTemplate).bind(dnCaptor.capture(),
objectToBindCaptor.capture(), attributesCaptor.capture());
assertEquals(dnToBind, dnCaptor.getValue());
assertNull(objectToBindCaptor.getValue());
assertEquals(attributes, attributesCaptor.getValue());
}
示例15: testBind
import javax.naming.directory.BasicAttributes; //导入依赖的package包/类
@Test
public void testBind() throws Exception {
String dn = "some dn";
BasicAttributes attributes = new BasicAttributes();
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage();
Map<String, Object> body = new HashMap<String, Object>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.ATTRIBUTES, attributes);
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.BIND);
processBody(exchange, in, body);
verify(ldapTemplate).bind(eq(dn), isNull(), eq(attributes));
}