Friday, November 1, 2013

Custom alfresco authentication by extending default authentication

Step 1 : Add following line in alfresco-global.properties file located at /alfresco/tomcat/shared/classes location.

authentication.chain=yamaha:yamaha

Step 2 : create new folder test at alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/subsystems/Authentication location.

Step 3 : create new file test-authentication.properties in test folder created with following content.


external.authentication.defaultAdministratorUserNames=admin


Step 3 : Create new file test-authentication-context.xml in same test folder with following content.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <bean id="authenticationComponent" class="org.alfresco.repo.security.authentication.test.TestCustomAuthenticationImpl"
      parent="authenticationComponentBase">
      <property name="nodeService">
         <ref bean="nodeService" />
      </property>
      <property name="personService">
         <ref bean="personService" />
      </property>
      <property name="transactionService">
         <ref bean="transactionService" />
      </property>
      <property name="defaultAdministratorUserNameList">
         <value>${external.authentication.defaultAdministratorUserNames}</value>
      </property>
   </bean>

   <!-- Wrapped version to be used within subsystem -->
   <bean id="AuthenticationComponent" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="proxyInterfaces">
         <list>
            <value>org.alfresco.repo.security.authentication.AuthenticationComponent</value>
         </list>
      </property>
      <property name="transactionManager">
         <ref bean="transactionManager" />
      </property>
      <property name="target">
         <ref bean="authenticationComponent" />
      </property>
      <property name="transactionAttributes">
         <props>
            <prop key="*">${server.transaction.mode.default}</prop>
         </props>
      </property>
   </bean>

   <!-- Authentication service for chaining -->
   <bean id="localAuthenticationService" class="org.alfresco.repo.security.authentication.AuthenticationServiceImpl">
      <property name="ticketComponent">
         <ref bean="ticketComponent" />
      </property>
      <property name="authenticationComponent">
         <ref bean="authenticationComponent" />
      </property>
      <property name="sysAdminParams">
         <ref bean="sysAdminParams" />
      </property>
   </bean>
</beans>


Step 4 : Create new file test-filter.properties in same test folder with following content.

external.authentication.proxyUserName=alfresco-system
external.authentication.proxyHeader=X-Alfresco-Remote-User
external.authentication.enabled=true
external.authentication.userIdPattern=


Step 5 : Create new file test-filter-context.xml in same test folder with following content.


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

   <!-- Enable control over mapping between request and user ID -->
   <bean id="remoteUserMapper" class="org.alfresco.web.app.servlet.DefaultRemoteUserMapper">
      <property name="proxyUserName">
         <value>${external.authentication.proxyUserName}</value>
      </property>
      <property name="proxyHeader">
         <value>${external.authentication.proxyHeader}</value>
      </property>
      <property name="active">
         <value>${external.authentication.enabled}</value>
      </property>
      <property name="userIdPattern">
         <value>${external.authentication.userIdPattern}</value>
      </property>
      <property name="personService">
         <ref bean="PersonService" />
      </property>
   </bean>

   <!-- Enable cookie-based handling of webscript logins. We must assume cookie based client authentication when external auth is in the chain. -->
   <bean id="webscriptAuthenticationFilter" class="org.alfresco.web.app.servlet.WebScriptSSOAuthenticationFilter">
      <property name="active">
         <value>true</value>
      </property>
      <property name="authenticationService">
         <ref bean="AuthenticationService" />
      </property>
      <property name="authenticationComponent">
         <ref bean="AuthenticationComponent" />
      </property>
      <property name="personService">
         <ref bean="personService" />
      </property>
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
      <property name="transactionService">
         <ref bean="TransactionService" />
      </property>
      <property name="container">
         <ref bean="webscripts.container" />
      </property>
   </bean>

</beans>


Step 5 : create new java project in eclipse with any name you want.

Step 6 : create package with name org.alfresco.repo.security.authentication.test in src folder.

Step 7 : Create java class TestCustomAuthenticationImpl.java with following content in same package created.


/**
 * Project Name : Alfresco Custom Authentication
 * ---------------------
 * @author      Sourabh Aggarwal
 * -----------------------------------------------------------------------------------
 * -----------------------------------------------------------------------------------
 */
package org.alfresco.repo.security.authentication.test;

import in.co.ymsli.sedocs.rest.client.ISeDocsRestClient;
import in.co.ymsli.sedocs.rest.client.dto.auth.ValidateTokenDTO;
import in.co.ymsli.sedocs.rest.client.impl.SeDocsRestClientImpl;
import net.sf.acegisecurity.Authentication;

import org.alfresco.repo.security.authentication.AbstractAuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationException;


/**
 * @author Sourabh Aggarwal
 *
 */
public class TestCustomAuthenticationImpl extends AbstractAuthenticationComponent
{


public void authenticateImpl(String userName, char[] password) throws AuthenticationException
{
System.out.println("userName = "+userName + " ::::::::::::::: password = "+String.valueOf(password));
             if(userName == "abc"){
setCurrentUser(oValidateTokenDTO.getUserName());
              }else{

System.out.println("Error calling login service");
throw new AuthenticationException("Unable to authentication");

                   }

}

/**
* The default is not to support Authentication token base authentication
*/
public Authentication authenticate(Authentication token) throws AuthenticationException
{

System.out.println("authenticating vi vi token");
//throw new AlfrescoRuntimeException("Authentication via token not supported");

return token;
}

@Override
protected boolean implementationAllowsGuestLogin() {
// TODO Auto-generated method stub
return false;
}
}


Step 8 : Import all library from alfresco/tomcat/webapps/alfresco/WEB-INF/lib folder.

Step 9 : create jar of java project and place it in alfresco/tomcat/webapps/alfresco/WEB-INF/lib folder.

Step 10: restart server.

Step 11 : its done.

Step 12 : only abc user with any password can login.





New Model in alfresco and make all field searchable

Step 1 : Create new file testCustomFields-model.xml in /alfresco/tomcat/shared/classes/alfresco/extension folder with following content.

<?xml version="1.0" encoding="UTF-8"?>

<model name="test:knowledgebase" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!-- Optional meta-data about the model -->
   <description>test Base Model</description>
   <author>Sourabh Aggarwal</author>
   <version>1.0</version>

   <!-- Imports are required to allow references to definitions in other models -->
   <imports>
      <!-- Import Alfresco Dictionary Definitions -->
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!-- Import Alfresco Content Domain Model Definitions -->
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <!-- Introduction of new namespaces defined by this model -->
   <namespaces>
      <namespace uri="test.model" prefix="yamaha"/>
   </namespaces>

    <aspects>
      <!-- Definition of new Content Aspect: Knowledge Base Document -->
      <aspect name="test:cutomfieldsdata">
         <title>Knowledge Base Referencable</title>
         <properties>

   <property name="test:metadata_serial_number">
               <type>d:text</type>
            </property>

   <property name="test:metadata_status">
               <type>d:text</type>
            </property>
   <property name="test:metadata_owner">
               <type>d:text</type>
            </property>
            <property name="test:metadata_name_of_agreement">
               <type>d:text</type>
            </property>
            <property name="test:metadata_type_of_agreement">
               <type>d:text</type>
            </property>

            <property name="test:metadata_title_of_agreement">
               <type>d:text</type>
            </property>

            <property name="test:metadata_renewal">
               <type>d:text</type>
            </property>
            <property name="test:metadata_area_of_agreement">
               <type>d:text</type>
            </property>
            <property name="test:metadata_nature_of_agreement">
               <type>d:text</type>
            </property>
            <property name="test:metadata_parties">
               <type>d:text</type>
            </property>
            <property name="test:metadata_department">
               <type>d:text</type>
            </property>
            <property name="test:metadata_department_created_by">
               <type>d:text</type>
            </property>

            <property name="test:metadata_agreement_linked_agreements">
               <type>d:text</type>
            </property>


            <property name="test:metadata_type_of_document">
               <type>d:text</type>
            </property>
         </properties>
      </aspect>
   </aspects>

</model>


Step 2 : create new file with name testCustomFields-model-context.xml  in /alfresco/tomcat/shared/classes/alfresco/extension folder with following content.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <!-- Registration of new models -->
    <bean id="extension.kb.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/testCustomFields-model.xml</value>
            </list>
        </property>
    </bean>

     <bean id="extension.kb.resourceBundle" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
       <property name="resourceBundles">
          <list>
             <value>alfresco.messages.testCustomFields</value>
          </list>
       </property>
    </bean>

</beans>


Step 3 : create new file web-client-config-custom.xml in /alfresco/tomcat/shared/classes/alfresco/extension folder with following content.

<alfresco-config>
   <config evaluator="string-compare" condition="Advanced Search">
      <advanced-search>
         <content-types>
         </content-types>
         <folder-types>
         </folder-types>
         <custom-properties>


<meta-data aspect="test:cutomfieldsdata" property="test:metadata_serial_number" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_status" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_owner" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_name_of_agreement" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_title_of_agreement" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_type_of_agreement" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_renewal" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_area_of_agreement" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_nature_of_agreement" />
<meta-data aspect="test:cutomfieldsdata" property="test:metadata_parties" />

<meta-data aspect="test:cutomfieldsdata" property="test:metadata_agreement_linked_agreements" />

<meta-data aspect="test:cutomfieldsdata" property="test:metadata_type_of_document" />
         </custom-properties>
      </advanced-search>
   </config>
  
</alfresco-config>

Step 4 : create new file testCustomFields.properties in alfresco/tomcat/shared/classes/alfresco/messages with following content.

# Custom test messages

test_knowledgebase.property.test_metadata_serial_number.title=Serial Number
test_knowledgebase.property.test_metadata_status.title=Status For Agreement
test_knowledgebase.property.test_metadata_owner.title=Owner
test_knowledgebase.property.test_metadata_name_of_agreement.title=Name Of Agreement
test_knowledgebase.property.test_metadata_title_of_agreement.title=Title Of Agreement
test_knowledgebase.property.test_metadata_type_of_agreement.title=Type Of Agreement
test_knowledgebase.property.test_metadata_renewal.title=Renewal
test_knowledgebase.property.test_metadata_area_of_agreement.title=Area Of Agreement
test_knowledgebase.property.test_metadata_nature_of_agreement.title=Nature Of Agreement
test_knowledgebase.property.test_metadata_parties.title=Parties

test_knowledgebase.property.test_metadata_agreement_linked_agreements.title=Linked Agreements

test_knowledgebase.property.test_metadata_type_of_document.title=Type Of Document

Step 5 : edit file share-config-custom.xml in alfresco/tomcat/shared/classes/alfresco/web-extension and add following content.

  <!-- cm:content type (existing nodes) -->
  <config  evaluator="node-type" condition="cm:content">
     <forms>

<form>
   <field-visibility>
<show id="test:metadata_serial_number" />

<show id="test:metadata_status" />
<show id="test:metadata_owner" />
<show id="test:metadata_name_of_agreement" />

<show id="test:metadata_title_of_agreement" />

<show id="test:metadata_type_of_agreement" />
<show id="test:metadata_renewal" />
<show id="test:metadata_area_of_agreement" />
<show id="test:metadata_nature_of_agreement" />
<show id="test:metadata_department" />
<show id="test:metadata_department_created_by" />

<show id="test:metadata_type_of_service" />

<show id="test:metadata_parties" />

<show id="test:metadata_agreement_linked_agreements" />

<show id="test:metadata_type_of_document" />
   </field-visibility>
</form>

<!-- Document Library pop-up Edit Metadata form -->
<form id="doclib-simple-metadata">
   <field-visibility>

<show id="test:metadata_serial_number" />

<show id="test:metadata_status" />
<show id="test:metadata_owner" />
<show id="test:metadata_name_of_agreement" />

<show id="test:metadata_title_of_agreement" />

<show id="test:metadata_type_of_agreement" />
<show id="test:metadata_renewal" />
<show id="test:metadata_area_of_agreement" />
<show id="test:metadata_nature_of_agreement" />
<show id="test:metadata_department" />
<show id="test:metadata_department_created_by" />

<show id="test:metadata_type_of_service" />

<show id="test:metadata_parties" />

<show id="test:metadata_agreement_linked_agreements" />

<show id="test:metadata_type_of_document" />
   </field-visibility>
   <edit-form template="../documentlibrary/forms/doclib-simple-metadata.ftl" />
</form>

<!-- Document Library Inline Edit form -->
<form id="doclib-inline-edit">
   <field-visibility>

<show id="test:metadata_serial_number" />

<show id="test:metadata_status" />
<show id="test:metadata_owner" />
<show id="test:metadata_name_of_agreement" />

<show id="test:metadata_title_of_agreement" />

<show id="test:metadata_type_of_agreement" />
<show id="test:metadata_renewal" />
<show id="test:metadata_area_of_agreement" />
<show id="test:metadata_nature_of_agreement" />
<show id="test:metadata_department" />
<show id="test:metadata_department_created_by" />

<show id="test:metadata_type_of_service" />

<show id="test:metadata_parties" />

<show id="test:metadata_agreement_linked_agreements" />

<show id="test:metadata_type_of_document" />
   </field-visibility>
</form>
     </forms>
  </config>

Step 6 : Optional if want this model as the aspect then we have to add following in the same share-config-custom.xml file.

  <!-- Document Library config section -->
  <config evaluator="string-compare" condition="DocumentLibrary">

     <!--
Used by the "Manage Aspects" action

For custom aspects, remember to also add the relevant i18n string(s)
   cm_myaspect=My Aspect
     -->
     <aspects>
<!-- Aspects that a user can see -->
<visible>
   <aspect name="cm:generalclassifiable" />
   <aspect name="cm:complianceable" />
   <aspect name="cm:dublincore" />
   <aspect name="cm:effectivity" />
   <aspect name="cm:summarizable" />
   <aspect name="cm:versionable" />
   <aspect name="cm:templatable" />
   <aspect name="cm:emailed" />
   <aspect name="emailserver:aliasable" />
   <aspect name="cm:taggable" />
   <aspect name="app:inlineeditable" />
   <aspect name="test:cutomfieldsdata" />
</visible>

<!-- Aspects that a user can add. Same as "visible" if left empty -->
<addable>
</addable>

<!-- Aspects that a user can remove. Same as "visible" if left empty -->
<removeable>
</removeable>
     </aspects>

  </config>

Step 7 : In file custom-slingshot-application-context.xml l in alfresco/tomcat/shared/classes/alfresco/web-extension and add following content between <beans></beans>.

   <!-- Add test messages -->
   <bean id="webscripts.kb.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>alfresco.messages.testCustomFields</value>
         </list>
      </property>
   </bean>

step 8 : restart.

Friday, July 20, 2012

Automatic index recovery in alfresco after fix time and set cluster environment

1:- Create file scheduled-jobs-context.xml in tomcat/shared/classes/alfresco/extension/ with following content.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <!-- enable DEBUG for 'org.alfresco.repo.cache.EhCacheTracerJob' and enable scheduler property to activate -->
   <bean id="ehCacheTracerJob" class="org.alfresco.util.TriggerBean">
<property name="jobDetail">
   <bean id="ehCacheTracerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
       <property name="jobClass">
           <value>org.alfresco.repo.cache.EhCacheTracerJob</value>
       </property>
   </bean>
</property>
<!-- enable this to activate bean-->
<!--sourabh-->
<property name="scheduler">
   <ref bean="schedulerFactory" />
</property>
<!--sourabh-->
<!-- start after an hour and repeat hourly -->
<property name="startDelayMinutes">
   <value>60</value>
</property>
<property name="repeatIntervalMinutes">
   <value>60</value>
</property>
<!--setting the statistic property be true-->
<!--<property name="statistics">
   <value>true</value>
</property>-->
   </bean>
</beans>
2:- In alfresco-global.properties file add following content.
####Alfresco repository extension for ####
index.tracking.cronExpression=0/5 * * * * ?
index.recovery.mode=AUTO
index.tracking.reindexLagMs=10000
index.tracking.maxTxnDurationMinutes=10
index.tracking.maxTransactionsPerLuceneCommit=100
index.recovery.maximumPoolSize=5
3:- Restart the alfresco server.
4:- Check whether solr indexes are updated or not.
5:- Its all the magic of alfresco index recovery services that recover indexes from database.
6:- Before doing it ehcache must be synchronized.

Alfresco disabling solr and activating lucene

1:- In alfresco-global.properties file comment following lines.


### Solr indexing ###
#index.subsystem.name=solr
#dir.keystore=${dir.root}/keystore
#solr.port.ssl=8444

and add this line

       index.recovery.mode=FULL

2:- See the Magic on restart of alfresco server.

Load balancing using Apache between two or more tomcat


1:- Stop httpd Server if running (service httpd stop).
2:- Go to /etc/httpd/modules/ and paste mod_jk-1.2.28-httpd-2.2.X.so file to it.
3:- Go to /etc/httpd/conf and create file workers.properties into it with content.
###Workerfor10.167.19.21,JVMRoute:tomcatA
worker.tomcatA.port=8009
worker.tomcatA.host=10.167.19.21
worker.tomcatA.type=ajp13
worker.tomcatA.lbfactor=1
worker.tomcatA.socket_keepalive=true
worker.tomcatA.ping_mode=I
worker.tomcatA.recovery_options=8
###########################################
###Workerfor10.167.19.30,JVMRoute:tomcatB
worker.tomcatB.port=8009
worker.tomcatB.host=10.167.19.19
worker.tomcatB.type=ajp13
worker.tomcatB.lbfactor=1
worker.tomcatB.socket_keepalive=true
worker.tomcatB.ping_mode=I
worker.tomcatB.recovery_options=8
###########################################
###LoadBalanceconfigurationforloadBalancer_1
worker.loadBalancer_1.type=lb
worker.loadBalancer_1.method=Request
worker.loadBalancer_1.sticky_session=1
worker.loadBalancer_1.sticky_session_force=1
worker.loadBalancer_1.balance_workers=tomcatA,tomcatB
worker.loadBalancer_1.retries=3
###LoadBalanceListconfiguration
worker.status.type=status
worker.list=status,loadBalancer_1
4:- HostName and port(AJP posts) must be according to your tomcat's installed on different server you can have more than two workers according to your number of tomcat's in load balanced environment.
 5:- In your alfresco server go to /tomcat/conf/ and modify server.xml file.
First Server:- <Engine name="Catalina" defaultHost="localhost"> to <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatA">.
Second Server:- <Engine name="Catalina" defaultHost="localhost"> to <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB">.
6:- Restart both server if running.
7:- Modify /etc/httpd/conf/httpd.conf to include at the end.
# Include mod_jk's specific configuration file.
Include conf/mod_jk.conf
# CoreDumpDirectory Setting.
CoreDumpDirectory /var/tmp
# Include mod_deflate specific configuration file
Include conf/mod_deflate.conf
8:- Include /etc/httpd/conf/mod_jk.conf file and add content.
### mod_jk configuration Starts
## Load mod_jk module for Load balancing & failover configurations
LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.X.so
### mod_jk worker property file path
JkWorkersFile conf/workers.properties
### Define the mod_jk log File Path
JkLogFile       logs/mod_jk.log
JkLogFile       "|/usr/sbin/rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400"
### Define Log Level
JkLogLevel      debug
JkLogStampFormat        "{%a %b %d %H:%M:%S %Y}"
JkRequestLogFormat "%w %V %T"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
### Server-status file for checking server up & running status
#JkMount                /share/*        loadBalancer_1
### Status Web files
### JkUnMount <URL Pattern>
### Shared memory file
JkShmFile       /tmp/jk.shm
### mod_jk's administrative page
<Location /jkstatus>
JkMount status
Order deny,allow
Allow from All
</Location>
NameVirtualHost *:80
Include conf/10.167.19.21_vhost.conf
9:- Ip Address must be your apache server IPAddress.
10:- Create file /etc/httpd/conf/virtualhost.conf with following content.
<VirtualHost *:80>
ServerName SERVER_NAME
        ServerAlias SERVER_NAME
        ### JkMount <URL Pattern>  <Load Balnacer name>
        JkMount         /jkstatus    status
        JkMount         /server-status.jsp loadBalancer_1
#JkMount/ab tomcatB
## Application mount points
11:- Create file /etc/httpd/conf/mod_deflate.conf with following content.
#Mod_deflate Configuration
#### mod_deflate Config
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%) "%{User-agent}i"' deflate
CustomLog logs/deflate_log deflate
DeflateCompressionLevel 6
<Directory />
# Insert filter
SetOutputFilter DEFLATE
</Directory>
<Location />
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
## End of mod_deflate Config
12:- Restart apache server after starting tomcat server.
13:- Check URL :- http://10.167.19.21/jkstatus for checking status of all the workers.
14:- Check URL :- http://10.167.19.21/share for checking the routing od apache to different servers.
15:- Feel the magic. Laughing
 

MYSQL DATABASE REPLICATION BETWEEN TWO DATABASE SERVER ON DIFFERENT MACHINE

1:- Open /etc/my.conf OR /etc/mysql/my.cnf file on both the server(server1 and server2).
2:- Edit file to make changes in my.cnf(on the on master1/slave2 side server)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
###Setting made by sourabh for master configuration###
log-bin=/var/lib/mysql/mysql-bin.log
binlog-do-db=alfresco
server-id=2
binlog-ignore-db=mysql
binlog-ignore-db=test
#information for becoming slave.
master-host=10.167.19.21
master-user=root
master-password=
master-connect-retry=20
replicate-do-db=alfresco
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3:- Edit file to make changes in my.cnf(on the on master2/slave1 side server)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
###Setting made by sourabh for master configuration###
log-bin=/var/lib/mysql/mysql-bin.log
binlog-do-db=alfresco
server-id=1
binlog-ignore-db=mysql
binlog-ignore-db=test
#information for becoming slave.
master-host=10.167.19.19
master-user=root
master-password=
master-connect-retry=20
replicate-do-db=alfresco
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
4:- Create database alfresco on server1 and server2 with exactly same tables and value For this :-use (mysqldump -u root -p alfresco>alfresco.sql)  to create sql file andgenerate database on another server using (mysql -u root -p alfresco<lfresco.sql) with that sql file.
5:- Execute command on both server mysql command prompt:- GRANT REPLICATION SLAVE ON *.* TO 'anotherServerMysqlUser'@'anotherServerIP' IDENTIFIED BY'anotherServerMysqlPassword';
6:- Execute command on both server mysql command prompt:- FLUSH PRIVILEGES;
7:- Restart mysql server on both machines.
8:- On server1 and server2 execute command :-
USE alfresco;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
9:- Configuration like this appears:-
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_do_db | Binlog_ignore_db |
+---------------+----------+--------------+------------------+
| mysql-bin.006 | 183      | alfresco     | mysql , test     |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)
10:- Save the configuration on both servers and quit (using command :-( quit;) )
11:- On both server execute command sequentially:-
:-    SLAVE STOP;
:-    CHANGE MASTER TO MASTER_HOST='anotherServerIP', MASTER_USER='anotherServerMysqlUserName', MASTER_PASSWORD='anotherServerMysqlPAssword', MASTER_LOG_FILE='mysql- bin.006', MASTER_LOG_POS=183;
:- MASTER_HOST is the IP address or hostname of the master (in this example it is 192.168.0.100).
:- MASTER_USER is the user we granted replication privileges on the master.
:- MASTER_PASSWORD is the password of MASTER_USER on the master.
:- MASTER_LOG_FILE is the file MySQL gave back when you ran SHOW MASTER STATUS; on the master.
:- MASTER_LOG_POS is the position MySQL gave back when you ran SHOW MASTER STATUS; on the master
:-    START SLAVE;
:-    quit;
12:- See the magic. Laughing

ALFRESCO REPOSITORY REPLICATION IN ENTERPRISE 4.0.0

1:- Repository replication between two different alfresco enterprise can be done with the help of common network file system(NFS).
2:- Create new file in alfresco/tomcat.shared/classes/alfresco/extension name replicating-content-services-context.xml.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
  <!--
     For a content cache, see <a href="http://wiki.alfresco.com/wiki/CachingContentStore">CachingContentStore</a>
  -->
  <!--
   This file is not included in the application context by default.
   If you include this file, please ensure that you review the sample
   beans contained here.
   -->
  <bean id="localDriveContentStore" class="org.alfresco.repo.content.filestore.FileContentStore">
     <constructor-arg>
<value>/home/sourabh/alfresco-4.0.0/alf_data/contentstore</value>
<!--<value>/var/alfresco/contentstore</value>-->
<!--<value>/development/java_arch/Alfresco/alf_data/contentstore</value>-->
     </constructor-arg>
  </bean>

  <bean id="networkContentStore" class="org.alfresco.repo.content.filestore.FileContentStore">
     <constructor-arg>
<value>/development/java_arch/Alfresco/alf_data/contentstore</value>
<!--<value>/share/alfresco/contentstore</value>-->
<!--<value>/home/sourabh/alfresco-4.0.0/alf_data/contentstore</value>-->
     </constructor-arg>
  </bean>

  <bean id="fileContentStore" class="org.alfresco.repo.content.replication.ReplicatingContentStore" >
     <property name="primaryStore">
<ref bean="localDriveContentStore" />
     </property>
     <property name="secondaryStores">
<list>
   <ref bean="networkContentStore" />
</list>
     </property>
     <property name="inbound">
<value>true</value>
     </property>
     <property name="outbound">
<value>true</value>
     </property>
     <property name="retryingTransactionHelper">
<ref bean="retryingTransactionHelper"/>
     </property>
  </bean>
</beans>

3:- Secondary content store is the Network File System(NFS).
4:- Restart the alfresco server on both the machine who replicate data(replication can be done for more than two machines).
5:- Before replicating repository the database must be replicated between machines.
6:- See the magic.Laughing