JT400.jar Disable Login Screen - jdbc

Can anyone help me out? I have small utility application that uses the Jt400-6.7.jar to connect to an AS400 server.
Please see the following code
private Connection buildConnection(String url, String userName, String password) throws ClassNotFoundException,
SQLException {
Connection connection = null;
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
DriverManager.setLoginTimeout(10000);
//OVER HERE!!!
connection = DriverManager.getConnection(url, userName, password);
return connection;
}
The code above works but if the the username or the password is wrong the application creates the following login screen. It happens when DriverManager.getConnection() is executed.
Cant post a picture but it looks something like this
Signon to the system X
System: AS400Server
User ID: User ID
Password: ********
O Default User ID
O Save Password
OK Cancel
Can anyone tell me how to disable this feature??

One way to disable this feature is to set the JVM property, com.ibm.as400.access.AS400.guiAvailable=false.
From a java command line, you would set this using java -Dcom.ibm.as400.access.AS400.guiAvailable=false ...
Here is an example using the jdbc client included in jt400.jar
C:\>java -cp jt400.jar -Dcom.ibm.as400.access.AS400.guiAvailable=false com.ibm.as400.access.jdbcClient.Main jdbc:as400:/SYSTEM
Warning: Unable to connect to jdbc:as400:/SYSTEM using null
CON is not defined
The second way to disable this feature is to use the prompt=false connection property. For example.
C:\jtopen_build\dist6>java -cp jt400.jar com.ibm.as400.access.jdbcClient.Main jdbc:as400:/SYSTEM;prompt=false
Warning: Unable to connect to jdbc:as400:/SYSTEM;prompt=false using null
CON is not defined

Another method for preventing the GUI password prompt.
AS400.setPasswordExpirationWarningDays(-1);
Properties properties = new Properties();
properties.put("extended metadata", "true");
properties.put("user", userProfile);
properties.put("password", password);
properties.put("driver", "native");
properties.put("prompt", "false");
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
Connection connection = DriverManager.getConnection("jdbc:as400://somedomain.com", properties);

Just to add, when calling a RPG program from java, same Sign-on pop up arrives.You can turn it off by setting com.ibm.as400.access.AS400 object's setGuiAvailable(false);

You can also set it when defining the DataSource:
final AS400JDBCDataSource dataSourceISeries = new AS400JDBCDataSource();
dataSourceISeries.setDatabaseName(...);
dataSourceISeries.setUser(...);
...
dataSourceISeries.setPrompt(false);

Related

Not able to connect to Oracle DB through Wallet from C#

I am trying to connect to the Vendor's database through the Wallet. For that, the vendor has provided a wallet zip files which contains two files (one .ora file and one .sso file) . The zip file contains tnsnames.ora and cwallet.sso
First, I installed the Oracle client version 19.0 Home1 which has created a file called sqlnet.ora automatically. I copied the file tnsnames.ora to the same folder where sqlnet.ora created, and tried different wasys to connect the database, but every attempt failed. I tried to implement in similar way which is explained in this link, but getting errors that "TNS:Lost contact", "TNS:Could not resolved the connect identifier specified".
I tried the solution which specified here, but ended up in error. Finally, the error now is "Connection failed because target host or object does not exist". The connection details are specified in tnsnames. ora that contains the service name and host name. I have added the Wallet location in sqlnet.ora file and also the following code:
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 1.2
SSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_CBC_SHA)
SSL_SERVER_DN_MATCH = ON
The connection code in C# is below:
//string strCon = "User Id =XXXX;Password=XXXXXXX;Data Source=(DESCRIPTION =(ADDRESS=(PROTOCOL=TCP)(HOST=XXXXXXXX)(PORT=2460))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXXX))" +
// "(SECURITY=(SSL_SERVER_CERT_DN='C=US,ST=Washington,L=Seattle,O=Amazon.com,OU=RDS,CN=mcsldb01.ckc6ued9hacf.ap-south1.rds.amazonaws.com')));";
using (OracleConnection con = new OracleConnection(strCon))
//using (OracleConnection con = new OracleConnection(#"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=XXXXXXXX)(PORT=2460)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXXX)));User Id=XXXX;Password=XXXXXXXX;"))
//using (OracleConnection con = new OracleConnection(cntn))
{
using (OracleCommand cmd = con.CreateCommand())
{
try
{
//TNS_ADMIN and wallet directory entries can be entered in the app.config file.
con.Open();
Console.WriteLine("Successfully connected to Oracle Autonomous Database");
//Retrieve database version info
cmd.CommandText = "SELECT BANNER FROM V$VERSION";
OracleDataReader reader = cmd.ExecuteReader();
reader.Read();
Console.WriteLine("Connected to " + reader.GetString(0));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
Please suggest any solution. Where I am going wrong? Not able to proceed further.
At a guess, it might have been a connection wallet not an SSL wallet that has been provided, ie, just a mechanism of hiding the username and password. If that is the case, the connection would look something like:
new OracleConnection(#"Data Source=NAME_IN_TNSNAMES;User Id=/"))
where NAME_IN_TNSNAMES maps to the entry in the tnsnames.ora file.
Examples of that (from a SQL Plus perspective) here
https://connor-mcdonald.com/2015/09/21/connection-shortcuts-with-a-wallet/

Connect to ec2 instance through JAVA

I have created REST API to create EC2 instance using AWS JAVA SDK provided.
Now I am trying to connect to created EC2 instance and then need to install software's in the instance again through java. I didn't find any appropriate article for this. Is there any possible way to do this? I don't want to use SSH client like putty.. Thanks..
Sounds like you're looking for a java ssh client.
You should set up key authentication and use the ssh client library from java to execute the installation for you.
See this post: for a list of solutions
public static void connectToEC2(){
try{
JSch jsch=new JSch();
String user = "User-name";
String host = "host";
int port = 22;
File directory = new File(".");
String privateKey = directory.getCanonicalPath() + File.separator + "pem file path";
jsch.addIdentity(privateKey);
System.out.println("identity added ");
Session session = jsch.getSession(user, host, port);
System.out.println("session created.");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel=session.openChannel("shell");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect(3*1000);
}
catch(Exception e){
System.out.println(e);
}
}

javamail ignoring socks proxy

I've setup javamail to run through a socks proxy, but it won't go through it. I tried setting both mail.smtp.socks.host and mail.smtp.socks.port but it keeps going direct to the mail host. I feel like I'm missing something very basic. any help would be appreciated. Here's my properties:
props.setProperty("mail.smtp.host", this.smtpHost);
props.setProperty("mail.smtp.port", Integer.toString(this.smtpPort));
props.setProperty("mail.smtp.user", this.smtpUser);
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.starttls.enable", Boolean.toString(this.smtpTLS));
props.setProperty("mail.debug", "true");
if (this.useSOCKSProxy) {
logger.info("Using proxy");
props.setProperty("mail.smtp.socks.host", "127.0.0.1");
props.setProperty("mail.smtp.socks.port", Integer.toString(1080));
props.setProperty("mail.smtps.socks.host", this.socksProxyHost);
props.setProperty("mail.smtps.socks.port", Integer.toString(this.socksProxyPort));
props.setProperty("proxySet", "true");
props.setProperty("socksProxyHost", this.socksProxyHost);
props.setProperty("socksProxyPort", Integer.toString(this.socksProxyPort));
}
//Session session = Session.getInstance(props, new SmtpAuthenticator(this.smtpUser,this.smtpPassword));
Session session = Session.getDefaultInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpUser, smtpPassword);
}
});
//Session session = Session.getInstance(props, null);
session.setDebugOut(System.out);
session.setDebug(true);
//Transport tr = session.getTransport("smtp");
//tr.connect();
//tr.connect(this.smtpHost,this.smtpPort, this.smtpUser, this.smtpPassword);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(this.smtpFrom));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
msg.setSubject(subject);
msg.setText(msgToSend.toString());
msg.saveChanges();
Transport.send(msg);
Start by fixing these common mistakes.
If that doesn't solve the problem, post the debugging output. Set the System property "mail.socket.debug" to "true" to get additional debugging output.
What version of JavaMail are you using? What JDK?
Unless "props" is coming from System.getProperties(), setting "socksProxyHost" has no effect. And if you do set it as a System property, you don't need the JavaMail socks properties.
You can try to figure out the correct combination of properties, including the common mistakes Bill mentioned, or you can also go the easy way and let Simple Java Mail (open source) figure it out for you:
Your example converted:
Mailer mailer = new Mailer(
new ServerConfig(smtpHost, smtpPort, smtpUser, smtpPassword),
TransportStrategy.SMTP_TLS,
this.useSOCKSProxy ? new ProxyConfig(socksProxyHost, socksProxyPort) : null
);
mailer.setDebug(true);
mailer.sendMail(new EmailBuilder()
.from(null, smtpForm)
.to(null, email)
.subject(subject)
.text(msgToSend.toString())
.build());
Note how you don't have to deal with any properties or JavaMail API anymore. You can also use authenticated proxy if you need.

Windows Authentication With WMI

I want to use Windows current credential when using WMI to query data on a remote machine, but in many examples I found that I have to use Connection object which needs you to provide a username, password and authority for validating username and password as shown below:
Dim connection As New ConnectionOptions
connection.Username = userNameBox.Text
connection.Password = passwordBox.Text
connection.Authority = "ntlmdomain:MyDomain"
Dim scope As New ManagementScope( _
"\\RemoteMachine\root\CIMV2", connection)
scope.Connect()
I want to bypass these inputs and use current Windows logon credentials instead, is there any way for this?
Here' the C# example with connnection options using Windows credentials.
ConnectionOptions connectionOptions = new ConnectionOptions
{
Authentication = AuthenticationLevel.PacketPrivacy,
Impersonation = ImpersonationLevel.Impersonate
};

How to connect to Play Framework in-memory database using JDBC?

I use the in-memory database that comes with Play Framework, when I have db=mem in the configuration file, for development.
How can I connect to this database using JDBC? and not the JPA that is the default way.
I have tried with this method in my controller:
public static void addToDB() {
try {
Connection conn = DriverManager.getConnection("jdbc:h2:mem:play");
Statement stmt = conn.createStatement();
stmt.execute(sql);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
But I get an error message that I need to provide an username and password:
org.h2.jdbc.JdbcSQLException: Wrong user name or password [8004-149]
If I visit the web-console on /#db the username sa is used and no password.
Now I logged in via the /#db interface and created a table users.
Then I connected to the database in a controller method and used this jdbc-string: jdbc:h2:mem:play:sa and then tried to insert to the table users but I get this error message:
org.h2.jdbc.JdbcSQLException: Table "USERS" not found; SQL statement:
How should I connect to the in-memory H2 database in Play Framework using JDBC?
DB.getConnection(), should do the job.
Try:
Connection conn = DriverManager.getConnection("jdbc:h2:mem:play", "sa", "");
because as you wrote, "the username sa is used and no password."

Resources