Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:15:30+00:00 2026-06-14T03:15:30+00:00

I’m studying JAAS and I’m implementing a simple example to use in a webapp

  • 0

I’m studying JAAS and I’m implementing a simple example to use in a webapp using Tomcat with a JaasRealm.

Now my problem is that I don’t know how to retrieve the subject since code like Subject subject = Subject.getSubject(AccessController.getContext()); always returns null.

I’m using Tomcat 7.0.27. Is there something I’ve missed?
In other terms how can I manage authorization in Java EE with JAAS? For example how can I implement an action within the secure context of JAAS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:15:31+00:00Added an answer on June 14, 2026 at 3:15 am

    i knew that and it works, but I need to retrieve subject to get also roleprincipal

    Unfortunately, it doesn’t work like that in Java EE. The JAAS Subject is just a “bag of principals”, and which of those represents the user/caller principal and/or the role principal(s) is simply not standardized. Every other container does things differently here. The Javadoc for Tomcat’s JAASRealm describes this and explains the Tomcat specific convention (emphasis mine):

    The JAAS Specification describes the result of a successful login as a
    javax.security.auth.Subject instance, which can contain zero or more
    java.security.Principal objects in the return value of the
    Subject.getPrincipals() method. However, it provides no guidance on
    how to distinguish Principals that describe the individual user (and
    are thus appropriate to return as the value of
    request.getUserPrincipal() in a web application) from the Principal(s)
    that describe the authorized roles for this user. To maintain as much
    independence as possible from the underlying LoginMethod
    implementation executed by JAAS, the following policy is implemented
    by this Realm: […]

    Besides that, from a Java EE environment you rarely even have access to the JAAS Subject, often not even via vendor specific methods. JAAS is far from the universal standard that you seem to think it is, especially when it concerns Java EE.

    The only things which you can access in a portable way are the caller principal and the roles associated with it, but even those do not have to be the exact caller principal that your JAAS login module constructed.

    JBoss AS for instance, copies this principal a couple of times using its own classes. So, if your JAAS module stored a kaz.zak.FooPrincipal into the Subject for the user/caller principal, then HttpServletRequest#getUserPrincipal() might return a org.jboss.security.SimplePrincipal. The only thing guaranteed is that getName() on that instance will return the same string.

    For some more background on this topic:

    • Implementing container authentication in Java EE with JASPIC
    • Whatever Happened to JAAS?
    • Using JAAS with Tomcat

    The last source basically says the same thing, in different wording;

    Although it is possible to use JAAS within Tomcat as an authentication
    mechanism (JAASRealm), the flexibility of the JAAS framework is lost
    once the user is authenticated. This is because the principals are
    used to denote the concepts of “user” and “role”, and are no longer
    available in the security context in which the webapp is executed. The
    result of the authentication is available only through
    request.getRemoteUser() and request.isUserInRole().

    This reduces the JAAS framework for authorization purposes to a simple
    user/role system that loses its connection with the Java Security
    Policy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.