Hi

I integrated T5.0.4 with Acegi and I wanted to share my code with this
forum. 
The solution may not be the best approach but it could save you sometime for
now. 
I am only providing the security related code. 

Login.html 
<t:layoutcmpnt
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>

        <t:loginForm>           
                <div class="error_message">                                   
                        ${errorMessage}
                </div>   
                <t:if test="feedbackMessage">      
                        <div class="feedback_message">                          
              
                ${feedbackMessage}
                </div>
                </t:if> 

                <t:label for="usernameField"/>:
                <input t:type="TextField" t:id="usernameField" size="15"/>
                <br/>
                <t:label for="passwordField"/>:
                <input t:type="PasswordField" t:id="passwordField" size="15"/>
                <br />  
                <div align="center">  
                        <p>
                                <t:Submit t:value="message:login-label" />
                        </p>  
                </div>          
        </t:loginForm>

Login.java
        private String username;
        private String password;
        private String emailAddress;

    @Component
    private Form loginForm;

        @Persist
        public String errorMessage;
        
        @Persist
        public String feedbackMessage;

        @Inject
        @Service("RequestGlobals")
        private RequestGlobals requestGlobals;  
        
        @Inject
        private Messages messages;
        
    @PageAttached
    void pageAttached(MarkupWriter writer)
    {
                @SuppressWarnings("unused")
                String errorParamAsString =
requestGlobals.getRequest().getParameter("error");
                
                boolean error = Boolean.parseBoolean(errorParamAsString);
        if(error)
        {
                errorMessage = messages.format("login-error-message", new 
Object[]{});
                feedbackMessage = "";
        }
        else
        {
//              errorMessage = "";
        }
    }   
        
    Object onSuccessFromLoginForm()
    {
        Link acegiLoginLink = new LinkImpl(new NoOpURLEncoder() , "jumpstart",
"j_security_check");
        acegiLoginLink.addParameter("j_username", username);
        acegiLoginLink.addParameter("j_password", password);
        
        
        return acegiLoginLink;
    }

... getters and setters

LayoutCmpnt.java
        public User getTapestryPrincipal() {
                User tapestryPrincipal = null;
                Authentication authentication =
SecurityContextHolder.getContext().getAuthentication();
                
                if(authentication != null)
                {
                        Object acegiPrincipal = authentication.getPrincipal();
                        if(acegiPrincipal != null)
                        {
                                
                                if(acegiPrincipal instanceof String)
                                {
                                        tapestryPrincipal = null;
                                }
                                else
                                {
                                        
                                        tapestryPrincipal = (User) 
acegiPrincipal;
                                }
                        }
                }
                return tapestryPrincipal;
        }       

LayoutCmpnt.html
<strong>${tapestryPrincipal.username}</strong>

Update Acegi Security Context
I also have this code where the user's details are updated in order to keep
the Acegi Principal up to date. 

UsernamePasswordAuthenticationToken token = new    
   UsernamePasswordAuthenticationToken(updatedUser,updatedUsername,
updatedAuthorities);
   SecurityContextHolder.getContext().setAuthentication(token);

Petros
-- 
View this message in context: 
http://www.nabble.com/Tapestry-5-and-Acegi-tf3769520.html#a10657302
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to