1 18 package sync4j.framework.core; 19 20 28 public final class Chal 29 implements java.io.Serializable { 30 31 private Meta meta = null; 33 34 36 protected Chal() {} 37 38 44 public Chal (final Meta meta) { 45 this.meta = meta; 46 String type = meta.getType(); 47 String format = meta.getFormat(); 48 49 if (type == null) { 50 throw new IllegalArgumentException ( 51 "The authentication type cannot be null"); 52 } 53 if (format == null) { 54 if (type.equalsIgnoreCase(Cred.AUTH_TYPE_BASIC)) { 55 meta.setFormat(Constants.FORMAT_B64); 56 } else if (type.equalsIgnoreCase(Cred.AUTH_TYPE_MD5)) { 57 meta.setFormat(Constants.FORMAT_B64); 58 } else { 59 throw new IllegalArgumentException ( 60 "The authentication format cannot be null"); 61 } 62 } 63 } 64 65 71 public Meta getMeta() { 72 return this.meta; 73 } 74 75 81 public void setMeta(Meta meta) { 82 this.meta = meta; 83 } 84 85 90 public NextNonce getNextNonce() { 91 return meta.getNextNonce(); 92 } 93 94 public void setNextNonce(NextNonce nextNonce) { 95 if (meta == null) { 96 meta = new Meta(); 97 } 98 meta.setNextNonce(nextNonce); 99 } 100 105 public String getType() { 106 return meta.getType(); 107 } 108 109 114 public String getFormat() { 115 return meta.getFormat(); 116 } 117 118 125 public static Chal getBasicChal() { 126 Meta m = new Meta(); 127 m.setType(Cred.AUTH_TYPE_BASIC); 128 m.setFormat(Constants.FORMAT_B64); 129 m.setNextNonce(null); 130 return new Chal(m); 131 } 132 133 140 public static Chal getMD5Chal() { 141 Meta m = new Meta(); 142 m.setType(Cred.AUTH_TYPE_MD5); 143 m.setFormat(Constants.FORMAT_B64); 144 m.setNextNonce(null); 145 return new Chal(m); 146 } 147 } 148 | Popular Tags |