Authentification(user:.. pwd:...)

828
5
04-22-2013 07:06 AM
lifeEsri
New Contributor III
Hello,
I want to create à page of authentification with  (flex,BlazeDS,Spring and java)
NB: I'm using postgresSQL
Tags (2)
0 Kudos
5 Replies
omega_cancer
Occasional Contributor II
Hello,
I want to create à page of authentification with  (flex,BlazeDS,Spring and java)
NB: I'm using postgresSQL



Where is the question??
0 Kudos
lifeEsri
New Contributor III
thank's already done
0 Kudos
GISDev1
Occasional Contributor III
thank's already done


Will you share your solution with us so we can learn more from it?
0 Kudos
lifeEsri
New Contributor III
<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:viewer="com.esri.viewer.*"
      xmlns:managers="com.esri.viewer.managers.*"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      backgroundColor="#F8F8F8" currentState="Authentification" 
      pageTitle="ArcGIS Viewer for Flex"
      xmlns:ns1="component.*"
      xmlns:ns="http://code.google.com/p/flexlib/"
      >
 
 
 
 <fx:Declarations>
  <mx:RemoteObject id="roAuthServiceDest" 
       destination="AuthServiceDest"
       result="onTrue(event)"
       fault="onFalse(event)"/>
 </fx:Declarations>
 
 <s:states>
  <s:State name="Authentification"/>
  <s:State name="acceuill"/>
  
 </s:states>
 
 <fx:Script>
  
  <![CDATA[
   import com.flexer.skin.*;
   
   import component.*;
   import component.acceuil;
   
   import mx.effects.easing.Back;
   import mx.effects.easing.Bounce;
   import mx.effects.easing.Cubic;
   import mx.effects.easing.Elastic;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.utils.ObjectProxy;
  
  [Bindable]
  public var colors:ObjectProxy = new ObjectProxy();
  
  private var acceu:acceuil=new acceuil();
  private var mycomponent:firstcomponent =new firstcomponent();
  private var macarte:carte =new carte();
  private var myconnexion:connexionDB =new connexionDB();
 
  public function afficheacceuil():void
  {
   currentState="acceuill";
   this.addElement(acceu);
   acceu.visible=true;
  }
  
   private function doCall():void{
    // Appeler le service distant
    taReponse.text==""
    swfMessage.visible = true;
   roAuthServiceDest.Authentif(username.text ,password.text);
   }
  private function onTrue(event : ResultEvent):void{
   // Afficher la réponse
   
   taReponse.text = event.result as String;
   if(taReponse.text=="")
   {
     afficheacceuil();
   }
   swfMessage.visible = false;
       }
  
  /**
   * Méthode invoquée en cas d'échec de l'appel RPC 
   */ 
  private function onFalse(event : FaultEvent):void{
   // Afficher le message d'erreur
   taReponse.text = event.fault.message;
   swfMessage.visible = false;
  }
  ]]>
 
 </fx:Script>
 <mx:Canvas id="viestk2" x="0" y="0" includeIn="Authentification" height="100%"  width="100%" >
  <s:Image left="0" right="0" top="0" bottom="0" horizontalCenter="0" scaleMode="stretch"
     smooth="false" source="assets/images/Env.jpg" verticalCenter="0"/>
  
  <s:Image top="20" bottom="20" width="562" horizontalCenter="0" source="assets/images/Auth.jpg"
     verticalCenter="0"/>
 <mx:Form horizontalCenter="13" verticalCenter="17">
  <mx:FormHeading label="S'authentifier (utiliser user/pass)"/>
  <mx:FormItem label="Nom d'utilisateur">
   <mx:TextInput id="username"/>
  </mx:FormItem>
  <mx:FormItem label="Mot de passe">
   <mx:TextInput id="password" displayAsPassword="true" enter="doCall()"/>
  </mx:FormItem>
  <mx:FormItem>
   <mx:Button id="submit" label="Valider" click="doCall()" />
   <s:Label id="taReponse" bottom="49" width="239" color="#E71515" fontFamily="Times New Roman"
      fontSize="13" fontWeight="bold" horizontalCenter="17"/>
  </mx:FormItem>
  <mx:FormItem>
   <mx:Image id="swfMessage"
       source="assets/images/loader.swf"
       visible="false"/>
   <mx:CheckBox id="rememberMe" label="Se souvenir de moi"/>
  </mx:FormItem>
 </mx:Form> 
  
  
 </mx:Canvas> 
 
  
</s:Application>


and this is my class Authentification.java
package com.developpez.service;
import java.sql.*;
public class Authentification
   {
 
 String username = "postgres";
    String password = "admin";
    String url = "jdbc:postgresql://localhost:5432/test";
    String addconfirm="";
      public String Authentif(String login ,String pass)
      {
       String userExist="Utilisateur ou Mot de passe incorrect";
         try
         {
   //connexion base
            Class.forName("org.postgresql.Driver");
            Connection connexion = DriverManager.getConnection(url,username,password);
            Statement instruction = connexion.createStatement();
            ResultSet resultat = instruction.executeQuery("SELECT * FROM users");
 
            while(resultat.next())
            { 
               if ((login.equals(resultat.getString("login"))) && (pass.equals(resultat.getString("password")))) 
               { 
                userExist = "";               
               }
              
            }
         }
            catch (Exception e)
            {
               System.out.println("echec pilote : "+e);
            }
  return userExist;
      }
   }
0 Kudos
fatizanady
New Contributor
hi lifeEsri,

Can you please explain me the  procedure (steps) of doing this authentification without using Spring.

Thanks in advances.
0 Kudos