[jboss-user] [JBoss Portal] - Re: Problems in doing JAAS login using code
tellarsrinivasprabhu
do-not-reply at jboss.com
Mon Sep 17 05:37:32 EDT 2007
hi,
All we did was that we created a custom valve that extends org.apache.catalina.valves.ValveBase;
in the invoke method , we added the user principals to the request using following lines of code.
| .
| List roles = new ArrayList();
| roles.add("Authenticated");
| roles.add("User");
| roles.add("Admin");
| roles.add("CustomRole"); // add any roles that you want to add depending on context
|
| .
| .
| request.setUserPrincipal(new GenericPrincipal(request.getContext().getRealm(), username,password, roles));
| .
| .
| .
| getNext().invoke(request, response);
|
you can also create new subjects and add to SecurityAssociation
Group roleGroup = new SimpleGroup("Roles");
|
| for (int i = 0; i < roles.size(); i++) {
| String rname = (String) roles.get(i);
| Principal p = new UserPrincipal(rname);
| roleGroup.addMember(p);
| }
|
| Subject subj = new Subject();
| subj.getPrincipals().add(new UserPrincipal(username));
| subj.getPrincipals().add(roleGroup);
| SecurityAssociation.setSubject(subj);
|
Once you are done with this, next we have to tell the application that it has to go through the custom valve that we created. This is done by creating a new file called context.xml having the following entry (specify your custom valve class name)
<Context>
| <Valve className="sample.util.CustomValve" />
| </Context>
place this file xml along with web.xml (in jboss-portal.sar\portal-server.war\WEB-INF)
create a jar of your custom valve class file and put it in any lib dir. we put it in server\default\lib.
then restart the server .
Hope this will help,
tellarsrinivasprabhu
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4084942#4084942
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4084942
More information about the jboss-user
mailing list