Welcome!

Open Source Cloud Authors: Stackify Blog, Vaibhaw Pandey, Automic Blog, John Walsh, Mehdi Daoudi

Related Topics: Java IoT, Open Source Cloud

Java IoT: Article

IWA for a Spring Desktop and Web Application

IWA is a powerful and user-friendly approach to secure your enterprise applications

Integrated Windows Authentication (IWA) provides a user-friendly interface for single sign-on. IWA uses ‘Simple and Protected GSSAPI Negotiation Mechanism' (SPNEGO) to allow the initiators and acceptors to negotiate the underlying protocol to be used for authentication. In this article, we will discuss how to enable SPENGO to support single sign-on for a two-tier web based application using the popular Spring framework.

Even though we only focus on a two-tier application, there are multiple places in these two tiers that SPNEGO needs to be enabled. At the client side, we need the client code to require the use of the SPNEGO protocol; we need to enable the Spring HTTP Invoker to use the HTTP 4.0.1 client, which needs to be SPNEGO enabled. At the server side, we need to configure the application server to support SPNEGO and we need to secure the Spring web application using SPNEGO protocol.

The Sample Application
The sample application used in this article retrieves a message such as "Hello world" from the server. The client uses the Spring HTTP Invoker to access the server application. It will first retrieve a Spring HelloWorld bean, then it will retrieve the message defined on that Spring bean. The Spring bean is a secured resource; it's configured to be protected by the container-managed security and the SPNEGO protocol for authentication. In order for the client to log on to the server, the client's Windows credential will be used for the authentication. The detailed authentication process can be described as follows:

  • The server authenticates itself to the security domain controller such as Microsoft Active Directory.
  • The client accesses a secured resource and wants to negotiate the security mechanisms using SPNEGO. The negotiated protocol could be Kerberos or NTLM.
  • The server sends back the challenge and the mechanism to use to the client.
  • The client uses its Windows credential to get a SPNEGO token from the security domain controller such as Microsoft Active Directory.
  • The client sends the SPNEGO token to the server.
  • The server uses its own SPNEGO ticket to decode the client's token and responses to the client.

This process can take several round-trips for the client to authenticate to the server.

The Un-Secure Implementation
Before attempting to secure the sample application with SPENGO, let's understand how the application is implemented using Spring and the Spring HTTP Invoker without security.

Let's start from the server side. As described in Pro String [2], the following areas are needed to build a Spring service-based web application that uses the HTTP Invoker architecture.

Create the Service Interface and Implementation
We will define an interface, an implementation and a bean. These are simple POJO classes. The interface defines one method:

public HelloWorldBean getHelloWorld();

For the Hello world implementation, we do not return a "Hello World" string. Instead, we return a HelloWorldBean.

public HelloWorldBean getHelloWorld() {
HelloWorldBean helloBean = new HelloWorldBean();
helloBean.setMessage("Hello World");
helloBean.setSender("Zhiyong Li");
return
helloBean;
}

The "Hello World" message can be retrieved from the bean when its "toString" method is called.

public class HelloWorldBean implements Serializable {
private
String message;
private
String sender;
public
String getMessage() { return message; }
public
void setMessage(String message) { this.message = message;}
public
String getSender() { return sender;}
public
void setSender(String sender) { this.sender = sender; }
public
String toString() {
return
"Message: " + message + " from \"" + sender +"\".";
}
}

The above bean class can be easily expanded to provide other business logic instead of simply returning the "Hello World" message.

Configure an Instance of HttpInvokerServiceExporter

The Hello World service needs to be made available for the client to consume. This is achieved by exporting the service through the HttpInvokeServiceExporter defined in httpinvoker-servlet.xml.

<bean name="/helloWorldService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="helloWorldService"/>
</property>
<property name="serviceInterface">
<value>com.sas.iwa.sample.server.HelloWorldService</value>
</property>
</bean>

The service bean in the above definition is defined in the applicationContext.xml file that specifies the actual implementation class for the service.

<bean id="helloWorldService" class="com.sas.iwa.sample.server.HelloWorldImpl"/>

Configure an Instance of Spring DispatcherServlet
To make this Spring application a web application, we need to use the Spring dispatcher servlet. This servlet dispatches and invokes the appropriate services based on the requested URL. The corresponding XML piece that defines the dispatcher servlet in the web.xml is shown below:

<web-app>
<servlet>
<servlet-name>httpinvoker</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>httpinvoker</servlet-name>
<url-pattern>/http/*</url-pattern>
</servlet-mapping>
</web-app>

Now let's look at the client side. At the client side, we configure to use the HTTP Invoker proxy bean as shown below. The proxy handles all the communication details between the client and the remote Spring services that are deployed in the application server. The service URL has several parts. The "HelloWorld" after the "machinename:port" is the context root of the web application. The service that will be accessed is the last part of the URL "helloWorldService" and its interface is called HelloWorldService.

<beans>
<bean id="helloWorldService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8080/HelloWorld/http/helloWorldService</value>
</property>
<property name="serviceInterface">
<value>com.sas.iwa.sample.server.HelloWorldService</value>
</property>
</bean>
</beans>

Since the proxy handles all the communication details, the client code is very simple (see below). It uses the above configuration information defined in the HelloWorld.xml to get the application context. The context is used to get the "helloWorldService" service interface and then its method of "getHelloWorld" is called. The "getHelloWorld" returns the "HelloWorldBean". The "toString" method of the bean is called and the result is printed out.

public static void main(String[] args) {
ApplicationContext ctx = new FileSystemXmlApplicationContext(
"helloworld/conf/http/HelloWorld.xml");
HelloWorldService helloWorld = (HelloWorldService)ctx.getBean("helloWorldService");
System.out.println(helloWorld.getHelloWorld());
}

Secure the Application with SPNEGO
Next we'll use SPNEGO to secure the sample applications. Figure 1 shows the different parts of the applications where SPNEGO needs to be enabled. Specifically, the orange and yellow colored components need to be enabled with SPENGO. Let's discuss the server side first.

The Server Side
At the server side, we need to configure SPNEGO support for JBoss. The "User Guide for JBoss Negotiation" discusses in detail how to accomplish this.[4] In addition, we need to configure container-managed security to secure the "Hello World" service. This can be done by adding the security constraint to the web.xml as shown in Listing 1. (The listings can be downloaded here.) In that list, the auth-method is "SPNEGO". This value should match the name of the "Authenticator" defined in JBoss jboss-service.xml for using "SPNEGO" authentication protocol. "SASWebUser" is a role that can be used for the role-based access security.

We also need to add another JBoss-specific jboss-web.xml file to specify which security domain (also called application policy) should be used for this Hello World application. The jboss-web.xml is listed below, where the "java:/jaas/SPNEGO" is the application-policy described in the "User Guide for JBoss Negotiation."[4] If you have followed that document, that application policy should have already been defined in login-config.xml in your deployed JBoss.

<?xml version="1.0" encoding="US-ASCII"?>
<!-- File containing settings specific to the JBoss application server -->
<jboss-web>
<context-root>HelloWorld</context-root>
<security-domain>java:/jaas/SPNEGO</security-domain>
</jboss-web>

The SPNEGO application policy also uses the role definition file, for example, spengo-roles.properties. If you have a user such as sasdemo who will log on, that user needs to have role SASWebUser, which is defined in the above mentioned properties file as follows:

[email protected]=SASWebUser
sasdemo=SASWebUser

The Client Side
The default HTTP client used by the Spring HTTP Invoker is the HTTP client shipped with the JDK. That HTTP client does not support SPENGO authentication (or any authentication mechanisms). We can also configure Spring to use the Commons HTTP client by using Spring CommonsHttpInvokerRequestExecutor. However, the current Spring implementation only supports Commons HTTP 3.x client. That client does not support SPNEGO either. We have two options for addressing this issue:

  • We can enhance the Commons HTTP client to support SPENGO. There is an open source SPNEGO implementation for it. However, that implementation only supports the HTTP client GetMethod. Spring relies on the HTTP client PostMethod. There is no easy solution to get the package to work with the PostMethod. HTTP Kerberos support [5] includes additional information.
  • We can try to use the Commons HTTP 4.0.1 client. There is an open source SPNEGO implementation for the HTTP 4.0.1 client as well. However, Spring does not support the HTTP 4.0.1 client in its 2.x and 3.x releases. More specifically, it does not provide an HTTP Invoker request executor for the HTTP 4.0.1 client.

We decided to pursue the second approach. We will port CommonsHttpInvokerRequestExecutor for the HTTP 4.0.1 client and use the open source HTTP Kerberos support as described in HTTP Kerberos support for the HTTP 4.0.1 client. The new Commons40HttpInvokerRequestExecutor is included in the source code that you can download. The HTTP Kerberos support requires two configuration files: one for Kerberos support and another for the JAAS login module. The first file is provided in Listing 2 and should be updated based on your specific configuration. The second file for the JAAS login module is listed below.

com.sun.security.jgss.login {
com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true debug=true;
};
com.sun.security.jgss.initiate {
com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true debug=true;
};
com.sun.security.jgss.accept {
com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true debug=true;
};

Further, the HTTP Invoker needs to update the HTTP context to use the NEGOTIATION schema; this is accomplished by sub-classing Commons40HttpInvokerRequestExecutor and overwriting its createHttpContext method. The code is provided in Listing 3. We also need to change the proxy factory bean so that it can provide an HTTP client that is configured to use the NEGOTIATION protocol. That code is in Listing 4. The key method in that class is "afterProperteisSet", which sets up the Kerberos specific properties and also sets "negotiate" as the authentication schema. You may notice that we define one of the Kerberos properties "sunSecurityKrb5Debug" as an instance variable. The purpose is to allow that value to be able to be overwritten in the Spring configure file. Other Kerberos properties in Listing 4 can be defined the same way as well.

We can now configure the requestExecutor at the Spring configuration file using the two classes discussed above.

<bean id="helloWorldService" class="org.springframework. remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl"
value = "http://windowpain.bci.sas.com:8080/HelloWorld/http/helloWorldService"/>
<property name="serviceInterface"
value = "com.sas.iwa.sample.server.HelloWorldService" />
<property name="httpInvokerRequestExecutor">
<ref local="requestExecutor"/>
</property>
</bean>
<bean id="requestExecutor" class="com.sas.security.auth.Commons40NegotiateHttpInvokerRequestExecutor">
<property name="httpClient">
<bean class="com.sas.security.auth.KerberosHttpClient40FactoryBean">
<property name="sunSecurityKrb5Debug" value="true" />
</bean>
</property>
</bean>

When "HelloWorld/http/helloWorldService" is requested, instead of using the default requestExecutor that uses the JDK's HTTP client, we have instrumented Spring to use our customized requestExecutor, which will use the HTTP 4.0.1 client and the customized SPNEGO-aware HTTP client factory bean. You may also notice the property sunSecurityKrb5Debug for KerberosHttpClient40FactoryBean in requestExecutor. That property definition allows us to turn on/off the debug from the Spring configuration file.

Of course, we need to update our client code HelloWorldClient to use this configuration file. This is a one-line change to our client code:

ApplicationContext ctx = new FileSystemXmlApplicationContext(
"helloworld/conf/http/iwaHelloWorld.xml");

Configure and Run the Sample Application
The sample application is packaged into two files: the client zip file IWA-HelloWorld.zip contains all source code and the required JARs. The hello.bat in the client zip file can be invoked to run the example. The server-side code is packaged into a war file, HelloWorld.war, and you need to deploy it to JBoss. However, before the example can be executed, you need to configure JBoss to support SPNEGO.

If you use JBoss 4.x such as 4.2.0, the SPNEGO is not packaged. You will need to download the jboss-negotiation by following the instructions in "User Guide for JBoss Negotiation." [4] To configure JBoss to support SPNEGO, you need to follow the JBoss negotiation document as well.

When following the JBoss negotiation document, make sure the name of the negotiation method in jboss-service.xml is "SPENGO" and the application-policy in jboss-login.xml is also "SPNEGO".

The Spring jar, the HTTP 4.1 client and the HTTP 4.1 Kerberos support have been packaged into the client zip file IWA-HelloWorld.zip. Since Kerberos support requires Java 6, Java 6 is required to run the client code.

You can download the source code for the sample application from the Resources Section. The sample application was deployed and tested on JBoss application server 4.2.0.

Conclusion
IWA is a powerful and user-friendly approach to secure your enterprise applications. However, to configure and implement such a system is a rather complicated process. This article has demonstrated the technologies involved and how to use them together to develop such an application using the popular Spring framework. Interested readers should be able to use the process and the code described in this article to develop their own IWA-enabled applications.

If your application has more than two tiers and you want to pass the client credential through the mid-tiers, you'll need the additional technology called "delegation." SPNEGO authentication and credential delegation with Java [6] has an example on how to implement the delegation. Finally, recently the Spring Security Kerberos Extension reached its first milestone. [7] Interested readers can decide whether that approach works for you.

Resources

  1. Download the client and server sample applications for this article here and here.
  2. Pro String, written by Rob Harrop and Jan Machacek, has a very good description about the Spring HTTP Invoker and the sample implementations.
  3. JBoss application server can be downloaded from here.
  4. User Guide for JBoss Negotiation contains the instructions on how to configure JBoss to support SPNEGO negotiation mechanism. The SPNEGO support for JBoss is packaged in a single jar: jboss-negotiation.jar.
  5. HTTP Kerberos support for HTTP Client 4.0.1 is described here. The contents of this zip file httpclient4kerb20090710.zip have been included in this article's sample application download.
  6. SPNEGO authentication and credential delegation with Java
  7. Spring Security Kerberos / SPNEGO Extension
  8. For Java 6 security features including SPNEGO support, refer to: http://java.sun.com/javase/6/docs/technotes/guides/security/index.html

More Stories By Zhiyong Li

Zhiyong Li is a senior manager of SAS Platform Division and the chair of the Java Technology Board at SAS institute. He started coding in Java in 1995 as a Sun’s development staff. He worked at IBM and iBiomatics as lead architect and developer for several enterprises Java applications. He holds a Ph.D from Computer Science Department of Duke University. He has published many papers in AI, parallel computation and program languages. He has also published several patents.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.