aboutsummaryrefslogtreecommitdiffstats
path: root/security-utils/src/main/java/com/yahoo/security/tls/UriGlobPattern.java
blob: 18d18a5ab3c80432a88f12aea6eabc9d6ca8a3ed (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;

import java.util.Objects;

/**
 * Pattern used for matching URIs in X.509 certificate subject alternative names.
 *
 * @author bjorncs
 */
class UriGlobPattern implements RequiredPeerCredential.Pattern {

    private final GlobPattern globPattern;

    UriGlobPattern(String globPattern) {
        this.globPattern = new GlobPattern(globPattern, new char[] {'/'}, false);
    }

    @Override public String asString() { return globPattern.asString(); }

    @Override public boolean matches(String fieldValue) { return globPattern.matches(fieldValue); }

    @Override
    public String toString() {
        return "UriPattern{" +
                "pattern='" + globPattern + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UriGlobPattern that = (UriGlobPattern) o;
        return Objects.equals(globPattern, that.globPattern);
    }

    @Override
    public int hashCode() {
        return Objects.hash(globPattern);
    }
}