View Javadoc
1   /*
2    * Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3    *
4    * This program is licensed to you under the Apache License Version 2.0,
5    * and you may not use this file except in compliance with the Apache License Version 2.0.
6    * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7    *
8    * Unless required by applicable law or agreed to in writing,
9    * software distributed under the Apache License Version 2.0 is distributed on an
10   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12   */
13  
14  package org.codehaus.plexus.components.secdispatcher;
15  
16  import java.util.Map;
17  
18  import static java.util.Objects.requireNonNull;
19  
20  /**
21   * Dispatcher.
22   *
23   * @author Oleg Gusakov
24   * @version $Id$
25   *
26   */
27  public interface Dispatcher {
28      /**
29       * The "encrypt payload" prepared by dispatcher.
30       */
31      final class EncryptPayload {
32          private final Map<String, String> attributes;
33          private final String encrypted;
34  
35          public EncryptPayload(Map<String, String> attributes, String encrypted) {
36              this.attributes = requireNonNull(attributes);
37              this.encrypted = requireNonNull(encrypted);
38          }
39  
40          public Map<String, String> getAttributes() {
41              return attributes;
42          }
43  
44          public String getEncrypted() {
45              return encrypted;
46          }
47      }
48  
49      /**
50       * Encrypt given plaintext string. Implementation must return at least same attributes it got, but may add more
51       * attributes to returned payload.
52       *
53       * @param str string to encrypt, never {@code null}
54       * @param attributes attributes, never {@code null}
55       * @param config configuration from settings-security.xml, never {@code null}
56       * @return encrypted string and attributes in {@link EncryptPayload}
57       */
58      EncryptPayload encrypt(String str, Map<String, String> attributes, Map<String, String> config)
59              throws SecDispatcherException;
60  
61      /**
62       * Decrypt given encrypted string.
63       *
64       * @param str string to decrypt, never {@code null}
65       * @param attributes attributes, never {@code null}
66       * @param config configuration from settings-security.xml, never {@code null}
67       * @return decrypted string
68       */
69      String decrypt(String str, Map<String, String> attributes, Map<String, String> config)
70              throws SecDispatcherException;
71  
72      /**
73       * Validates dispatcher configuration.
74       */
75      SecDispatcher.ValidationResponse validateConfiguration(Map<String, String> config);
76  }