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 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 (Authentication) getCheckedRef();
52      }
53  
54      public void setRefid(Reference ref) {
55          if (username != null || password != null || privateKeyFile != null || passphrase != null) {
56              throw tooManyAttributes();
57          }
58          super.setRefid(ref);
59      }
60  
61      public String getUsername() {
62          if (isReference()) {
63              return getRef().getUsername();
64          }
65          return username;
66      }
67  
68      public void setUsername(String username) {
69          checkAttributesAllowed();
70          this.username = username;
71      }
72  
73      public String getPassword() {
74          if (isReference()) {
75              return getRef().getPassword();
76          }
77          return password;
78      }
79  
80      public void setPassword(String password) {
81          checkAttributesAllowed();
82          this.password = password;
83      }
84  
85      public String getPrivateKeyFile() {
86          if (isReference()) {
87              return getRef().getPrivateKeyFile();
88          }
89          return privateKeyFile;
90      }
91  
92      public void setPrivateKeyFile(String privateKeyFile) {
93          checkAttributesAllowed();
94          this.privateKeyFile = privateKeyFile;
95      }
96  
97      public String getPassphrase() {
98          if (isReference()) {
99              return getRef().getPassphrase();
100         }
101         return passphrase;
102     }
103 
104     public void setPassphrase(String passphrase) {
105         checkAttributesAllowed();
106         this.passphrase = passphrase;
107     }
108 
109     public List<String> getServers() {
110         if (isReference()) {
111             return getRef().getServers();
112         }
113         return servers;
114     }
115 
116     public void setServers(String servers) {
117         checkAttributesAllowed();
118         this.servers.clear();
119         String[] split = servers.split("[;:]");
120         for (String server : split) {
121             server = server.trim();
122             if (server.length() > 0) {
123                 this.servers.add(server);
124             }
125         }
126     }
127 }