IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Sécurité Java Discussion :

Authentification en JAVA sur de l'HTTP


Sujet :

Sécurité Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Points : 143
    Points
    143
    Par défaut Authentification en JAVA sur de l'HTTP
    Je souhaiterai pouvoir donner mon user / mot de passe pour l'ouverture d'une connection en HTTP.

    J'ai donc appliquer ce bout de code, trouver chez Sun :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    try {
    			String username="XXX";
    			String password="XXX";
    			String endpointAddress = "http://....";
    			Stub stub = createProxy();
    			stub._setProperty(
    					javax.xml.rpc.Stub.USERNAME_PROPERTY,
    					username);
    			stub._setProperty(
    					javax.xml.rpc.Stub.PASSWORD_PROPERTY,
    					password);
    			stub._setProperty
    			(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
    					endpointAddress);
     
    			HelloIF hello = (HelloIF)stub;
    			System.out.println(hello.sayHello("Duke (secure)"));
    Ainsi que cette méthode :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    private static Stub createProxy() {
            // Note: MyHelloService_Impl is implementation-specific.
            return (Stub)(new
            		MyHelloService_Impl().getHelloIFPort());
        }
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
    Voir chapitre 32 : Security

    Mais je ne vois pas ce que c'est que leur classe MyHelloService_Impl(). Et comment l'appliquer à mon cas d'utilisation, qui consiste à juste foutre dans mon appli, tu prends ces identifiants quand tu vas sur cette page, pour m'autoriser l'accès. Sachant que c'est dans l'ApplicationContext.xml de Spring que j'appel ma page HTTP.
    Merci beaucoup.

  2. #2
    Membre du Club
    Inscrit en
    Janvier 2005
    Messages
    38
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Janvier 2005
    Messages : 38
    Points : 46
    Points
    46
    Par défaut
    Ceci est exemple d'appel a un WEB SERVICE pour lequel on doit avoir une authentification pour pourvoir l'utiliser. Je pense que ce n'est pas cela que tu veux faire ?

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Points : 143
    Points
    143
    Par défaut
    Bah si, c'est justement pour accèder à l'URL où il y a le wsdl du webservice que j'ai besoin d'authentification !

  4. #4
    Membre du Club
    Inscrit en
    Janvier 2005
    Messages
    38
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Janvier 2005
    Messages : 38
    Points : 46
    Points
    46
    Par défaut
    Tous ce qui commence par HelloIF ou MyHelloService_Impl sont des classes clientes généré par axis ou autre pour accéder a ton WebService.

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Points : 143
    Points
    143
    Par défaut
    C'est l'exemple donné dans la doc de la J2EE ! Moi, jvoudrais faire de l'authentification dans mon cas de figure, c'est-à-dire, que jvoudrais qu'il prenne en compte mes login / mot de passe quand Spring appel l'URL. J'ai pas à manipuler le WebService, j'ai juste ses classes...

    Quelqu'un connait la syntaxe pour faire cette authentification ?

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Points : 143
    Points
    143
    Par défaut
    Sun proposes ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    package basicauthclient;
     
    import javax.xml.rpc.Stub;
     
    public class HelloClient {
     
        public static void main(String[] args) {
     
            if (args.length !=3) {
              System.out.println("HelloClient Error: Wrong 
               number of runtime arguments!");
              System.exit(1);
            }
     
            String username=args[0];
            String password=args[1];
            String endpointAddress=args[2];
     
          // print to display for verification purposes
            System.out.println("username: " + username);
            System.out.println("password: " + password);
            System.out.println("Endpoint address = " +
               endpointAddress); 
     
     
        try {
          Stub stub = createProxy();
            stub._setProperty(
              javax.xml.rpc.Stub.USERNAME_PROPERTY,
                username);
            stub._setProperty(
              javax.xml.rpc.Stub.PASSWORD_PROPERTY,
                password);
            stub._setProperty
              (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
              endpointAddress);
     
          HelloIF hello = (HelloIF)stub;
          System.out.println(hello.sayHello("Duke (secure)"));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }    
     
        private static Stub createProxy() {
            // Note: MyHelloService_Impl is implementation-specific.
            return (Stub)(new
              MyHelloService_Impl().getHelloIFPort());
        }
    }
    Mais je ne vois par quoi remplacer la dernière méthode createProxy ?
    car je n'ai pas de MyHelloService_Impl... ni de méthode avec ...Port()...
    Je ne peux pas modifier mon WebService !

    Une idée?

  7. #7
    Membre du Club
    Inscrit en
    Janvier 2005
    Messages
    38
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Janvier 2005
    Messages : 38
    Points : 46
    Points
    46
    Par défaut
    Si tu as que l'adresse de ton WebService (wsdl) tu peux l'attaquer avec JAVA-RPC voici un exemple que j'avais fait mais il n'y a la gestion de l'authentification il faudra chercher ds la librairy dsl

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    ServiceFactory factory = ServiceFactory.newInstance();
    Service service = factory.createService(new QName("WS_XMLService"));
    Call    call    = (Call) service.createCall();
    String endpoint = "http://127.0.0.1:8080/axis/WS_XML.jws";
    call.setTargetEndpointAddress(endpoint);
    call.setOperationName(new QName("run")); //nom de la methode du WebService
    Object[] param = new Object[] {fileData, xml, new Integer(fileData.length), new Integer(xml.length), "contentsecure", new Boolean(true), new Integer(3), new Integer(4)}; //  parametre de la methode à passer dans un Objet[]
     
    Boolean rs = (Boolean) call.invoke(param); //execution de la méthode du WebService et dans mon cas le résultat est un boolean ;)
    Là il faudra mettre les librairie d'axis si ton WebService est sous axis dans ton WEB-INF/lib/

  8. #8
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Points : 143
    Points
    143
    Par défaut
    Quelqu'un a une idée pour s'authentifier simplement en Java sur une page HTTP ?

  9. #9
    Membre actif
    Inscrit en
    Mai 2005
    Messages
    217
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 217
    Points : 220
    Points
    220
    Par défaut
    Regardes du coté de l'objet "HttpURLConnection"
    il y a peut etre qqchose à faire avec.


    http://www.developpez.net/forums/arc...p/t-86043.html

  10. #10
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Points : 143
    Points
    143
    Par défaut
    Merki collègue !

    En fait, ça donne ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    URL ndurl = new URL("http://...");
    HttpURLConnection ndconn = (HttpURLConnection)ndurl.openConnection();
    HTTP Basic authentification
    String auth = new String("A138049:val93alx");
    BASE64Encoder b64 = new BASE64Encoder();
    ndconn.setRequestProperty ("Authorization", "Basic " + b64.encode(auth.getBytes()));
    Ca marche bien ! Le problème vient en fait du fait qu'il ne veut pas mon authentification au niveau de mon code Java mais dans mon fichier Spring, car c'est là qu'il en a besoin pour appeler mon fichier wsdl qui décrit mon WebService. Et, j'ai un 401 !!!
    J'ai plus qu'à utiliser TCPMon pour observer mes flux, et voir où l'authentification merde.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2003] authentification sur site web https
    Par Oliv- dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 06/11/2009, 17h07
  2. Form d'authentification en http postant sur un form https
    Par kaboume dans le forum Sécurité
    Réponses: 2
    Dernier message: 26/05/2009, 15h09
  3. Réponses: 3
    Dernier message: 11/03/2008, 01h14
  4. [Servlet][Deb]envoyer image gif sur le flux http
    Par ptitBoutchou dans le forum Servlets/JSP
    Réponses: 15
    Dernier message: 09/04/2004, 10h12
  5. identification sur le protocole HTTP
    Par windob dans le forum Développement
    Réponses: 20
    Dernier message: 31/03/2004, 22h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo