Skip to main content

Posts

Installing GoDaddy certificate in Wildfly/Keycloak

In the previous post we saw how to set up Keycloak . Here we will see how to generate and install GoDaddy.com certificate in Keycloak. The steps are similar for Wildfly as well. Step 1: Generate CSR file Run the following commands in your terminal. <mydomain.com> has to be replaced with your actual domain name. keytool -genkey -alias mydomain_com -keyalg RSA -keysize 2048 -keystore mydomain_com.jks keytool -certreq -alias mydomain_com -file mydomain_com.csr -keystore mydomain_com.jks Step 2: Generate certificate Upload  mydomain_com . csr  file content into GoDaddy.com, generate and download certificate for tomcat server (steps to generating SSL certificate is beyond the scope of this article). If you unzip the file, you will see the following files. gd_bundle-g2-g1.crt ..5f8c...3a89.crt   #some file with alphanumeric name gdig2.crt Files 1 and 2 are of our interest. Third file is not required. Step 3: Import certificate to key...

Configuring and using Keycloak

In this article we will see how to use Keycloak , one of the popular SSO software. Here is the excerpt from the official website. Integrated SSO and IDM for browser apps and RESTful web services.  Built on top of the OAuth 2.0, Open ID Connect, JSON Web Token (JWT) and SAML 2.0 specifications.  Keycloak has tight integration with a variety of platforms and has a HTTP security proxy service where we don't have tight integration.  Options are to deploy it with an existing app server, as a black-box appliance, or as an Openshift cloud service and/or cartridge. Installation Download the software from   here . Let's use  keycloak-1.4.0.Final   for the purpose of demonstration in this article and we will try to set it as a standalone server. To install first download either the zip or tar.gz and extract. Then start by running either: keycloak-1.4.0.Final/bin/standalone.sh or: keycloak-1.4.0.Final/bin/standalone.bat That's it. you are do...

How to execute a singleton task in a cluster?

Have you come across a situation where you wanted a singleton to execute a task in a cluster of servers (such as running a clean up task every day, sending a report everyday etc)? You know that these type of tasks should be executed by exactly only one of many servers you have. Here you go. Following simple program will let you do that exactly. import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.jgroups.Address; import org.jgroups.JChannel; import org.jgroups.ReceiverAdapter; import org.jgroups.View; import org.springframework.stereotype.Component; /** * * @author Pragalathan M */ @Component public class ClusteredSingletonManager { private JChannel channel; private Address ownAddress; private static final Logger logger = Logger.getLogger(ClusteredSingletonManager.class.getName()); @PostConstruct private void init() { try { logger.info(...

Transform Object into XML using JAXB (Part 2)

In one of the posts  we had seen how to convert Java objects into XML. This was done using JAXB and XSD .  What if you don't like to write XSD by hand. Well, you can use any online or offline tools available, to generate the desired XSD from XML. Most of the times the generated XSD will be nearly accurate and you have to hand edit them to make it 100% perfect. Alright. What if you don't know XSD at all. Is there a simpler way? Yes there is. Here we are going to use a different approach to achieve exactly the same result that we have got in the  old  post. Open Netbeans and create a Java Application File->New Project->Java Application Enter "XMLBinding2" in the Project Name field Click Finish Create the following Java classes Replace the Java files with the following contents appropriately. package xmlbinding2; import java.util.List; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrappe...

Dynamic SOAP Service Client

If you have written SOAP service client, you might know that you need the WSDL file; need to generate Java code for that,compile that Java classes and add it as dependency for your module. What would you do if you have to incorporate your code with a new SOAP service every now and then? What would you do if all you need is to consume the service and do a little processing on the output, i.e., you need the data in XML format? What would you do if you don't have a complete WSDL? What would you do if your service is in .NET whose WSDL is having problem while generating Java classes? Is there a way to write a dynamic client which can consume any SOAP service? .... YES!... there is a way. Let's quickly write a web (SOAP) service. Software used: Java 7 NetBeans IDE 7.4 GlassFish 4.0 Maven Create a web project and choose Glassfish as server. Now add web service (not a rest service) as below. Edit the SimpleService.java as follows. package com.mycom...

Permutaion Program

Let's see how we can apply permutation on the following input. a, b,c The expected output is, a b c a c b b c a b a c c a b c b a The logic is simple. Each position p (where p>1) will have p rotations after which the next position is rotated. input: a b c position: 3 2 1 print (a, b, c) rotate b   and print (a, c, b) rotate c ; (a, b, c) count exhausted. position 2 is already rotated 2 times rotate next position which is a and print (b, c, a) rotate c and print (b, a, c) rotate a ; (b, c, a) count exhausted. position 2 is already rotated 2 times rotate next position which is b and print (c, a, b) rotate a and print (c, b, a) rotate b ; (c, a, b) count exhausted. position 2 is already rotated 2 times try rotating next position which is c ;  count is exhausted. position 3 is already rotated 3 times. look for next position no more positions, hence terminate public class Permutation {     public static void main(String[] ar...

REST Service on JBoss 7 (using CXF) - Part 4

In the last three posts we have been seeing how to host a RESTful service on JBoss 7 by defaulting to the container implementation of JAX-RS, i.e., RESTEasy . However you can use any other implementation with JBoss 7. In fact JBoss 7 itself uses RESTEasy as JAX-RS (RESTful service) implementation and CXF as JAX-WS (SOAP service) implementation. But what you will miss if you use other implementations such as CXF or other containers such as Spring , is the container management/injection. That is, you can inject any resource such as CDI bean, EJB, Persistence context, transaction, etc into our LibraryService (using annotation/xml configuration) that we saw in the last post . Where as you need to lookup them manually if you use CXF or use any other dependency injection provider such as Spring. Generally it is less hassle to leave it to the app server to manage these resources; but if you dont have a choice (when other teams are using different library or the feature you need is not sup...