use of com.haleconnect.api.user.v1.model.Credentials 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();
}
use of com.haleconnect.api.user.v1.model.Credentials in project hale by halestudio.
the class UserServiceHelper method buildCredentials.
/**
* Build a {@link Credentials} object. Any null values passed in will be
* converted to an empty string.
*
* @param username the user name
* @param password the password
* @return a Credentials object with the given credentials
*/
public static Credentials buildCredentials(String username, String password) {
Credentials credentials = new Credentials();
credentials.setUsername(Optional.ofNullable(username).orElse(""));
credentials.setPassword(Optional.ofNullable(password).orElse(""));
return credentials;
}
Aggregations