How to retrieve user name from a given Subject?

I am in a situation where I need to retrieve user name from the Subject that is populated when user logs in. I have the active Subject and I do following to get the principals in the subject and iterate through them:
Set principals = subject.getPrincipals();
Iterator ite = principals.iterator();
while (ite.hasNext()) {
Principal prin = (Principal)ite.next();
String name = prin.getName();
But this contains all the principals, including user name, roles, password, etc. How do I programmatically determine which one is user name?

Don't you have different principal types? I am making a jaas module and I have different principals for roles, groups etc. I think of principals as attributes, the type in the attribute name and the principal name is the attribute value.
To get all the principals of the type SomePrincipal, you can use:
Set principals = subject.getPrincipals(SomePrincipal.class)
You can also take som principal an test wether it is an instance of som type:
if (Principal p instanceof SomePrincipal){..}
An other solution which might be better if you have many different attributes is to store both attribute name and value in the name of the principal.
If "mark" is a username the principal name will be "username:mark" el.
Then it will be easy to find the username.

Similar Messages

  • How to reasd user name from the request

    Hi,
    My application is hosted on tomcat 5.5 and it is front ended by apache http server where the web agent 3.0 is installed. opensso application is installed on a different host on tomcat 6.0. I have configured external ldap for user application authentication and DS store is used for opensso application login.
    If I try to access and protected resource of my portal application, I am getting redirected to opensso's log in page. If I provide improper credentials, authentication fails. And if I give valid credentials it looks like opensso is authenticating the user, but I am not getting redirected to our portal application main page.
    Instead it is taking us to login page of portal application.
    The portal application is expecting HTTP_REMOTE_USER header to be set in the respone. When I checked the header using Mozilla Live headers, I didn't find HTTP_REMOTE_USER header. Where does the user name information get stored? It looks like com.sun.identity.agents.config.userid.param is the configuration parameter for specifying the desired header name for storing user id. How to change it?
    Regards,
    Pratap

    To give an update on the question, I tried printing all the headers in a sample jsp page that is protected. The sample jsp page is not protected in the portal but I marked that as protected in the opensso. If I try to access this sample jsp I am being redirect opensso login page. I supplied proper credentials and web agent redirected me to the sample login page. I don't see any headers for user id there. I also printed request.getRemoteUser() which is printed as null.
    Can someone please tell me how do I get the user id?
    Regards,
    Pratap

  • File information -- How to retrieve file name from header variable

    Hi
    I am using File Adapters to read files(.xml) and then I need to perform some database operations.
    One of the requirement is storing the file name read into the DB.
    I searched through the forum and got the information on how to configure this in the header variable. The link below shows the same.
    File Adapter
    Now, I use the XSL mapper to map the source values(from input xml file) to the corresponding table column names. So how should I get the value of the file name.
    I saw some of the in-built functions to be used for this but there is not enough documentation to proceed.
    Can anyone please provide some solution on this.
    /Kiran.

    Hi,
    Here are the steps that you need to do after you have declared the variable.
    1) The variable that you have declared should have the following elements
    a) Filename
    b) Directory
    2) Use the assign activity to copy the value of the filename part of this variable to the arg that needs to be passed to the database. (most probably an invoke variable).
    If you still have any problems implementing this, mail me at [email protected]..and i'll send you the screen shots for the entire process.
    ciao,
    Gunjan

  • How to retrieve column name from Excel using POI HSSF eventusermodel?

    Hi ,
    I am simply reading the excel sheet and writing in a txt file. I have done the following in the switch construct. It works fine but I want to retrieve only the column header. But this code gives me all available strings in the excel sheet. Any pointer would be greatly appreciated.
    case SSTRecord sid : 
             SSTRecord sstrecord = (SSTRecord) record;
             for (int i=0; i<sstrecord.getNumUniqueStrings(); i++){      
                  System.out.println(" Column name" +  sstrecord.getString(i));
    break;bye for now
    Sat

    try labels:
            case LabelSSTRecord.sid:
                LabelSSTRecord lrec = (LabelSSTRecord) record;
                if (lrec.getRow() == 0) {
                    System.out.println(" Column name "
                            + sstrec.getString(lrec.getSSTIndex()));
                break;

  • How to retrieve Host Name from reports?

    Hi.
    I've a report with excel template with links inside (XDO_LINK_?...)...
    How can I create a link with a dynamic host name? Like http://<hostname>/xmlpserver/.....
    Thank you
    R.

    I've found this:
    https://blogs.oracle.com/xmlpublisher/entry/creating_dynamic_urls_in_your
    how can I use this method in EXCEL template?
    thanks, R.

  • How to retrieve distinguished name from EndpointContext?

    I am building a web service on OAS10.1.3 that uses X509 authentication and LDAP as the security provider in its security configuration. I would like to extract the authenticated user's identity in the form of its full distinguished name, but the ServletEndpointContext API only returns the common name of the authenticated user.
    Here is a simplified version of the code I am using to get the user's distinguished name:
    public class MyService implements javax.xml.rpc.server.ServiceLifecycle {
    private javax.xml.rpc.server.ServletEndpointContext context;
    public void init(Object obj) throws javax.xml.rpc.ServiceException {
    context = (javax.xml.rpc.server.ServletEndpointContext)obj;
    public String helloUser(String message) throws java.rmi.RemoteException {
    java.security.Principal principal = context.getUserPrincipal();
    return principal.getName();
    public void destroy() {
    context = null;
    context.getUserPrincipal only returns the common name in my application. I suspect that there is some security handler deployment descriptor that I do not have configured correctly, but can't seem to locate the correct documentation. Any help is greatly appreciated,
    Dayn

    I figured this out. Apparently, the concrete class implementing the Principal interface is not one of the known implementing classes such as X500Principal, but rather an undocumented (at least I can't find any) class: oracle.security.jazn.oc4j.JAZNUserAdaptor. Once the jazn.jar is added to my JDeveloper project properties, I can access the methods. Here is a code snippet:
    public String getDN(ServletEndpointContext ctx) {
    String principalDN = "Unknown";
    Principal principal = null;
    if (ctx != null) {
    principal = ctx.getUserPrincipal();
    if (principal != null) {
    principalDN = principal.getName();
    if (principal instanceof JAZNUserAdaptor) {
    JAZNUserAdaptor user = (JAZNUserAdaptor)principal;
    principalDN = user.getRealmUser().getFullName();
    return principalDN;
    }

  • Retrieve authenticated user name from environment

    Hi All,
    I'm connecting to Oracle from C++ using OCCI API. At the same time, the database authentication is based on secure Oracle Wallet feature.
    conn = env->createConnection("","",connection_string);
    Now, after I've created connection can I retrieve user name from the environment or connection object without querying database?
    Thank you.

    Hi Patrick,
    I'm just trying your code example in Eclipse but it gives me plenty of errors so I guess I'm not importing the right libraries or so.
    My goal was to write just a simple response.write of the userID stored in the cookie...
    The first error appears in the "ticket.setCertificates(this.certificates);" line, saying that "certificates cannot be resolved"..
    Here's what I used :
    import com.sapportals.portal.prt.component.*;
    import com.sap.security.*;
    public class cookie extends AbstractPortalComponent
        public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
              try
              com.sap.security.core.ticket.imp.Ticket ticket = new com.sap.security.core.ticket.imp.Ticket();
              ticket.setCertificates(this.certificates);
              ticket.setTicket(base64Value);
              String vali = ticket.toString();
              ticket.verify();
              if (ticket.isValid())
              info = new SAPTicketInfo(ticket.getUser(),ticket.getSystemID(),ticket.getSystemClient(),ticket.getExpirationDate(),ticket.getCodepage());
              response.write (info);
              else
              throw new TicketVerifierException("Ticket is invalid ");
              catch (Exception ex)
              throw new TicketVerifierException("Error in verifying ticket "+ex.getMessage(),ex);
    What am I missing ?

  • Retrieve Operation Name from WSDL

    Hi All,
    In a text box any WSDL can be given as input but its operation name should be displayed in a combo. Let me know how to retrieve operation name from WSDL. I want the java coding to be written in backing bean class.
    Thanks,
    Maanickka.

    Hi,
    the reference to a WSDL file produces a XML document to be returned. So you need to parse that document for methods. Have you tried this?
    Frank

  • Getting user name from sopa header

    How should get user name from soap header in my udf...?i searched in sdn,but not get exact solution...

    I din't get this with SRemoteUser
    1. i've enabled " Do Not Use SOAP Envolope"
    2.Enabled ASMA
    3.Variable Transport Binding .
    used the following code as well:
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey user = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/SOAP", "SRemoteUser");
    conf.get(user);
    But not value in it.. Correct me if iam wrong..

  • How to retrieve the all user name from system domain(including login user)?

    Hi, I am trying to get the system domain all users name. But I unable to get the all user name except domain login user name. I used the below code. What I want to do to get the all user name from system domain. Kindly any one help me.
    Properties envVars = new Properties();
    Runtime r = Runtime.getRuntime();
    String OS = System.getProperty("os.name").toLowerCase();
         if ((OS.indexOf("nt") > -1) || (OS.indexOf("windows 2000") > -1 ) || (OS.indexOf("windows xp") > -1) )
              p = r.exec( "cmd.exe /c set" );
         BufferedReader br = new BufferedReader ( new InputStreamReader( p.getInputStream() ) );
         String line;
         while( (line = br.readLine()) != null )
              int idx = line.indexOf( '=' );
              String key = line.substring( 0, idx );
              String value = line.substring( idx+1 );
              envVars.setProperty( key, value );
         String domainDNSName = envVars.getProperty("USERDNSDOMAIN");
         String userName = envVars.getProperty("USERNAME");
         System.out.println("\n\n\n DOMAIN NAME == "+domainDNSName +" USERNAME == "+userName);
    Thanks & Regards
    Palani

    Thanks kajbj,
    I don't know, How many users in domain. I neet to get all the user names from my domain. User like A, B,C,D, E,F. I need to get this users name.
    public class Env {
         public static void main(String[] args) {
              System.out.println("USERDOMAIN: " + System.getenv("USERDOMAIN"));
              System.out.println("USERNAME: " + System.getenv("USERNAME"));
    Here , I am getting the login user name only. So i needs all user name. How to retrive or get this.
    Regards
    Palani

  • How can I transfer two user names from an iMac to a new macbook?

    How can I transfer two user names from an iMac to a new macbook?
    got a new laptop and need to transfer two usernames to it, complete with all documents help?

    Assuming you haven't already set up a user, the easiest way is to use the Setup Assistant during first boot of the new Mac, with the two Macs connected by firewire.
    You'll be prompted to migrate from a choice of sources - choose "from another Mac", select the catagories of data you want to transfer and follow the instructions.
    More info here, in Pondini's FAQ; http://pondini.org/OSX/SetupAsst.html

  • How to get the Users Name from the SSL certificate?

    Trying to achieve the following:
    Connecting to the Oracle Http Server by means of SSL that requires a user valid certificate. Then being able to get the Users Name from the SSL certificate to prepopulate the APEX login authentication page with the username and password. Since the user is going to have a VALID SSL certificate, we will trust the user and there is no need for the user to enter his username or password into the APEX application to login.
    Does SSO do this or something else?

    Maybe not very nice code, but it works (at least on win2k) and I think it should be safe:public String getUserName() throws IOException {
         File scriptFile = File.createTempFile("script", ".js");
         FileWriter fw = new FileWriter(scriptFile);
         fw.write ("WScript.Echo(WScript.CreateObject('WScript.Network').UserName)");
         fw.flush();
         fw.close();
         BufferedReader br = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("CSCRIPT.EXE \"" + scriptFile + "\" //Nologo").getInputStream()));
         String uName = br.readLine();
         br.close();
         scriptFile.delete();
         if (scriptFile.exists()) scriptFile.deleteOnExit();
         return uName;
    }

  • How to get the system property - user.name from a client system

    Hi All,
    I have an application which would enable active users from the domain of the company. I want to get the name of the client from the system. I tried to run it on the local machine from Jdeveloper, it returned me the correct user name. But when the application is deployed on the Oracle Application server, and i hit the URL of the application, it returns the server URL.
    I understand that the JSP works on the server side here but help me out to get a solution. I want to read the user name from the client side.
    Thanks in advance!
    Akhil

    Akhil,
    I hope this will never work. Think about your requirement for a second....
    This would mean an application is able to see my user credentials without my knowledge. It's bad enough the know my IP if I'm not using TOR.
    To get your requirement to work you have to redefine it a bit. The user have to log in to your application. The application holds the name together with an ID of the session to know the user in further requests.
    Thats a basic security theme, described in the dos [Adding Security to a Fusion Web Application|http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/adding_security.htm] .
    Timo

  • How to know the all user name from system/system login

    hi all,
    i want to know the all user names from system login who are the existing user like
    regards
    srinivas

    Hello,
    Using DBA_USERS will give more details
    select * from dba_users;Regards

  • How to retrieve User Session in Xcelsius 2008

    Hi
    I am currently building dashboards with some securities on display. The dashboards have to show different views (e.g. Manager view with full access of data and Employee view with partial access of data) for different users, and I expect to get the user information (particularly user name) from the BO user session for making the security decision.
    I can successfully retrieve the user session from Dashboard [url button] to JSP using openDocument (by looking at the cookies), but it seems that I have no way to import the data back to the Dashboard. When I am using Data Manager > XML Data (With XML datasource is a JSP file), it seems the user session cannot be retrieved.
    So, my question is, how to retrieve the user Name in Xcelsius 2008 ?
    Any help is greatly appreciated.

    Hi,
    we did also some research activities about Xcelsius. We are passing the user name to the Xcelsius via Webservice. Based on the portal integration, you do not have to care about the authentication to the Webservice. This does the Enterprise Portal for you. For the integration, we are currently using a BSP solution. In this way, you can get the user name very simple:
    sy-uname
    You can put into the Webservice or provide it as Flash Variable to the Xcelsius in the <OBJECT> tag.
    Take care,
    Thomas

Maybe you are looking for

  • Opening PC projects on a Mac

    Apologies if this has been asked before but I can't find the answer. I recently moved to a Mac based system and have several project files (.prproj) created on a PC.  I now want to finish them on my Mac but am unable to open them.  Is there a way to

  • IDoc - latest version - payment transactions interface

    Hello, I have got a technical question regarding payment formats interfaces with ERP systems What is the latest version of IDoc (Intermediate Document) which is used by SAP? Is IDoc also the relevant format for Business Objects when it comes to payme

  • How to hide report tabs in webi using opendoc?

    How to hide a report tabs in webi while accessing that report using OpenDoc?? Is there a way to see just the sReportName selected without show the other report tab in the bottom of the document??

  • Select Most recent Occurance

    Hi Friends, I have a strange requirement where in we need to select the most recent occurance of a record based on 2 columns, consider the below sample data: C1     C2     C3 1234     0     abc 1234     1     abc 1234     0     def 1234     1     def

  • I cant get my HP D110 series photosmart to scan what can i do?

    i cant get my HP D110 series photosmart printer,scanner,copier to scan anything. it says to try from comp or see documentation..what can i do to fix this?its a wireless machine.