Authenticated user.
@return User identity
@throws IOException If fails
11146
public Identity identity() throws IOException {
        final Iterator<String> headers =
            new RqHeaders.Base(this).header(this.header).iterator();
        final Identity user;
        if (headers.hasNext()) {
            user = new CcPlain().decode(
                new Utf8String(headers.next()).asBytes()
            );
        } else {
            user = Identity.ANONYMOUS;
        }
        return user;
    }
137563
private Identity fetch(final String token) throws IOException {
        final String uri = new Href(this.api).path("user")
            .with(PsGithub.ACCESS_TOKEN, token).toString();
        return PsGithub.parse(
            new JdkRequest(uri)
                .header("accept", "application/json")
                .fetch().as(RestResponse.class)
                .assertStatus(HttpURLConnection.HTTP_OK)
                .as(JsonResponse.class).json().readObject()
        );
    }
834988
@Override
	public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		final String requestURI = request.getRequestURI();
		UserAuthentication userAuth = null;
		String username = request.getParameter(USERNAME);
		String password = request.getParameter(PASSWORD);
		String appid = SecurityUtils.getAppidFromAuthRequest(request);

		if (requestURI.endsWith(LDAP_ACTION) && !StringUtils.isBlank(username) && !StringUtils.isBlank(password)) {
			try	{
				App app = Para.getDAO().read(App.id(appid == null ? Config.getRootAppIdentifier() : appid));
				Authentication auth = new LDAPAuthentication(username, password).withApp(app);
				// set authentication in context to avoid warning message from SpringSecurityAuthenticationSource
				SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("key",
						"anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS")));
				Authentication ldapAuth = getAuthenticationManager().authenticate(auth);
				if (ldapAuth != null) {
					//success!
					userAuth = getOrCreateUser(app, ldapAuth);
				}
			} catch (Exception ex) {
				LOG.info("Failed to authenticate '{}' with LDAP server: {}", username, ex.getMessage());
				throw new AuthenticationServiceException(ex.getMessage(), ex.getCause());
			}
		}

		return SecurityUtils.checkIfActive(userAuth, SecurityUtils.getAuthenticatedUser(userAuth), true);
	}
1200638
@Override
    public synchronized void authenticate() throws PortalSecurityException {
        this.isauth = false;
        if (this.myPrincipal.UID != null && this.myOpaqueCredentials.credentialstring != null) {

            try {

                ILocalAccountDao accountStore = LocalAccountDaoLocator.getLocalAccountDao();
                IPortalPasswordService passwordService =
                        PortalPasswordServiceLocator.getPortalPasswordService();

                // retrieve the account from the local user store
                ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID);

                if (account != null) {

                    // get the account password as an ASCII string
                    String loginPassword =
                            new String(this.myOpaqueCredentials.credentialstring, UTF_8);

                    // if the password provided at login matches the hashed
                    // account password, authenticate the user
                    if (passwordService.validatePassword(loginPassword, account.getPassword())) {

                        // set the full name for this user
                        String fullName = (String) account.getAttributeValue("displayName");
                        this.myPrincipal.FullName = fullName;
                        if (log.isInfoEnabled())
                            log.info("User " + this.myPrincipal.UID + " is authenticated");
                        this.isauth = true;
                    } else {
                        log.info("Password Invalid");
                    }

                } else {
                    if (log.isInfoEnabled()) log.info("No such user: " + this.myPrincipal.UID);
                }
            } catch (Exception e) {
                log.error("Error authenticating user", e);
                throw new RuntimeException("Error authenticating user", e);
            }
        }
        // If the principal and/or credential are missing, the context authentication
        // simply fails. It should not be construed that this is an error. It happens for guest
        // access.
        else {
            log.info("Principal or OpaqueCredentials not initialized prior to authenticate");
        }
        // Ok...we are now ready to authenticate all of our subcontexts.
        super.authenticate();
        return;
    }
527598
protected Integer getUserId() {
        Integer userId = ThreadContext.getContext(UserWebConstant.CTX_USERID);
        if (userId != null) {
            return userId;
        }
        return null;
    }
116304
public Authentication getAuthentication() {
        String username = getValueModel(LoginDetails.PROPERTY_USERNAME, String.class).getValue();
        String password = getValueModel(LoginDetails.PROPERTY_PASSWORD, String.class).getValue();
        return new UsernamePasswordAuthenticationToken( username, password );
    }
292760
private boolean doUserPasswordAuthentication(Socket s,
                                                InputStream in,
                                                OutputStream out) 
                                                throws IOException{
     int version = in.read();
     if(version != 1) return false;
     int ulen = in.read();
     if(ulen < 0) return false;
     byte[] user = new byte[ulen];
     in.read(user);
     int plen = in.read();
     if(plen < 0) return false;
     byte[] password = new byte[plen];
     in.read(password);

     if(validator.isUserValid(new String(user), new String(password),s)){
       //System.out.println("user valid");
       out.write(new byte[]{1,0});
     }else{
       //System.out.println("user invalid");
       out.write(new byte[]{1,1});
       return false;
     }

     return true;
   }
977462
public static final User readUserForIdentifier(final User u) {
		if (u == null || StringUtils.isBlank(u.getIdentifier())) {
			return null;
		}
		User user = null;
		String password = null;
		String identifier = u.getIdentifier();
		// Try to read the identifier object first, then read the user object linked to it.
		Sysprop s = CoreUtils.getInstance().getDao().read(u.getAppid(), identifier);
		if (s != null && s.getCreatorid() != null) {
			user = CoreUtils.getInstance().getDao().read(u.getAppid(), s.getCreatorid());
			password = (String) s.getProperty(Config._PASSWORD);
		}
		// Try to find the user by email if already created, but with a different identifier.
		// This prevents users with identical emails to have separate accounts by signing in through
		// different identity providers.
		if (user == null && !StringUtils.isBlank(u.getEmail())) {
			HashMap<String, Object> terms = new HashMap<>(2);
			terms.put(Config._EMAIL, u.getEmail());
			terms.put(Config._APPID, u.getAppid());
			List<User> users = CoreUtils.getInstance().getSearch().
					findTerms(u.getAppid(), u.getType(), terms, true, new Pager(1));
			if (!users.isEmpty()) {
				user = users.get(0);
				password = Utils.generateSecurityToken();
				user.createIdentifier(u.getIdentifier(), password);
			}
		}
		if (user != null) {
			if (password != null) {
				user.setPassword(password);
			}
			if (!identifier.equals(user.getIdentifier())) {
				logger.info("Identifier changed for user '{}', from {} to {}.",
						user.getId(), user.getIdentifier(), identifier);
				// the main identifier was changed - update
				user.setIdentifier(identifier);
				CoreUtils.getInstance().getDao().update(user.getAppid(), user);
			}
			return user;
		}
		logger.debug("User not found for identifier {}/{}, {}.", u.getAppid(), identifier, u.getId());
		return null;
	}
1429
@Override
    public Subject authenticate(@Sensitive byte[] tokenBytes) throws AuthenticationException {
        AuthenticationData authenticationData = createAuthenticationData(tokenBytes);
        return authenticationService.authenticate(jaasEntryName, authenticationData, null);
    }
1289785
public void identity_user_user_DELETE(String user) throws IOException {
		String qPath = "/me/identity/user/{user}";
		StringBuilder sb = path(qPath, user);
		exec(qPath, "DELETE", sb.toString(), null);
	}
769129
public static  UUID getOrCreateUserToken() {
        UUID userToken;
        if (Request.getPerThreadRequestData().getRequestId() != null) {
            try {
                userToken = UUID.fromString(Request.getPerThreadRequestData().getRequestId());
            } catch (final IllegalArgumentException ignored) {
                userToken = UUIDs.randomUUID();
            }
        } else {
            userToken = UUIDs.randomUUID();
        }
        return userToken;
    }
3080
public void login(AuthenticatedUser user) throws AuthenticationException
    {
        if (!user.isAnonymous() && !Auth.isExistingUser(user.getName()))
           throw new AuthenticationException(String.format("User %s doesn't exist - create it with CREATE USER query first",
                                                           user.getName()));
        this.user = user;
    }
714922
public static User get(AlluxioConfiguration conf) throws IOException {
    if (!SecurityUtils.isAuthenticationEnabled(conf)) {
      throw new IOException(ExceptionMessage.AUTHENTICATION_IS_NOT_ENABLED.getMessage());
    }
    return sUserThreadLocal.get();
  }
389070
public OkCoinFuturesUserInfoCross getFutureUserInfo() throws IOException {

    OkCoinFuturesUserInfoCross futuresUserInfoCross =
        okCoin.getFuturesUserInfoCross(apikey, signatureCreator());

    return returnOrThrow(futuresUserInfoCross);
  }
853999
@JsonIgnore
	public String getUsername() {
		if (App.isRoot(user.getAppid())) {
			return user.getIdentifier();
		} else {
			return user.getAppid() + "/" + user.getIdentifier();
		}
	}
1196938
@Override
	public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		final String requestURI = request.getRequestURI();
		UserAuthentication userAuth = null;

		if (requestURI.endsWith(TWITTER_ACTION)) {
			String verifier = request.getParameter("oauth_verifier");
			String appid = SecurityUtils.getAppidFromAuthRequest(request);
			String denied = request.getParameter("denied");
			String redirectURI = SecurityUtils.getRedirectUrl(request) + (appid == null ? "" : "?appid=" + appid);
			App app = Para.getDAO().read(App.id(appid == null ? Config.getRootAppIdentifier() : appid));
			String[] keys = SecurityUtils.getOAuthKeysForApp(app, Config.TWITTER_PREFIX);
			if (denied != null) {
				throw new BadCredentialsException("Cancelled.");
			}

			if (verifier == null && stepOne(response, redirectURI, keys)) {
				return null;
			} else {
				userAuth = stepTwo(request, verifier, keys, app);
			}
		}

		return SecurityUtils.checkIfActive(userAuth, SecurityUtils.getAuthenticatedUser(userAuth), true);
	}
187365
protected IPromise<BasicAuthenticationResult> getCredentials(String user, String pw, String jwt) {
        Promise p = new Promise();
        if ( SESSIONID_SPECIAL_STRING.equals(pw) ) {
            sessionStorage.getUserFromSessionId(user).then( (r,e) -> {
                if ( r != null ) {
                    sessionStorage.getUser(r).then( (rec,err) -> {
                        if ( rec != null )
                            getCredentials(rec.getKey(),rec.getString("pwd"), null ).then(p);
                        else
                            p.reject("unknown user");
                    });
                } else {
                    p.reject("authentication failed");
                }
            });
        } else {
            sessionStorage.getUser(user).then((rec, err) -> {
                if (rec == null) {
                    p.reject("wrong user or password");
                } else {
                    if (pw.equals(rec.getString("pwd"))) {
                        if (!rec.getBool("verified")) {
                            // e.g. email verification etc.
                            p.reject("account not verified");
                        } else
                            p.resolve(new BasicAuthenticationResult().userName(rec.getKey()));
                    }
                }
            });
        }
        return p;
    }