วันศุกร์ที่ 12 พฤศจิกายน พ.ศ. 2553

Java Development with NetBeans and Maven: Part 3

Overview


Since the Maven can integrate to the other system, such as "Issue Tracker", "Version Control System", especially the "Repository Manager", which we will deploy our artifact for sharing to our team. All those target system is usually protected. We must provide the "security information / credential" such as user id and password for accessing it.

Normally we can declare the "security information /credential" inside the "Project POM File" (pom.xml). Please consider, in the real world development environment, they are many people joining the same project. The "Project POM File" (pom.xml) is also shared, too. If we decide to store that security information /credential" at the "Project POM File" (pom.xml). We may face a difficult if everyone keep updating the "Project POM File" (pom.xml) over and over. It would be nice that we can link the personal information, such as the security information /credential", to the

"Project POM File" (pom.xml).

Declare Our Own Information


You may have seen it berfore, The "settings.xml". Please refer to my previous post, about the "Maven Repository Manager", the "Artifactory" which can manage the repository and artifact for us. We use the "settings.xml" to notify "Maven" that it should connect to our  "Maven Repository Manager", the "Artifactory" instead of connect to the remote repository in the internet.

Inside the <profile> tag, we can declare a <properties> tag. The element inside this tag can be named any as we need. e.g. <userId>, and we can refer it in the "Project POM File" (pom.xml) by the ${MY_VARIABLE}, e.g. ${userId}. Pleases see further information here.

The we can declare our own "security information /credential" such as <issueUserId>, <issuePassword>,<vcsUserId>, <vcsPassword> and so on, so that we achieve configure our own "security information /credential".







01 <profiles>

02     <profile>

03         ..........

04         <id>artifactory</id>

05         <properties>

06             <svnUser>user1</svnUser>

07             <svnPassword>password</svnPassword>

08             <bugzillaUser>user2</bugzillaUser>

09             <bugzillaPassword>password</bugzillaPassword>

10         </properties>

11     </profile>

12 </profiles>




Special Feature for the Maven Repository Manager


We can declare our credential for accessing the "Maven Repository Manager", please note the "Maven Repository Manager" usually anonymous downloading, but not for deploying.







01 <servers>

02     <server>

03         <id>The Reference Id</id>

04         <username>User</username>

05         <password>password</password>

06         <filePermissions>777</filePermissions>

07         <directoryPermissions>777</directoryPermissions>

08         <!--

09         <privateKey>${user.home}/.ssh/id_dsa</privateKey>

10         <passphrase>some_passphrase</passphrase>

11         <filePermissions>664</filePermissions>

12         <directoryPermissions>775</directoryPermissions>

13         <configuration></configuration>

14         -->

15     </server>

16 </servers>





The password encryption


It can be done by following this document. I will intoduce you an overview.

Create Master Password


Create the master passowrd
mvn --encrypt-master-password <password>

Store it for future referencing


Please create a file named "settings-security.xml" at <USER_HOME>/.m2 and put the following content into it.







1 <settingsSecurity>

2   <master>Master Password</master>

3 </settingsSecurity>





Encrypt The Password


Create the master passowrd
mvn --encrypt-password <password>

Please copy the encrypted password and paste to the "settings.xml", the <server> tag.

The Artifactory


If the security is enable for the "Artifactory", we can not use the "clear password", or take it to encrypt with the master password. The "Artifactory" encrypted value is required. The step for picking that vaule is as following: -
       
  1. Please log in to "Maven     Repository Manager", the "Artifactory".
  2.    
  3. Go to your profile page by     clicking the name displayed at the top-right of the screen.
  4.    
  5. Enter your current password and     press "Unlock" button.
  6.    
  7. The encrypted password will be     displayed at the "Encrypted Password"     text box.
  8.    
  9. Copy the whole displayed value,     including the {DESede} or other.
  10.    
  11. You can use this value at the     "settings.xml", the     <server> tag.
  12.    
  13. You can also "double     encrypt" by using the maven encryption, too.

Summary


At the moment we can declare our own information at the "settings.xml" and link it to the "Project POM File" (pom.xml). We also understand the special feature for the "Maven Repository Manager", the password encryption, including the specific for the "Artifactory".

Next I will make use of these to integrate with Version Control System, Issue Tracker, especially to create a report and maven site. Please stay tuned as always.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น