View Javadoc

1   /*
2    *  Copyright 2004-2006 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 org.asteriskjava.manager.action;
18  
19  /***
20   * The LoginAction authenticates the connection.<p>
21   * A successful login is the precondition for sending any other action except
22   * for the ChallengeAction.<p>
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 org.asteriskjava.manager.action.ChallengeAction
28   * @see org.asteriskjava.manager.response.ManagerError
29   * @author srt
30   * @version $Id: LoginAction.java 729 2007-05-26 05:16:57Z sprior $
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.<p>
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     @Override
114    public String getAction()
115     {
116         return "Login";
117     }
118 
119     /***
120      * Returns the username.
121      */
122     public String getUsername()
123     {
124         return username;
125     }
126 
127     /***
128      * Sets the username as configured in asterik's <code>manager.conf</code>.
129      */
130     public void setUsername(String username)
131     {
132         this.username = username;
133     }
134 
135     /***
136      * Returns the secret.
137      */
138     public String getSecret()
139     {
140         return secret;
141     }
142 
143     /***
144      * Sets the secret to use when using cleartext login.<p>
145      * The secret contains the user's password as configured in Asterisk's
146      * <code>manager.conf</code>.<p>
147      * The secret and key properties are mutually exclusive.
148      */
149     public void setSecret(String secret)
150     {
151         this.secret = secret;
152     }
153 
154     /***
155      * Returns the digest alogrithm when using challenge/response.
156      */
157     public String getAuthType()
158     {
159         return authType;
160     }
161 
162     /***
163      * Sets the digest alogrithm when using challenge/response.<p>
164      * The digest algorithm is used to create the key based on the challenge and
165      * the user's password.<p>
166      * Currently Asterisk supports only "MD5".
167      */
168     public void setAuthType(String authType)
169     {
170         this.authType = authType;
171     }
172 
173     /***
174      * @return Returns the key.
175      */
176     public String getKey()
177     {
178         return key;
179     }
180 
181     /***
182      * @param key The key to set.
183      */
184     public void setKey(String key)
185     {
186         this.key = key;
187     }
188 
189     /***
190      * Returns the event mask.
191      * 
192      * @return the event mask.
193      */
194     public String getEvents()
195     {
196         return events;
197     }
198 
199     /***
200      * Sets the event mask.
201      * 
202      * @param events the event mask. Set to "on" if all events should be send,
203      *            "off" if not events should be sent or a combination of
204      *            "system", "call" and "log" (separated by ',') to specify what
205      *            kind of events should be sent.
206      */
207     public void setEvents(String events)
208     {
209         this.events = events;
210     }
211 }