Buggy code:
public class OAuth2Util { public static final String IMPLICIT = "implicit" ; private static Log log = LogFactory . getLog ( OAuth2Util . class ) ; private static boolean cacheEnabled = OAuthServerConfiguration . getInstance ( ) . isCacheEnabled ( ) ; private static OAuthCache cache = OAuthCache . getInstance ( OAuthServerConfiguration . getInstance ( ) . getOAuthCacheTimeout ( ) ) ; private static long timestampSkew = ( OAuthServerConfiguration . getInstance ( ) . getTimeStampSkewInSeconds ( ) ) * 1000 ; private static ThreadLocal < Integer > clientTenatId = new ThreadLocal < > ( ) ; private OAuth2Util ( ) { } public static int getClientTenatId ( ) { } public static void setClientTenatId ( int tenantId ) { } public static void clearClientTenantId ( ) { } public static String buildScopeString ( String [ ] scopes ) { } public static String [ ] buildScopeArray ( String scopeStr ) { } public static boolean authenticateClient ( String clientId , String clientSecretProvided ) throws IdentityOAuthAdminException , InvalidOAuthClientException , IdentityOAuth2Exception { } public static String getAuthenticatedUsername ( String clientId , String clientSecretProvided ) throws IdentityOAuthAdminException , InvalidOAuthClientException , IdentityOAuth2Exception { } public static String buildCacheKeyStringForAuthzCode ( String clientId , String authzCode ) { } public static AccessTokenDO validateAccessTokenDO ( AccessTokenDO accessTokenDO ) { } public static boolean checkAccessTokenPartitioningEnabled ( ) { } public static boolean checkUserNameAssertionEnabled ( ) { } public static String getAccessTokenPartitioningDomains ( ) { } public static Map < String , String > getAvailableUserStoreDomainMappings ( ) throws IdentityOAuth2Exception { } public static String getUserStoreDomainFromUserId ( String userId ) throws IdentityOAuth2Exception { } public static String getUserStoreDomainFromAccessToken ( String apiKey ) throws IdentityOAuth2Exception { } public static String getAccessTokenStoreTableFromUserId ( String userId ) throws IdentityOAuth2Exception { } public static String getAccessTokenStoreTableFromAccessToken ( String apiKey ) throws IdentityOAuth2Exception { } public static String getUserIdFromAccessToken ( String apiKey ) { } public static String getSafeText ( String text ) { } public static long getTokenExpireTimeMillis ( AccessTokenDO accessTokenDO ) { } public static long getRefreshTokenExpireTimeMillis ( AccessTokenDO accessTokenDO ) { } public static long getAccessTokenExpireMillis ( AccessTokenDO accessTokenDO ) { } public static int getTenantId ( String tenantDomain ) throws IdentityOAuth2Exception { } public static String getTenantDomain ( int tenantId ) throws IdentityOAuth2Exception { } public static int getTenantIdFromUserName ( String username ) throws IdentityOAuth2Exception { } public static String hashScopes ( String [ ] scope ) { } public static String hashScopes ( String scope ) { } public static boolean isUsernameCaseSensitive ( String username ) { boolean isUsernameCaseSensitive = false ; try { String tenantDomain = MultitenantUtils . getTenantDomain ( username ) ; int tenantId = OAuthComponentServiceHolder . getRealmService ( ) . getTenantManager ( ) . getTenantId ( tenantDomain ) ; UserStoreManager userStoreManager = ( ( UserStoreManager ) ( OAuthComponentServiceHolder . getRealmService ( ) . getTenantUserRealm ( tenantId ) . getUserStoreManager ( ) ) ) ; <START_BUG> UserStoreManager UserAvailableUserStoreManager = userStoreManager . getSecondaryUserStoreManager ( OAuth2Util . getDomainFromName ( username ) ) ; <END_BUG> String caseInsensitiveUsername = UserAvailableUserStoreManager . getRealmConfiguration ( ) . getUserStoreProperty ( "CaseInsensitiveUsername" ) ; if ( caseInsensitiveUsername != null ) { isUsernameCaseSensitive = ! ( Boolean . parseBoolean ( caseInsensitiveUsername ) ) ; } } catch ( UserStoreException e ) { if ( OAuth2Util . log . isDebugEnabled ( ) ) { OAuth2Util . log . debug ( "Error<seq2seq4repair_space>while<seq2seq4repair_space>reading<seq2seq4repair_space>user<seq2seq4repair_space>store<seq2seq4repair_space>property<seq2seq4repair_space>CaseInsensitiveUsername.<seq2seq4repair_space>Considering<seq2seq4repair_space>as<seq2seq4repair_space>false." ) ; } } return isUsernameCaseSensitive ; } public static String getDomainFromName ( String name ) { } public static User getUserFromName ( String username ) { } public static String getUsernameFromUser ( User user ) { } }

Fix:
UserStoreManager UserAvailableUserStoreManager = userStoreManager . getSecondaryUserStoreManager ( UserCoreUtil . extractDomainFromName ( username ) ) ;