Search in sources :

Example 1 with UserInfo

use of com.developmentontheedge.be5.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();
}
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)

Example 2 with UserInfo

use of com.developmentontheedge.be5.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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) UserInfo(com.developmentontheedge.be5.model.UserInfo)

Example 3 with UserInfo

use of com.developmentontheedge.be5.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);
}
Also used : UsersApi(com.haleconnect.api.user.v1.api.UsersApi) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 4 with UserInfo

use of com.developmentontheedge.be5.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);
}
Also used : UserInfo(com.developmentontheedge.be5.model.UserInfo) Session(com.developmentontheedge.be5.api.Session)

Example 5 with UserInfo

use of com.developmentontheedge.be5.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;
}
Also used : UserInfo(com.developmentontheedge.be5.model.UserInfo)

Aggregations

UserInfo (com.developmentontheedge.be5.model.UserInfo)3 ApiException (com.haleconnect.api.user.v1.ApiException)2 UsersApi (com.haleconnect.api.user.v1.api.UsersApi)2 UserInfo (com.haleconnect.api.user.v1.model.UserInfo)2 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)2 HaleConnectUserInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo)2 Session (com.developmentontheedge.be5.api.Session)1 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)1 Credentials (com.haleconnect.api.user.v1.model.Credentials)1 Token (com.haleconnect.api.user.v1.model.Token)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1