View Javadoc

1   /*
2    * Apache License
3    * Version 2.0, January 2004
4    * http://www.apache.org/licenses/
5    *
6    * Copyright 2008 by chenillekit.org
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   */
14  
15  package org.chenillekit.access.components;
16  
17  import org.apache.tapestry5.ValidationTracker;
18  import org.apache.tapestry5.annotations.ApplicationState;
19  import org.apache.tapestry5.annotations.Component;
20  import org.apache.tapestry5.annotations.Property;
21  import org.apache.tapestry5.corelib.components.Form;
22  import org.apache.tapestry5.ioc.Messages;
23  import org.apache.tapestry5.ioc.annotations.Inject;
24  import org.apache.tapestry5.ioc.annotations.Local;
25  import org.chenillekit.access.ChenilleKitAccessConstants;
26  import org.chenillekit.access.WebSessionUser;
27  import org.chenillekit.access.services.AuthenticationService;
28  
29  /**
30   * Login component
31   *
32   * @version $Id$
33   */
34  public class Login
35  {
36  	@ApplicationState
37  	private WebSessionUser webSessionUser;
38  	
39  	@Inject
40  	private Messages messages;
41  	
42  	@Inject @Local
43  	private AuthenticationService authenticationService;
44  	
45  	@Component
46  	private Form chenillekitLoginForm;
47  	
48  	@Property
49  	private String username;
50  
51  	@Property
52  	private String password;
53  	
54  	private WebSessionUser tmpUser;
55  	
56  	void onValidateForm()
57  	{
58  		ValidationTracker tracker = chenillekitLoginForm.getDefaultTracker();
59  		
60  		tmpUser = authenticationService.doAuthenticate(username, password);
61  		
62  		if (tmpUser == null)
63  			tracker.recordError(messages.format(ChenilleKitAccessConstants.NOT_AUTHENTICATED_ERROR_MESSAGE, username));
64  		
65  	}
66  	
67  	void onFailure()
68  	{
69  		// TODO What to do in here?
70  	}
71  	
72  	void onSuccess()
73  	{
74  		webSessionUser = tmpUser;
75  	}
76  
77  }