Results 1 to 2 of 2

Thread: Struggling w/ Acegi authentication....

  1. #1
    Join Date
    Aug 2006
    Posts
    6

    Exclamation Struggling w/ Acegi authentication....

    Hey guys!!!

    I'm completely new to using Spring, Hibernate and Acegi security. I've gotten a hang of Spring and Hibernate, so that's not a problem. I'm really really struggling with Acegi security. I'm trying to write validation code for my web application using Acegi security. Here's what I want to do:

    1) Validate the username/password against my DB2 database using spring and Hibernate (e.g. Cbo & Dao objects).

    2) Verify the user has security roles to access certain pages.

    My problem is figuring out how to configure the applicationContext.xml file and how to implement AuthenticationDao, PasswordAuthenticationDao or JdbcDaoImpl to read in the username/password.

    I can't find examples for show how to implement this approach using Acegi and most of the ones I see use InMemoryDaoImpl, which I don't want.
    Please please....I'll appreciate all the guidance you can give me to figure this out.

    Here's the code I have so far:
    ################################################## ################################################## ##########
    LOGIN.jsp

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <HTML>
    <HEAD>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <META name="GENERATOR" content="IBM Software Development Platform">
    <META http-equiv="Content-Style-Type" content="text/css">
    <LINK href="theme/Master.css" rel="stylesheet" type="text/css">
    <TITLE>login.jsp</TITLE>
    </HEAD>
    <BODY>
    <p>JSESSIONID: <%= session.getId() %>

    <h2>Login.jsp</h2>

    <form method="post" action="j_acegi_security_check">
    <p>Username <input type="text" name="j_username" >

    <p>Password <input type="password" name="j_password" >

    <p><input type="submit" >

    </form>
    <jsp:include page="_footer.jsp" flush="true" />
    </BODY>
    </HTML>

    ################################################## ################################################## #########
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>
    webApp</display-name>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/applicationContext.xml
    </param-value>
    </context-param>

    <!-- Obtains Authentication from HttpSession attribute, puts it into
    ContextHolder for request duration, proceeds with request, then
    copies Authentication from ContextHolder back into HttpSession -->
    <filter>
    <filter-name>Acegi Security System for Spring HttpSession Integration Filter</filter-name>
    <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
    <param-name>targetClass</param-name>
    <param-value>net.sf.acegisecurity.context.HttpSessionCont extIntegrationFilter</param-value>
    </init-param>
    </filter>

    <filter>
    <filter-name>Acegi Authentication Processing Filter</filter-name>
    <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
    <param-name>targetClass</param-name>
    <param-value>net.sf.acegisecurity.ui.webapp.Authenticatio nProcessingFilter</param-value>
    </init-param>
    </filter>

    <filter>
    <filter-name>Acegi HTTP Request Security Filter</filter-name>
    <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
    <param-name>targetClass</param-name>
    <param-value>net.sf.acegisecurity.intercept.web.SecurityE nforcementFilter</param-value>
    </init-param>
    </filter>


    <filter-mapping>
    <filter-name>Acegi Security System for Spring HttpSession Integration Filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
    <filter-name>Acegi Authentication Processing Filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
    <filter-name>Acegi HTTP Request Security Filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <session-config>
    <session-timeout>600</session-timeout>
    </session-config>

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

    </web-app>

    ################################################## ################################################## ##################
    applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd" >

    <beans>
    <bean id="memoryAuthenticationDao" class="net.sf.acegisecurity.providers.dao.memory.I nMemoryDaoImpl">
    <property name="userMap">
    <value>
    user=pass,ROLE_USER,ROLE_SUPERVISOR
    user1=pass,ROLE_USER
    user2=pass,ROLE_USER
    </value>
    </property>
    </bean>

    <bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthe nticationProvider">
    <property name="authenticationDao">
    <ref local="memoryAuthenticationDao"/>
    </property>
    </bean>

    <bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderMana ger">
    <property name="providers">
    <list>
    <ref bean="daoAuthenticationProvider"/>
    </list>
    </property>
    </bean>

    <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.Authenticati onProcessingFilter">
    <property name="authenticationManager">
    <ref bean="authenticationManager"/>
    </property>
    <property name="authenticationFailureUrl">
    <value>/login.jsp?error=1</value>
    </property>
    <property name="defaultTargetUrl">
    <value>/</value>
    </property>
    <property name="filterProcessesUrl">
    <value>/j_acegi_security_check</value>
    </property>
    </bean>

    <bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter"/>

    <bean id="accessDecisionManager" class="net.sf.acegisecurity.vote.UnanimousBased">
    <property name="allowIfAllAbstainDecisions">
    <value>false</value>
    </property>
    <property name="decisionVoters">
    <list>
    <ref local="roleVoter"/>
    </list>
    </property>
    </bean>

    <bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.Security EnforcementFilter">
    <property name="filterSecurityInterceptor">
    <ref bean="filterInvocationInterceptor"/>
    </property>
    <property name="authenticationEntryPoint">
    <ref bean="authenticationEntryPoint"/>
    </property>
    </bean>

    <!--
    <bean id="httpSessionIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionCon textIntegrationFilter"/>
    -->
    <bean id="httpSessionIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionCon textIntegrationFilter">
    <property name="context">
    <value>net.sf.acegisecurity.context.security.Secur eContextImpl</value>
    </property>
    </bean>

    <bean id="authenticationEntryPoint" class="net.sf.acegisecurity.ui.webapp.Authenticati onProcessingFilterEntryPoint">
    <property name="loginFormUrl">
    <value>/login.jsp</value>
    </property>
    </bean>

    <bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSe curityInterceptor">
    <property name="authenticationManager">
    <ref bean="authenticationManager"/></property>
    <property name="accessDecisionManager">
    <ref bean="accessDecisionManager"/></property>
    <property name="objectDefinitionSource">
    <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /secure/super/**=ROLE_SUPERVISOR
    /secure/**=ROLE_USER,ROLE_SUPERVISOR
    </value>
    </property>
    </bean>

    </beans>
    ################################################## ################################################## #####

    Thanks in advance...:o

  2. #2
    Join Date
    Aug 2004
    Location
    Berne, Switzerland
    Posts
    42

    Default

    Hi

    Here is a link to a sample chapter form the interesting book "Professional java Development with the Spring Framework" by Rod Johnson et. al. This chapter is dedicated to security and Acegi in particular:

    http://searchappsecurity.techtarget....ework_ch10.pdf

    When I started working with Aceig, the contact sample application provided with the Acegi distribution helped me as well to figure out how the different features need to be configured.


    I hope this helps to get a better understanding of the way Acegi works and how it needs to be configured.
    Guido Schmutz
    Principal Consultant, Trivadis Switzerland
    Email: guido.schmutz AT trivadis.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •