Tuesday, September 29, 2015

Cluster Guide changes for wso2 BPS 3.5.0

Please follow this link as the general cluster guide for bps 3.5.0.  (yet to be released) http://nandikajayawardana.blogspot.com/2014/02/how-to-cluster-wso2-bps-320.html   But make sure you add below changes for your cluster setup, if you are trying to cluster bps 3.5.0.

1. Regarding the persistence database (BPS_DB in above blog post) ,  you will not find a database.properties file as mentioned in this new release. Therefore you need to add the configurations of your BPS_DB to   bps-datasources.xml file in <product_home>/repository/conf/datasources.

Suppose you create a MYSQL database called BPS_DB, you will need to add a similar configuration to bps-datasources.xml file. You need to change the db name, driverClassName,username,password according to your custom settings.

            <definition type="RDBMS">
                    <validationQuery>SELECT 1</validationQuery>

Note that this needs to be done in both master/slave nodes.

Tuesday, September 22, 2015

Creating jar files with external dependencies using maven-antrun plugin

In most projects, you would want to write your own logic for the build to happen. You might want to copy certain files to different locations, compile source files etc. One easy way to do this is using maven-antrun plugin. By defining this in your pom file, you can execute the target commands that you perform when  creating a build.xml file.  Let us take a look at an example. Here I need to perform two tasks on a given sample at runtime.

1. Compile the source (.java) files provided.  (javac)
2. Create a jar from compiled files.    (jar)

First you need to add the plugin [2] to your pom.xml like below.



If you were to create a simple build.xml file [1] ,you would define different targets and perform operations under these targets. In the same way, you can define tasks under this plugin, and add any operation that you would add under task, instead of target. In below sample I'm adding my first task , that is to compile and create a jar.
                             <dependencyfilesets prefix="jarDepends." />
                                <property name="build.compiler" value="extJavac" />
                                <property name="classdir" value="target/class" />
                                <property name="jardir" value="target/jar" />
                                <property name="project" value="BookOrder" />
                                <property name="main-class" value="newProject.BookOrder" />
                                <mkdir dir="${classdir}" />
                                <path id="build.classpath">
                                    <fileset refid="jarDepends.maven.project.dependencies" />

                                <javac srcdir="${basedir}" destdir="${classdir}" classpathref="build.classpath">
                                <mkdir dir="${jardir}" />
                                <jar destfile="${jardir}/${project}.jar" basedir="${classdir}">
                                        <attribute name="Main-Class" value="${main-class}" />


What you need to remember here is that, you are running the executions under this plugin, which is a separate space. So in above sample, I'm trying to compile a source file that has external dependencies. Though these dependencies are listed in the pom, you need to load them into this plugin for the compilation to succeed.

The easy way to do is by defining fileset ref id with 'maven.project.dependencies' [3] (a property available with antrun plugin) that would load all the dependencies from the pom to the plugin. You could also load individual dependencies like below.

<fileset refid="mydeps.junit:junit:jar"/>
fileset refid="mydeps.org.apache.ant:ant:jar"/>

 So once you have them loaded, you could create a build path, and refer the loaded dependencies to that. This is done by above lines marked in green. So then in your javac command, you can add the classpath, saying to retrieve these dependencies when compiling the given sources.

In the next command 'jar' we are creating the jar file from the .class file that was created from 'javac' command.

Sometimes when using javac command with maven plugin, it tends to give an error saying 'Maybe Jre is defined instead of JDK' and fail the process. This seems to be a known issue , and the fix is to add  below property.
<property name="build.compiler" value="extJavac" />

[1] https://java.net/projects/ant-simple-sample/sources/ant-super-simple-code/content/build.xml
[2] https://maven.apache.org/plugins/maven-antrun-plugin/
[3] https://maven.apache.org/plugins/maven-antrun-plugin/tasks/dependencyFilesets.html 

Tuesday, September 1, 2015

Customize login page of WSO2 Identity Server based on different tenants

Following post https://docs.wso2.com/display/IS500/Customizing+Login+Pages, explains how to customize the login page of Identity Server based on different Service Providers. In this post I will explain how you can customize SAML2 SSO login page based on different tenants.

As explained in above post, you could go ahead with either two methods, and here I will be talking bout the method where to use a JSP to direct to relevant custom login page.  The default login page is located at <IS_HOME>/repository/deployment/server/webapps/authenticationendpoint/login.jsp.

1.Rename login.jsp to default_login.jsp.
2. Create a new file with file name as login.jsp, and add below content. 
Note: Make sure you don't add any additional spaces as this would lead to errors later. Therefore you can open this file in an IDE and check for any errors.

String tenant = request.getParameter("tenantDomain");

if (tenant.equals("abc.com")) {
 RequestDispatcher dispatcher = request.getRequestDispatcher("abc_login.jsp");
 dispatcher.forward(request, response);
} else {
 RequestDispatcher dispatcher = request.getRequestDispatcher("default_login.jsp");
 dispatcher.forward(request, response);

Above is a sample code , so you could add different if cases, based on your tenants. Now what you need to do is, make sure your SP sends  request parameter named 'tenantDomain' , so this code snippet can pick up that value.  

Useful mac terminal commands!

This post contains pretty useful commands in a mac terminal.


mdfind  : similar to grep but by adding -onlyin you can restrict the search.
screencapture : lets you take screenshot of the current terminal window
pbcopy/pbpaste : copy/paster terminal content