What are the authentication steps of UnboundID LDAP SDK - java-8

I am implementing a LDAP client to LDAP server which make a connection with the server and do authentication.What steps do I need to follow?

There are lot of options in UnboundID LDAP. You can use connection pool if you want and that will reduce extra load on LDAP server at the connection establishment.
To make the connection pool
try {
connection = new LDAPConnection(address, port);
BindResult bindResult = connection.bind(DN, password);
connectionPool = new LDAPConnectionPool(connection, max_numbof_connection);
} catch (LDAPException e) {
String es = e.getExceptionMessage();
System.out.println(es);
}
You can achieve this by making a single connection too.
First you need to make an unauthenticated connection using address and port and then bind that connection using a DN and password. At the bind request you may find whether given DN is an authorized one or not.
Example for authenticate user from a connection without Connection pool
LDAPConnection connection = new LDAPConnection();
connection.connect("server.example.com", 389);
connection.bind("uid=john.doe,ou=People,dc=example,dc=com", "password");

Related

UCP Connection pool cannot create connection after a database network error

I have a problem with the Oracle Universal Connection Pool (UCP) implemented in a Scala application, for an Oracle Database.
It works perfectly while there's a connection to the database, but when the network has some problem for a limited period of time (the application or the database goes offline) it obviously fails to create a Connection while the problem persists, but then it doesn't manage to create new ones when the application can ping the database again. The only way to get the application work again is to restart it.
I've set up a class in which I manage the connection, and I create the pool data source with this method:
private def createConnectionPool(
connectionString: String,
username: String,
password: String
): PoolDataSource =
{
val p = PoolDataSourceFactory.getPoolDataSource()
p.setConnectionPoolName("main_ucp_pool")
p.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource")
p.setURL(connectionString)
p.setUser(username)
p.setPassword(password)
p.setInitialPoolSize(5)
p.setMinPoolSize(3)
p.setMaxPoolSize(20)
p
}
private lazy val pds = createConnectionPool('url', 'username', 'pass')
Then, every time I need a database connection, I get it through this method invocation:
pds.getConnection()
Am I missing something in the code, or is it true that the pool data source should retry to establish a connection to the database when the getConnection method is invoked, even after a network problem?
In other words, if it fails to create the connection when the network goes down, the second time, if the application can now ping the database, the connection must be established?

ActiveMQ Connection is not working

I created the ActiveMQ Connection with ActiveMQConnectionFactory,
connectionFactory = new ActiveMQConnectionFactory("nio://0.0.0.0:" + activeMqPort);
connection = connectionFactory.createConnection();
connection.start();
Later some point of time I am using the connection to get the session:
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
While creating session from Connection it will fail with a NullPointerException (connection is null),
PS: Connection was working before, suddenly its null.
Can anyone explain it to me when this will happen and how to fix this ?
Your URI is incorrect for a client-side connection. nio:// is only relevant on the server-side, and specifying "0.0.0.0" is used by the server-side to instruct the server to listen on all ip interfaces.
Try this instead to connect to an ActiveMQ server running on the same computer as this client code:
connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:" + activeMqPort);
connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Bonus recommendations:
Externalize the entire client url, not just the port. This will allow you to specify multiple servers for failover, reconnect timeout parameters and other client connectivity settings that would otherwise require a code change.
Do not use CLIENT_ACKNOWLEDGE unless you really know what it does. Its is a source of a lot of pain and suffering if you don't clearly have a handle on how it works. If you want per-message Acknowledgement, use ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE. For non-transacted, use Session.AUTO_ACKNOWLEDGE.

Can't connect to ibm mq using jms

I had a problem with connecting to the IBM MQ queue from Java. I tried to change the passwords for the service of the IBM MQ, create a connection without specifying a login and password, but nothing happens. I wrote the code:
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
props.setProperty(Context.PROVIDER_URL, "file:/D:/JNDI/");
try {
InitialContext initialContext = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup(connectionFactoryName);
Destination destination = (Destination) initialContext.lookup(queueName);
initialContext.close();
Connection queueConnection = connectionFactory.createConnection("login", "password");// .createConnection();
which falls when I create a connection. I get an error:
JMSWMQ2013: Invalid credentials were passed to the queue manager QueueManager 'QM_LOCAL' in the 'Client' connection mode using the host 'localhost (1414)'.
Verify that the provided user name and password are correct in the queue administrator that you are connecting to.
can I turn off the authentication so that the method ".createConnection();" works? If not, where do I set the password? I Use the Windows.
Thanks.
p.s.: I get the completion code '2' ('MQCC_FAILED'), reason'2035' ('MQRC_NOT_AUTHORIZED').

How to know if an OracleConnection coming from the connection pool was used before

My application needs to authenticate all session on the DB via a trusted procedure (that sets some values in the session context). Currently this procedure is called for each new session just after it is opened.
I'd now like to improve this by removing unneeded round-trips. Connections from the connection pool which were used (and authenticated) before don't need to call the procedure again because the session context variables are still set on the server.
But I can't find a way to identify reused connections. Is there any way (which of course doesn't need a round-trip too)?
Architecture: Multiple client applications use the same DB account (a read-only account with synonyms to the real schema) to connect. After the connection it is required that each new session calls an authentication procedure to set some session context variables. These context variables are checked on select/insert/update/delete by Oracle FGAC (virtual private database).
My code:
OracleConnection conn = new OracleConnection();
conn.ConnectionString = _connectionString;
conn.Open();
if (true) { // TODO: Identify not yet authenticated connections.
using (OracleCommand cmd = new OracleCommand("authentication.login", conn)) {
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("i_user_id", OracleDbType.Int64).Value = _userId;
cmd.Parameters.Add("i_role_id", OracleDbType.Int64).Value = _roleId;
cmd.ExecuteNonQuery();
}
}
You could create a connection pool for your oracle connections.
And each connection you create could be inserted with a some key (using conn.setSessionInfo(key)) that can be verified later when you get the connection back.
The key can be a any thing of your choice or maybe a hashkey you generate.
I finally found an answer that clearly states that this isn't possible: ODP.NET connection pooling: How to tell if a connection has been used
You should clear all contexts and reset all packages anyway when you get a connection from a connectionpool. Add this authentication to your initialization.
Preparing an Oracle Connection after being retrieved from a ConnectionPool
I'm not clear what your authentication is doing - verifying that the connection comes from your app? - and whether you're passing anything to your procedure. Could you consider using a logon trigger to call your procedure from the DB side, only for the user your pool is using, as the session is created?

ADO.NET for oracle doesn't close connections

When connecting to oracle server from .NET application using ADO.NET for oracle, even if i closed the connection, the connection remains inactive at the Oracle server, so new connections could not be established because of the sessions per user limitation, is there is any way to make sure that all connections are closed? from Oracle server or from .NET application.
Thanks in advance
Could it be the connections stay open for a while due to connection pooling? Can you please paste some code showing how you close the connections? Also are you using ODP.NET or the Microsoft supplied classes?
You could try turning connection pooling off (add ;Pooling=false to the connection string in ODP.NET) to see if your issue is caused as a consequence of using it (just be aware that creating a new physical connection to the DB is an expensive operation, so you probably actually don't want to turn off connection pooling permantly).
Something similar to:
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString);
command.Connection = connection;
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

Resources