code: static Subject createSubject(final String recoverUserName, final String recoverPassword,
                                  final ManagedConnectionFactory mcf)
     {
        if (System.getSecurityManager() == null)
        {
           Set<Principal> principals = new HashSet<Principal>();
           Set<Object> pubCredentials = new HashSet<Object>();
           Set<Object> privCredentials = new HashSet<Object>();
  
           // Principals
           Principal p = new SimplePrincipal(recoverUserName);
           principals.add(p);
  
           // PublicCredentials
           // None
  
           // PrivateCredentials
           PasswordCredential pc = new PasswordCredential(recoverUserName, recoverPassword.toCharArray());
           pc.setManagedConnectionFactory(mcf);
           privCredentials.add(pc);
  
           return new Subject(false, principals, pubCredentials, privCredentials);
        }
  
        return AccessController.doPrivileged(new PrivilegedAction<Subject>() 
        {
           public Subject run()
           {
              Set<Principal> principals = new HashSet<Principal>();
              Set<Object> pubCredentials = new HashSet<Object>();
              Set<Object> privCredentials = new HashSet<Object>();
  
              // Principals
              Principal p = new SimplePrincipal(recoverUserName);
              principals.add(p);
  
              // PublicCredentials
              // None
  
              // PrivateCredentials
              PasswordCredential pc = new PasswordCredential(recoverUserName, recoverPassword.toCharArray());
              pc.setManagedConnectionFactory(mcf);
              privCredentials.add(pc);
  
              return new Subject(false, principals, pubCredentials, privCredentials);
           }
        });
     }
docs: Get a Subject instance
  @param recoverUserName The user name
  @param recoverPassword The password
  @param mcf The ManagedConnectionFactory
  @return The instance