View Javadoc
1   /*
2    * Copyright 2017 the original author or authors.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package org.openehealth.ipf.commons.audit.model;
18  
19  import lombok.EqualsAndHashCode;
20  import lombok.Getter;
21  
22  import java.io.Serializable;
23  import java.nio.charset.StandardCharsets;
24  import java.util.Base64;
25  
26  import static java.util.Objects.requireNonNull;
27  
28  /**
29   * The ValuePair is used in {@link ParticipantObjectIdentificationType} descriptions to capture
30   * parameters.
31   * All values (even those that are normally plain text) are encoded as Base64.
32   * This is to preserve details of encoding (e.g., nulls) and to protect against text
33   * contents that contain XML fragments. These are known attack points against applications,
34   * so security logs can be expected to need to capture them without modification by the
35   * audit encoding process.
36   *
37   * @author Christian Ohr
38   * @since 3.5
39   */
40  @EqualsAndHashCode
41  public class TypeValuePairType implements Serializable {
42  
43      @Getter
44      private final String type;
45  
46      @Getter
47      private final byte[] value;
48  
49      /**
50       * Creates an instance
51       *
52       * @param type  type
53       * @param value value string, NOT yet base64 encoded
54       */
55      public TypeValuePairType(String type, String value) {
56          this(type, Base64.getEncoder().encode(value.getBytes(StandardCharsets.UTF_8)));
57      }
58  
59      /**
60       * Creates an instance
61       *
62       * @param type  type
63       * @param value value string, base64 encoded
64       */
65      public TypeValuePairType(String type, byte[] value) {
66          this.type = requireNonNull(type, "Type of TypeValuePairType must be not null");
67          this.value = requireNonNull(value, "Value of TypeValuePairType must be not null");
68      }
69  
70  }