Search in sources :

Example 1 with Token

use of com.haleconnect.api.user.v1.model.Token in project hale by halestudio.

the class HaleConnectServiceImpl method login.

/**
 * @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#login(java.lang.String,
 *      java.lang.String)
 */
@Override
public boolean login(String username, String password) throws HaleConnectException {
    LoginApi loginApi = UserServiceHelper.getLoginApi(this);
    Credentials credentials = UserServiceHelper.buildCredentials(username, password);
    try {
        Token token = loginApi.login(credentials);
        if (token != null) {
            UsersApi usersApi = UserServiceHelper.getUsersApi(this, token.getToken());
            // First get the current user's profile to obtain the user ID
            // required to fetch the extended profile (including the user's
            // roles/organisations) in the next step
            UserInfo shortProfile = usersApi.getProfileOfCurrentUser();
            session = new HaleConnectSessionImpl(username, token.getToken(), usersApi.getProfile(shortProfile.getId()));
            notifyLoginStateChanged();
        } else {
            clearSession();
        }
    } catch (ApiException e) {
        if (e.getCode() == 401) {
            clearSession();
        } else {
            throw new HaleConnectException(e.getMessage(), e);
        }
    }
    return isLoggedIn();
}
Also used : UsersApi(com.haleconnect.api.user.v1.api.UsersApi) Token(com.haleconnect.api.user.v1.model.Token) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) LoginApi(com.haleconnect.api.user.v1.api.LoginApi) Credentials(com.haleconnect.api.user.v1.model.Credentials) ApiException(com.haleconnect.api.user.v1.ApiException)

Aggregations

ApiException (com.haleconnect.api.user.v1.ApiException)1 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)1 UsersApi (com.haleconnect.api.user.v1.api.UsersApi)1 Credentials (com.haleconnect.api.user.v1.model.Credentials)1 Token (com.haleconnect.api.user.v1.model.Token)1 UserInfo (com.haleconnect.api.user.v1.model.UserInfo)1 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)1 HaleConnectUserInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo)1