{"id":335,"date":"2010-12-16T11:09:00","date_gmt":"2010-12-16T11:09:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/securing-gwt-apps-with-spring-security.html"},"modified":"2012-10-21T19:23:54","modified_gmt":"2012-10-21T19:23:54","slug":"securing-gwt-apps-with-spring-security","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html","title":{"rendered":"Securing GWT apps with Spring Security"},"content":{"rendered":"<p>In this tutorial we will see how to integrate GWT with Spring&#8217;s security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how to retrieve the user&#8217;s credentials and how to log the various authentication events. Moreover, we are going to implement a custom authentication provider so that existing authentication schemes can be reused.<\/p>\n<p>If you are a regular <a href=\"http:\/\/www.javacodegeeks.com\/\">JavaCodeGeeks<\/a> reader, you should probably know by now that we are really fond of <a href=\"http:\/\/code.google.com\/webtoolkit\/\">GWT<\/a>. In the past, Justin has written some killer articles on <a href=\"http:\/\/www.javacodegeeks.com\/?tag=gwt\">GWT<\/a>: <a href=\"http:\/\/www.javacodegeeks.com\/2010\/05\/gwt-2-spring-3-jpa-2-hibernate-35.html\">how to integrate GWT with Spring and Hibernate (JPA)<\/a> and <a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/gwt-2-spring-3-jpa-2-hibernate-35.html\">how to add Eclipse and Maven in the mix<\/a>. Moreover, I have written about how to <a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/add-json-gwt-application.html\">add JSON capabilities into your GWT application<\/a>, <a href=\"http:\/\/www.javacodegeeks.com\/2010\/06\/add-captcha-gwt-application.html\">how to add CAPTCHA for GWT<\/a> and <a href=\"http:\/\/www.javacodegeeks.com\/2010\/06\/getting-started-smartgwt-gwt-interfaces.html\">how to get started with SmartGWT<\/a>. Finally, Pat has written about <a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/building-your-own-gwt-spring-manen.html\">building your own GWT Spring Maven Archetype<\/a> and <a href=\"http:\/\/www.javacodegeeks.com\/2010\/09\/gwt-ejb3-maven-jboss-51-integration.html\">integrating GWT, EJB3, Maven and JBoss<\/a>.<\/p>\n<p>Thus, it should be of no surprise that we are now bringing <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/\">Spring&#8217;s Security module<\/a> into play. As the official site states, <span style=\"font-style: italic\">Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications<\/span>. Spring Security is the evolution of the Acegi framework which used Spring under the hood in order to provide security mainly to web applications. However, Spring Security is now a full-blown security framework, incorporating functionality not only for the web, but also for <a href=\"http:\/\/en.wikipedia.org\/wiki\/Ldap\">LDAP<\/a> integration  and <a href=\"http:\/\/en.wikipedia.org\/wiki\/Access_control_list\">ACL<\/a>s creation. Before getting started with this tutorial, it would be nice to take a look at the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/reference\/springsecurity.html\">Spring Security Reference Documentation<\/a> and having at hand the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/index.html\">Spring Security API Javadocs<\/a>.<\/p>\n<p>For this tutorial I will be using GWT 2.1.0 and Spring Security 3.0.5. You can download the latest production release <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/downloads.html\">here<\/a>. As you might have guessed, some libraries from the core Spring framework   will also be needed. You can download the framework <a href=\"http:\/\/www.springsource.com\/download\/community\">here<\/a>.<\/p>\n<p>Let&#8217;s get started by creating a new Web Application project in Eclipse (I suppose you have already installed the Google plugin for Eclipse and that you also have GWT deployed). I chose the profound name \u201cGwtSpringSecurityProject\u201d for the project&#8217;s name. Here what the Eclipse screen will look like:<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TQnRHALXN1I\/AAAAAAAAAOI\/7r0uw9U3FdY\/s1600\/01-gwt-spring-security-project.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/_piNjpdpJZXA\/TQnRHALXN1I\/AAAAAAAAAOI\/7r0uw9U3FdY\/s320\/01-gwt-spring-security-project.png\" style=\"cursor: pointer;height: 320px;margin: 0px auto 10px;text-align: center;width: 276px\" \/><\/a><\/p>\n<p>The first step for adding Spring security to our project is declaring a filter in our \u201cweb.xml\u201d file. This filter, which is an instance of the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/index.html?org\/springframework\/security\/web\/FilterChainProxy.html\">FilterChainProxy<\/a> class, will intercept all incoming requests and delegate the request&#8217;s control to the appropriate Spring handler.  The relevant web declaration file snippet is the following:<\/p>\n<pre class=\"brush:xml\">\u2026\r\n&lt;filter&gt;\r\n        &lt;filter-name&gt;springSecurityFilterChain&lt;\/filter-name&gt;\r\n        &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;\/filter-class&gt;\r\n&lt;\/filter&gt;\r\n\r\n&lt;filter-mapping&gt;\r\n      &lt;filter-name&gt;springSecurityFilterChain&lt;\/filter-name&gt;\r\n      &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n&lt;\/filter-mapping&gt;\r\n...\r\n<\/pre>\n<p>We also have to define a ContextLoaderListener in our \u201cweb.xml\u201d in order to bootstrap the Spring context. This is done via the following snippet:<\/p>\n<pre class=\"brush:xml\">\u2026\r\n    &lt;listener&gt;\r\n        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;\/listener-class&gt;\r\n    &lt;\/listener&gt;\r\n...\r\n<\/pre>\n<p>Next we create a file named \u201capplicationContext.xml\u201d inside the \u201cwar\/WEB-INF\u201d folder. There we declare the spring security related information. The most important element is the \u201c<a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.1.x\/reference\/appendix-namespace.html#nsa-http\">http<\/a>\u201d, which can be used to define on which URLs should security be applied, as well as what roles should the users have in order to access particular resources. In our case, the snippet is the following:<\/p>\n<pre class=\"brush:xml\">\u2026\r\n&lt;http auto-config=\"true\"&gt;\r\n        &lt;intercept-url pattern=\"\/gwtspringsecurityproject\/**\" access=\"ROLE_USER\"\/&gt;\r\n        &lt;intercept-url pattern=\"\/gwt\/**\" access=\"ROLE_USER\"\/&gt;\r\n        &lt;intercept-url pattern=\"\/**\/*.html\" access=\"ROLE_USER\"\/&gt;\r\n        &lt;intercept-url pattern=\"\/**\" access=\"IS_AUTHENTICATED_ANONYMOUSLY\" \/&gt;\r\n&lt;\/http&gt;\r\n...\r\n<\/pre>\n<p>In short, the above states that role \u201cROLE_USER\u201d is required in order to gain access to the files under the \u201cgwt\u201d and the \u201cgwtspringsecurityproject\u201d folders (where the GWT related resources reside). Similarly, all HTML files (like GWT&#8217;s entrypoint) require the same role. The \u201cIS_AUTHENTICATED_ANONYMOUSLY\u201d means that all users can access the particular resource, without having to be part of a specific role. With this simple usage of the \u201c<a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.1.x\/reference\/appendix-namespace.html#nsa-http\">http<\/a>\u201d element, the default login page and logout URL will be used by Spring.<\/p>\n<p>All the authentication requests are handled by an <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/index.html?org\/springframework\/security\/authentication\/AuthenticationManager.html\">AuthenticationManager<\/a>, so an instance of that has to be declare in our file. More specifically, the requests are usually delegated to an <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/authentication\/AuthenticationProvider.html\">AuthenticationProvider<\/a>. Some already created implementations can be used, such as the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/authentication\/dao\/DaoAuthenticationProvider.html\">DaoAuthenticationProvider<\/a> (when working with roles and users defined in a DB) or the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/ldap\/authentication\/LdapAuthenticationProvider.html\">LdapAuthenticationProvider<\/a> (which authenticates users against an LDAP server). For the purposes of this tutorial however, we are going to create a custom authentication provider and integrate it with spring&#8217;s security infrastructure.<\/p>\n<p>Before we delve into the application&#8217;s code, we have to take care of dependencies first. Here are the JARs that have to be added to the project&#8217;s classpath:<\/p>\n<ul>\n<li>org.springframework.context-3.0.5.RELEASE.jar<\/li>\n<li>spring-security-core-3.0.5.RELEASE.jar<\/li>\n<li>spring-security-web-3.0.5.RELEASE.jar<\/li>\n<\/ul>\n<p>Ok, now we are ready. Our provider is quite plain and just uses a static Map in order to store users and their corresponding password. Here is the code:<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gwt.security.server.auth;\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\nimport org.springframework.security.authentication.AuthenticationProvider;\r\nimport org.springframework.security.authentication.BadCredentialsException;\r\nimport org.springframework.security.authentication.UsernamePasswordAuthenticationToken;\r\nimport org.springframework.security.core.Authentication;\r\nimport org.springframework.security.core.AuthenticationException;\r\nimport org.springframework.security.core.userdetails.UsernameNotFoundException;\r\n\r\npublic class CustomAuthenticationProvider implements AuthenticationProvider {\r\n    \r\n    private static Map&lt;String, String&gt; users = new HashMap&lt;String, String&gt;();\r\n    \r\n    static {\r\n        users.put(\"fabrizio\", \"javacodegeeks\");\r\n        users.put(\"justin\", \"javacodegeeks\");\r\n    }\r\n\r\n    @Override\r\n    public Authentication authenticate(Authentication authentication) \r\n            throws AuthenticationException {\r\n        \r\n        String username = (String) authentication.getPrincipal();\r\n        String password = (String)authentication.getCredentials();\r\n        \r\n        if (users.get(username)==null)\r\n            throw new UsernameNotFoundException(\"User not found\");\r\n        \r\n        String storedPass = users.get(username);\r\n        \r\n        if (!storedPass.equals(password))\r\n            throw new BadCredentialsException(\"Invalid password\");\r\n        \r\n        Authentication customAuthentication = \r\n            new CustomUserAuthentication(\"ROLE_USER\", authentication);\r\n        customAuthentication.setAuthenticated(true);\r\n        \r\n        return customAuthentication;\r\n        \r\n    }\r\n\r\n    @Override\r\n    public boolean supports(Class&lt;? extends Object&gt; authentication) {\r\n        return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>Let&#8217;s begin the elaboration on that code from the end. The <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/authentication\/AuthenticationProvider.html#supports%28java.lang.Class%29\">supports<\/a> method defines the kind of authentication that this provider provides. In our case, the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/authentication\/UsernamePasswordAuthenticationToken.html\">UsernamePasswordAuthenticationToken<\/a> is the one we wish to handle. That implementation is designed for simple presentation of a username and password.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/authentication\/AuthenticationProvider.html#authenticate%28org.springframework.security.core.Authentication%29\">authenticate<\/a> method is implemented and inside that we retrieve the username provided in the login form (via the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html#getPrincipal%28%29\">getPrincipal<\/a> method) as well as the accompanying password (via the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html#getCredentials%28%29\">getCredentials<\/a> method). First, we check if the specific username exists and if not, a <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/userdetails\/UsernameNotFoundException.html\">UsernameNotFoundException<\/a> is thrown. Similarly, if the username exists but the password is incorrect, a <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/authentication\/BadCredentialsException.html\">BadCredentialsException<\/a> is thrown. Note that both theses exceptions extend the parent <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/AuthenticationException.html\">AuthenticationException<\/a> class.<\/p>\n<p>If both the username and the password are correct, we are in place to authenticate the user. In order to do so, we have to return a concrete instance of the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html\">Authentication<\/a> interface. In that, we have to encapsulate the already known user information (credentials etc.) as well as the roles (authorities) that the user has. Note that the assigned role (ROLE_USER) matches the one declared in the \u201capplicationContext.xml\u201d file. In addition, the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html#setAuthenticated%28boolean%29\">setAuthenticated<\/a> method has to be invoked (with true as argument) in order to indicate to the rest of the authentication chain that the specific user was successfully authenticated by our module. Let&#8217;s see how the custom authentication object is defined in our case:<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gwt.security.server.auth;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Collection;\r\n\r\nimport org.springframework.security.core.Authentication;\r\nimport org.springframework.security.core.GrantedAuthority;\r\nimport org.springframework.security.core.authority.GrantedAuthorityImpl;\r\n\r\npublic class CustomUserAuthentication implements Authentication {\r\n    \r\n    private static final long serialVersionUID = -3091441742758356129L;\r\n    \r\n    private boolean authenticated;\r\n    \r\n    private GrantedAuthority grantedAuthority;\r\n    private Authentication authentication;\r\n    \r\n    public CustomUserAuthentication(String role, Authentication authentication) {\r\n        this.grantedAuthority = new GrantedAuthorityImpl(role);\r\n        this.authentication = authentication;\r\n    }\r\n\r\n    @Override\r\n    public Collection&lt;GrantedAuthority&gt; getAuthorities() {\r\n        Collection&lt;GrantedAuthority&gt; authorities = new ArrayList&lt;GrantedAuthority&gt;();\r\n        authorities.add(grantedAuthority);\r\n        return authorities;\r\n    }\r\n\r\n    @Override\r\n    public Object getCredentials() {\r\n        return authentication.getCredentials();\r\n    }\r\n\r\n    @Override\r\n    public Object getDetails() {\r\n        return authentication.getDetails();\r\n    }\r\n\r\n    @Override\r\n    public Object getPrincipal() {\r\n        return authentication.getPrincipal();\r\n    }\r\n\r\n    @Override\r\n    public boolean isAuthenticated() {\r\n        return authenticated;\r\n    }\r\n\r\n    @Override\r\n    public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {\r\n        this.authenticated = authenticated;\r\n    }\r\n\r\n    @Override\r\n    public String getName() {\r\n        return this.getClass().getSimpleName();\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>In the constructor, we pass the user&#8217;s role and the original <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html\">Authentication<\/a> object. In the implemented methods, the most important one is the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html#getAuthorities%28%29\">getAuthorities<\/a>, which returns the authorities that the principal has been granted. That information is provided inside a collection of <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/GrantedAuthority.html\">GrantedAuthority<\/a> objects.<\/p>\n<p>Let&#8217;s see now how the \u201capplicationContext.xml\u201d looks like:<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n\r\n&lt;beans:beans xmlns=\"http:\/\/www.springframework.org\/schema\/security\"\r\n    xmlns:beans=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n    xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n    xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.0.xsd\r\n                        http:\/\/www.springframework.org\/schema\/security http:\/\/www.springframework.org\/schema\/security\/spring-security-3.0.xsd\"&gt;\r\n\r\n    &lt;beans:bean id=\"customAuthListener\" class=\"com.javacodegeeks.gwt.security.server.auth.CustomAuthListener\"\/&gt;\r\n\r\n    &lt;http auto-config=\"true\"&gt;\r\n        &lt;intercept-url pattern=\"\/gwtspringsecurityproject\/**\" access=\"ROLE_USER\"\/&gt;\r\n        &lt;intercept-url pattern=\"\/gwt\/**\" access=\"ROLE_USER\"\/&gt;\r\n        &lt;intercept-url pattern=\"\/**\/*.html\" access=\"ROLE_USER\"\/&gt;\r\n        &lt;intercept-url pattern=\"\/**\" access=\"IS_AUTHENTICATED_ANONYMOUSLY\" \/&gt;\r\n    &lt;\/http&gt;\r\n    \r\n    &lt;beans:bean id=\"customAuthenticationProvider\" class=\"com.javacodegeeks.gwt.security.server.auth.CustomAuthenticationProvider\" \/&gt;    \r\n    \r\n    &lt;authentication-manager alias=\"authenticationManager\"&gt;\r\n     &lt;authentication-provider ref=\"customAuthenticationProvider\"\/&gt;\r\n &lt;\/authentication-manager&gt;\r\n        \r\n&lt;\/beans:beans&gt;\r\n<\/pre>\n<p>Every element of the declaration file has been defined except for the \u201cCustomAuthListener\u201d. Being part of the Spring framework, Spring Security allows the application developer to provide callbacks which will be invoked on specific parts of the application&#8217;s lifecycle. Thus, we can register our methods to be called when specific authentication events occur. In our case, we will create a listener that receives <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/index.html?org\/springframework\/security\/access\/event\/AbstractAuthorizationEvent.html\">AbstractAuthorizationEvent<\/a>s, i.e. all security interception related events. Let&#8217;s see how this is accomplished:<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gwt.security.server.auth;\r\n\r\nimport org.apache.commons.logging.Log;\r\nimport org.apache.commons.logging.LogFactory;\r\nimport org.springframework.context.ApplicationListener;\r\nimport org.springframework.security.authentication.event.AbstractAuthenticationEvent;\r\nimport org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;\r\n\r\npublic class CustomAuthListener implements ApplicationListener&lt;AbstractAuthenticationEvent&gt; {\r\n \r\n private static final Log logger = LogFactory.getLog(CustomAuthListener.class);\r\n\r\n @Override\r\n public void onApplicationEvent(AbstractAuthenticationEvent event) {\r\n  \r\n final StringBuilder builder = new StringBuilder();\r\n        builder.append(\"Authentication event \");\r\n        builder.append(event.getClass().getSimpleName());\r\n        builder.append(\": \");\r\n        builder.append(event.getAuthentication().getName());\r\n        builder.append(\"; details: \");\r\n        builder.append(event.getAuthentication().getDetails());\r\n\r\n        if (event instanceof AbstractAuthenticationFailureEvent) {\r\n            builder.append(\"; exception: \");\r\n            builder.append(((AbstractAuthenticationFailureEvent) event).getException().getMessage());\r\n        }\r\n\r\n        logger.warn(builder.toString());\r\n\r\n }\r\n\r\n}\r\n<\/pre>\n<p>In our implementation, we just log all successful and unsuccessful authentication events (based on the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/access\/event\/LoggerListener.html\">LoggerListener<\/a> class) but it is obviously quite straightforward to provide your own business logic here.<\/p>\n<p>Finally, we will create a GWT asynchronous server side service that will provide the client with information regarding the user and the username that he has logged in with. If you have the tiniest experience with GWT, you will not have any problems understanding the code. Here are the two interfaces and the concrete implementation of the service:<\/p>\n<p>AuthService<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gwt.security.client;\r\n\r\nimport com.google.gwt.user.client.rpc.RemoteService;\r\nimport com.google.gwt.user.client.rpc.RemoteServiceRelativePath;\r\n\r\n\/**\r\n * The client side stub for the RPC service.\r\n *\/\r\n@RemoteServiceRelativePath(\"auth\")\r\npublic interface AuthService extends RemoteService {\r\n String retrieveUsername();\r\n}\r\n<\/pre>\n<p>AuthServiceAsync<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gwt.security.client;\r\n\r\nimport com.google.gwt.user.client.rpc.AsyncCallback;\r\n\r\n\/**\r\n * The async counterpart of &lt;code&gt;AuthService&lt;\/code&gt;.\r\n *\/\r\npublic interface AuthServiceAsync {\r\n void retrieveUsername(AsyncCallback&lt;String&gt; callback);\r\n}\r\n<\/pre>\n<p>AuthServiceImpl<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gwt.security.server;\r\n\r\nimport org.springframework.security.core.Authentication;\r\nimport org.springframework.security.core.context.SecurityContextHolder;\r\n\r\nimport com.google.gwt.user.server.rpc.RemoteServiceServlet;\r\nimport com.javacodegeeks.gwt.security.client.AuthService;\r\n\r\n@SuppressWarnings(\"serial\")\r\npublic class AuthServiceImpl extends RemoteServiceServlet implements AuthService {\r\n\r\n    @Override\r\n    public String retrieveUsername() {\r\n        \r\n        Authentication authentication =\r\n            SecurityContextHolder.getContext().getAuthentication();\r\n        \r\n        if (authentication==null){\r\n            System.out.println(\"Not logged in\");\r\n            return null;\r\n        }\r\n        else {\r\n            return (String) authentication.getPrincipal();\r\n        }\r\n        \r\n    }\r\n    \r\n}\r\n<\/pre>\n<p>The code is very simple. We use the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/context\/SecurityContextHolder.html\">SecurityContextHolder<\/a> class to retrieve the current <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/context\/SecurityContext.html\">SecurityContext<\/a> and then the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/context\/SecurityContext.html#getAuthentication%28%29\">getAuthentication<\/a> method in order to take reference of the underlying <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html\">Authentication<\/a> object. From that, we retrieve the username, if any, via the <a href=\"http:\/\/static.springsource.org\/spring-security\/site\/docs\/3.0.x\/apidocs\/org\/springframework\/security\/core\/Authentication.html#getPrincipal%28%29\">getPrincipal<\/a> method.<\/p>\n<p>Of course, we have to declare the specific servlet in our application \u201cweb.xml\u201d file. Here it is:<\/p>\n<pre class=\"brush:xml\">... \r\n&lt;servlet&gt;\r\n &lt;servlet-name&gt;authServlet&lt;\/servlet-name&gt;\r\n &lt;servlet-class&gt;com.javacodegeeks.gwt.security.server.AuthServiceImpl&lt;\/servlet-class&gt;\r\n&lt;\/servlet&gt;\r\n\r\n&lt;servlet-mapping&gt;\r\n &lt;servlet-name&gt;authServlet&lt;\/servlet-name&gt;\r\n &lt;url-pattern&gt;\/gwtspringsecurityproject\/auth&lt;\/url-pattern&gt;\r\n&lt;\/servlet-mapping&gt;\r\n...\r\n<\/pre>\n<p>And here is the whole web declaration file:<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;!DOCTYPE web-app\r\n    PUBLIC \"-\/\/Sun Microsystems, Inc.\/\/DTD Web Application 2.3\/\/EN\"\r\n    \"http:\/\/java.sun.com\/dtd\/web-app_2_3.dtd\"&gt;\r\n\r\n&lt;web-app&gt;\r\n\r\n    &lt;filter&gt;\r\n        &lt;filter-name&gt;springSecurityFilterChain&lt;\/filter-name&gt;\r\n        &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;\/filter-class&gt;\r\n    &lt;\/filter&gt;\r\n\r\n    &lt;filter-mapping&gt;\r\n      &lt;filter-name&gt;springSecurityFilterChain&lt;\/filter-name&gt;\r\n      &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n    &lt;\/filter-mapping&gt;\r\n     \r\n    &lt;listener&gt;\r\n        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;\/listener-class&gt;\r\n    &lt;\/listener&gt;\r\n\r\n    &lt;!-- Servlets --&gt;\r\n    &lt;servlet&gt;\r\n        &lt;servlet-name&gt;greetServlet&lt;\/servlet-name&gt;\r\n        &lt;servlet-class&gt;\r\n            com.javacodegeeks.gwt.security.server.GreetingServiceImpl\r\n        &lt;\/servlet-class&gt;\r\n    &lt;\/servlet&gt;\r\n\r\n    &lt;servlet-mapping&gt;\r\n        &lt;servlet-name&gt;greetServlet&lt;\/servlet-name&gt;\r\n        &lt;url-pattern&gt;\/gwtspringsecurityproject\/greet&lt;\/url-pattern&gt;\r\n    &lt;\/servlet-mapping&gt;\r\n    \r\n    &lt;servlet&gt;\r\n        &lt;servlet-name&gt;authServlet&lt;\/servlet-name&gt;\r\n        &lt;servlet-class&gt;com.javacodegeeks.gwt.security.server.AuthServiceImpl&lt;\/servlet-class&gt;\r\n    &lt;\/servlet&gt;\r\n\r\n    &lt;servlet-mapping&gt;\r\n        &lt;servlet-name&gt;authServlet&lt;\/servlet-name&gt;\r\n        &lt;url-pattern&gt;\/gwtspringsecurityproject\/auth&lt;\/url-pattern&gt;\r\n    &lt;\/servlet-mapping&gt;\r\n\r\n    &lt;!-- Default page to serve --&gt;\r\n    &lt;welcome-file-list&gt;\r\n        &lt;welcome-file&gt;GwtSpringSecurityProject.html&lt;\/welcome-file&gt;\r\n    &lt;\/welcome-file-list&gt;\r\n\r\n&lt;\/web-app&gt;\r\n<\/pre>\n<p>Let&#8217;s see how this service is used inside the application&#8217;s entry point. We add the following code snippet just before the end of the <a href=\"http:\/\/google-web-toolkit.googlecode.com\/svn\/javadoc\/1.6\/com\/google\/gwt\/core\/client\/EntryPoint.html#onModuleLoad%28%29\">onModuleLoad<\/a> method:<\/p>\n<pre class=\"brush:java\">authService.retrieveUsername(\r\n new AsyncCallback&lt;String&gt;() {\r\n  public void onFailure(Throwable caught) {\r\n   dialogBox.setText(\"Remote Procedure Call - Failure\");\r\n  }\r\n  public void onSuccess(String result) {\r\n   nameField.setText(result);\r\n  }\r\n }\r\n);\r\n<\/pre>\n<p>A last step before launching our application is to take care of the runtime dependencies. Spring requires a bunch of libraries in order to do its DI magic, so here is the list of the JARs that have to be present inside your \u201cwar\/WEB-INF\/lib\u201d folder:<\/p>\n<ul>\n<li>org.springframework.aop-3.0.5.RELEASE.jar<\/li>\n<li>org.springframework.asm-3.0.5.RELEASE.jar<\/li>\n<li>org.springframework.beans-3.0.5.RELEASE.jar<\/li>\n<li>org.springframework.context-3.0.5.RELEASE.jar<\/li>\n<li>org.springframework.core-3.0.5.RELEASE.jar<\/li>\n<li>org.springframework.expression-3.0.5.RELEASE.jar<\/li>\n<li>org.springframework.web-3.0.5.RELEASE.jar<\/li>\n<li>spring-security-config-3.0.5.RELEASE.jar<\/li>\n<li>spring-security-core-3.0.5.RELEASE.jar<\/li>\n<li>spring-security-web-3.0.5.RELEASE.jar<\/li>\n<\/ul>\n<p>After copying all of the above, launch the Eclipse project configuration and try to access the default URL:<br \/>\n<a href=\"http:\/\/draft.blogger.com\/%20http:\/\/127.0.0.1:8888\/GwtSpringSecurityProject.html?gwt.codesvr=127.0.0.1:9997\"><br \/>\nhttp:\/\/127.0.0.1:8888\/GwtSpringSecurityProject.html?gwt.codesvr=127.0.0.1:9997<\/a><\/p>\n<p>The request will be intercepted by Spring Security and you will be presented with a default login page. Provide the valid credentials as below:<\/p>\n<p><a href=\"http:\/\/4.bp.blogspot.com\/_piNjpdpJZXA\/TQnTLry2M6I\/AAAAAAAAAOQ\/KrfAwIkO64g\/s1600\/02-login-screen.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/4.bp.blogspot.com\/_piNjpdpJZXA\/TQnTLry2M6I\/AAAAAAAAAOQ\/KrfAwIkO64g\/s320\/02-login-screen.png\" style=\"cursor: pointer;height: 169px;margin: 0px auto 10px;text-align: center;width: 312px\" \/><\/a><\/p>\n<p>Submit the form data and you will be redirected to the original URL. Notice that the text field will be populated with the username used to log in.<\/p>\n<p><a href=\"http:\/\/1.bp.blogspot.com\/_piNjpdpJZXA\/TQnTVUDMtKI\/AAAAAAAAAOY\/RKoAZheZxhs\/s1600\/03-gwt-main-page.png\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/1.bp.blogspot.com\/_piNjpdpJZXA\/TQnTVUDMtKI\/AAAAAAAAAOY\/RKoAZheZxhs\/s320\/03-gwt-main-page.png\" style=\"cursor: pointer;height: 320px;margin: 0px auto 10px;text-align: center;width: 293px\" \/><\/a><\/p>\n<p>Return to your Eclipse Console view and check out the various logs printed there. You should see something like the following:<\/p>\n<p><span style=\"font-style: italic\"><br \/>\n12 Dec 2010 8:45:49 PM com.javacodegeeks.gwt.security.server.auth.CustomAuthListener onApplicationEvent<br \/>\nWARNING: Authentication event AuthenticationSuccessEvent: CustomUserAuthentication; details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffdaa08: RemoteIpAddress: 127.0.0.1; SessionId: im1fdjvdu7yw<br \/>\n12 Dec 2010 8:45:49 PM com.javacodegeeks.gwt.security.server.auth.CustomAuthListener onApplicationEvent<br \/>\nWARNING: Authentication event InteractiveAuthenticationSuccessEvent: CustomUserAuthentication; details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffdaa08: RemoteIpAddress: 127.0.0.1; SessionId: im1fdjvdu7yw<\/span><\/p>\n<p>That&#8217;s all folks. You can find <a href=\"http:\/\/dl.dropbox.com\/u\/7215751\/JavaCodeGeeks\/GWTSpringSecurityTutorial\/GwtSpringSecurityProject.zip\">here<\/a> the Eclipse project created. Have fun!<\/p>\n<div style=\"margin: 0px\"><strong><i>Related Articles :<\/i><\/strong><\/div>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/05\/gwt-2-spring-3-jpa-2-hibernate-35.html\">GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/06\/getting-started-smartgwt-gwt-interfaces.html\">Getting Started with SmartGWT for awesome GWT interfaces<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/building-your-own-gwt-spring-manen.html\">Building your own GWT Spring Maven Archetype<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/gwt-2-spring-3-jpa-2-hibernate-35.html\">GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial \u2013 Eclipse and Maven 2 showcase<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/07\/java-mail-spring-gmail-smtp.html\">Sending e-mails in Java with Spring \u2013 GMail SMTP server example<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will see how to integrate GWT with Spring&#8217;s security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how to retrieve the user&#8217;s credentials and how to log the various authentication events. Moreover, we are going to implement a custom authentication provider so that existing authentication schemes &hellip;<\/p>\n","protected":false},"author":3,"featured_media":242,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[27,30,125],"class_list":["post-335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-google-gwt","tag-spring","tag-spring-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Securing GWT apps with Spring Security - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this tutorial we will see how to integrate GWT with Spring&#039;s security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Securing GWT apps with Spring Security - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we will see how to integrate GWT with Spring&#039;s security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2010-12-16T11:09:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T19:23:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ilias Tsagklis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ilias Tsagklis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html\"},\"author\":{\"name\":\"Ilias Tsagklis\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/9a83496b285d30c61e8a674625c1350e\"},\"headline\":\"Securing GWT apps with Spring Security\",\"datePublished\":\"2010-12-16T11:09:00+00:00\",\"dateModified\":\"2012-10-21T19:23:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html\"},\"wordCount\":1615,\"commentCount\":19,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"keywords\":[\"Google GWT\",\"Spring\",\"Spring Security\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html\",\"name\":\"Securing GWT apps with Spring Security - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"datePublished\":\"2010-12-16T11:09:00+00:00\",\"dateModified\":\"2012-10-21T19:23:54+00:00\",\"description\":\"In this tutorial we will see how to integrate GWT with Spring's security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2010\\\/12\\\/securing-gwt-apps-with-spring-security.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Securing GWT apps with Spring Security\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/9a83496b285d30c61e8a674625c1350e\",\"name\":\"Ilias Tsagklis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g\",\"caption\":\"Ilias Tsagklis\"},\"description\":\"Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.\",\"sameAs\":[\"http:\\\/\\\/www.iliastsagklis.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/iliastsagklis\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/ilias-tsagklis\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Securing GWT apps with Spring Security - Java Code Geeks","description":"In this tutorial we will see how to integrate GWT with Spring's security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html","og_locale":"en_US","og_type":"article","og_title":"Securing GWT apps with Spring Security - Java Code Geeks","og_description":"In this tutorial we will see how to integrate GWT with Spring's security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how","og_url":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2010-12-16T11:09:00+00:00","article_modified_time":"2012-10-21T19:23:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","type":"image\/jpeg"}],"author":"Ilias Tsagklis","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ilias Tsagklis","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html"},"author":{"name":"Ilias Tsagklis","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/9a83496b285d30c61e8a674625c1350e"},"headline":"Securing GWT apps with Spring Security","datePublished":"2010-12-16T11:09:00+00:00","dateModified":"2012-10-21T19:23:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html"},"wordCount":1615,"commentCount":19,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","keywords":["Google GWT","Spring","Spring Security"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html","url":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html","name":"Securing GWT apps with Spring Security - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","datePublished":"2010-12-16T11:09:00+00:00","dateModified":"2012-10-21T19:23:54+00:00","description":"In this tutorial we will see how to integrate GWT with Spring's security module, i.e. Spring Security. We will see how to protect the GWT entrypoint, how","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2010\/12\/securing-gwt-apps-with-spring-security.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Securing GWT apps with Spring Security"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/9a83496b285d30c61e8a674625c1350e","name":"Ilias Tsagklis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/43505f28bb49f6e290c24be0b209ccc1af350f0f6587025ffd4847ef44bf6b78?s=96&d=mm&r=g","caption":"Ilias Tsagklis"},"description":"Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.","sameAs":["http:\/\/www.iliastsagklis.com\/","https:\/\/www.linkedin.com\/in\/iliastsagklis"],"url":"https:\/\/www.javacodegeeks.com\/author\/ilias-tsagklis"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=335"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/335\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/242"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}