BEA Systems, Inc.

weblogic.security
Class SubjectUtils

java.lang.Object
  extended by weblogic.security.SubjectUtils

public class SubjectUtils
extends Object

This class contains utilities for managing Subjects.


Constructor Summary
SubjectUtils()
           
 
Method Summary
static void checkSubjectNonNull(Object subject)
          Throws an IllegalArgumentException if the Subject is null.
static String displaySubject(Subject subject)
          Gives a detailed display of a Subject.
static Subject getAnonymousUser()
          Returns an unmodifiable Subject that corresponds to an anonymous user.
static String getUsername(Subject s)
          Returns a username for the specified Subject.
static Principal getUserPrincipal(Subject s)
          Returns a principal for the specified Subject that represents the current user of the Web application.
static boolean isUserAnAdministrator(Subject subject)
          Returns true if the Subject has Administrator privileges.
static boolean isUserAnonymous(Subject subject)
          Returns true if and only if the user is the anonymous user.
static boolean isUserInGroup(weblogic.security.acl.internal.AuthenticatedSubject s, String group)
          Returns true if the Subject is in the specified group.
static boolean isUserInGroup(Subject s, String group)
          Returns true if the Subject is in the specified group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubjectUtils

public SubjectUtils()
Method Detail

getUserPrincipal

public static Principal getUserPrincipal(Subject s)
Returns a principal for the specified Subject that represents the current user of the Web application. This method returns a WLSUser Principal if one exists in the current user. In the case of multiple WLSUser Principals, the method returns the first in the ordering defined by the Subject.getPrincipals().iterator() method. If there are no WLSUser Principals, then the getUserPrincipal method returns the first non-WLSGroup Principal. If there are no Principals or all Principals are of type WLSGroup, this method returns null.

Parameters:
s - the Subject to extract the user from
Returns:
a Principal representing the user for the Subject or null
See Also:
WLSUser, WLSGroup

getUsername

public static String getUsername(Subject s)
Returns a username for the specified Subject. Simply a utility to call getUserPrincipal() then getName() on the returned Principal.

Parameters:
s - the Subject to extract the user name from.
Returns:
the name of the Subject or null.

displaySubject

public static String displaySubject(Subject subject)
Gives a detailed display of a Subject.

Parameters:
subject - Subject to display.
Returns:
detailed display of Subject.

isUserInGroup

public static boolean isUserInGroup(Subject s,
                                    String group)
Returns true if the Subject is in the specified group. This method knows how to handle both WLSGroup's and RealmAdapter groups as well.

Parameters:
s - Subject to determine if the user is in the group.
group - name of group to compare.
Returns:
true if the user is in the group, false otherwise.
See Also:
WLSGroup

isUserInGroup

public static boolean isUserInGroup(weblogic.security.acl.internal.AuthenticatedSubject s,
                                    String group)
Returns true if the Subject is in the specified group.

Parameters:
s - AuthenticatedSubject to determin if the user is in the group
group - name of group to compare
Returns:
true if the user is in the group, false otherwise
See Also:
WLSGroup

getAnonymousUser

public static Subject getAnonymousUser()
Returns an unmodifiable Subject that corresponds to an anonymous user.

Returns:
the anonymous user. It is set Read Only.

isUserAnonymous

public static boolean isUserAnonymous(Subject subject)
Returns true if and only if the user is the anonymous user.

Parameters:
subject - the subject.
Returns:
true if and only if the user is the anonymous user.

isUserAnAdministrator

public static boolean isUserAnAdministrator(Subject subject)
Returns true if the Subject has Administrator privileges.

Parameters:
subject - subject to test for Administrator privileges.
Returns:
true if subject has Administrator privileges, false otherwise.

checkSubjectNonNull

public static void checkSubjectNonNull(Object subject)
Throws an IllegalArgumentException if the Subject is null.

Parameters:
subject - the subject to check.
Throws:
IllegalArgumentException - if subject is null.

Documentation is available at
http://download.oracle.com/docs/cd/E13222_01/wls/docs92
Copyright 2006 BEA Systems Inc.