aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixUser.java
blob: 78fc4b151c75db721f5ca29bffeffd7885722116 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.file;

import java.util.Objects;

/**
 * A regular UNIX-style user and its primary group.
 *
 * @author mpolden
 */
public class UnixUser {

    public static final UnixUser ROOT = new UnixUser("root", 0, "root", 0);
    public static final UnixUser VESPA = new UnixUser("vespa", 1000, "vespa", 1000);

    private final String name;
    private final int uid;
    private final String group;
    private final int gid;

    public UnixUser(String name, int uid, String group, int gid) {
        this.name = name;
        this.uid = uid;
        this.group = group;
        this.gid = gid;
    }

    /** Username of this */
    public String name() { return name; }

    /** User ID of this */
    public int uid() { return uid; }

    /** Primary group of this */
    public String group() { return group; }

    /** Primary group ID of this */
    public int gid() { return gid; }

    @Override
    public String toString() {
        return "user " + name + ":" + group;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UnixUser unixUser = (UnixUser) o;
        return uid == unixUser.uid && name.equals(unixUser.name) &&
                gid == unixUser.gid && group.equals(unixUser.group);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uid, name, gid, group);
    }
}