[OOM cert-service-client] Add validation of email, ip and domain name
[oom/platform/cert-service.git] / certServiceClient / src / main / java / org / onap / oom / certservice / client / configuration / model / San.java
1 /*
2  * ============LICENSE_START=======================================================
3  * oom-certservice-client
4  * ================================================================================
5  * Copyright (C) 2020 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.oom.certservice.client.configuration.model;
22
23 import java.util.Objects;
24
25 public final class San {
26
27     private final String value;
28     private final int type;
29
30     public San(String value, int type) {
31         this.value = value;
32         this.type = type;
33     }
34
35     public String getValue() {
36         return value;
37     }
38
39     public int getType() {
40         return type;
41     }
42
43     public String toString() {
44         return "{SAN value: " + value + ", type: " + getReadableType(type) + '}';
45     }
46
47     public boolean equals(Object o) {
48         if (this == o) {
49             return true;
50         }
51         if (o == null || getClass() != o.getClass()) {
52             return false;
53         }
54         San san1 = (San) o;
55         return type == san1.type &&
56             Objects.equals(value, san1.value);
57     }
58
59     public int hashCode() {
60         return Objects.hash(value, type);
61     }
62
63     private String getReadableType(int type) {
64         String readableType = "undefined";
65         switch (type) {
66             case 1: readableType = "rfc822Name"; break;
67             case 2: readableType = "dNSName"; break;
68             case 6: readableType = "uniformResourceIdentifier"; break;
69             case 7: readableType = "iPAddress"; break;
70         }
71         return readableType;
72     }
73 }