Search in sources :

Example 6 with ApiException

use of com.haleconnect.api.user.v1.ApiException 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 7 with ApiException

use of com.haleconnect.api.user.v1.ApiException in project hale by halestudio.

the class HaleConnectServiceImpl method testUserPermission.

@SuppressWarnings("unchecked")
@Override
public boolean testUserPermission(String resourceType, String role, String permission) throws HaleConnectException {
    com.haleconnect.api.user.v1.api.PermissionsApi api = UserServiceHelper.getPermissionsApi(this, this.getSession().getToken());
    try {
        Map<String, Object> permissions = (Map<String, Object>) api.getResourcePermissionInfo(resourceType, permission);
        if ("user".equals(role)) {
            Object userPermission = permissions.get("user");
            return !"false".equals(userPermission.toString());
        } else {
            // Interpret role as orgId
            Object orgPermission = permissions.get("organisations");
            if (orgPermission instanceof Map) {
                // keySet is set of organisation ids
                Map<String, Object> orgPermissions = (Map<String, Object>) orgPermission;
                Object conditions = Optional.ofNullable(orgPermissions.get(role)).orElse(Collections.EMPTY_LIST);
                if ("false".equals(conditions.toString())) {
                    return false;
                } else if (conditions instanceof List) {
                    return ((List<?>) conditions).stream().anyMatch(cond -> "organisation".equals(cond.toString()));
                }
            }
        }
    } catch (ApiException e) {
        throw new HaleConnectException(e.getMessage(), e);
    }
    return false;
}
Also used : HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) StringUtils(org.apache.commons.lang.StringUtils) Credentials(com.haleconnect.api.user.v1.model.Credentials) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ALogger(de.fhg.igd.slf4jplus.ALogger) Feedback(com.haleconnect.api.projectstore.v1.model.Feedback) SettableFuture(com.google.common.util.concurrent.SettableFuture) HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ApiException(com.haleconnect.api.user.v1.ApiException) BucketIdent(com.haleconnect.api.projectstore.v1.model.BucketIdent) SharingOptions(eu.esdihumboldt.hale.io.haleconnect.project.SharingOptions) BucketDetail(com.haleconnect.api.projectstore.v1.model.BucketDetail) NewBucket(com.haleconnect.api.projectstore.v1.model.NewBucket) FilesApi(com.haleconnect.api.projectstore.v1.api.FilesApi) LocatableInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.LocatableInputSupplier) UsersApi(com.haleconnect.api.user.v1.api.UsersApi) Map(java.util.Map) Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) PermissionsApi(com.haleconnect.api.projectstore.v1.api.PermissionsApi) URI(java.net.URI) OrganisationInfo(com.haleconnect.api.user.v1.model.OrganisationInfo) OrganisationsApi(com.haleconnect.api.user.v1.api.OrganisationsApi) ProgressIndicator(eu.esdihumboldt.hale.common.core.io.ProgressIndicator) ApiCallback(com.haleconnect.api.projectstore.v1.ApiCallback) HaleConnectSession(eu.esdihumboldt.hale.io.haleconnect.HaleConnectSession) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Token(com.haleconnect.api.user.v1.model.Token) ALoggerFactory(de.fhg.igd.slf4jplus.ALoggerFactory) HaleConnectProjectInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) File(java.io.File) HaleConnectInputSupplier(eu.esdihumboldt.hale.io.haleconnect.HaleConnectInputSupplier) HaleConnectUrnBuilder(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUrnBuilder) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) LoginApi(com.haleconnect.api.user.v1.api.LoginApi) List(java.util.List) HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) HaleConnectServiceListener(eu.esdihumboldt.hale.io.haleconnect.HaleConnectServiceListener) Optional(java.util.Optional) BasePathManager(eu.esdihumboldt.hale.io.haleconnect.BasePathManager) Collections(java.util.Collections) BucketsApi(com.haleconnect.api.projectstore.v1.api.BucketsApi) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ApiException(com.haleconnect.api.user.v1.ApiException)

Aggregations

ApiException (com.haleconnect.api.user.v1.ApiException)5 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)5 UsersApi (com.haleconnect.api.user.v1.api.UsersApi)3 UserInfo (com.haleconnect.api.user.v1.model.UserInfo)3 HaleConnectUserInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo)3 ApiCallback (com.haleconnect.api.projectstore.v1.ApiCallback)2 ApiException (com.haleconnect.api.projectstore.v1.ApiException)2 BucketsApi (com.haleconnect.api.projectstore.v1.api.BucketsApi)2 FilesApi (com.haleconnect.api.projectstore.v1.api.FilesApi)2 BucketDetail (com.haleconnect.api.projectstore.v1.model.BucketDetail)2 Feedback (com.haleconnect.api.projectstore.v1.model.Feedback)2 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)2 OrganisationsApi (com.haleconnect.api.user.v1.api.OrganisationsApi)2 Credentials (com.haleconnect.api.user.v1.model.Credentials)2 OrganisationInfo (com.haleconnect.api.user.v1.model.OrganisationInfo)2 Token (com.haleconnect.api.user.v1.model.Token)2 HaleConnectOrganisationInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo)2 File (java.io.File)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1