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<String> 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<String, Object> hashtable = new Hashtable<String, Object>(); <br />
<br />
groups = new ArrayList<String>();<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) && "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) && "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 />
<?xml version="1.0" encoding="UTF-8"?><br />
<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"><br />
<description>JAAS Login Web Application</description><br />
<display-name>JAASLogin</display-name><br />
<servlet><br />
<display-name>login</display-name><br />
<servlet-name>login</servlet-name><br />
<jsp-file>/login.jsp</jsp-file><br />
</servlet><br />
<servlet><br />
<display-name>dspCred</display-name><br />
<servlet-name>dspCred</servlet-name><br />
<jsp-file>/dspCred.jsp</jsp-file><br />
</servlet><br />
<servlet><br />
<display-name>configSecurity</display-name><br />
<servlet-name>configSecurity</servlet-name><br />
<jsp-file>/configSecurity.jsp</jsp-file><br />
</servlet><br />
<servlet><br />
<display-name>loginError</display-name><br />
<servlet-name>loginError</servlet-name><br />
<jsp-file>/loginError.jsp</jsp-file><br />
</servlet><br />
<!-- ### Servlets --><br />
<servlet><br />
<servlet-name>SecureServlet</servlet-name><br />
<servlet-class>com.tavant.jaas.jaasloginwar.SampleServlet</servlet-class><br />
</servlet><br />
<br />
<servlet-mapping><br />
<servlet-name>SecureServlet</servlet-name><br />
<url-pattern>/restricted/SecureServlet</url-pattern><br />
</servlet-mapping><br />
<br />
<!-- ### Security --><br />
<security-constraint><br />
<web-resource-collection><br />
<web-resource-name>Restricted</web-resource-name><br />
<description>Declarative security tests</description><br />
<url-pattern>/restricted/*</url-pattern><br />
<http-method>GET</http-method><br />
<http-method>POST</http-method><br />
</web-resource-collection><br />
<auth-constraint><br />
<role-name>admin</role-name><br />
</auth-constraint><br />
</security-constraint><br />
<br />
<login-config><br />
<auth-method>FORM</auth-method><br />
<realm-name>WSJAASLogin</realm-name><br />
<form-login-config><br />
<form-login-page>/login.jsp</form-login-page><br />
<form-error-page>/loginError.jsp</form-error-page><br />
</form-login-config><br />
</login-config> <br />
<!-- Security roles used in the application --><br />
<security-role><role-name>admin</role-name></security-role><br />
</web-app><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