Glassfish 4 no password credential for resource - java

I have set up a project to use Glassfish 4 with a resource that links back to a MySql database and I am using Eclipse Keplar. I have set up the connection pool with the relevant details and pinging it from the glassfish admin page succeeds. I have an EJB project with JPA set up to access the resource but when access is atempted either in a browser or Eclipse I get a "No database selected" error.
After searching around I found that there are issues with the Url parameter of the pool and renaming that parameter to URL might solve it. the post I found also suggested that I enter the connection string as he suspected that different calls were being made and the string was not getting constructed correctly outside of Glassfish. I did these things but I then get an error "No Password Credential" even though I do have the password entered in the connection string.
Has anyone else encountered this and have any advice as to what the problem is and how I can solve it?

For me, editing the URL and Url parameters didn't work. However after restarting Glassfish (domain), the problem disappeared.

I have figured this out and it was the url value that needed to be set correctly. I didn't need it all but I did need to set the server and database name on it:
jdbc:mysql://localhost:3306/<DB Name Here>
I had changed the parameter name to URL from Url but it turns out that this is not required.I have no idea why this step is required as the values are all there in other parameters and the ping succeeds from the admin pages.

MYSQL and Glassfish.
In glassfish 4.0 if "No password credential found" error appears whenever you try to ping, it most probably means, you did not setup password(you gave empty password) when you first installed mysql server on your system, glassfish4.0 has a problem with empty password. Either you need to reset the password or uninstall the mysql server completely, and then re-install, by giving new password. To uninstall the mysql-server completely please flow this link, https://askubuntu.com/questions/640899/how-do-i-uninstall-mysql completely it worked for me.

I am using Payara 5.181 and after I changed some properties and clicked flush, it throwed exceptions and ping resulted in this error. After domain restart it works, don't know why.

Related

Connection Java - MySQL : Public Key Retrieval is not allowed

I try to connect MySQL database with Java using connector 8.0.11. Everything seems to be OK, but I get this exception:
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108) at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at
com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:444) at
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) at
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) at
com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:438) at
com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:146) at
com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:119) at
ConnectionManager.getConnection(ConnectionManager.java:28) at
Main.main(Main.java:8)
Here is my Connection Manager class:
public class ConnectionManager {
public static final String serverTimeZone = "UTC";
public static final String serverName = "localhost";
public static final String databaseName ="biblioteka";
public static final int portNumber = 3306;
public static final String user = "anyroot";
public static final String password = "anyroot";
public static Connection getConnection() throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUseSSL( false );
dataSource.setServerTimezone( serverTimeZone );
dataSource.setServerName( serverName );
dataSource.setDatabaseName( databaseName );
dataSource.setPortNumber( portNumber );
dataSource.setUser( user );
dataSource.setPassword( password );
return dataSource.getConnection();
}
}
You should add client option to your mysql-connector allowPublicKeyRetrieval=true to allow the client to automatically request the public key from the server. Note that allowPublicKeyRetrieval=True could allow a malicious proxy to perform a MITM attack to get the plaintext password, so it is False by default and must be explicitly enabled.
See MySQL .NET Connection String Options
you could also try adding useSSL=false when you use it for testing/develop purposes
example:
jdbc:mysql://localhost:3306/db?allowPublicKeyRetrieval=true&useSSL=false
For DBeaver users:
Right click your connection, choose "Edit Connection"
On the "Connection settings" screen (main screen) click on "Edit Driver Settings"
Click on "Connection properties", (In recent versions it named "Driver properties")
Right click the "user properties" area and choose "Add new property"
Add two properties: "useSSL" and "allowPublicKeyRetrieval"
Set their values to "false" and "true" by double clicking on the "value" column
When doing this from DBeaver I had to go to "Connection settings" -> "SSL" tab and then :
uncheck the "Verify server certificate"
check the "Allow public key retrival"
This is how it looks like.
Note that this is suitable for local development only.
Use jdbc url as :
jdbc:mysql://localhost:3306/Database_dbName?allowPublicKeyRetrieval=true&useSSL=False;
PortNo: 3306 can be different in your configuation
Alternatively to the suggested answers you could try and use mysql_native_password authentication plugin instead of caching_sha2_password authentication plugin.
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password_here';
I updated this parameter when I faced the issue of "public-key-retrieval-is-not-allowed" with root account.
Open DBeaver->Edit connection->find driver properties->allowPublicKeyRetrieval=true and useSSl=true
spring.datasource.url=jdbc:mysql://localhost:3306/database?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false
You can insert this line to your applications.properties file and this means,
spring.datasource.url=jdbc:mysql://localhost:3306/ This one uses mysql as the database service. I think this can changed by using relavent name and the port of your database name.
database?createDatabaseIfNotExist=true = use the database named database if you haven't already make a database like that, make a new one.
allowPublicKeyRetrieval=true = to allow the client to automatically request the public key from the server. (This part might be additional)
useSSL=false = This will disable SSL and also suppress the SSL errors
Furthermore, be alert about the spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect property in the same file.
Finally check whether you've added following dependency in dependencies in your pom.xml file.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
First of all, please make sure your Database server is up and running.
I was getting the same error, after trying all the answers listed here I found out that my Database server was not running.
You can check the same from MySQL Workbench, or Command line using
mysql -u USERNAME -p
This sounds obvious, but many times we assume that Database server is up and running all the time, especially when we are working on our local machine, when we restart/shutdown the machine, Database server will be shutdown automatically.
I solve this issue using below configuration on spring boot framework
spring.datasource.url=jdbc:mysql://localhost:3306/db-name?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
This also can be happened due to wrong user name or password.
As solutions I've added allowPublicKeyRetrieval=true&useSSL=false part but still I got error then I checked the password and it was wrong.
Another way, on DBeaver.
You can edit the connection of a database, go to SSL tab in connection settings. There's a checkbox "allow public key retrieval" mark it as true. That'll sove the issue.
The above error in my case was actually due to the wrong username and password.
Solving the issue:
1. Go to the line DriverManager.getConnection("jdbc:mysql://localhost:3306/?useSSL=false", "username", "password");
The fields username and password might be wrong. Enter the username and password which you use to start your mysql client. The username is generally root and password is the string which you enter when a screen similar to this appears Startup screen of mysql
Note: The portname 3306 might be different in your case.
In MySQL 8.0 the default authentication plugin was changed from mysql_native_password to caching_sha2_password.
See https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password for more information about this change.
What that means is that in order to use caching_sha2_password the connection must do one of the following:
use a secure connection (useSSL=true)
use an unencrypted connection that supports password exchange using an RSA key pair (useSSL=false and additional configuration parameters - see https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html)
You have a few options:
ALTER the users to use the mysql_native_password plugin (like how it was doing historically and will also work with older clients / connections which don't support caching_sha2_password)
useSSL=true
useSSL=false and configure public key retrieval (this doesn't mean using allowPublicKeyRetrieval=true which would avoid the error - but defeats the objective of this extra security and is slow - it does mean using something like server-public-key-path to point to the client side copy of the public key)
I found this issue frustrating because I was able to interact with the database yesterday, but after coming back this morning, I started getting this error.
I tried adding the allowPublicKeyRetrieval=true flag, but I kept getting the error.
What fixed it for me was doing Project->Clean in Eclipse and Clean on my Tomcat server. One (or both) of those fixed it.
I don't understand why, because I build my project using Maven, and have been restarting my server after each code change. Very irritating...
This solution worked for MacOS Sierra, and running MySQL version 8.0.11. Please make sure driver you have added in your build path - "add external jar" should match up with SQL version.
String url = "jdbc:mysql://localhost:3306/syscharacterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
In my case it was user error. I was using the root user with an invalid password. I am not sure why I didn't get an auth error but instead received this cryptic message.
Give connection URL as
jdbc:mysql://localhost:3306/hb_student_tracker?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC
If you are getting the following error while connecting the mysql (either local or mysql container running the mysql):
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
Solution:
Add the following line in your database service:
command: --default-authentication-plugin=mysql_native_password
Update the useSSL=true in spring boot application connection with mysql;
jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8&useSSL=true&useLegacyDatetimeCode=false&serverTimezone=UTC
I was also facing such an issue while dockerizing our existing application. The solution si to add allowPublicKeyRetrieval connection option of MySQL with a value of true to the JDBC connection string.
If that is not working , try adding useSSL option to false as well .
The resultant string would look like this :
jdbc:mysql://<database server ip>:3306/databaseName?allowPublicKeyRetrieval=true&useSSL=false
Setting Server Time Zone to my local place, fixed the issue.
My problem was in pom.xml (spring boot).
My pom.xml had two dependencies entries for different databases. Make sure to keep only the MySQL dependency and remove any other database dependency entry.

Error connecting to Oracle database using JDBC [duplicate]

I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong?
Update:
I am using JDBC.
Database is local, and I actually had it working but it stopped working just today. I'm not really sure why though. Would you mind giving me some procedures to follow by since I don't know much.
Either:
The database isn't running
You got the URL wrong
There is a firewall in the way.
(This strange error message is produced by Oracle's JDBC driver when it can't connect to the database server. 'Network adapter' appears to refer to some component of their code, which isn't very useful. Real network adapters (NICs) don't establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)
I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.
private final String DB_URL = "jdbc:oracle:thin:#localhost:1521:orcll"; // 1521 my wrong port
go to your localhost
(my localhost address) : https://localhost:1158/em
login
user name
password
connect as --> normal
Below 'General' click on LISTENER_localhost
look at you port number
Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
Connect to port 1522
Edit you connection
change port 1521 to 1522.
done
Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:
HOST = localhost
to
HOST = 192.168.XX.XX
then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.
I figured out that in my case, my database was in different subnet than the subnet from where i was trying to access the db.
I had this error when i renamed the pc in the windows-properties. The pc-name must be updated in the listener.ora-file
Most probably you have listener configured wrongly, the hostname you specify in connection string must be the same as in the listener.
First check the Firewall and network related issues.
Check if Oracle Listener service is available and running. If not you may use Oracle Net Configuration Assistant tool to add and register new listener.
If the above steps are ok then you need to configure Oracle Listener appropriately. You may use Oracle Net Manager tool or edit “%ORACLE_HOME%\network\admin\listener.ora” file manually.
There are 2 options that need to be considered carefully:
Listening Locations associated with the Listener – Hostname(IP) and Port in Listening Location must exactly match the ones used in the connection string.
For example, if you use 192.168.74.139 as target hostname, then there must be Listening Location registered with the same IP address.
Also make sure the you use the same SID as indicated in Database Service associated with the Listener.
https://adhoctuts.com/fix-oracle-io-error-the-network-adapter-could-not-establish-the-connection-error/
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=iKQM6lBbSLiArrYuDqud8A==)
if you are facing this issue
1- make sure you have downloaded oracle databases like oracle 11g,19c, 21c, or any latest databases.
2- search for services in your computer or type win+r then services.mis then search for oracleservice you will find orcl or xe or any other sid like oracleserviceorcl;
after that you can test your connection using sql developer, sql plus or cmd
To resolve the Network Adapter Error I had to remove the - in the name of the computer name.
In my case, I needed to specify a viahost and viauser. Worth trying if you're in a complex system. :)
For me the basic oracle only was not installed. Please ensure you have oracle installed and then try checking host and port.
I was having issues with this as well. I was using the jdbc connection string to connect to the database. The hostname was incorrectly configured in the string. I am using Mac, and the same string was being used on Windows machines without an issue. On my connection string, I had to make sure that I had the full url with the appending "organizationname.com" to the end of the hostname.
Hope this helps.
Just try to re-create connection. In my situation one of jdbc connection stopped working for no reason. From console sqlplus was working ok.
It took me 2 hours to realize that If i create the same connection - it works.

Derby authentication error from Glassfish console but same credentials work from ij

I am trying, for the first time, to run a java EE 7 web app without an IDE and struggling through the learning curve. To keep things simple I have started with Glassfish 4.1 and Derby 10.11.1.2 which is what I used for development.
My current problem is an error configuring the connection pool on the Glassfish web interface. The error is 'Connection authentication failure occurred. Reason: Userid or password invalid'. However I have ij runing in a dos prompt and the Glashfish web console in Chrome.
from ij I can type 'connect 'jdbc:derby:localhost:1527/databasename;user=username;password=password'; and I connect fine and can look at tables, etc. In the Glassfish web console I have name/value pairs with the same 'user' and 'password' values and it fails (exact same letters & case). I've tried changing the 'databaseName' property to make sure the error wasn't misleading and confirmed it has found the database correctly.
At face value, the error message seems wrong as I have proven from the DOS window. I am sure I am doing something wrong but am lost at how to diagnose it. Any suggestions?
More details of the steps taken: (Although I am sure some of these steps superceed others my lack of success has me in the mindset that redundancy is better than omission - all-in-all it seems much more complicated than it needs to be for a basic setup). My target is Wildfly but Glassfish documentation is better so I figured I would start there.
relevant Windows environment variables:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
DERBY_HOME=%JAVA_HOME%\db
DERBY_INSTALL=%DERBY_HOME%
JAVADB_HOME=%DERBY_HOME%
GLASSFISH=C:\Program Files\Java\GlassFish-4.1
Path=%JAVA_HOME%\bin;%DERBY_HOME%\bin;%GLASSFISH%\bin;%GLASSFISH%\glassfish
CLASSPATH=%DERBY_HOME%\lib\derbynet.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\derbyclient.jar;%DERBY_HOME%\lib\derbyrun.jar
WILDFLY_HOME=C:\program files\java\wildfly\8.2.0.Final
sysinfo shows all the right paths and versions
Copied many of the derby jars from %derby_home%\lib to %glassfish%\glassfish\domains\domain1\lib\ext per a post by BalusC. I think classpath duplicates this it but can't hurt
Started Domain 'asadmin start-domain' defaulting to domain 1
Started DB by changing directories and using java. Wanted to use 'asadmin start-database --dbhome DB path' but this always started the wrong version. Glassfish and JDK both package derby/javadb and I couldn't figure out how to upgrade Glassfish or start the correct version any other way
cd \users\john\.netbeans-derby (root of the DB created by Netbeans)
Java –jar “%derby_home%\lib\derbyrun.jar" server start
connect browser to 'localhost:4848' to create JDBC connection pool and resource
connection pool: pool name=connectionPool, resource type=javax.sql.DataSource, DB driver Vendor=Derby, introspect was not enabled (found very little documentation to explain what it is) - step 2 was left as defaults
editing connectionPool - enabled Ping on General tab to identify errors, Additional Properties tab: changed User to DB username, left other attributes as default, added... password=db password, databaseName=ClubScoring
errors were presented along the way which prompted setting each attribute. No error was presented for lack of URL but tested steps below with and without URL=jdbc:derby://localhost:1527/ClubScoring
jdbc resources. Added jdbc/ClubScoring, pool=connectionPool => selected and enabled
starting db from correct directory using 'asadmin start-database' does let the application find the correct DB but it crashes since the DB was created with version 10.11.1.2 and this command starts the Glassfish version of 10.10.2.0
Sorry for making this so long but I haven't found anywhere that lays out all of the steps in a simple fashion and figured the details would save time in the long run.
I was dealing with this issue today and found a solution:
https://db.apache.org/derby/docs/10.14/ref/rrefattribsecmech.html
Basically the only security options allowable (as far as 10.14 is concerned) is 3, 4 and 9.
4 is the default and means "Just UserID". You would think this means that as long as a UserID is given, you could connect. But having both set appears to be an issue.
In order to use a (clear text) password and userID, you have to specify 3. It works also if the attribute is deleted or 0 as well but I don't think you get any security that way.

Access denied for user 'root'#'localhost' (using password: YES)

Hi I'm working on a Liferay portlet that accesses the database using JPA. I'm using Tomcat 7 and MySQL.
This portlet works fine in my machine but when I move the portlet to a test environment in another server and try to use it in the test portal I get the following error:
Access denied for user 'root'#'localhost' (using password: YES)
The database connection database in my persistence.xml is ok.
I tried putting wrong connection data in the persistence.xml to see if the error changed but it didn't. For example I set the user as "wronguser" and when I deployed the portlet and tried to use it again I got exactly the same error:
Access denied for user 'root'#'localhost' (using password: YES)
Even if I change the database name or URL the error is always the same. It's like something is not getting updated. I tried deleting the Tomcat temp folder but didn't help.
Any ideas?
Thanks in advance.
I tried putting wrong connection data in the persistence.xml to see if
the error changed but it didn't. For example I set the user as
"wronguser" and when I deployed the portlet and tried to use it again
I got exactly the same error:
This just shows that the username/password given to mysql at the end is not coming from your configuration file as expected, but from to-be-identified-elsewhere.
Until you see mysql complaining about "wronguser" not being able to connect, this is the first roadblock to clear, and the problem is most likely in the application setup, not in mysql.
Should the mysql server complain later about privileges for "wronguser", then sure, the area to investigate then will be grants for this user, but you need to convey the proper user/host/password information to the server first.

Play! framework - Cannot connect to database

this is the error I get when I'm trying to connect to my local postgresql db:
Cannot connect to database [default]
this is the database configuration. I'm convinced that there is not typo (fat finger error):
db.default.url="postgres://localhost:5432/myproject/"
db.default.user="postgres"
db.default.pass="mypassword"
db.default.driver="org.postgresql.Driver"
db.default.initSQL="SELECT 1"
where is the problem? with pgAdmin I can connect easily
p.s.
I'm using ubuntu. I've noticed that in order to change to postgres user
I must use "su", otherwise it fails changing the current user.
is that has something to do with play! failure to connect my db?
thanks
There might be two things wrong or at least dubious in your setup.
First: The postgres:... URL syntax is not a plain JDBC URL. This format is not understood by the PostgreSQL JDBC driver. See this answer to a similar problem.
Second: You are trying to use the PostgreSQL superuser account for Play. The superuser account should be used only for administrative work, but not "normal" work. Especially not for work which includes public access to the DB via some webfrontend. Any SQL-Injection attack gives the attacker the golden key to your database - including the nuke to wreck your complete DB cluster at once or install any backdoor into you DB server.
So I recommand, that you create a new user which you configure in your Play! settings.
That said: The default password for the postgres user is not set on Ubuntu. This setup allows login to the DB user only from the same OS user. How you can fix this is explained in this answer.
If these two tips don't help: The error you quoted is very vague. There must be more detailed error logs somewhere. Please find them and attach them to your question with the "edit" button.
This is not an answer directly to your question, but I had the same error message and came here via Google. Using Scala Play 2.3, I had
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true
which needed to be
db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true
I accidentally left the quotes around the driver name out. Now it works perfectly.
here is my conf, it works:
db.default.url="jdbc:postgresql://127.0.0.1:5432/dbname"
db.default.driver="org.postgresql.Driver"
just add the jdbc: before postgresql in db.default.url.

Categories

Resources