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();
}
Aggregations