Hitachi

uCosminexus Application Server Security Management Guide


5.10.2 Implementation of the API-based session to obtain user IDs

After authentication is completed, the authenticated user ID is stored in the Subject as the Principal object (java.security.Principal). The following is an example of implementing the session to obtain the user ID.

<%@ page import="javax.security.auth.Subject" %>
<%@ page import="java.security.Principal" %>
...
<%
  ...
  Subject subject = lc.getSubject();
  Principal principal = (Principal)subject.getPrincipals().iterator().next();
  String userid = principal.getName();
%>
...

The above example fetches the iterator, which stores the Principal from the Subject, converts the first value in the iterator to the Principal object, and then uses the getName method of the Principal object to obtain the user ID.