Thursday, June 25, 2015

Some Commonly used postgre sql commands



Log in command to access the postgre sql database

psql -U

psql -U postgresadmin postgres


List down all the in schemas in the database

\l

List down all the tables in a schema

\dt

List down all the tables in a schema

\dt

Executing a sql file in a schema

CREATE DATABASE userdb; 
psql -U postgresadmin -f /usr/local/script/userdb/postgresql.sql -d userdb;

Wednesday, June 24, 2015

How to handle ldap certificate exception with WSO2 carbon server

WSO2 Identity product can be configured to use external ldap as a primary or secondary user store. You can follow the document to learn more about configuring ldap.


After configuring the ldap and during server startup, you may experience the following handshake error message

TID: [0] [IS] [2015-06-24 08:29:51,120] ERROR {org.wso2.carbon.user.core.ldap.LDAPConnectionContext} -  Error obtaining connection.Trying again to get connection...  {org.wso2.carbon.user.core.ldap.LDAPConnectionContext}
javax.naming.CommunicationException: ldap.wso2.org:3269 [Root exception is 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]
        at com.sun.jndi.ldap.Connection.(Connection.java:226)
        at com.sun.jndi.ldap.LdapClient.(LdapClient.java:136)
        at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1608)
        at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2698)
        at com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:316)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
        at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
        at javax.naming.InitialContext.init(InitialContext.java:242)
        at javax.naming.InitialContext.(InitialContext.java:216)
        at javax.naming.directory.InitialDirContext.(InitialDirContext.java:101)
        at org.wso2.carbon.user.core.ldap.LDAPConnectionContext.getContext(LDAPConnectionContext.java:160)

In order to solve this issue, you have to import the public key of the ldap in to the client-trustore,jks(CARBON_HOME/repository/resources/security).

You can obtain the ldap's public certificate by executing following command

echo -n | openssl s_client -connect ldap.wso2.org:3269 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ldapserver.crt

Later you can import the cer file in to client-truststore.jks to be used by WSO2 carbon products

keytool -import -trustcacerts -alias ldapcert -file ldapserver.crt -keystore client-truststore.jks

You can validate the certificate by running following command

 keytool -list -keystore client-truststore.jks -alias ldapcert


Saturday, June 6, 2015

How to create web app specific custom log file in WSO2 carbon platform



Use case

Need to have a custom log file to log the web applications deployed into wso2 Application Server 5.2.1.


Prerequisites

Steps

You can have the basic idea about log4j 1.2 by going through following link.

You can create the log file from the code like this.



As an alternative, you can prepare your own log4j.properties file for the web application and configure it to load the configurations from the file. I will be explaining that approach.



I am going to modify the web application which can be found in AS_HOME/samples/Jaxws-Jaxrs/jaxrs_basic.

I did following modifications to the web app
  1. Modified the the pom.xml file to add the commons-logging and log4j dependencies. Changed the scope to provided for the dependencies of cxf, ws.rs and commons client.
  2. Removed the "packagingExcludes" option to make sure that the jars related to log4j is packed in the WEB-INF/lib folder. We are packing this in to lib folder to make sure, that the defined log4j.properties files is loaded again for the web application. If not the logging will use the log4j.properties defined in carbon environment.
  3. Updated the "maven-antrun-plugin" to copy the "log4j.properties" files in to the target/classes in web app war file.
You can view the pom file over here.


Once you build this maven file, you can deploy it into Application Server and check for the log file in the custom path that you defined in log4j.properties file.

You can check for logs by hitting the endpoint with the following url


The source code can be found here for this web app.