View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.resolver.internal.ant.types;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.maven.resolver.internal.ant.AntRepoSys;
25  import org.apache.tools.ant.Project;
26  import org.apache.tools.ant.types.DataType;
27  import org.apache.tools.ant.types.Reference;
28  
29  /**
30   */
31  public class Authentication extends DataType {
32  
33      private String username;
34  
35      private String password;
36  
37      private String privateKeyFile;
38  
39      private String passphrase;
40  
41      private final List<String> servers = new ArrayList<>();
42  
43      @Override
44      public void setProject(Project project) {
45          super.setProject(project);
46  
47          AntRepoSys.getInstance(project).addAuthentication(this);
48      }
49  
50      protected Authentication getRef() {
51          return getCheckedRef(Authentication.class);
52      }
53  
54      @Override
55      public void setRefid(Reference ref) {
56          if (username != null || password != null || privateKeyFile != null || passphrase != null) {
57              throw tooManyAttributes();
58          }
59          super.setRefid(ref);
60      }
61  
62      public String getUsername() {
63          if (isReference()) {
64              return getRef().getUsername();
65          }
66          return username;
67      }
68  
69      public void setUsername(String username) {
70          checkAttributesAllowed();
71          this.username = username;
72      }
73  
74      public String getPassword() {
75          if (isReference()) {
76              return getRef().getPassword();
77          }
78          return password;
79      }
80  
81      public void setPassword(String password) {
82          checkAttributesAllowed();
83          this.password = password;
84      }
85  
86      public String getPrivateKeyFile() {
87          if (isReference()) {
88              return getRef().getPrivateKeyFile();
89          }
90          return privateKeyFile;
91      }
92  
93      public void setPrivateKeyFile(String privateKeyFile) {
94          checkAttributesAllowed();
95          this.privateKeyFile = privateKeyFile;
96      }
97  
98      public String getPassphrase() {
99          if (isReference()) {
100             return getRef().getPassphrase();
101         }
102         return passphrase;
103     }
104 
105     public void setPassphrase(String passphrase) {
106         checkAttributesAllowed();
107         this.passphrase = passphrase;
108     }
109 
110     public List<String> getServers() {
111         if (isReference()) {
112             return getRef().getServers();
113         }
114         return servers;
115     }
116 
117     public void setServers(String servers) {
118         checkAttributesAllowed();
119         this.servers.clear();
120         String[] split = servers.split("[;:]");
121         for (String server : split) {
122             server = server.trim();
123             if (!server.isEmpty()) {
124                 this.servers.add(server);
125             }
126         }
127     }
128 }