You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sa...@apache.org on 2011/12/14 09:40:51 UTC

svn commit: r1214110 - in /directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store: MultiBaseSearch.java SingleBaseSearch.java

Author: saya
Date: Wed Dec 14 08:40:51 2011
New Revision: 1214110

URL: http://svn.apache.org/viewvc?rev=1214110&view=rev
Log:
added txn demarcation for getting pricipal entry and changing password

Modified:
    directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java
    directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java

Modified: directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java?rev=1214110&r1=1214109&r2=1214110&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java (original)
+++ directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java Wed Dec 14 08:40:51 2011
@@ -28,6 +28,7 @@ import javax.security.auth.kerberos.Kerb
 
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.txn.TxnManager;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.kerberos.shared.store.operations.ChangePassword;
 import org.apache.directory.server.kerberos.shared.store.operations.GetPrincipal;
@@ -50,14 +51,32 @@ class MultiBaseSearch implements Princip
 {
     private final Catalog catalog;
     private final DirectoryService directoryService;
+    private TxnManager txnManager; 
 
 
     MultiBaseSearch( String catalogBaseDn, DirectoryService directoryService )
     {
         this.directoryService = directoryService;
+        txnManager = directoryService.getTxnManager();
+        
         try
         {
-            catalog = new KerberosCatalog( ( Map<String, String> ) execute( directoryService.getSession(), new GetCatalog() ) );
+            txnManager.beginTransaction( true );
+            
+            try
+            {
+                catalog = new KerberosCatalog( ( Map<String, String> ) execute( directoryService.getSession(),
+                    new GetCatalog() ) );
+            }
+            catch ( Exception e )
+            {
+                txnManager.abortTransaction();
+
+                throw e;
+            }
+            
+            txnManager.commitTransaction();
+
         }
         catch ( Exception e )
         {
@@ -69,29 +88,81 @@ class MultiBaseSearch implements Princip
 
     public PrincipalStoreEntry getPrincipal( KerberosPrincipal principal ) throws Exception
     {
+        PrincipalStoreEntry entry = null;
+        
         try
         {
-            return ( PrincipalStoreEntry ) execute( directoryService.getSession(), new GetPrincipal( principal ) );
+            txnManager.beginTransaction( true );
+            
+            try
+            {
+                entry = ( PrincipalStoreEntry ) execute( directoryService.getSession(), new GetPrincipal( principal ) );
+            }
+            catch ( NamingException ne )
+            {
+                txnManager.abortTransaction();
+
+                throw ne;
+            }
+            
+            txnManager.commitTransaction();
+
         }
-        catch ( NamingException ne )
+        catch ( Exception e )
         {
             String message = I18n.err( I18n.ERR_625, principal.getRealm() );
-            throw new ServiceConfigurationException( message, ne );
+            throw new ServiceConfigurationException( message, e );
         }
+        
+        return entry;
     }
 
 
     public String changePassword( KerberosPrincipal principal, String newPassword ) throws Exception
     {
+        String result = null;
+        boolean done = false;
+        
         try
         {
-            return ( String ) execute( directoryService.getSession(), new ChangePassword( principal, newPassword ) );
+            do
+            {
+                txnManager.beginTransaction( false );
+            
+                try
+                {
+                    result = ( String ) execute( directoryService.getSession(), new ChangePassword( principal, newPassword ) );
+                }
+                catch ( NamingException ne )
+                {
+                    txnManager.abortTransaction();
+    
+                    throw ne;
+                }
+                
+                done = true;
+                
+                try
+                {
+                    txnManager.commitTransaction();
+                }
+                catch ( Exception e )
+                {
+                    // TODO check for conflict
+                    throw e;
+                }
+            }
+            while ( !done );
+
         }
-        catch ( NamingException ne )
+        catch ( Exception e )
         {
             String message = I18n.err( I18n.ERR_625, principal.getRealm() );
-            throw new ServiceConfigurationException( message, ne );
+            throw new ServiceConfigurationException( message, e );
         }
+        
+        return result;
+        
     }
 
 

Modified: directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java?rev=1214110&r1=1214109&r2=1214110&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java (original)
+++ directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java Wed Dec 14 08:40:51 2011
@@ -21,10 +21,12 @@ package org.apache.directory.server.kerb
 
 
 
+import javax.naming.NamingException;
 import javax.security.auth.kerberos.KerberosPrincipal;
 
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.txn.TxnManager;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.kerberos.shared.store.operations.ChangePassword;
 import org.apache.directory.server.kerberos.shared.store.operations.GetPrincipal;
@@ -42,13 +44,14 @@ class SingleBaseSearch implements Princi
 {
     private final CoreSession session;
     private final Dn searchBaseDn;
-
+    private TxnManager txnManager;
 
     SingleBaseSearch( DirectoryService directoryService, Dn searchBaseDn )
     {
         try
         {
             session = directoryService.getAdminSession();
+            txnManager = directoryService.getTxnManager();
             this.searchBaseDn = searchBaseDn;
         }
         catch ( Exception e )
@@ -61,12 +64,71 @@ class SingleBaseSearch implements Princi
 
     public PrincipalStoreEntry getPrincipal( KerberosPrincipal principal ) throws Exception
     {
-        return ( PrincipalStoreEntry ) new GetPrincipal( principal ).execute( session, searchBaseDn );
+        
+        PrincipalStoreEntry entry = null;
+        
+        try
+        {
+            txnManager.beginTransaction( true );
+            
+            try
+            {
+                entry = ( PrincipalStoreEntry ) new GetPrincipal( principal ).execute( session, searchBaseDn );
+            }
+            catch ( Exception e )
+            {
+                txnManager.abortTransaction();
+
+                throw e;
+            }
+            
+            txnManager.commitTransaction();
+
+        }
+        catch ( Exception e )
+        {
+            String message = I18n.err( I18n.ERR_625, principal.getRealm() );
+            throw new ServiceConfigurationException( message, e );
+        }
+        
+        return entry;
     }
 
 
     public String changePassword( KerberosPrincipal principal, String newPassword ) throws Exception
     {
-        return (String) new ChangePassword( principal, newPassword ).execute( session, searchBaseDn );
+        String result = null;
+        boolean done = false;
+ 
+        do
+        {
+            txnManager.beginTransaction( false );
+
+            try
+            {
+                result = ( String ) new ChangePassword( principal, newPassword ).execute( session, searchBaseDn );
+            }
+            catch ( Exception e )
+            {
+                txnManager.abortTransaction();
+
+                throw e;
+            }
+
+            done = true;
+            
+            try
+            {
+                txnManager.commitTransaction();
+            }
+            catch ( Exception e )
+            {
+                // TODO check for conflict
+                throw e;
+            }
+        }
+        while ( !done );
+        
+        return result;
     }
 }