Authenticate the username, create it's Subject and push it on to the thread.
It's up to the caller to save off the prior subject and make sure it gets restored,
and guard against any threading issues.

@param username
@return true if successful
174232
public static synchronized boolean pushSubject(String username) {
        if (securityService == null || username == null) {
            if (tc.isDebugEnabled()) {
                Tr.debug(tc, "returning false because user or securityService is null,"
                        + " user= " + username + " secsvc= " + securityService);
            }
            return false;
        }
        AuthenticationService authenticationService = securityService.getAuthenticationService();
        Subject tempSubject = new Subject();

        Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
        if (!authenticationService.isAllowHashTableLoginWithIdOnly()) {
            hashtable.put(AuthenticationConstants.INTERNAL_ASSERTION_KEY, Boolean.TRUE);
        }
        hashtable.put("com.ibm.wsspi.security.cred.userId", username);
        tempSubject.getPublicCredentials().add(hashtable);
        try {
            Subject new_subject = authenticationService.authenticate(JaasLoginConfigConstants.SYSTEM_WEB_INBOUND, tempSubject);
            return setRunAsSubject(new_subject);

        } catch (AuthenticationException e) {
            FFDCFilter.processException(e,
                    TokenPropagationHelper.class.getName(), "pushSubject",
                    new Object[] { username });
            Tr.error(tc, "ERROR_AUTHENTICATE", new Object[] { e.getMessage() }); // CWWKS6103E
            return false;
        } catch (Exception e) {
            FFDCFilter.processException(e,
                    TokenPropagationHelper.class.getName(), "pushSubject",
                    new Object[] { username });
            return false;
        }
    }
369371
public void deleteUser(String userName){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.DeleteUser);

        DeleteUserProtocol p = new DeleteUserProtocol(userName);

        connection.submitRequest(header, p, null);
    }
341793
public OneTimeTokenAccount create(final String username) {
        val key = getGoogleAuthenticator().createCredentials();
        return new GoogleAuthenticatorAccount(username, key.getKey(), key.getVerificationCode(), key.getScratchCodes());
    }
1114880
public ApiResponse createUser(String username, String name, String email,
            String password) {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("type", "user");
        if (username != null) {
            properties.put("username", username);
        }
        if (name != null) {
            properties.put("name", name);
        }
        if (email != null) {
            properties.put("email", email);
        }
        if (password != null) {
            properties.put("password", password);
        }
        return createEntity(properties);
    }
1023431
public Response addUserToGroup(String username, String groupName) {
		return restClient.post("users/" + username + "/groups/"+ groupName, null,
				new HashMap<String, String>());
	}
425694
public static String getUserNameFromSubject(Subject subject) {
        Iterator<Principal> it = subject.getPrincipals().iterator();
        String username = it.next().getName();
        return username;
    }
454718
public static UsernameAttribute createUsernameAttribute(byte username[]) {
		UsernameAttribute attribute = new UsernameAttribute();

		attribute.setUsername(username);
		return attribute;
	}
297052
public boolean hasUser(String userName) {
        boolean result = false;
        for (User item : getUsersList()) {
            if (item.getName().equals(userName)) {
                result = true;
            }
        }
        return result;
    }
696121
public void setUserName(String userName) {
        SystemAssert.requireArgument(userName != null && !userName.isEmpty(), "Username cannot be null or empty.");
        this.userName = userName;
    }
267553
private String username( String username ) {
        return (username.startsWith("<") && username.endsWith(">")) ? username.substring(1, username.length() - 1) : username;
    }
451212
public void authenticateAndSignin(String username, String password) {
		logger.debug("authenticateAndSignin:" + username);

		Authentication request = new UsernamePasswordAuthenticationToken(username, password);
		Authentication result = authenticationManager.authenticate(request);
		SecurityContextHolder.getContext().setAuthentication(result);
	}
121936
public Principal authenticate(String username, char password[]) 
    throws NamingException
	{
		DirContext ctx = null;
		try
		{
			String userDN = toDN(username);
			ctx = initContext(userDN, password);

			return new X500Principal(userDN);
		}
		finally
		{
			if(ctx != null)
				try{ ctx.close(); } catch(Exception e){e.printStackTrace();}
		}
	}
38102
public void setUsernamePattern(String usernamePattern) {
        Assert.hasText(usernamePattern, "Username pattern must not be empty");
        this.usernamePattern = Pattern.compile(usernamePattern);
    }
95649
@SuppressWarnings({ "squid:S1166" })
    private static UserDetails loadUserByUsername(final String username) {
        final UserDetailsService userDetailsService = SpringContextHelper.getBean(UserDetailsService.class);
        try {
            return userDetailsService.loadUserByUsername(username);
        } catch (final UsernameNotFoundException e) {
            return new User(username, "", Collections.emptyList());
        }
    }
73280
public Proxy setSocksUsername(String username) {
    verifyProxyTypeCompatibility(ProxyType.MANUAL);
    this.proxyType = ProxyType.MANUAL;
    this.socksUsername = username;
    return this;
  }
308408
@Programmatic
    public ApplicationUser findOrCreateUserByUsername(
            final String username) {
        // slightly unusual to cache a function that modifies state, but safe because this is idempotent
        return queryResultsCache.execute(new Callable<ApplicationUser>() {
            @Override
            public ApplicationUser call() throws Exception {
                final ApplicationUser applicationUser = findByUsername(username);
                if (applicationUser != null) {
                    return applicationUser;
                }
                return newDelegateUser(username, null, null);
            }
        }, ApplicationUserRepository.class, "findOrCreateUserByUsername", username);
    }
329184
@ReadOperation
    public Set<? extends MultifactorAuthenticationTrustRecord> devicesForUser(@Selector final String username) {
        val onOrAfter = expireRecordsByDate();
        return this.mfaTrustEngine.get(username, onOrAfter);
    }