View Javadoc

1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.fatwire.gst.foundation.facade.runtag.user;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  import COM.FutureTense.Interfaces.Utilities;
21  import COM.FutureTense.Util.ftErrors;
22  
23  import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner;
24  import com.fatwire.gst.foundation.facade.runtag.TagRunnerRuntimeException;
25  
26  /**
27   * <user.login>
28   * 
29   * @author Tony Field
30   * @since Feb 1, 2011
31   */
32  public final class Login extends AbstractTagRunner {
33      public Login() {
34          super("user.login");
35      }
36  
37      public void setUsername(String s) {
38          if (!Utilities.goodString(s))
39              throw new IllegalArgumentException("Username cannot be null");
40          set("username", s);
41      }
42  
43      public void setPassword(String s) {
44          if (!Utilities.goodString(s))
45              throw new IllegalArgumentException("Password cannot be null");
46          set("password", s);
47      }
48  
49      public static boolean login(ICS ics, String username, String password) {
50          Login l = new Login();
51          l.setUsername(username);
52          l.setPassword(password);
53          try {
54              l.execute(ics);
55          } catch (TagRunnerRuntimeException e) {
56              if (e.getErrno() == ftErrors.badpassword || e.getErrno() == ftErrors.unknownuser) {
57                  return false;
58              } else
59                  throw e;
60          }
61          return true;
62      }
63  
64  }