KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > security > Login


1 package org.apache.slide.projector.processor.security;
2
3 import java.util.Map JavaDoc;
4
5 import org.apache.commons.httpclient.Credentials;
6 import org.apache.slide.projector.Context;
7 import org.apache.slide.projector.Information;
8 import org.apache.slide.projector.Processor;
9 import org.apache.slide.projector.Projector;
10 import org.apache.slide.projector.Result;
11 import org.apache.slide.projector.descriptor.ParameterDescriptor;
12 import org.apache.slide.projector.descriptor.ResultDescriptor;
13 import org.apache.slide.projector.descriptor.StateDescriptor;
14 import org.apache.slide.projector.descriptor.StringValueDescriptor;
15 import org.apache.slide.projector.i18n.DefaultMessage;
16 import org.apache.slide.projector.i18n.ErrorMessage;
17 import org.apache.slide.projector.i18n.ParameterMessage;
18
19 /**
20  * @version $Revision: 1.3 $
21  */

22
23 public class Login implements Processor {
24     private final static String JavaDoc USERNAME = "username";
25     private final static String JavaDoc PASSWORD = "password";
26     
27     private final static String JavaDoc LOGIN_OK = "loginOk";
28     private final static String JavaDoc LOGIN_FAILED = "loginFailed";
29     public final static String JavaDoc ERRORS = "errors";
30
31     public Result process(Map JavaDoc parameter, Context context) throws Exception JavaDoc {
32         String JavaDoc username = parameter.get(USERNAME).toString();
33         String JavaDoc password = parameter.get(PASSWORD).toString();
34         Credentials credentials = Projector.getRepository().login(username, password);
35         if ( credentials == null ) {
36             context.addInformation(new Information(Information.ERROR, new ErrorMessage("login/invalidLogin"), new String JavaDoc[] { USERNAME, PASSWORD }));
37             return new Result(LOGIN_FAILED);
38         }
39         context.setCredentials(credentials);
40         return new Result(LOGIN_OK);
41     }
42
43     public ParameterDescriptor[] getParameterDescriptors() {
44         return new ParameterDescriptor[] {
45             new ParameterDescriptor(USERNAME, new ParameterMessage("login/user"), new StringValueDescriptor(1,20)),
46             new ParameterDescriptor(PASSWORD, new ParameterMessage("login/password"), new StringValueDescriptor(4,12)),
47         };
48     }
49
50     public ResultDescriptor getResultDescriptor() {
51         return new ResultDescriptor(new StateDescriptor[] {
52            new StateDescriptor(LOGIN_OK, new DefaultMessage("login/state/ok")),
53            new StateDescriptor(LOGIN_FAILED, new DefaultMessage("login/state/failed"))
54         });
55     }
56 }
Popular Tags