Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JAAS CustomLogin module:com.ibm.websphere.wim.exception.PasswordCheckFailed

1,311 views
Skip to first unread message

shwe...@rediffmail.com

unread,
Feb 29, 2008, 2:22:53 AM2/29/08
to
Hi,<br />
<br />
I am using WAS 6.1. I have created a custom login module and placed it in &lt;WAS root&gt;/lib/ext. I've configured my customlogin module in bot JAAS application logins and system logins. in System Logins I've added the customLoginModule in default, WEB_INBOUND, and RMI_INBOUND and mark it REQUIRED. after doing all this I m getting exception :<br />
<b>com.ibm.websphere.wim.exception.PasswordCheckFailedException:CWWIM4537E No principal is found from the '&lt;user name&gt;' principal name.</b><br />
<br />
Then on the following link I found that it is a bug in websphere and they have released a fix pack for this. but unfortunately APAR PK46513 does not resolve the issue of User registry check during authentication for custom login modules.<br />
<br />
http://www-1.ibm.com/support/docview.wss?rs=180&#38;uid=swg1PK46513<br />
<br />
even after applying fix pak 6.1.0.13 I m getting the same error. Kindly help me.

Paul Ilechko

unread,
Feb 29, 2008, 8:00:23 AM2/29/08
to

shwe...@rediffmail.com

unread,
Mar 4, 2008, 2:42:24 AM3/4/08
to
Thanks Paul for your quick reply. . .<br />
I am able to authenticate the user using custom login module. But now I m stuck with authorization.I am using FormLogin. . .Once the authentication is successful I get the following error in SystemOut.log:<br />
<br />
<b>SECJ0129E: Authorization failed for sysadmin while invoking GET on default_host:/webSecurity/restricted/SecureServlet, Authorization failed, Not granted any of the required roles: admin</b> <br />
<br />
I am posting my LoginModule code here. . . <br />
<br />
public class SimpleLoginModule implements LoginModule {<br />
<br />
private Subject subject;<br />
private CallbackHandler callbackHandler;<br />
private String name;<br />
private String password;<br />
InitialContext ctx;<br />
UserRegistry reg; <br />
ArrayList&lt;String&gt; groups;<br />
String uniqueid ;<br />
<br />
public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {<br />
this.subject = subject;<br />
this.callbackHandler = callbackHandler;<br />
}<br />
<br />
public boolean login() throws LoginException {<br />
System.out.println("*************** Coming in login()of SimpleLoginModule ***************");<br />
// Each callback is responsible for collecting a credential<br />
// needed to authenticate the user.<br />
NameCallback nameCB = new NameCallback("Username");<br />
PasswordCallback passwordCB = new PasswordCallback("Password",false);<br />
Callback<a href="http://www-128.ibm.com/developerworks/forums/">] callbacks = new Callback[</a> { nameCB, passwordCB };<br />
// Delegate to the provided CallbackHandler to gather the<br />
// username and password.<br />
try {<br />
callbackHandler.handle(callbacks);<br />
} catch (IOException e) {<br />
e.printStackTrace();<br />
LoginException ex = new LoginException(<br />
"IOException logging in.");<br />
ex.initCause(e);<br />
throw ex;<br />
} catch (UnsupportedCallbackException e) {<br />
String className = e.getCallback().getClass().getName();<br />
LoginException ex = new LoginException(className<br />
+ " is not a supported Callback.");<br />
ex.initCause(e);<br />
throw ex;<br />
}<br />
<br />
// Now that the CallbackHandler has gathered the username and password,<br />
// use them to authenticate the user against the expected passwords.<br />
name = nameCB.getName();<br />
if(passwordCB.getPassword()!=null)<br />
password = String.valueOf(passwordCB.getPassword());<br />
<br />
Hashtable&lt;String, Object&gt; hashtable = new Hashtable&lt;String, Object&gt;(); <br />
<br />
groups = new ArrayList&lt;String&gt;();<br />
// add admin group <br />
groups.add("sysadmin");<br />
groups.add("admin");<br />
groups.add("Administrator");<br />
groups.add("sysuser");<br />
<br />
if ("sysadmin".equals(name) &#38;&#38; "password".equals(password)) {<br />
// login in sysadmin<br />
Principal p = new SysAdminPrincipal(name);<br />
<br />
subject.getPrincipals().add(p);<br />
// stash in hashtable<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID,name);<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_SECURITYNAME,name);<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_GROUPS, groups);<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_PRIMARYGROUPID,"admin");<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_CACHE_KEY,name+"MyCustom");<br />
<br />
subject.getPublicCredentials().add(hashtable); <br />
return true;<br />
} else if ("sysuser".equals(name) &#38;&#38; "password".equals(password)) {<br />
Principal p = new UserPrincipal(name);<br />
// login user<br />
subject.getPrincipals().add(p);<br />
// stash in hashtable<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID,name);<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_SECURITYNAME,name);<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_GROUPS, groups);<br />
hashtable.put(AttributeNameConstants.WSCREDENTIAL_CACHE_KEY,name+"MyCustom");<br />
<br />
subject.getPublicCredentials().add(hashtable);<br />
return true;<br />
} else {<br />
return false;<br />
}<br />
}<br />
<br />
public boolean commit() {<br />
System.out.println("************ Coming in Commit() of SimpleLoginModule *************");<br />
// If this method is called, the user successfully authenticated, and<br />
// we can add the appropriate Principles to the Subject.<br />
if ("sysadmin".equals(name)) {<br />
password = null;<br />
return true;<br />
} else if ("sysuser".equals(name)) {<br />
password = null;<br />
return true;<br />
} else {<br />
return false;<br />
}<br />
}<br />
<br />
public boolean abort() {<br />
System.out.println("************ Coming in abort() of SimpleLoginModule *************");<br />
name = null;<br />
password = null;<br />
return true;<br />
}<br />
<br />
public boolean logout() {<br />
System.out.println("************ Coming in logout() of SimpleLoginModule *************");<br />
name = null;<br />
password = null;<br />
return true;<br />
}<br />
<br />
}<br />
My web.xml is as follows:<br />
<br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"&gt;<br />
&lt;description&gt;JAAS Login Web Application&lt;/description&gt;<br />
&lt;display-name&gt;JAASLogin&lt;/display-name&gt;<br />
&lt;servlet&gt;<br />
&lt;display-name&gt;login&lt;/display-name&gt;<br />
&lt;servlet-name&gt;login&lt;/servlet-name&gt;<br />
&lt;jsp-file&gt;/login.jsp&lt;/jsp-file&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet&gt;<br />
&lt;display-name&gt;dspCred&lt;/display-name&gt;<br />
&lt;servlet-name&gt;dspCred&lt;/servlet-name&gt;<br />
&lt;jsp-file&gt;/dspCred.jsp&lt;/jsp-file&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet&gt;<br />
&lt;display-name&gt;configSecurity&lt;/display-name&gt;<br />
&lt;servlet-name&gt;configSecurity&lt;/servlet-name&gt;<br />
&lt;jsp-file&gt;/configSecurity.jsp&lt;/jsp-file&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet&gt;<br />
&lt;display-name&gt;loginError&lt;/display-name&gt;<br />
&lt;servlet-name&gt;loginError&lt;/servlet-name&gt;<br />
&lt;jsp-file&gt;/loginError.jsp&lt;/jsp-file&gt;<br />
&lt;/servlet&gt;<br />
&lt;!-- ### Servlets --&gt;<br />
&lt;servlet&gt;<br />
&lt;servlet-name&gt;SecureServlet&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;com.tavant.jaas.jaasloginwar.SampleServlet&lt;/servlet-class&gt;<br />
&lt;/servlet&gt;<br />
<br />
&lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;SecureServlet&lt;/servlet-name&gt;<br />
&lt;url-pattern&gt;/restricted/SecureServlet&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
<br />
&lt;!-- ### Security --&gt;<br />
&lt;security-constraint&gt;<br />
&lt;web-resource-collection&gt;<br />
&lt;web-resource-name&gt;Restricted&lt;/web-resource-name&gt;<br />
&lt;description&gt;Declarative security tests&lt;/description&gt;<br />
&lt;url-pattern&gt;/restricted/*&lt;/url-pattern&gt;<br />
&lt;http-method&gt;GET&lt;/http-method&gt;<br />
&lt;http-method&gt;POST&lt;/http-method&gt;<br />
&lt;/web-resource-collection&gt;<br />
&lt;auth-constraint&gt;<br />
&lt;role-name&gt;admin&lt;/role-name&gt;<br />
&lt;/auth-constraint&gt;<br />
&lt;/security-constraint&gt;<br />
<br />
&lt;login-config&gt;<br />
&lt;auth-method&gt;FORM&lt;/auth-method&gt;<br />
&lt;realm-name&gt;WSJAASLogin&lt;/realm-name&gt;<br />
&lt;form-login-config&gt;<br />
&lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;<br />
&lt;form-error-page&gt;/loginError.jsp&lt;/form-error-page&gt;<br />
&lt;/form-login-config&gt;<br />
&lt;/login-config&gt; <br />
&lt;!-- Security roles used in the application --&gt;<br />
&lt;security-role&gt;&lt;role-name&gt;admin&lt;/role-name&gt;&lt;/security-role&gt;<br />
&lt;/web-app&gt;<br />
<br />
Kindly tell me what is going wrong here? And how to grant permissions to the user for accessing a particular resource? What is the diff between rols and group in websphere?<br />
<br />
Thank you very much !!!!<br />
<br />
~ Shweta

Paul Ilechko

unread,
Mar 4, 2008, 10:24:22 AM3/4/08
to
shwe...@rediffmail.com wrote:

> Kindly tell me what is going wrong here? And how to grant permissions
> to the user for accessing a particular resource? What is the diff
> between rols and group in websphere?<br />
>

Groups are things that exist in a user registry. Roles are JEE
constructs. All that your login module does is define the group
memberships for the user that is authenticating. Those groups need to be
mapped to the appropriate JEE roles, using the WebSphere tooling (either
ASTK or RAD).

shwe...@rediffmail.com

unread,
Mar 5, 2008, 2:24:09 AM3/5/08
to
I think ASTK means Application Server Tool kit. . is ASTK different from Admin console? For my project we've to read user details and all the roles information from database. So can you tell me how to map this role information, retrieved from Database, with groups in admin console?

Paul Ilechko

unread,
Mar 5, 2008, 8:54:07 AM3/5/08
to
shwe...@rediffmail.com wrote:
> I think ASTK means Application Server Tool kit. . is ASTK different
> from Admin console?

Yes. ASTK is a developer tool, used to package the EAR file that gets
deployed in the console (or by scripts). It builds the deployment
descriptors and the IBM binding files. Some of these settings can be
overridden by the deployer in the admin console.


> For my project we've to read user details and all
> the roles information from database. So can you tell me how to map
> this role information, retrieved from Database, with groups in admin
> console?

The only way to use a database as the WAS user registry would be to
implement the custom user registry interface.

shwe...@rediffmail.com

unread,
Mar 7, 2008, 6:39:54 AM3/7/08
to
Hi Paul,<br />
Now the authentication and authorization is successful for my user using Custom Login module. But the issue is "Authentication strategy" is set up as "REQUIRED" for my custom login module. I have to make it "SUFFICIENT". But if I try to make it "SUFFICIENT", authentication is failing AND I am getting following error in System.Out.log :<br />
<b>FormLoginExte E SECJ0118E: Authentication error during authentication for user sysuser</b><br />
<br />
and following exception in &lt;logs&gt;/ffdc/ log file:<br />
<b>java.lang.NullPointerException com.ibm.ws.security.auth.ContextManagerImpl.processSubjectForPropagationAfterLogin 3495</b><br />
<br />
Kindly tell me what is causing this error?<br />
<br />
Thanks in advance.

Paul Ilechko

unread,
Mar 7, 2008, 7:51:45 AM3/7/08
to

It's all described in the paper I referenced earlier. If you make your
login module sufficient, the WAS ones will not run, and the Subject will
not be populated. There is no way to build a valid Subject purely in
your own code.

0 new messages