KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > Cred


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19
20 package sync4j.framework.core;
21
22 /**
23  *
24  * Corresponds to <Cred> element in SyncML represent DTD
25  *
26  * @author Stefano Fornari @ Funambol
27  *
28  * @version $Id: Cred.java,v 1.8 2005/03/02 20:57:37 harrie Exp $
29  */

30 public final class Cred
31 implements java.io.Serializable JavaDoc {
32
33     // --------------------------------------------------------------- Constants
34
public static final String JavaDoc AUTH_TYPE_MD5 = "syncml:auth-md5" ;
35    public static final String JavaDoc AUTH_TYPE_BASIC = "syncml:auth-basic";
36    public static final String JavaDoc AUTH_TYPE_HMAC = "syncml:auth-MAC" ;
37    public static final String JavaDoc AUTH_NONE = "none" ;
38    public static final String JavaDoc AUTH_SUPPORTED_TYPES = AUTH_TYPE_BASIC
39                                                    + ','
40                                                    + AUTH_TYPE_MD5
41                                                    + ','
42                                                    + AUTH_TYPE_HMAC;
43
44     // ------------------------------------------------------------ Private data
45
private Authentication authentication;
46
47     // ------------------------------------------------------------ Constructors
48
/** For serialization purposes */
49     protected Cred() {}
50
51     /**
52      * Creates a new Cred object with the given Authentication
53      *
54      * @param authentication the authentication object - NOT NULL
55      * This parameter will usually be an instance of
56      * BasicAuthentication or ClearAuthentication
57      *
58      */

59     public Cred(final Authentication authentication) {
60         if (authentication == null) {
61             throw new IllegalArgumentException JavaDoc("authentication cannot be null");
62         }
63         this.authentication = authentication;
64     }
65
66     // ---------------------------------------------------------- Public methods
67

68     /**
69      * Gets type property
70      *
71      * @return type property
72      */

73     public String JavaDoc getType() {
74         return authentication.getType();
75     }
76
77     /**
78      * Gets format property
79      *
80      * @return format property
81      */

82     public String JavaDoc getFormat() {
83         return authentication.getFormat();
84     }
85
86     /**
87      * Gets data property
88      *
89      * @return data property
90      */

91     public String JavaDoc getData() {
92         return authentication.getData();
93     }
94
95     /**
96      * Gets the username stored in this credential
97      *
98      * @return the username stored in this credential
99      */

100     public String JavaDoc getUsername() {
101         return authentication.getUsername();
102     }
103
104
105     /**
106      * Create and return the Authentication object corresponding to the given
107      * type and data.
108      *
109      * @param type the type of the required Authentication object
110      * @param data the data to be interpreted based on the type
111      *
112      * @return the corresponding Authentication object.
113      */

114     public static Authentication createAuthentication(String JavaDoc data,
115                                                       String JavaDoc type) {
116         return new Authentication(type,data);
117     }
118
119     /**
120      * Gets the Authentication object.
121      *
122      * @return authentication the authentication objects
123      */

124     public Authentication getAuthentication() {
125         return authentication;
126     }
127
128     /**
129      * Sets the Authentication object.
130      *
131      * @param auth the new Authentication object
132      *
133      */

134     public void setAuthentication(Authentication auth) {
135         this.authentication = auth;
136     }
137     public String JavaDoc toString() {
138         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
139         res.append(getUsername()).append(" with ").append(getType());
140         res.append(" from ").append(getData());
141         return res.toString();
142     }
143 }
144
Popular Tags