1 20 21 package org.jivesoftware.smack.packet; 22 23 import org.jivesoftware.smack.util.StringUtils; 24 25 29 public class Authentication extends IQ { 30 31 private String username = null; 32 private String password = null; 33 private String digest = null; 34 private String resource = null; 35 36 44 public Authentication() { 45 setType(IQ.Type.SET); 46 } 47 48 53 public String getUsername() { 54 return username; 55 } 56 57 62 public void setUsername(String username) { 63 this.username = username; 64 } 65 66 72 public String getPassword() { 73 return password; 74 } 75 76 81 public void setPassword(String password) { 82 this.password = password; 83 } 84 85 95 public String getDigest() { 96 return digest; 97 } 98 99 111 public void setDigest(String connectionID, String password) { 112 this.digest = StringUtils.hash(connectionID + password); 113 } 114 115 126 public void setDigest(String digest) { 127 this.digest = digest; 128 } 129 130 135 public String getResource() { 136 return resource; 137 } 138 139 144 public void setResource(String resource) { 145 this.resource = resource; 146 } 147 148 public String getChildElementXML() { 149 StringBuffer buf = new StringBuffer (); 150 buf.append("<query xmlns=\"jabber:iq:auth\">"); 151 if (username != null) { 152 if (username.equals("")) { 153 buf.append("<username/>"); 154 } 155 else { 156 buf.append("<username>").append( username).append("</username>"); 157 } 158 } 159 if (digest != null) { 160 if (digest.equals("")) { 161 buf.append("<digest/>"); 162 } 163 else { 164 buf.append("<digest>").append(digest).append("</digest>"); 165 } 166 } 167 if (password != null && digest == null) { 168 if (password.equals("")) { 169 buf.append("<password/>"); 170 } 171 else { 172 buf.append("<password>").append(password).append("</password>"); 173 } 174 } 175 if (resource != null) { 176 if (resource.equals("")) { 177 buf.append("<resource/>"); 178 } 179 else { 180 buf.append("<resource>").append(resource).append("</resource>"); 181 } 182 } 183 buf.append("</query>"); 184 return buf.toString(); 185 } 186 } 187 | Popular Tags |