JAAS – request.isUserInRole always returns false

It is because you omitted to add (for every role you use):

 <security-role>
<role-name>your role</role-name>

</security-role>

in your web.xml

Two roles example:

….

 <security-role>
<role-name>your role 1</role-name>

</security-role>

 <security-role>
<role-name>your role 2</role-name>

</security-role>

….

Advertisements

Deploy on save/publish on save in Eclipse

I am using a remote Glassfish server and Eclipse published my web app every time when I saved or created any file. Publishing was very slow. I found this to disable auto deploy/publish:
1. In Eclipse menu click “Window->show view->servers”, it shows your servers.
2. RightClick on server -> Open
3. Expand tag Publishing, click on your choice and save it – ctrl+s

How to use SSL socket in Java

I have been searching for a long time how to use SSL socket in java…. we will continue soon.

Code:

 SSLContext ctx = null;
// load keystore
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
char[] password = getPassword();
InputStream in = ClassLoader.getSystemResourceAsStream(keystore);
ks.load(in, password);
in.close();
// set-up SSLContext
KeyManagerFactory kmf = KeyManagerFactory.getInstance(“SunX509”, “SunJSSE”);
kmf.init(ks, password);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(“PKIX”, “SunJSSE”);
tmf.init(ks);
ctx = SSLContext.getInstance(“TLS”);
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);