Search in sources :

Example 1 with UserInfo

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

Example 3 with UserInfo

use of org.alfresco.repo.event.v1.model.UserInfo in project alfresco-repository by Alfresco.

the class NodeResourceHelper method createNodeResourceBuilder.

public NodeResource.Builder createNodeResourceBuilder(NodeRef nodeRef) {
    final QName type = nodeService.getType(nodeRef);
    final Path path = nodeService.getPath(nodeRef);
    final Map<QName, Serializable> properties = getProperties(nodeRef);
    // minor: save one lookup if creator & modifier are the same
    Map<String, UserInfo> mapUserCache = new HashMap<>(2);
    return NodeResource.builder().setId(nodeRef.getId()).setName((String) properties.get(ContentModel.PROP_NAME)).setNodeType(getQNamePrefixString(type)).setIsFile(isSubClass(type, ContentModel.TYPE_CONTENT)).setIsFolder(isSubClass(type, ContentModel.TYPE_FOLDER)).setCreatedByUser(getUserInfo((String) properties.get(ContentModel.PROP_CREATOR), mapUserCache)).setCreatedAt(getZonedDateTime((Date) properties.get(ContentModel.PROP_CREATED))).setModifiedByUser(getUserInfo((String) properties.get(ContentModel.PROP_MODIFIER), mapUserCache)).setModifiedAt(getZonedDateTime((Date) properties.get(ContentModel.PROP_MODIFIED))).setContent(getContentInfo(properties)).setPrimaryHierarchy(PathUtil.getNodeIdsInReverse(path, false)).setProperties(mapToNodeProperties(properties)).setAspectNames(getMappedAspects(nodeRef));
}
Also used : Path(org.alfresco.service.cmr.repository.Path) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) UserInfo(org.alfresco.repo.event.v1.model.UserInfo) Date(java.util.Date)

Example 4 with UserInfo

use of org.alfresco.repo.event.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);
}
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 5 with UserInfo

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

Aggregations

UserInfo (com.developmentontheedge.be5.model.UserInfo)3 UserInfo (org.alfresco.repo.event.v1.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 Serializable (java.io.Serializable)2 QName (org.alfresco.service.namespace.QName)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 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 ContentInfo (org.alfresco.repo.event.v1.model.ContentInfo)1 Builder (org.alfresco.repo.event.v1.model.NodeResource.Builder)1