Tech Kraft

Documentum, AWS, Java, Ruby on Rails, Linux, Windows, App Servers


Setting up Spring Security in Eclipse – I

Setting up Spring

Create a new Dynamic Web Project in Eclipse (needs Web tools download from Eclipse) with the following parameters:

Project name: <your-project-name>

Rest default settings

Download and unzip the latest Spring jar files from http://www.springsource.org/download/community?project=Spring%2520Framework

Copy the following files from the above unzipped folder into the Web/WEB-INF/lib folder:

org.springframework.asm-3.x.x.RELEASE-x.jar

org.springframework.beans-3. x.x.RELEASE-x.jar

org.springframework.context-3. x.x.RELEASE-x.jar

org.springframework.core-3. x.x.RELEASE-x.jar

org.springframework.expression-3. x.x.RELEASE-x.jar

org.springframework.web.servlet-3. x.x.RELEASE-x.jar

org.springframework.web-3. x.x.RELEASE-x.jar

Download and unzip the latest jar file from http://commons.apache.org/logging/download_logging.cgi

Copy the following files from the above unzipped folder into the Web/WEB-INF/lib/ folder:

commons-logging-1.x.x.jar

Download and unzip the latest jstl jar file from http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/

Copy the following files from the above unzipped folder into the Web/WEB-INF/lib/ folder:

jakarta-taglibs-standard-1.x.x.zip

Create the following files using the code supplied:

———————————————————————

WEB-INF/web.xml

 <?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

version="2.5">

 <display-name>Spring ACL Demo</display-name>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

 <!-- For issues with multiple apps on tomcat -->

<context-param>

<param-name>webAppRootKey</param-name>

<param-value>springacldemo_root</param-value>

</context-param>

 <!-- MVC application controller. See springacldemo-servlet.xml. -->

<servlet>

<servlet-name>springacldemo</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

 <servlet-mapping>

<servlet-name>springacldemo</servlet-name>

<url-pattern>*.htm</url-pattern>

</servlet-mapping>

 </web-app>

 

———————————————————————

Create our welcome file – index.jsp as defined in web.xml under <welcome-file-list> tag:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Spring ACL Demo Index page</title>

</head>

<body>

<a href="hello.htm">Say Hello</a>

</body>

</html>

———————————————————————

Create our hello file – hello.jsp linked from index.jsp as hello.htm:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Spring ACL Demo Hello page</title>

</head>

<body>${message}

</body>

</html>

———————————————————————

Create WEB-INF/springacldemo-servlet.xml. Spring knows to look for this file because of “springacldemo” in servlet-name. The servlet class is defined in <servlet-name>-servlet.xml

 <?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

 <!--

This configuration will take any url request that matches *.htm pattern and

map it to file with the same name but with a .jsp extension using the

UrlFilenameViewController and InternalResourceViewResolver provided by spring.      -->

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

<property name="mappings">

<value>

/*.htm=urlController

</value>

</property>

</bean>

<bean id="urlController"

class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
<!--

Because of the viewResolver, we do not have to specify our internal structure.

-->

<bean id="viewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass"

value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="WEB-INF/jsp/" />

<property name="suffix" value=".jsp" />

</bean>

</beans>

———————————————————————

Create build.xml

 <project name="Spring ACL Demo" default="war" basedir=".">

 <property name="app.name" value="springacldemo" />

<property name="app.path" value="/${app.name}" />

<property name="web.home" value="WebContent" />

<property name="webDir" value="${web.home}/WEB-INF" />

<property name="build.home" value="${basedir}/build" />

<property name="war.dir" value="${basedir}/warfile" />

<property name="catalina.home" value="/Users/amitabh/programs/apache-tomcat-6.0.29" />

<property name="manager.url" value="http://localhost:8080/manager" />

<property name="src.home" value="${basedir}/src" />

<property name="manager.username" value="admin" />

<property name="manager.password" value="admin" />

 <property name="dist.home" value="${basedir}/dist" />

 <path id="classpath">

<pathelement path="." />

<fileset dir="${webDir}/lib">

<include name="*.jar" />

</fileset>

 <pathelement location="${catalina.home}/common/classes" />

<fileset dir="${catalina.home}/common/endorsed">

<include name="*.jar" />

</fileset>

<fileset dir="${catalina.home}/common/lib">

<include name="*.jar" />

</fileset>

 <pathelement location="${catalina.home}/shared/classes" />

<fileset dir="${catalina.home}/shared/lib">

<include name="*.jar" />

</fileset>

 <fileset dir="${catalina.home}/lib">

<include name="catalina-ant.jar" />

</fileset>

</path>

 <target name="clean">

<delete dir="${build.home}" />

</target>

 <target name="init" depends="clean">

<mkdir dir="${build.home}" />

<mkdir dir="${build.home}/WEB-INF" />

<mkdir dir="${build.home}/WEB-INF/classes" />

<copy todir="${build.home}">

<fileset dir="${web.home}" />

</copy>

<mkdir dir="${build.home}/WEB-INF/lib" />

</target>

 <target name="compile" depends="init" description="Compile Java sources">

<mkdir dir="${build.home}/WEB-INF/classes" />

<javac srcdir="${src.home}" destdir="${build.home}/WEB-INF/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">

<classpath refid="compile.classpath" />

</javac>

<copy todir="${build.home}/WEB-INF/classes">

<fileset dir="${src.home}" excludes="**/*.java" />

</copy>

</target>

 <target name="all" depends="clean,compile" description="Clean build and dist directories, then compile" />

 <target name="war" depends="compile" description="Create binary distribution">

<jar jarfile="${war.dir}/${app.name}.war" basedir="${build.home}" />

</target>

 <target name="undeploy" description="Undeploy war from tomcat">

<delete file="${catalina.home}/webapps/${app.name}.war" />

</target>

 <target name="deploy" depends="war, undeploy" description="Deploy application to servlet container">

<copy file="${war.dir}/${app.name}.war" todir="${catalina.home}/webapps" />

</target>

 </project>

———————————————————————

Use terminal to go the root of the project, and type:

ant deploy

 This will deploy the web application to the tomcat server and available at http://localhost:8080/springacldemo

The error logs will be available at

$CATALINA_HOME/logs/Catalina.out and 

$CATALINA_HOME/logs/localhost.yyyy-mm-dd.log


Leave a comment

About Me

Senior Software Engineer professional with over 16 years of success with multiple open source technologies and various Content Management platforms and solutions.

Proven technical abilities through numerous projects involving enterprise web application design and development, application installation, configuration and support, and workflow and collaboration system designs.

  • Ability to learn new technologies and platforms quickly and apply them to the task at hand.
  • Excellent analytical skills, and strong communication and collaboration abilities.
  • Technical emphasis in including but not limited to Java, Ruby on Rails, Documentum and Alfresco
    in both Linux and Windows based environments

Newsletter