use of com.haleconnect.api.user.v1.model.UserInfo 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.UserInfo in project be5 by DevelopmentOnTheEdge.
the class AuthenticationPropagationListener method requestInitialized.
@Override
public void requestInitialized(ServletRequestEvent event) {
HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
HttpSession session = request.getSession(false);
if (session == null) {
return;
}
UserInfo user = (UserInfo) session.getAttribute(SessionConstants.USER_INFO);
UserInfoHolder.setUserInfo(user);
}
use of com.haleconnect.api.user.v1.model.UserInfo in project hale by halestudio.
the class HaleConnectServiceImpl method getUserInfo.
/**
* @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#getUserInfo(java.lang.String)
*/
@Override
public HaleConnectUserInfo getUserInfo(String userId) throws HaleConnectException {
if (!this.isLoggedIn()) {
return null;
}
if (!userInfoCache.containsKey(userId)) {
UsersApi api = UserServiceHelper.getUsersApi(this, this.getSession().getToken());
try {
UserInfo info = api.getProfile(userId);
userInfoCache.put(info.getId(), new HaleConnectUserInfo(info.getId(), info.getScreenName(), info.getFullName()));
} catch (ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
}
return userInfoCache.get(userId);
}
use of com.haleconnect.api.user.v1.model.UserInfo in project be5 by DevelopmentOnTheEdge.
the class LoginServiceImpl method saveUser.
@Override
public void saveUser(String username, Request req) {
List<String> availableRoles = selectAvailableRoles(username);
if (ModuleLoader2.getDevRoles().size() > 0) {
availableRoles.addAll(ModuleLoader2.getDevRoles());
}
String savedRoles = coreUtils.getUserSetting(username, DatabaseConstants.CURRENT_ROLE_LIST);
List<String> currentRoles;
if (savedRoles != null) {
currentRoles = parseRoles(savedRoles);
} else {
currentRoles = availableRoles;
}
UserInfo ui = userHelper.saveUser(username, availableRoles, currentRoles, req.getLocale(), req.getRemoteAddr(), req.getSession());
Session session = req.getSession();
session.set("remoteAddr", req.getRemoteAddr());
session.set(SessionConstants.USER_INFO, ui);
session.set(SessionConstants.CURRENT_USER, ui.getUserName());
log.fine("Login user: " + username);
}
use of com.haleconnect.api.user.v1.model.UserInfo in project be5 by DevelopmentOnTheEdge.
the class UserHelper method saveUser.
public UserInfo saveUser(String userName, List<String> availableRoles, List<String> currentRoles, Locale locale, String remoteAddr, Session session) {
UserInfo ui = new UserInfo(userName, availableRoles, currentRoles, session);
ui.setRemoteAddr(remoteAddr);
ui.setLocale(meta.getLocale(locale));
UserInfoHolder.setUserInfo(ui);
return ui;
}
Aggregations