aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/SimplePrincipal.java
blob: 1ac43d4bb149c2cba4db9382c50e12e3deb88f7a (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.role;

import java.security.Principal;

/**
 * A principal wrapper of a single String entry.
 *
 * @author jonmv
 */
public class SimplePrincipal implements Principal {

    private final String name;

    public SimplePrincipal(String name) {
        if (name.isBlank())
            throw new IllegalArgumentException("Name cannot be blank");
        this.name = name;
    }

    public static SimplePrincipal of(Principal principal) {
        return new SimplePrincipal(principal.getName());
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        return name.equals(((SimplePrincipal) o).name);
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }

}