ESB Get & Set Auth Header

SET HEADER

<property xmlns:ns="http://org.apache.synapse/xsd"  
           name="Authorization"  
           expression="fn:concat('Basic ', base64Encode('username:password'))"  
           scope="transport"/>

GET HEADER

<property name="AuthHeader" expression="$trp:Authorization"/>

<log>
 <property name ="====HEADER====" expression=get-property('AuthHeader')/>
</log>


GET JWT HEADER


<property name="authheader" expression="get-property('transport','X-JWT-Assertion')"></property>

Read & Add resource using Governance Registry Libraries

Maven Repo & Dependencies

<repository>
    <id>wso2-nexus</id>
    <name>WSO2 internal Repository</name>
    <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
    <releases>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
        <checksumPolicy>fail</checksumPolicy>
    </releases>
</repository>

<dependency> 
     <groupId>org.wso2.carbon</groupId> 
     <artifactId>org.wso2.carbon.registry.api</artifactId> 
     <version>4.3.0</version> 
</dependency> 
        
<dependency> 
    <groupId>org.wso2.carbon</groupId> 
    <artifactId>org.wso2.carbon.registry.core</artifactId> 
    <version>4.3.0</version> 
</dependency>

Import these Classes

import org.wso2.carbon.context.CarbonContext; 
import org.wso2.carbon.context.RegistryType; 
import org.wso2.carbon.registry.api.Registry; 
import org.wso2.carbon.registry.api.RegistryException; 
import org.wso2.carbon.registry.api.Resource;

Reading a Resource 

try {
    CarbonContext cCtx = CarbonContext.getThreadLocalCarbonContext();
    Registry registry = cCtx.getRegistry(RegistryType.LOCAL_REPOSITORY);
    Resource resource = registry.get("/c1/c2/r1");
    Object content = resource.getContent();
    String output = new String((byte[]) content);
    System.out.println(output);
} catch (RegistryException e) {
    e.printStackTrace();
}

Adding a Resource

try { 
      CarbonContext cCtx = CarbonContext.getThreadLocalCarbonContext(); 
      Registry registry = cCtx.getRegistry(RegistryType.LOCAL_REPOSITORY); 
      Resource resource = registry.newResource(); 
      String str = "My File Content"; 
      resource.setContent(str.getBytes()); 
      registry.put("/c1/c2/r1", resource); 
    } 
catch (RegistryException e) { 
      e.printStackTrace(); 
}

WSO2 Read Registry

Registry registry = messageContext.getConfiguration().getRegistry();
Object obj=registry.getResource(new Entry("conf:/repository/wso2telco/configurations/mediationConfig.xml"),null);
if (obj!=null) {
String content = obj.toString();
}

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Linux


1. Generate crt file from InstallCert.java (output file is cert )

2. keytool -importcert -file cert -alias localhostdas -keystore $JAVA_HOME/jre/lib/security/cacerts

3. Enter keystore password:  changeit



for Windows



1. Go to URL in your firefox browser, click on HTTPS certificate chain (next to URL address). Click "more info" > "security" > "show certificate" > "details" > "export..". Pickup the name and choose file type example.cer. Now you have file with keystore and you have to add it to your JVM

2. Determine location of cacerts files, eg. C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts.

3. Next import the example.cer file into cacerts in command line:
keytool -import -alias example -keystore  C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts -file example.cer
You will be asked for password which default is changeit

4. Restart your JVM/PC.

Create MySql user with all grants

GRANT ALL PRIVILEGES ON dbTest.* To 'user'@'hostname' IDENTIFIED BY 'password';