茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1664626 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00024.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2021/8/11 8:23:51

Java InitialLdapContext類代碼示例

本文整理匯總了Java中javax.naming.ldap.InitialLdapContext的典型用法代碼示例。如果您正苦於以下問題:Java InitialLdapContext類的具體用法?Java InitialLdapContext怎麽用?Java InitialLdapContext使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

InitialLdapContext類屬於javax.naming.ldap包,在下文中一共展示了InitialLdapContext類的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: getContext


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
private LdapContext getContext() throws Exception {
Hashtable<String, String> envDC = new Hashtable<String, String>();
envDC.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
envDC.put(
Context.PROVIDER_URL,
GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.url"));
envDC.put(
Context.SECURITY_AUTHENTICATION,
"simple");
envDC.put(
Context.SECURITY_PRINCIPAL,
GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.principal"));
envDC.put(
Context.SECURITY_CREDENTIALS,
GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.credentials"));
return new InitialLdapContext(envDC, null);
}

開發者ID:GovernIB, 項目名稱:helium, 代碼行數:20, 代碼來源: PersonesPluginLdap.java


示例2: init


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
private void init()
throws Exception
{
@SuppressWarnings("UseOfObsoleteCollectionType")
Hashtable<String,String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, sdsUrl);
if (ConditionalCompilationControls.LDAPS && !ConditionalCompilationControls.OPENTEST) {
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.SECURITY_AUTHENTICATION, "none");
if (ConditionalCompilationControls.LDAPOVERTLS && !ConditionalCompilationControls.OPENTEST) {
env.put("java.naming.ldap.factory.socket", "org.warlock.spine.connection.SpineSecurityContext");
}
}
ldapContext = new InitialLdapContext(env, null);
}

開發者ID:DamianJMurphy, 項目名稱:SpineTools-Java, 代碼行數:17, 代碼來源: SDSconnection.java


示例3: setSchemaContext


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
private void setSchemaContext(KdcConfiguration configuration, DirectoryService service,
String connectionUser)
throws DirectoryServerException {
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(DirectoryService.JNDI_KEY, service);
env.put(Context.SECURITY_PRINCIPAL, connectionUser);
env.put(Context.SECURITY_CREDENTIALS, configuration.getSystemAdminPassword());
env.put(Context.SECURITY_AUTHENTICATION, ConfigurationConstants.SIMPLE_AUTHENTICATION);
env.put(Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());
env.put(Context.PROVIDER_URL, SchemaConstants.OU_SCHEMA);
try {
schemaRoot = new InitialLdapContext(env, null);
} catch (NamingException e) {
throw new DirectoryServerException(
"Unable to create Schema context with user " + connectionUser, e);
}
}

開發者ID:wso2-attic, 項目名稱:carbon-identity, 代碼行數:21, 代碼來源: ApacheKDCServer.java


示例4: bindDNReferralAuthentication


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* This method validates absoluteName and credential against referral LDAP and returns used user DN.
*
* <ol>
* <li> Parses given absoluteName to URL and DN
* <li> creates initial LDAP context of referral LDAP to validate credential
* <li> closes the initial context
* </ol>
*
* It uses all options from login module setup except of ProviderURL.
*
* @param userDN - userDN which has to be used instead of parsed absoluteName (if is null, use absoluteName) - value is gained using distinguishedNameAttribute
* @param absoluteName - absolute user DN
* @param credential
* @return used user DN for validation
* @throws NamingException
*/
private String bindDNReferralAuthentication(final String userDN, String absoluteName, Object credential)
throws NamingException
{
URI uri;
try {
uri = new URI(absoluteName);
}
catch (URISyntaxException e)
{
throw PicketBoxMessages.MESSAGES.unableToParseReferralAbsoluteName(e, absoluteName);
}
String name = (userDN != null ? userDN : uri.getPath().substring(1));
String namingProviderURL = uri.getScheme() + "://" + uri.getAuthority();
Properties refEnv = constructLdapContextEnvironment(namingProviderURL, name, credential);
InitialLdapContext refCtx = new InitialLdapContext(refEnv, null);
refCtx.close();
return name;
}

開發者ID:picketbox, 項目名稱:picketbox, 代碼行數:38, 代碼來源: LdapExtLoginModule.java


示例5: testGetControlInstanceControl


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control)'</p>
* <p>Here we are going to test if we can get an instance with the controls sended.</p>
*/
public void testGetControlInstanceControl() {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
MockControl[] cs = { new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
MockControl cs2 = new MockControl("c1", false, new byte[] { 1, 2, 3, 4 });
InitialLdapContext ilc=new InitialLdapContext(env, cs);
assertEquals(cs2,ControlFactory.getControlInstance(cs2,ilc,env));
} catch (NamingException e) {
}
}

開發者ID:shannah, 項目名稱:cn1, 代碼行數:21, 代碼來源: TestControlFactoryWhiteBoxDevelopment.java


示例6: testReconnect003


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* <p>
* Test method for
* 'javax.naming.ldap.InitialLdapContext.reconnect(Control[])'
* </p>
* <p>
* Here we are testing if this method correctly reconnects to the LDAP
* server. In this case we are using a different set of controls for the
* reconnection.
* </p>
* <p>
* The expected result is a reconection with the new set of controls.
* </p>
*/
public void testReconnect003() throws Exception {
System
.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
Control[] cs = {
new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
Control[] cs2 = {
new MockControl("c2", false, new byte[] { 1, 2, 3, 4 }),
new MockControl("c2", true, new byte[] { 'a', 'b', 'c', 'd' }), };
InitialLdapContext ilc = new InitialLdapContext(null, cs);
ilc.reconnect(cs2);
assertEquals(cs2, ilc.getConnectControls());
ilc.close();
}

開發者ID:shannah, 項目名稱:cn1, 代碼行數:30, 代碼來源: TestInitialLdapContext.java


示例7: testConnectControls3


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
public void testConnectControls3() throws Exception {
// set connect controls by InitialLdapContext
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
InitialLdapContext initialDirContext = new InitialLdapContext(env,
new Control[] { new SortControl("", Control.NONCRITICAL) });
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_SEARCH_RESULT_DONE,
new EncodableLdapResult(), null) });
LdapContext context = (LdapContext) initialDirContext.lookup("");
Control[] controls = context.getConnectControls();
assertNotNull(controls);
assertEquals(1, controls.length);
Control c = controls[0];
assertTrue(c instanceof SortControl);
assertEquals(Control.NONCRITICAL, c.isCritical());
}

開發者ID:shannah, 項目名稱:cn1, 代碼行數:21, 代碼來源: LdapContextServerMockedTest.java


示例8: findAccountByAccountName


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* Find account by account name.
*
* @param accountName the account name
* @return the search result
* @throws NamingException the naming exception
*/
protected SearchResult findAccountByAccountName(String accountName) throws NamingException {
String searchFilter = String.format(searchFilterPattern, accountName);
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
InitialLdapContext ctx = new InitialLdapContext(env, null);
try {
NamingEnumeration<SearchResult> results = ctx.search(searchBase, searchFilter, searchControls);
if (!results.hasMoreElements()) {
throw new UserConfigLoaderException("LDAP Search returned no accounts");
}
SearchResult searchResult = results.nextElement();
if (results.hasMoreElements()) {
throw new UserConfigLoaderException("More than one account found in ldap search");
}
return searchResult;
} finally {
ctx.close();
}
}

開發者ID:apache, 項目名稱:lens, 代碼行數:27, 代碼來源: LDAPBackedDatabaseUserConfigLoader.java


示例9: testGetControlInstanceControl


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control)'</p>
* <p>Here we are gonna test if we can get an instance with the controls sended.</p>
*/
public void testGetControlInstanceControl() {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
MockControl[] cs = { new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
MockControl cs2 = new MockControl("c1", false, new byte[] { 1, 2, 3, 4 });
InitialLdapContext ilc=new InitialLdapContext(env, cs);
assertEquals(cs2,ControlFactory.getControlInstance(cs2,ilc,env));
} catch (NamingException e) {
}
}

開發者ID:freeVM, 項目名稱:freeVM, 代碼行數:21, 代碼來源: TestControlFactoryWhiteBoxDevelopment.java


示例10: testReconnect003


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* <p>
* Test method for
* 'javax.naming.ldap.InitialLdapContext.reconnect(Control[])'
* </p>
* <p>
* Here we are testing if this method reconnects to the LDAP server using
* the supplied controls and this context's environment. In this case we are
* sending a new set of controls to reconection.
* </p>
* <p>
* The expected result is a reconection with the new set of controls.
* </p>
*/
public void testReconnect003() throws Exception {
System
.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
Control[] cs = {
new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
Control[] cs2 = {
new MockControl("c2", false, new byte[] { 1, 2, 3, 4 }),
new MockControl("c2", true, new byte[] { 'a', 'b', 'c', 'd' }), };
InitialLdapContext ilc = new InitialLdapContext(null, cs);
ilc.reconnect(cs2);
assertEquals(cs2, ilc.getConnectControls());
ilc.close();
}

開發者ID:freeVM, 項目名稱:freeVM, 代碼行數:30, 代碼來源: TestInitialLdapContext.java


示例11: setUp


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
protected void setUp() throws Exception {
super.setUp();
configuration = new MutableServerStartupConfiguration();
configuration.setWorkingDirectory(new File(workingDir));
cleanWorkingDir(configuration.getWorkingDirectory());
port = AvailablePortFinder.getNextAvailable(1024);
configuration.setLdapPort(port);
// configuration.setShutdownHookEnabled(false);
serverEnv = new Hashtable<String, Object>(configuration
.toJndiEnvironment());
initialAuth();
serverEnv.put(Context.INITIAL_CONTEXT_FACTORY,
ServerContextFactory.class.getName());
serverEnv.put(Context.PROVIDER_URL, "");
rootDSE = new InitialLdapContext(serverEnv, null);
}

開發者ID:freeVM, 項目名稱:freeVM, 代碼行數:21, 代碼來源: Support_LdapTest.java


示例12: getFullyQualifiedNameByUserId


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
protected String getFullyQualifiedNameByUserId(String userId) throws UnauthorizedOperationException {
env.put(Context.SECURITY_PRINCIPAL, ctxPrinciplePattern.replaceAll(userNamePattern, delegatedUserName));
env.put(Context.SECURITY_CREDENTIALS, delegatedUserPassword);
try {
LdapContext ctx = new InitialLdapContext(env,null);
String searchFilter = searchFilterPattern.replaceAll(userNamePattern, userId);
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase,
searchFilter, searchControls);
SearchResult searchResult = null;
if (results.hasMoreElements()) {
searchResult = results.nextElement();
return searchResult.getNameInNamespace();
}
return null;
} catch (NamingException e) {
throw new UnauthorizedOperationException(e.getMessage());
}
}

開發者ID:ndexbio, 項目名稱:ndex-rest, 代碼行數:25, 代碼來源: LDAPAuthenticator.java


示例13: createContext


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
public LdapContext createContext()
{
init();
final Hashtable<String, String> env;
final String authentication = ldapConfig.getAuthentication();
if ("none".equals(authentication) == false) {
env = createEnv(ldapConfig.getManagerUser(), ldapConfig.getManagerPassword());
} else {
env = createEnv(null, null);
}
try {
final LdapContext ctx = new InitialLdapContext(env, null);
return ctx;
} catch (final NamingException ex) {
log.error("While trying to connect LDAP initally: " + ex.getMessage(), ex);
throw new RuntimeException(ex);
}
}

開發者ID:micromata, 項目名稱:projectforge-webapp, 代碼行數:19, 代碼來源: LdapConnector.java


示例14: ActiveDirectory


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
public ActiveDirectory(String serverName, String username, String password,
String domain) throws NamingException {
if (StringUtils.isEmpty(domain))
throw new NamingException("The domain is empty");
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
domainSearchName = getDomainSearch(domain);
String login = StringUtils.fastConcat(username, "@", domain);
if (serverName != null) {
properties.put(Context.PROVIDER_URL,
StringUtils.fastConcat("ldap://", serverName, ":389"));
}
properties.put(Context.SECURITY_PRINCIPAL, login);
properties.put(Context.SECURITY_CREDENTIALS, password);
properties.put(Context.REFERRAL, "follow");
properties.put("java.naming.ldap.attributes.binary", "objectSID");
dirContext = new InitialLdapContext(properties, null);
}

開發者ID:jaeksoft, 項目名稱:opensearchserver, 代碼行數:21, 代碼來源: ActiveDirectory.java


示例15: getCurrentSession


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
/**
* Return the session which the current thread holds. If not exist, a new
* session will be created and bind to current thread.
*
* @return
*/
@Override
public Session getCurrentSession() {
Map.Entry<Session, InitialLdapContext> current = sessions.get();
if (null == current) {
try {
InitialLdapContext ldapConnection = getContext();
Session session = new SessionImpl(this, ldapConnection, true);
current = new AbstractMap.SimpleEntry<Session, InitialLdapContext>(
session, ldapConnection);
} catch (NamingException e) {
throw new ODMException("Cannot instantiate a session", e);
}
}
return current.getKey();
}

開發者ID:xingyuli, 項目名稱:some-ldap, 代碼行數:22, 代碼來源: AbstractThreadLocalSessionFactory.java


示例16: getDirContextInstance


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
@Override
protected DirContext getDirContextInstance(Hashtable<String, Object> env) throws NamingException {
String url = (String) env.get(Context.PROVIDER_URL);
try {
if (new URI(url).getScheme().equalsIgnoreCase("ldaps")) {
env.put("java.naming.ldap.factory.socket", "cz.inqool.uas.security.ldap.ssl.DummySSLSocketFactory");
}
} catch (URISyntaxException e) {
log.error("LDAP URL {} is wrong", url, e);
}
return new InitialLdapContext(env, null);
}

開發者ID:LIBCAS, 項目名稱:ARCLib, 代碼行數:13, 代碼來源: DummySSLLdapContextSource.java


示例17: userList


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
public static ArrayList<String> userList()
{
loadAdmindetails();
System.out.println("Details Loaded");
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, url);
props.put(Context.SECURITY_PRINCIPAL, "cn="+ldapadminuname+",dc=serverless,dc=com");//adminuser - User with special priviledge, dn user
props.put(Context.SECURITY_CREDENTIALS, ldapadminpassword);//dn user password
ArrayList<String> resp = new ArrayList<String>();
try {
LdapContext ctx = new InitialLdapContext(props, null);
ctx.setRequestControls(null);
NamingEnumeration<?> namingEnum = ctx.search("ou=ias,dc=serverless,dc=com", "(objectclass=posixAccount)", AuthenticationService.getSimpleSearchControls());
while (namingEnum.hasMore ()) {
SearchResult result = (SearchResult) namingEnum.next ();
Attributes attrs = result.getAttributes ();
resp.add(attrs.get("cn").toString().substring(4));
}
namingEnum.close();
} catch (Exception e) {
e.printStackTrace();
}
return resp;
}

開發者ID:hemantverma1, 項目名稱:ServerlessPlatform, 代碼行數:28, 代碼來源: AuthenticationService.java


示例18: getByDn


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
public Attributes getByDn(final String dn) throws NamingException {
LdapContext ctx = new InitialLdapContext(env, null);
Attributes result = ctx.getAttributes(dn);
ctx.close();
return result;
}

開發者ID:klenkes74, 項目名稱:openshift-ldapsync, 代碼行數:8, 代碼來源: LdapServer.java


示例19: search


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
public NamingEnumeration<SearchResult> search(final String baseDN, final String filter) throws NamingException {
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
LdapContext ctx = new InitialLdapContext(env, null);
NamingEnumeration<SearchResult> result = ctx.search(baseDN, filter, searchControls);
ctx.close();
return result;
}

開發者ID:klenkes74, 項目名稱:openshift-ldapsync, 代碼行數:11, 代碼來源: LdapServer.java


示例20: startKerberos


import javax.naming.ldap.InitialLdapContext; //導入依賴的package包/類
@SuppressWarnings("unused")
private ApacheDS startKerberos() throws Exception {
Preconditions.checkState(ldapServer.isStarted());
kdcServer.setDirectoryService(directoryService);
// FIXME hard-coded ports
kdcServer.setTransports(new TcpTransport(6088), new UdpTransport(6088));
kdcServer.setEnabled(true);
kdcServer.setPrimaryRealm(realm);
kdcServer.setSearchBaseDn(baseDn);
kdcServer.setKdcPrincipal("krbtgt/" + realm + "@" + baseDn);
kdcServer.start();
// -------------------------------------------------------------------
// Enable the krb5kdc schema
// -------------------------------------------------------------------
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(DirectoryService.JNDI_KEY, directoryService);
env.put(Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());
env.put(Context.PROVIDER_URL, ServerDNConstants.OU_SCHEMA_DN);
InitialLdapContext schemaRoot = new InitialLdapContext(env, null);
// check if krb5kdc is disabled
Attributes krb5kdcAttrs = schemaRoot.getAttributes("cn=Krb5kdc");
boolean isKrb5KdcDisabled = false;
if (krb5kdcAttrs.get("m-disabled") != null) {
isKrb5KdcDisabled = ((String) krb5kdcAttrs.get("m-disabled").get()).equalsIgnoreCase("TRUE");
}
// 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);
}
return this;
}

開發者ID:SonarQubeCommunity, 項目名稱:sonar-activedirectory, 代碼行數:39, 代碼來源: ApacheDS.java



注: 本文中的javax.naming.ldap.InitialLdapContext類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。


原文出處:Java InitialLdapContext類代碼示例 - 純淨天空
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|