Search in sources :

Example 1 with UserType

use of cn.edu.tsinghua.iginx.thrift.UserType in project IginX by thulab.

the class UsersClientImpl method findUsers.

@Override
public List<User> findUsers() throws IginXException {
    GetUserReq req = new GetUserReq(sessionId);
    GetUserResp resp;
    synchronized (iginXClient) {
        iginXClient.checkIsClosed();
        try {
            resp = client.getUser(req);
            RpcUtils.verifySuccess(resp.status);
        } catch (TException | ExecutionException e) {
            throw new IginXException("find users failure: ", e);
        }
    }
    if (resp.usernames == null || resp.userTypes == null || resp.auths == null) {
        return Collections.emptyList();
    }
    List<User> users = new ArrayList<>();
    for (int i = 0; i < resp.usernames.size(); i++) {
        String username = resp.usernames.get(i);
        UserType userType = resp.userTypes.get(i);
        Set<AuthType> auths = resp.auths.get(i);
        users.add(new User(username, userType, auths));
    }
    return users;
}
Also used : TException(org.apache.thrift.TException) IginXException(cn.edu.tsinghua.iginx.session_v2.exception.IginXException) User(cn.edu.tsinghua.iginx.session_v2.domain.User) GetUserReq(cn.edu.tsinghua.iginx.thrift.GetUserReq) ArrayList(java.util.ArrayList) GetUserResp(cn.edu.tsinghua.iginx.thrift.GetUserResp) AuthType(cn.edu.tsinghua.iginx.thrift.AuthType) ExecutionException(cn.edu.tsinghua.iginx.exceptions.ExecutionException) UserType(cn.edu.tsinghua.iginx.thrift.UserType)

Example 2 with UserType

use of cn.edu.tsinghua.iginx.thrift.UserType in project IginX by thulab.

the class DefaultMetaManager method resolveUserFromConf.

private UserMeta resolveUserFromConf() {
    String username = ConfigDescriptor.getInstance().getConfig().getUsername();
    String password = ConfigDescriptor.getInstance().getConfig().getPassword();
    UserType userType = UserType.Administrator;
    Set<AuthType> auths = new HashSet<>();
    auths.add(AuthType.Read);
    auths.add(AuthType.Write);
    auths.add(AuthType.Admin);
    auths.add(AuthType.Cluster);
    return new UserMeta(username, password, userType, auths);
}
Also used : AuthType(cn.edu.tsinghua.iginx.thrift.AuthType) UserType(cn.edu.tsinghua.iginx.thrift.UserType)

Example 3 with UserType

use of cn.edu.tsinghua.iginx.thrift.UserType in project IginX by thulab.

the class UsersClientImpl method findUserByName.

@Override
public User findUserByName(String username) throws IginXException {
    Arguments.checkNotNull(username, "username");
    GetUserReq req = new GetUserReq(sessionId);
    req.setUsernames(Collections.singletonList(username));
    GetUserResp resp;
    synchronized (iginXClient) {
        iginXClient.checkIsClosed();
        try {
            resp = client.getUser(req);
            RpcUtils.verifySuccess(resp.status);
        } catch (TException | ExecutionException e) {
            throw new IginXException("find user failure: ", e);
        }
    }
    if (resp.usernames == null || resp.usernames.isEmpty()) {
        return null;
    }
    UserType userType = resp.userTypes.get(0);
    Set<AuthType> auths = resp.auths.get(0);
    return new User(username, userType, auths);
}
Also used : TException(org.apache.thrift.TException) GetUserResp(cn.edu.tsinghua.iginx.thrift.GetUserResp) IginXException(cn.edu.tsinghua.iginx.session_v2.exception.IginXException) User(cn.edu.tsinghua.iginx.session_v2.domain.User) GetUserReq(cn.edu.tsinghua.iginx.thrift.GetUserReq) AuthType(cn.edu.tsinghua.iginx.thrift.AuthType) ExecutionException(cn.edu.tsinghua.iginx.exceptions.ExecutionException) UserType(cn.edu.tsinghua.iginx.thrift.UserType)

Aggregations

AuthType (cn.edu.tsinghua.iginx.thrift.AuthType)3 UserType (cn.edu.tsinghua.iginx.thrift.UserType)3 ExecutionException (cn.edu.tsinghua.iginx.exceptions.ExecutionException)2 User (cn.edu.tsinghua.iginx.session_v2.domain.User)2 IginXException (cn.edu.tsinghua.iginx.session_v2.exception.IginXException)2 GetUserReq (cn.edu.tsinghua.iginx.thrift.GetUserReq)2 GetUserResp (cn.edu.tsinghua.iginx.thrift.GetUserResp)2 TException (org.apache.thrift.TException)2 ArrayList (java.util.ArrayList)1