1 /* 2 * Copyright 2006-2012 smartics, Kronseder & Reiner GmbH 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 package de.smartics.maven.plugin.buildmetadata.common; 17 18 import org.apache.maven.settings.Server; 19 import org.apache.maven.settings.Settings; 20 21 /** 22 * The SCM connection information for authentication. 23 * 24 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 25 * @version $Revision:591 $ 26 */ 27 public final class ScmCredentials 28 { 29 // ********************************* Fields ********************************* 30 31 // --- constants ------------------------------------------------------------ 32 33 // --- members -------------------------------------------------------------- 34 35 /** 36 * The user's settings. 37 */ 38 private final Settings settings; 39 40 /** 41 * The user name (used by svn and starteam protocol). 42 */ 43 private String userName; 44 45 /** 46 * The user password (used by svn and starteam protocol). 47 */ 48 private String password; 49 50 /** 51 * The private key (used by java svn). 52 */ 53 private String privateKey; 54 55 /** 56 * The pass phrase (used by java svn). 57 */ 58 private String passPhrase; 59 60 // ****************************** Initializer ******************************* 61 62 // ****************************** Constructors ****************************** 63 64 /** 65 * Default constructor. 66 * 67 * @param settings the settings to fetch SCM information. 68 * @param userName the user name (used by svn and starteam protocol). 69 * @param password the user password (used by svn and starteam protocol). 70 * @param privateKey the private key (used by java svn). 71 * @param passphrase the passphrase (used by java svn). 72 */ 73 public ScmCredentials(final Settings settings, final String userName, // NOPMD 74 final String password, final String privateKey, final String passphrase) 75 { 76 this.settings = settings; 77 this.userName = userName; 78 this.password = password; 79 this.privateKey = privateKey; 80 this.passPhrase = passphrase; 81 } 82 83 // ****************************** Inner Classes ***************************** 84 85 // ********************************* Methods ******************************** 86 87 // --- init ----------------------------------------------------------------- 88 89 // --- get&set -------------------------------------------------------------- 90 91 /** 92 * Returns the user name (used by svn and starteam protocol). 93 * 94 * @return the user name (used by svn and starteam protocol). 95 */ 96 public String getUserName() 97 { 98 return userName; 99 } 100 101 /** 102 * Returns the user password (used by svn and starteam protocol). 103 * 104 * @return the user password (used by svn and starteam protocol). 105 */ 106 public String getPassword() 107 { 108 return password; 109 } 110 111 /** 112 * Returns the private key (used by java svn). 113 * 114 * @return the private key (used by java svn). 115 */ 116 public String getPrivateKey() 117 { 118 return privateKey; 119 } 120 121 /** 122 * Returns the pass phrase (used by java svn). 123 * 124 * @return the pass phrase (used by java svn). 125 */ 126 public String getPassPhrase() 127 { 128 return passPhrase; 129 } 130 131 // --- business ------------------------------------------------------------- 132 133 /** 134 * Fetches the server information from the settings for the specified host. 135 * 136 * @param host the host whose access information is fetched from the settings 137 * file. 138 */ 139 public void configureByServer(final String host) 140 { 141 final Server server = settings.getServer(host); 142 if (server != null) 143 { 144 if (userName == null) 145 { 146 userName = settings.getServer(host).getUsername(); 147 } 148 149 if (password == null) 150 { 151 password = settings.getServer(host).getPassword(); 152 } 153 154 if (privateKey == null) 155 { 156 privateKey = settings.getServer(host).getPrivateKey(); 157 } 158 159 if (passPhrase == null) 160 { 161 passPhrase = settings.getServer(host).getPassphrase(); 162 } 163 } 164 } 165 166 // --- object basics -------------------------------------------------------- 167 168 }