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 @@ *
  • os.arch: l'architecture du systeme d'exploitation sur lequel l'applic= ation fonctionne (ex: amd64) * *

    format du fichier de properties

    - * [osName.][osArch.]appName.version=3Dversion de l'application - * [osName.][osArch.]appName.url=3Durl du fichier compresse de la nouvelle v= ersion - * (format common= s-vfs2) * + *
  • [osName.][osArch.]appName.version=3Dversion de l'application
  • + *
  • [osName.][osArch.]appName.auth=3Dtrue ou false selon que l'acces a l'= url + * demande une authentification a fournir par le callback + * (voir {@link ApplicationUpdaterCallback#updateToDo})
  • + *
  • [osName.][osArch.]appName.url=3Durl du fichier compresse de la nouvel= le version + * (format common= s-vfs2)
  • + * * appName est a remplacer par le nom de l'application. Il est possible * d'avoir plusieurs application dans le meme fichier ou plusieurs version * en fonction de l'os et de l'architecture. @@ -134,6 +138,7 @@ final static public String HTTP_PROXY =3D "http_proxy"; =20 final static public String URL_KEY =3D "url"; + final static public String AUTHENTICATION_KEY =3D "auth"; final static public String VERSION_KEY =3D "version"; final static public String VERSION_FILE =3D "version.appup"; =20 @@ -197,8 +202,18 @@ * Permet de modifier le repertoire destination ou l'url du zip de * l'application pour une application/version * particuliere ou d'annuler la mise a jour en le supprimant de la m= ap - * qui sera retourne + * qui sera retourne. * + * Si {@link ApplicationInfo#needAuthentication} est vrai, il faut q= ue + * les valeurs {@link ApplicationInfo#login} et {@link ApplicationIn= fo#password} + * soient renseignees. Si elle ne le sont pas la recuperation de la = + * ressource echouera. Pour des raisons de securite vous pouvez souh= aiter + * mettre le mot de passe sous une forme encrypte. Dans ce cas il do= it + * etre encadrer par '{' et '}'. Pour encrypter le mot de passe + * vous devez utiliser: + *
    +         * 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==--