File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Java Products and Servers and the fly likes isUserInRole problem in glassfish (Solved) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "isUserInRole problem in glassfish (Solved)" Watch "isUserInRole problem in glassfish (Solved)" New topic

isUserInRole problem in glassfish (Solved)

Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

I've created a a web project in Netbeans which contains a Web Service on Glassfish 2.1 as follows

I'm doing programmatic login of glassfish using the class (I had to do it because of some logging requirement). After I do the login, I call the serviceContext.isUserInRole() method to see if the user is in the correct role. The "Default Principal To Role Mapping" is checked in glassfish (I tried after disabling it too). Still I've mapped the user role to group names in the sun-web.xml file as follows (I have tried it without this code in the sun-web.xml too)

Still the isUserInRole method is returning false. If I declare <principal-name> elements to define individual principals, then it works fine. A similar approach is working fine on a simple servlet where I'm using programmatic login with HttpServletRequest.isUserInRole in a filter. Am I doing something wrong here??

Edit: one more detail, another EJB based web service is injected into this web service. The code looks like this

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

Stupid of me, I just created a filter for the web service and it was solved, the WebServiceContext.isUserInRole was creating the problem, I still don't know what the problem was but its at least solved for now...
I agree. Here's the link:
subject: isUserInRole problem in glassfish (Solved)
Similar Threads
Declarative Security with Java EE (Glassfish)
Having serious trouble configuring Authorization
securing web service developed as an EJB
Unable to get the login.jsp to fire from example of book "Java EE 5 Development with NetBeans 6"
JDBCRealm and Form Login