com.microsoft.tfs.core.util
Class UserNameUtil

java.lang.Object
  extended by com.microsoft.tfs.core.util.UserNameUtil

public class UserNameUtil
extends java.lang.Object

UserNameUtil contains static utility methods for working with TFS / Windows user names.

Equivalent to: Microsoft.TeamFoundation.Common.UserNameUtil

Since:
TEE-SDK-10.1
Thread-safety:
thread-safe

Nested Class Summary
static class UserNameUtil.ParsedUserName
          Represents a parsed user name's two components: domain and account name.
 
Field Summary
static char DOMAIN_SEPARATOR
           
 
Constructor Summary
UserNameUtil()
           
 
Method Summary
static int compare(java.lang.String username1, java.lang.String username2)
          Does a compare of two usernames / domains.
static boolean equals(java.lang.String username1, java.lang.String username2)
          Compares two usernames / domains for equality.
static java.lang.String format(java.lang.String username, java.lang.String domain)
          Formats the specified user account name and domain name.
static java.lang.String getCurrentUserDomain()
          Obtains the current user domain for this process, if available.
static java.lang.String getCurrentUserName()
          Obtains the current user name for this process, if available.
static java.lang.String getDomain(java.lang.String userName)
          Gets the domain portion of the specified user name.
static void getIdentityName(java.lang.String identityType, java.lang.String displayName, java.lang.String attribute, java.lang.String attribute2, int uniqueUserID, java.util.concurrent.atomic.AtomicReference<java.lang.String> outResolvableName, java.util.concurrent.atomic.AtomicReference<java.lang.String> outDisplayableName)
           
static java.lang.String getName(java.lang.String userName)
          Gets the name-only (no domain) portion of the specified user name.
static boolean hasDomain(java.lang.String userName)
          Tests whether the given user name contains a domain.
static boolean isComplete(java.lang.String userName)
          Tests whether the given user name is complete (contains a domain separator or equals the authenticated user constant).
static java.lang.String makeComplete(java.lang.String userName, java.lang.String relative, boolean allowAuthenticatedUserConstant)
          Completes the specified user name.
static java.util.Comparator<java.lang.String> newUsernameComparator()
           
static UserNameUtil.ParsedUserName parse(java.lang.String userName)
          Parses the specified user name, returning a UserNameUtil.ParsedUserName object that contains the user and domain portions.
static java.lang.String removeDomain(java.lang.String userName)
          Removes the domain portion from the specified user name, if present.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOMAIN_SEPARATOR

public static final char DOMAIN_SEPARATOR
Constant Field Value:
92
See Also:
Constant Field Values
Constructor Detail

UserNameUtil

public UserNameUtil()
Method Detail

getCurrentUserName

public static java.lang.String getCurrentUserName()
Obtains the current user name for this process, if available.

Returns:
the current user name, or null if not available

getCurrentUserDomain

public static java.lang.String getCurrentUserDomain()
Obtains the current user domain for this process, if available.

Returns:
the current user domain, or null if not available

equals

public static boolean equals(java.lang.String username1,
                             java.lang.String username2)
Compares two usernames / domains for equality. The strings are simply compared case-insensitively.

Parameters:
username1 - the first username to compare (must not be null)
username2 - the second username to compare (must not be null)
Returns:
true if the two usernames are equal

compare

public static int compare(java.lang.String username1,
                          java.lang.String username2)
Does a compare of two usernames / domains.

Parameters:
username1 - the first username (must not be null)
username2 - the second username (must not be null)
Returns:
the compare value

newUsernameComparator

public static java.util.Comparator<java.lang.String> newUsernameComparator()
Returns:
a new Comparator that uses the compare(String, String) method to sort usernames / domains (never null)

hasDomain

public static boolean hasDomain(java.lang.String userName)
Tests whether the given user name contains a domain.

Parameters:
userName - the user name to test (must not be null)
Returns:
true if the specified user name contains a domain

getDomain

public static java.lang.String getDomain(java.lang.String userName)
Gets the domain portion of the specified user name.

Parameters:
userName - the user name to get the domain for (must not be null )
Returns:
the domain portion or null if there is no domain portion

getName

public static java.lang.String getName(java.lang.String userName)
Gets the name-only (no domain) portion of the specified user name.

Parameters:
userName - the user name to get the name for (must not be null)
Returns:
the name portion (never null)

getIdentityName

public static void getIdentityName(java.lang.String identityType,
                                   java.lang.String displayName,
                                   java.lang.String attribute,
                                   java.lang.String attribute2,
                                   int uniqueUserID,
                                   java.util.concurrent.atomic.AtomicReference<java.lang.String> outResolvableName,
                                   java.util.concurrent.atomic.AtomicReference<java.lang.String> outDisplayableName)

isComplete

public static boolean isComplete(java.lang.String userName)
Tests whether the given user name is complete (contains a domain separator or equals the authenticated user constant).

Parameters:
userName - the user name to test (must not be null or empty)
Returns:
true if the user name is complete, false if it is not.

makeComplete

public static java.lang.String makeComplete(java.lang.String userName,
                                            java.lang.String relative,
                                            boolean allowAuthenticatedUserConstant)
Completes the specified user name. Completing a user name works the following way:
  1. If the specified user name contains a domain, the specified user name is returned
  2. If the specified user name is equal to the "authenticated user" constant (.) and allowAuthenticatedUserConstant is true, the specified user name is returned
  3. If a domain can be determined, the specified username is combined with that domain and the result is returned
  4. Otherwise, the specified user name is returned
A domain is determined in the following way:
  1. If the specified relative argument is non- null, the domain is either the relative argument or the domain portion of the relative argument
  2. If the current user domain can be determined ( getCurrentUserDomain()), that is used as the domain
  3. Otherwise, no domain can be determined

Parameters:
userName - the user name to complete (must not be null or empty)
relative - the relative argument (can be null)
allowAuthenticatedUserConstant - true to allow usernames that are equal to the authenticated user constant
Returns:
the completed user name (never null)

format

public static java.lang.String format(java.lang.String username,
                                      java.lang.String domain)
Formats the specified user account name and domain name. The result is a full NT4 style user spec (DOMAIN\\user).

Parameters:
username - the user account portion (must not be null)
domain - the domain portion (may be null)
Returns:
the full NT4 style username

removeDomain

public static java.lang.String removeDomain(java.lang.String userName)
Removes the domain portion from the specified user name, if present. If no domain portion is present, the specified user name is returned.

Parameters:
userName - user name to parse (must not be null)
Returns:
the specified user name with any domain portion removed

parse

public static UserNameUtil.ParsedUserName parse(java.lang.String userName)
Parses the specified user name, returning a UserNameUtil.ParsedUserName object that contains the user and domain portions.

Parameters:
userName - the user name to parse (must not be null)
Returns:
the parsed user name (never null)


© 2015 Microsoft. All rights reserved.