I am using this below code to connect to the ldap and assigning roles to the users.
IdentityStoreFactoryBuilder builder =
new IdentityStoreFactoryBuilder();
IdentityStoreFactory oidFactory = null;
IdentityStore oidStore = null;
Hashtable factEnv = new Hashtable();
Hashtable storeEnv = new Hashtable();
factEnv.put(OIDIdentityStoreFactory.ST_SECURITY_PRINCIPAL, "Obu");
factEnv.put(OIDIdentityStoreFactory.ST_SECURITY_CREDENTIALS,
"password123");
factEnv.put(OIDIdentityStoreFactory.ST_LDAP_URL,
"ldap://localhost:3060/");// here i'm getting exception
oidFactory =
builder.getIdentityStoreFactory("oracle.security.idm.providers.oid.OIDIdentityStoreFactory",
factEnv);
storeEnv.put(OIDIdentityStoreFactory.ADF_IM_SUBSCRIBER_NAME,
"dc=us,dc=oracle,dc=com");
oidStore = oidFactory.getIdentityStoreInstance(storeEnv);
Exception stack trace is:
Exception in thread "main" oracle.security.idm.ConfigurationException: javax.naming.CommunicationException: localhost:3060 [Root exception is java.net.ConnectException: Connection refused: connect]
at oracle.security.idm.providers.stdldap.TestConnectionPool.execute(LDIdentityStoreFactory.java:1026)
at oracle.security.idm.providers.stdldap.LDIdentityStoreFactory.setupConnPool(LDIdentityStoreFactory.java:620)
at oracle.security.idm.providers.stdldap.LDIdentityStoreFactory.setup(LDIdentityStoreFactory.java:333)
at oracle.security.idm.providers.oid.OIDIdentityStoreFactory.<init>(OIDIdentityStoreFactory.java:56)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at oracle.security.idm.IdentityStoreFactoryBuilder.getIdentityStoreFactory(IdentityStoreFactoryBuilder.java:128)
at view.AddRolesToUsers.main(AddRolesToUsers.java:60)
Caused by: javax.naming.CommunicationException: localhost:3060 [Root exception is java.net.ConnectException: Connection refused: connect]
at com.sun.jndi.ldap.Connection.<init>(Connection.java:210)
at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1580)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2652)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:134)
at oracle.security.idm.providers.stdldap.TestConnectionPool.run(LDIdentityStoreFactory.java:1006)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at com.sun.jndi.ldap.Connection.createSocket(Connection.java:352)
at com.sun.jndi.ldap.Connection.<init>(Connection.java:187)
java.net.ConnectException: Connection refused
means The port name you have specified for the LDAP server is incorrect. Also check for other parameters you are passing those are making it unreachable.
Nothing listening at the port. Where did you get port 3060 from? The usual LDAP port is 389, or 636 for LDAPS.
I got the same error. coz I did not give some below props in application.properties. please do not forget to give those props.
spring.ldap.embedded.ldif = classpath:test-server.ldif
spring.ldap.embedded.base-dn = dc=springframework,dc=org
spring.ldap.embedded.port = 8389
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.