Changeset 21

Show
Ignore:
Timestamp:
06/22/04 23:05:07
Author:
DenisG
Message:

[SubversionSharp] Add interactive authentication providers and AuthBaton?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SubversionSharp/dev/src/SubversionSharp.prjx

    r19 r21  
    1111    <File name="./SvnAuthCred.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
    1212    <File name="./SvnAuthSslServerCertInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
     13    <File name="./SvnAuthBaton.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
    1314  </Contents> 
    1415  <References> 
  • trunk/SubversionSharp/dev/src/Svn.cs

    r19 r21  
    142142                                                svn_auth_ssl_client_cert_pw_prompt_func_t prompt_func, 
    143143                                                IntPtr prompt_baton, int retry_limit, IntPtr pool); 
     144        #endregion 
     145         
     146        #region AuthBaton 
     147        [DllImport("svn_client-1")] static extern 
     148        internal void svn_auth_open(out IntPtr auth_baton, IntPtr providers, IntPtr pool); 
     149         
     150        [DllImport("svn_client-1")] static extern 
     151        internal void svn_auth_set_parameter(IntPtr auth_baton, IntPtr name, IntPtr value); 
     152         
     153        [DllImport("svn_client-1")] static extern 
     154        internal IntPtr svn_auth_get_parameter(IntPtr auth_baton, IntPtr name); 
    144155        #endregion 
    145156    } 
  • trunk/SubversionSharp/dev/src/SvnAuthProvider.cs

    r19 r21  
    1717    public struct SvnAuthProviderObject 
    1818    { 
    19         IntPtr mAuthProviderObject; 
     19        private IntPtr mAuthProviderObject; 
     20        internal SvnAuthProvider mAuthProvider; 
    2021 
    2122        #region Generic embedding functions of an IntPtr 
     
    2324        { 
    2425            mAuthProviderObject = ptr; 
     26            mAuthProvider = null; 
     27        } 
     28 
     29        private SvnAuthProviderObject(IntPtr ptr, SvnAuthProvider authProvider) 
     30        { 
     31            mAuthProviderObject = ptr; 
     32            mAuthProvider = authProvider; 
    2533        } 
    2634         
     
    8593 
    8694        #region Wrapper client method 
    87         public static SvnAuthProviderObject GetSimplePromptProvider(  
     95        public static SvnAuthProviderObject GetPromptProvider(  
    8896                                                    SimplePrompt promptFunc,  
    8997                                                    IntPtr promptBaton, int retryLimit, AprPool pool) 
    9098        { 
    9199            IntPtr authObj; 
    92             throw new NotImplementedException();  
    93             //return(new SvnAuthProviderObject()); 
     100            SvnAuthProvider auth = new SvnAuthProvider(promptFunc); 
     101            Svn.svn_client_get_simple_prompt_provider(out authObj,  
     102                                            (Svn.svn_auth_simple_prompt_func_t) auth.Wrapper,  
     103                                            promptBaton, retryLimit, pool); 
     104            return(new SvnAuthProviderObject(authObj,auth)); 
    94105        } 
    95106                                                     
    96         public static SvnAuthProviderObject GetUsernamePromptProvider( 
     107        public static SvnAuthProviderObject GetPromptProvider( 
    97108                                                UsernamePrompt promptFunc, 
    98109                                                IntPtr promptBaton, int retryLimit, AprPool pool) 
    99110        { 
    100111            IntPtr authObj;  
    101             throw new NotImplementedException();  
    102             //return(new SvnAuthProviderObject()); 
     112            SvnAuthProvider auth = new SvnAuthProvider(promptFunc); 
     113            Svn.svn_client_get_username_prompt_provider(out authObj,  
     114                                            (Svn.svn_auth_username_prompt_func_t) auth.Wrapper,  
     115                                            promptBaton, retryLimit, pool); 
     116            return(new SvnAuthProviderObject(authObj,auth)); 
    103117        } 
    104118                                                 
     
    138152        } 
    139153         
    140         public static SvnAuthProviderObject GetSslServerTrustPromptProvider( 
     154        public static SvnAuthProviderObject GetPromptProvider( 
    141155                                                SslServerTrustPrompt promptFunc, 
    142156                                                IntPtr promptBaton, AprPool pool) 
    143157        { 
    144158            IntPtr authObj;  
    145             throw new NotImplementedException();  
    146             //return(new SvnAuthProviderObject()); 
    147         } 
    148          
    149         public static SvnAuthProviderObject GetSslClientCertPromptProvider( 
     159            SvnAuthProvider auth = new SvnAuthProvider(promptFunc); 
     160            Svn.svn_client_get_ssl_server_trust_prompt_provider(out authObj,  
     161                                        (Svn.svn_auth_ssl_server_trust_prompt_func_t) auth.Wrapper,  
     162                                        promptBaton, pool); 
     163            return(new SvnAuthProviderObject(authObj,auth)); 
     164        } 
     165         
     166        public static SvnAuthProviderObject GetPromptProvider( 
    150167                                                SslClientCertPrompt promptFunc, 
    151168                                                IntPtr promptBaton, int retryLimit, AprPool pool) 
    152169        { 
    153170            IntPtr authObj;  
    154             throw new NotImplementedException();  
    155             //return(new SvnAuthProviderObject()); 
    156         } 
    157          
    158         public static SvnAuthProviderObject GetSslClientCertPwPromptProvider( 
     171            SvnAuthProvider auth = new SvnAuthProvider(promptFunc); 
     172            Svn.svn_client_get_ssl_client_cert_prompt_provider(out authObj,  
     173                                        (Svn.svn_auth_ssl_client_cert_prompt_func_t) auth.Wrapper,  
     174                                        promptBaton, retryLimit, pool); 
     175            return(new SvnAuthProviderObject(authObj,auth)); 
     176        } 
     177         
     178        public static SvnAuthProviderObject GetPromptProvider( 
    159179                                                SslClientCertPwPrompt promptFunc, 
    160180                                                IntPtr promptBaton, int retryLimit, AprPool pool) 
    161181        { 
    162182            IntPtr authObj;  
    163             throw new NotImplementedException();  
    164             //return(new SvnAuthProviderObject()); 
     183            SvnAuthProvider auth = new SvnAuthProvider(promptFunc); 
     184            Svn.svn_client_get_ssl_client_cert_pw_prompt_provider(out authObj,  
     185                                        (Svn.svn_auth_ssl_client_cert_pw_prompt_func_t) auth.Wrapper,  
     186                                        promptBaton, retryLimit, pool); 
     187            return(new SvnAuthProviderObject(authObj,auth)); 
    165188        } 
    166189        #endregion 
    167190    } 
    168191     
    169     public class SvnAuthProvider 
     192    internal class SvnAuthProvider 
    170193    { 
    171194        object mFunc; 
     195        object mWrapperFunc; 
     196         
     197        public SvnAuthProvider(SvnAuthProviderObject.SimplePrompt func) 
     198        { 
     199            mFunc = func; 
     200            mWrapperFunc = new Svn.svn_auth_simple_prompt_func_t(SvnAuthSimplePrompt); 
     201        } 
     202         
     203        public SvnAuthProvider(SvnAuthProviderObject.UsernamePrompt func) 
     204        { 
     205            mFunc = func; 
     206            mWrapperFunc = new Svn.svn_auth_username_prompt_func_t(SvnAuthUsernamePrompt); 
     207        } 
     208 
     209        public SvnAuthProvider(SvnAuthProviderObject.SslServerTrustPrompt func) 
     210        { 
     211            mFunc = func; 
     212            mWrapperFunc = new Svn.svn_auth_ssl_server_trust_prompt_func_t(SvnAuthSslServerTrustPrompt); 
     213        } 
     214 
     215        public SvnAuthProvider(SvnAuthProviderObject.SslClientCertPrompt func) 
     216        { 
     217            mFunc = func; 
     218            mWrapperFunc = new Svn.svn_auth_ssl_client_cert_prompt_func_t(SvnAuthSslClientCertPrompt); 
     219        } 
     220 
     221        public SvnAuthProvider(SvnAuthProviderObject.SslClientCertPwPrompt func) 
     222        { 
     223            mFunc = func; 
     224            mWrapperFunc = new Svn.svn_auth_ssl_client_cert_pw_prompt_func_t(SvnAuthSslClientCertPwPrompt); 
     225        } 
     226         
     227        public object Wrapper 
     228        { 
     229            get 
     230            { 
     231                return(mWrapperFunc); 
     232            } 
     233        } 
    172234         
    173235        private IntPtr SvnAuthSimplePrompt(out IntPtr cred, IntPtr baton,  
     
    227289        } 
    228290                                                                
    229         [CLSCompliant(false)] 
     291        //[CLSCompliant(false)] 
    230292        private  IntPtr SvnAuthSslServerTrustPrompt(out IntPtr cred, IntPtr baton,  
    231293                                                    IntPtr realm, uint failures,  
  • trunk/SubversionSharp/test/src/Main.cs

    r7 r21  
    22using System; 
    33using System.Diagnostics; 
     4using System.Collections; 
    45using Softec.AprSharp; 
    56using Softec.SubversionSharp; 
     
    1516        SvnClientContext ctx = SvnClientContext.Create(pool); 
    1617        ctx.Config = SvnConfig.GetConfig(pool); 
    17         AprHash ctxcfg = ctx.Config; 
    18         foreach(AprHashEntry cfg in ctxcfg) 
    19         { 
    20             Console.WriteLine("{0}\t{1:X}",cfg.KeyAsString,cfg.Value.ToInt32()); 
    21         } 
     18         
     19        ArrayList authObj = new ArrayList(); 
     20        authObj.Add(SvnAuthProviderObject.GetSimpleProvider(pool)); 
     21        authObj.Add(SvnAuthProviderObject.GetUsernameProvider(pool)); 
     22        authObj.Add(SvnAuthProviderObject.GetSslServerTrustFileProvider(pool)); 
     23        authObj.Add(SvnAuthProviderObject.GetSslClientCertFileProvider(pool)); 
     24        authObj.Add(SvnAuthProviderObject.GetSslClientCertPwFileProvider(pool)); 
     25        authObj.Add(SvnAuthProviderObject.GetPromptProvider( 
     26                        new SvnAuthProviderObject.SimplePrompt(SimpleAuth), 
     27                        IntPtr.Zero, 2, pool)); 
     28        authObj.Add(SvnAuthProviderObject.GetPromptProvider( 
     29                        new SvnAuthProviderObject.UsernamePrompt(UsernameAuth), 
     30                        IntPtr.Zero, 2, pool)); 
     31         
     32         
    2233        pool.Destroy(); 
    2334    } 
     35     
     36    public static SvnError SimpleAuth(out SvnAuthCredSimple cred, IntPtr baton,  
     37                           AprString realm, AprString username,  
     38                           bool maySave, AprPool pool) 
     39    { 
     40        Console.WriteLine("Simple Authentication"); 
     41        Console.WriteLine("---------------------"); 
     42        Console.WriteLine("Realm: {0}", realm); 
     43        Console.WriteLine(""); 
     44         
     45        bool valid = false; 
     46        string line; 
     47         
     48        while(!valid) 
     49        { 
     50            if (!username.IsNull) 
     51                Console.Write("Enter Username ({0}): ", username); 
     52            else 
     53                Console.Write("Enter Username: "); 
     54 
     55            line = Console.ReadLine(); 
     56 
     57            if (line.Trim().Length == 0 && !username.IsNull) 
     58            { 
     59                line = username.ToString(); 
     60                valid = true; 
     61            } 
     62            else if (line.Trim().Length > 0) 
     63            { 
     64                valid = true; 
     65            } 
     66        } 
     67         
     68        cred = SvnAuthCredSimple.Alloc(pool); 
     69        cred.Username = new AprString(pool, line); 
     70        Console.Write("Enter Password: "); 
     71        cred.Password = new AprString(pool, Console.ReadLine()); 
     72        cred.MaySave = maySave; 
     73        return(SvnError.NoError); 
     74    } 
     75     
     76    public static SvnError UsernameAuth(out SvnAuthCredUsername cred, IntPtr baton,  
     77                                        AprString realm, bool maySave, AprPool pool) 
     78    { 
     79        Console.WriteLine("Username Authentication:"); 
     80        Console.WriteLine("------------------------"); 
     81        Console.WriteLine("Realm: {0}", realm); 
     82        Console.WriteLine(""); 
     83 
     84        bool valid = false; 
     85        string line; 
     86         
     87        while(!valid) 
     88        { 
     89            Console.Write("Enter Username: "); 
     90 
     91            line = Console.ReadLine(); 
     92 
     93            if (line.Trim().Length > 0) 
     94            { 
     95                valid = true; 
     96            } 
     97        } 
     98         
     99        cred = SvnAuthCredUsername.Alloc(pool); 
     100        cred.Username = new AprString(pool, line); 
     101        cred.MaySave = maySave; 
     102        return(SvnError.NoError); 
     103    } 
    24104}