You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Asim Khaja <th...@gmail.com> on 2007/05/04 02:42:17 UTC

tapestry-acegi

Is there a good tutorial on using the tapestry-acegi (
http://www.carmanconsulting.com/tapestry-acegi/) library?

Thanks,
Asim

Re: tapestry-acegi

Posted by Asim Khaja <th...@gmail.com>.
I will try it out, thanks a lot.
Asim

On 5/3/07, William Keller <wi...@gmail.com> wrote:
>
> I forgot to mention that you will need to map your User and
> GrantedAuthority
> as per usual on Acegi. The stuff I gave you doesn't go in depth on setting
> up your models (your User needs to implement UserDetails). Once you set up
> yoru GrantedAuthority for your users your tapestry pages can now use the
> annotations like mine: @Secured(value = { "ROLE_AGENT", "ROLE_ADMIN" })
>
> Hope it works!
>

Re: tapestry-acegi

Posted by William Keller <wi...@gmail.com>.
I forgot to mention that you will need to map your User and GrantedAuthority
as per usual on Acegi. The stuff I gave you doesn't go in depth on setting
up your models (your User needs to implement UserDetails). Once you set up
yoru GrantedAuthority for your users your tapestry pages can now use the
annotations like mine: @Secured(value = { "ROLE_AGENT", "ROLE_ADMIN" })

Hope it works!

Re: tapestry-acegi

Posted by William Keller <wi...@gmail.com>.
I've got this working. Code supplied. Please customise for your purpose :)

hivemodule.xml

<module id="com.ews.tapestry.acegi" version="1.0.0">
    <contribution configuration-id="hivemind.ApplicationDefaults">
        <default symbol="hivemind.acegi.dao.passwordEncoder"
            value="
org.acegisecurity.providers.encoding.PlaintextPasswordEncoder" />
        <default symbol="hivemind.acegi.dao.systemWideSalt" value="" />
          <default symbol="tapestry.acegi.authenticationProcessingFilter"
value="com.ews.tapestry.acegi.FormProcessingFilter"/>
        <default symbol="tapestry.acegi.authenticationEntryPoint" value="
com.ews.tapestry.acegi.FormAuthenticationEntryPoint"/>
    </contribution>

    <implementation
        service-id="hivemind.acegi.dao.UserDetailsService">
        <invoke-factory service-id="hivemind.lib.SpringLookupFactory">
            <lookup-bean name="authoriserService" />
        </invoke-factory>
    </implementation>

    <contribution
        configuration-id="hivemind.acegi.AccessDecisionVoters">
        <voter object="instance:org.acegisecurity.vote.RoleVoter" />
    </contribution>

    <service-point id="FormProcessingFilter"
        interface="javax.servlet.Filter">
        <invoke-factory>
            <construct
                class="
org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"
                initialize-method="afterPropertiesSet">
                <set property="authenticationFailureUrl"
                    value="/app?page=Home;service=page" />
                <set property="defaultTargetUrl"
value="/app?page=Landing;service=page" />
                <set property="filterProcessesUrl"
                    value="/j_acegi_security_check" />
            </construct>
        </invoke-factory>
    </service-point>

    <service-point id="FormAuthenticationEntryPoint"
        interface="org.acegisecurity.ui.AuthenticationEntryPoint">
        <invoke-factory>
            <construct
                class="
org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
                <set property="loginFormUrl"
                    value="/app?page=Home;service=page" />
                <set property="forceHttps" value="false" />
            </construct>
        </invoke-factory>
    </service-point>

    <contribution configuration-id="tapestry.state.ApplicationObjects">
      <state-object name="EWSSession" scope="session">
        <create-instance class="com.ews.web.session.EWSSession"/>
      </state-object>
    </contribution>
</module>

AuthoriserServiceImpl code:

import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ews.domain.core.User;
import com.ews.domain.core.UserService;

/**
 * Implementation of the authoriser service
 *
 * @author williamk
 *
 */
public class AuthoriserServiceImpl implements AuthoriserService
{

    /**
     * Injected user service
     */
    private UserService userService;

    /**
     * Constructor
     *
     * @param userService
     */
    public AuthoriserServiceImpl(UserService userService)
    {
        this.userService = userService;
    }

    /**
     * {@inheritDoc}
     */
    @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
    public UserDetails loadUserByUsername(String arg0)
            throws UsernameNotFoundException, DataAccessException
    {
        User user = userService.fetchByUsername(arg0);
        if (user == null)
        {
            throw new UsernameNotFoundException("Authentication failed");
        }
        return user;
    }

}


Hopefully that will get you started!

On 5/4/07, Asim Khaja <th...@gmail.com> wrote:
>
> Is there a good tutorial on using the tapestry-acegi (
> http://www.carmanconsulting.com/tapestry-acegi/) library?
>
> Thanks,
> Asim
>