JavaMail crashes after build/deploy on Glassfish 4 - eclipse

My current project includes using of a JavaMail for confirming an user email. The problem I have is that, using eclipse, every time I build & deploy my web application on the local Glassfish server the JavaMail crashes with the following exception:
Severe: java.lang.SecurityException: Access to default session denied
at javax.mail.Session.getDefaultInstance(Session.java:333)
at utils.MailService.sendEmailSSL(MailService.java:58)
And here the code snipped where I'm obtaining the session and which is throwing the above exception:
Session session = Session.getDefaultInstance(
props,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(usr, pwd);
}
});
The workaround I've found so far is restarting Glassfish and after that JavaMail functions properly again. The problem is it is very annoying and time consuming doing a restart even after the smallest change in my code.
My question: Is there a possibility to reset only the JavaMail service and bind this with the build event?
Off course any other suggestions are welcome too :)

If you can avoid using Session.getDefaultInstance. Use Session.getInstance and fix some of the common mistakes.

Related

Vertx Form Login Handler with Postgresql Failure

I am trying to authenticate user using FormLoginHandler and Postgresql Database with SqlAuthentication.
But I get the following error:
Jun 15, 2022 1:14:34 PM io.vertx.ext.web.RoutingContext
SEVERE: Unhandled exception in router
io.vertx.ext.web.handler.HttpException: Unauthorized
Caused by: io.vertx.core.impl.NoStackTraceThrowable: Invalid username/password
I am providing the right credentials.
The code snippet is:
SqlAuthenticationOptions sauthopts = new SqlAuthenticationOptions();
sauthopts.setAuthenticationQuery(AUTHENTICATE_QUERY);
SqlAuthentication authenticationProvider = SqlAuthentication.create(sqlClient, sauthopts);
router.route("/secure/*").handler(RedirectAuthHandler.create(authenticationProvider, "/login.html"));
FormLoginHandler formLoginHandler = FormLoginHandler.create(authenticationProvider);
router.route("/loginhandler").handler(formLoginHandler);
Please let me know if I am missing something here; or point me to a sample example.
Thanks in Advance.
Your setup doesn't show anything abnormal at first sight. For security reasons, we cannot "just" log the authentication data, as it would be a critical OWASP bug and security vulnerability.
My best guess is that probably is something not totally correct with the query, so this means you have now 2 options:
debug the application and see the query that is being sent + the arguments
prepare a small complete example that shows the bug and open an issue in vert.x so we can debug it further.
If you're upgrading from an older version, be aware that in vert.x 4.2.0 some changes were made to the base64 encoding to keep it consistent across modules. This could be a reason why authentication could fail as the encoded hashes may be slightly different. If you're just doing 4.3.0 from the start, then this would not be a problem.

Application is active in server but page is not loading, shows err - Access denied

I was preparing production environment to deploy my ADF web application developed in jdeveloper 12.2.1. Installed and configured weblogic 12.2.1.1.0(latest version) and database( Oracle DB 11g) in different servers. I tired to deploy a simple demo application which worked smoothly. But when i tired to deploy my application with MDS enabled which also having login credentials it's not get loading. Application and servers(3 managed servers added in a cluster) are active and its health is fine.
While I checked the log i can found the error message as below:
weblogic.kernel.Default (self-tuning)'> <OracleSystemUser> <BEA1-00A6CDC0DF4E2399D225> <c21c09b7-a391-47ae-b2eb-0d8dc5bec343-00000d61> <1477317511991> <[severity-value: 64] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-010227> <EJB exception occurred during invocation from home or business: oracle.wsm.policymanager.bean.ejb.impl.UsageTracker_oi3aq7_Intf generated exception
: java.lang.SecurityException: WSM-02084 : Access denied. Permission "oracle.wsm.security.PolicyManagerPermission" is required to access the wsm policy manager "UsageTracker" method "recordUsage".>
I am stuck with this issues. Tried by starting and stopping servers and deploy and undeploy application many times.
Any help would be appreciable.
Thanks in advance.
You may want to check the suggestions on "SOA Suite 12.2.1 - OWSM WSM-02084 issue" from Michel Schildmeijer.
He suggests editing the policy.Accessor and adding oracle.wsm.security.PolicyManagerPermission for resource UsageTracker#recordUsage to the wsm-pm Application Stripe via "Fusion Middleware Control" under WebLogic Domain > Security > Application Policies.
https://community.oracle.com/blogs/mnemonic/2016/10/16/soa-suite-1221-owsm-wsm-02084-issue

Error loading war to tomcat6

I'm attempting to load my war file to Tomcat 6 and constantly get this error:
May 20, 2014 12:35:42 AM org.apache.catalina.startup.ContextConfig
init
SEVERE: Exception fixing docBase for context [/MyService]
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
...
May 20, 2014 12:35:42 AM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Invalid or unreadable WAR file : error in opening zip file
I've found several suggestions and tried them all, still stumped.
Moved the file to a diff directory, then copied to webapps
Changed the file permissions before moving to webapps
Stopped Tomcat, delete the old, add the new, then restart
Added a random class to the war before re-deploying
Uninstalled tomcat6 (also removing the tomcat6 directory) and re-installed tomcat6 fully
Here's the strangest part - I've also taken old wars (older versions of the same app) that used to work on this same server, and those don't work either (same error), even after re-installing Tomcat. This leads me to believe it's a Tomcat problem, however the uninstall didn't fix anything.
Also, I've created war files from this same project (Eclipse) and deployed them fine to a different tomcat6 server. Also, when I run the app on my dev box localhost Eclipse/Tomcat connecting to the same database remotely, everything works fine.
When I actually make an http request, the app is deployed, however I have a static initializer that is not working and causing a null pointer exception. I assume this is related to the
SEVERE: Error starting static Resources
Here is the static initializer, it is creating a BoneCP connection pool, which also has always worked and I confirmed that MySQL is working fine (replication is also still occurring - it is a slave MySQL). The connectionPool object is null and I don't get a stack trace in my logs for the openPool() method, I also don't see any root connections to MySQL:
protected static BoneCP connectionPool = null;
static
{
openPool();
}
protected static void openPool()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/mydatabase");
config.setUsername("root");
config.setPassword("mypassword"); //SLAVE
config.setMinConnectionsPerPartition(2);
config.setMaxConnectionsPerPartition(6);
config.setPartitionCount(7);
connectionPool = new BoneCP(config);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
Welp, I figured this out...
Somehow the password for the mysql root user was changed, which is very odd since I'm the ONLY person that ever touches any of this. I have a feeling MySQLWorkbench somehow did this without me knowing? I just recently installed a new version (6.1).
Basically this seems to be a catch all error, which I saw some people mention on other threads, so I've been on a 4 day wild goose chase. The only reason I figured this out was because I finally tried to log in to mysql as root through the console, in retrospect I should have tried that earlier.

Communicating with DB through SSH in GWT app (using RPC)

I am trying to write a GWT back-end using the RPC model for java servlets.
Is it possible to ssh tunnel within an RPC in order to communicate with a remote sql database?
The code I try to execute is below, using Jsch. The error occurs on "session.connect();"
String host="xxxxx.xxx.edu";
String user="username";
String password="password";
Session session= null;
try{
//Set StrictHostKeyChecking property to no to avoid UnknownHostKey issue
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
}
The runtime error I get on the 'session.connect()' line is as follows: (scroll right to see whole error)
com.jcraft.jsch.JSchException: java.security.AccessControlException: access denied (java.net.SocketPermission xxxxx.xxx.edu resolve)
at com.jcraft.jsch.Util.createSocket(Util.java:341)
at com.jcraft.jsch.Session.connect(Session.java:194)
at com.jcraft.jsch.Session.connect(Session.java:162)
at com.front.server.GameServiceImpl.createGame(GameServiceImpl.java:39)
The frustrating part about this is that I copied/pasted the exact same code into a simple java program and it works. So I know the code is correct; obviously the jetty server which GWT creates for local testing has a problem executing the code. What else can I do / what should I be doing in this situation with GWT? Shouldn't the back-end of a GWT application have the capacity to ssh??
I suggest you try running your gwt app with a different web container (Tomcat, JBoss). You can still make use of debugging functionality by running the hosted mode with the -noserver flag.
See here

JBoss MDB - JMSBytesMessage class cast exception

I'm working on an EJB3 MDB that listen to a MQ queue in a distant server.
All is working fine (MDB triggered when a message is put into the listenned queue) except the treatment done by the MDB. For information, i use WMQ resource adapter to map the queue.
Into the method 'onMessage' of the MDB, i try to cast the given message into the class 'com.ibm.jms.JMSBytesMessage', but i get a strange error message.
The code is the following one (simple for the example):
public void onMessage(Message theMessage) {
((JMSBytesMessage) theMessage).readBytes(myBytes);
}
And the exception message:
Exception while reading input request: com.ibm.jms.JMSBytesMessage incompatible with com.ibm.jms.JMSBytesMessage
Ok, the message received should be (and is) type 'com.ibm.jms.JMSBytesMessage', so why the application doesn't work ? Should it be possible that my JBoss server already use another version of the library 'com.ibm.mqjms.jar' (including the JMSBytesMessage class) and cause this kind of error ?
ps: i've deployed the application on a JBoss server version 4.2.3 under linux system.
I've already make the application work on my local machine with same version of JBoss server but under window system (same configuration, same libraries, etc.)
Does someone have an idea about the reason of such error ?
Thanks in advance for any help.
Regards,
EDIT: SOLUTION: cast with javax.jms.BytesMessage instead of com.ibm.jms.JMSBytesMessage
Might as well reproduce my comment as answer:
Don't cast to the MQ-specific com.ibm.jms.JMSBytesMessage, cast to the JMS-standard javax.jms.BytesMessage. Coupling your code to the implementation-specific types is counter to what JMS tries to achieve.