From bpoussin@users.nuiton.org Mon Jan 28 20:05:28 2013 From: bpoussin@users.nuiton.org To: nuiton-utils-commits@list.nuiton.org Subject: [Nuiton-utils-commits] r2479 - trunk/nuiton-utils/src/main/java/org/nuiton/util Date: Mon, 28 Jan 2013 20:05:28 +0100 Message-ID: <20130128190528.7410F1594A@nuiton.codelutin.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6505902896067542737==" --===============6505902896067542737== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Author: bpoussin Date: 2013-01-28 20:05:28 +0100 (Mon, 28 Jan 2013) New Revision: 2479 Url: http://nuiton.org/projects/nuiton-utils/repository/revisions/2479 Log: ajout du support de l'authentification Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationUpdater.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationUpdater= .java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationUpdater.java = 2013-01-28 13:57:54 UTC (rev 2478) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationUpdater.java = 2013-01-28 19:05:28 UTC (rev 2479) @@ -74,10 +74,14 @@ *
+ * java -cp commons-vfs-2.0.jar org.apache.commons.vfs2.util.Encrypt= Util encrypt mypassword + ** @param appToUpdate liste des applications a mettre a jour * @return null or empty map if we don't want update, otherwize list= of * app to update @@ -232,16 +247,25 @@ public String oldVersion; public String newVersion; public String url; + public boolean needAuthentication; + public String login; + public char[] password; public File destDir; =20 - public ApplicationInfo(String name, String oldVersion, String newVer= sion, String url, File destDir) { + public ApplicationInfo(String name, String oldVersion, String newVer= sion, String url, File destDir, boolean needAuthentication) { this.name =3D name; this.oldVersion =3D oldVersion; this.newVersion =3D newVersion; this.url =3D url; + this.needAuthentication =3D needAuthentication; this.destDir =3D destDir; } =20 + public void setAuthentication(String login, char[] password) { + this.login =3D login; + this.password =3D password; + } + @Override public String toString() { String result =3D String.format( @@ -301,9 +325,11 @@ if (greater) { String urlString =3D releaseConfig.getOption( app + SEPARATOR_KEY + URL_KEY); + boolean needAuthentication =3D releaseConfig.getOpti= onAsBoolean( + app + SEPARATOR_KEY + AUTHENTICATION_KEY); =20 appToUpdate.put(app, new ApplicationInfo( - app, currentVersion, newVersion, urlString, = destDir)); + app, currentVersion, newVersion, urlString, = destDir, needAuthentication)); } } =20 @@ -367,7 +393,12 @@ protected void doUpdate(FileSystemOptions vfsConfig, ApplicationInfo= info) throws Exception { if (info.destDir !=3D null) { File dest =3D new File(info.destDir, info.name); - deepCopy(vfsConfig, info.url, dest.getAbsolutePath()); + String url =3D toVfsURL(info.url); + if (info.needAuthentication) { + StringUtils.replaceOnce(url, "://", + String.format("://%s:%s@", info.login, new Strin= g(info.password))); + } + deepCopy(vfsConfig, url, dest.getAbsolutePath()); =20 // ajout du fichier de version File versionFile =3D new File(dest, VERSION_FILE); @@ -393,7 +424,7 @@ protected void deepCopy(FileSystemOptions vfsConfig, String srcPath, String targetPath) throws FileSystemExceptio= n { FileSystemManager fsManager =3D VFS.getManager(); - FileObject archive =3D fsManager.resolveFile(toVfsURL(srcPath), = vfsConfig); + FileObject archive =3D fsManager.resolveFile(srcPath, vfsConfig); =20 FileObject[] children =3D archive.getChildren(); if (children.length =3D=3D 1) { --===============6505902896067542737==--