View Javadoc

1   /*
2    * Copyright  2004-2005 Stefan Reuter
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 net.sf.asterisk.manager.action;
18  
19  /***
20   * The LoginAction authenticates the connection.<br>
21   * A successful login is the precondition for sending any other action except
22   * for the ChallengeAction.<br>
23   * An unsuccessful login results in an ManagerError being received from the
24   * server with a message set to "Authentication failed" and the socket being
25   * closed by Asterisk.
26   * 
27   * @see net.sf.asterisk.manager.action.ChallengeAction
28   * @see net.sf.asterisk.manager.response.ManagerError
29   * @author srt
30   * @version $Id: LoginAction.java,v 1.4 2005/08/07 00:09:42 srt Exp $
31   */
32  public class LoginAction extends AbstractManagerAction
33  {
34      /***
35       * Serializable version identifier
36       */
37      static final long serialVersionUID = -2600694249339115032L;
38  
39      private String username;
40      private String secret;
41      private String authType;
42      private String key;
43      private String events;
44  
45      /***
46       * Creates a new empty LoginAction.
47       */
48      public LoginAction()
49      {
50          
51      }
52      
53      /***
54       * Creates a new LoginAction that performs a cleartext login.<br>
55       * You should not use cleartext login if you are concerned about security,
56       * using {@see ChallengeAction} and login with a password hash instead.
57       * 
58       * @param username the username as configured in Asterisk's
59       *            <code>manager.conf</code>
60       * @param secret the user's password as configured in Asterisk's
61       *            <code>manager.conf</code>
62       * @since 0.2
63       */
64      public LoginAction(String username, String secret)
65      {
66          this.username = username;
67          this.secret = secret;
68      }
69  
70      /***
71       * Creates a new LoginAction that performs a login via challenge/response.
72       * 
73       * @param username the username as configured in Asterisk's
74       *            <code>manager.conf</code>
75       * @param authType the digest alogrithm, must match the digest algorithm
76       *            that was used with the corresponding ChallengeAction.
77       * @param key the hash of the user's password and the challenge
78       * @since 0.2
79       */
80      public LoginAction(String username, String authType, String key)
81      {
82          this.username = username;
83          this.authType = authType;
84          this.key = key;
85      }
86  
87      /***
88       * Creates a new LoginAction that performs a login via challenge/response.
89       * 
90       * @param username the username as configured in Asterisk's
91       *            <code>manager.conf</code>
92       * @param authType the digest alogrithm, must match the digest algorithm
93       *            that was used with the corresponding ChallengeAction.
94       * @param key the hash of the user's password and the challenge
95       * @param events the event mask. Set to "on" if all events should be send,
96       *            "off" if not events should be sent or a combination of
97       *            "system", "call" and "log" (separated by ',') to specify what
98       *            kind of events should be sent.
99       * @since 0.2
100      */
101     public LoginAction(String username, String authType, String key,
102             String events)
103     {
104         this.username = username;
105         this.authType = authType;
106         this.key = key;
107         this.events = events;
108     }
109 
110     /***
111      * Returns the name of this action, i.e. "Login".
112      */
113     public String getAction()
114     {
115         return "Login";
116     }
117 
118     /***
119      * Returns the username.
120      */
121     public String getUsername()
122     {
123         return username;
124     }
125 
126     /***
127      * Sets the username as configured in asterik's <code>manager.conf</code>.
128      */
129     public void setUsername(String username)
130     {
131         this.username = username;
132     }
133 
134     /***
135      * Returns the secret.
136      */
137     public String getSecret()
138     {
139         return secret;
140     }
141 
142     /***
143      * Sets the secret to use when using cleartext login.<br>
144      * The secret contains the user's password as configured in Asterisk's
145      * <code>manager.conf</code>.<br>
146      * The secret and key properties are mutually exclusive.
147      */
148     public void setSecret(String secret)
149     {
150         this.secret = secret;
151     }
152 
153     /***
154      * Returns the digest alogrithm when using challenge/response.
155      */
156     public String getAuthType()
157     {
158         return authType;
159     }
160 
161     /***
162      * Sets the digest alogrithm when using challenge/response.<br>
163      * The digest algorithm is used to create the key based on the challenge and
164      * the user's password.<br>
165      * Currently Asterisk supports only "MD5".
166      */
167     public void setAuthType(String authType)
168     {
169         this.authType = authType;
170     }
171 
172     /***
173      * @return Returns the key.
174      */
175     public String getKey()
176     {
177         return key;
178     }
179 
180     /***
181      * @param key The key to set.
182      */
183     public void setKey(String key)
184     {
185         this.key = key;
186     }
187 
188     /***
189      * Returns the event mask.
190      * 
191      * @return the event mask.
192      */
193     public String getEvents()
194     {
195         return events;
196     }
197 
198     /***
199      * Sets the event mask.
200      * 
201      * @param events the event mask. Set to "on" if all events should be send,
202      *            "off" if not events should be sent or a combination of
203      *            "system", "call" and "log" (separated by ',') to specify what
204      *            kind of events should be sent.
205      */
206     public void setEvents(String events)
207     {
208         this.events = events;
209     }
210 }