Spring + Sitemesh

web.xml
 
<!--Sitemesh-->
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter
</filter-class>
</filter>
 
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
decorators.xml
 
<?xml version="1.0" encoding="UTF-8"?>
 
<decorators defaultdir="/WEB-INF/jsp/layouts">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
 
</decorators>
main.jsp
 
 
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
 
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
 
<title><decorator:title default="MySite" /></title>
 
</head>
<body>
<h1>Template</h1>
 
<decorator:body />
 
</body>
</html>
Comments (0)

Spring Locale Change

 dispatcher-servlet.xml
 
    <!--Message/Locale-->
 
    <mvc:interceptors>  
        <bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="lang" />
        </bean>
    </mvc:interceptors>
    <bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="es"/>
    </bean>
    <bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="/WEB-INF/messages" />
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>
 messages_en_US.properties
 
button.cancel=Cancel
button.create=Create
button.edit=Edit
button.delete=Delete
button.reset=Reset
button.save=Save
button.search=Search
 messages_es.properties
 
button.cancel=Cancelar
button.create=Crear
button.edit=Corregir
button.delete=Borrar
button.reset=Restaurar
button.save=Guardar
button.search=Buscar

To change locale: any url?lang=en

Comments (0)

Spring Security Configuration

web.xml
<!–Spring security–>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

applicationContext.xml

<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:sec=”http://www.springframework.org/schema/security”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd”>

<!–Spring Security–>

<sec:global-method-security secured-annotations=”enabled” />

<sec:http auto-config=”true” access-denied-page=”/accessDenied.jsp” >

<sec:intercept-url pattern=”/login.jsp*” filters=”none”/>
<sec:intercept-url pattern=”/admin/editUser.do” access=”ROLE_ADMIN”  />
<sec:intercept-url pattern=”/admin/searchUsers.do” access=”ROLE_ADMIN”  />
<sec:intercept-url pattern=”/**” access=”ROLE_USER”  />
<sec:form-login authentication-failure-url=”/login.jsp?login_error=1″ default-target-url=”/home.do”/>
<sec:logout logout-success-url=”/home.do”/>

</sec:http>

<sec:authentication-manager>
<sec:authentication-provider>
<sec:password-encoder hash=”md5″/>
<sec:user-service>
<sec:user name=”rod” password=”a564de63c2d0da68cf47586ee05984d7″ authorities=”ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER” />
<sec:user name=”dianne” password=”65d15fe9156f9c4bbffd98085992a44e” authorities=”ROLE_USER,ROLE_TELLER” />
<sec:user name=”scott” password=”2b58af6dddbd072ed27ffc86725d7d3a” authorities=”ROLE_USER” />
<sec:user name=”peter” password=”22b5c9accc6e1ba628cedc63a72d57f8″ authorities=”ROLE_USER” />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>

<!–
Usernames/Passwords are
rod/koala
dianne/emu
scott/wombat
peter/opal
–>

login.jsp

<%@ taglib prefix=’c’ uri=’http://java.sun.com/jstl/core_rt’ %>
<%@ page import=”org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter” %>
<%@ page import=”org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter” %>
<%@ page import=”org.springframework.security.core.AuthenticationException” %>

<html>
<head>
<title>Spring Security Login — </title>
</head>

<body>
<h1>Login</h1>

<c:if test=”${not empty param.login_error}”>
<font color=”red”>
Your login attempt was not successful, try again.<br/><br/>
Reason: <c:out value=”${SPRING_SECURITY_LAST_EXCEPTION.message}”/>.
</font>
</c:if>

<form name=”f” action=”<c:url value=’j_spring_security_check’/>” method=”POST”>
<table>
<tr><td>User:</td><td><input type=’text’ name=’j_username’ value=’<c:if test=”${not empty param.login_error}”><c:out value=”${SPRING_SECURITY_LAST_USERNAME}”/></c:if>’/></td></tr>
<tr><td>Password:</td><td><input type=’password’ name=’j_password’></td></tr>
<tr><td><input type=”checkbox” name=”_spring_security_remember_me”></td><td>Don’t ask for my password for two weeks</td></tr>

<tr><td colspan=’2′><input name=”submit” type=”submit”></td></tr>

</table>
</form>
</body>

<a href=”<c:url value=”/j_spring_security_logout”/>”>Logout</a>

</html>

Comments (0)

Send SMS when Email received using Fetchmail/gnokii

fetchmail -v | grep ‘message for alert’| sed ‘s/message for
alert.*//’| nawk ‘{ if($0 > 0) print system(“gnokii
–sendsms 01712345678 < alert.txt “) }’

Comments (0)

Using Cisco vpnclient in Linux

Download vpnclient-linux-4.8.00.0490-k9.tar.gz
ftp://ftp.cs.cornell.edu/pub/rvr/upload/vpnclient-linux-4.8.00.0490-k9.tar.gz

http://www.longren.org/files/vpnclient-linux-4.8.00.0490-k9.tar.gz

Untar
$ tar xzf vpnclient-linux-4.8.00.0490-k9.tar.gz

Download the patch

http://tuxx-home.at/projects/cisco-vpnclient/vpnclient-linux-2.6.22.diff

http://www.longren.org/files/vpnclient-linux-2.6.22.diff

Apply patch
$ patch < vpnclient-linux-2.6.22.diff Install
$ sudo ./vpn_install

Start
$ sudo /etc/init.d/vpnclient_init start

Place .pcf configuration files in /etc/opt/cisco-vpnclient/Profiles/

Connect
$ sudo vpnclient connect configFile

Comments (0)
Go to Top