@@ -34,30 +34,52 @@ public class RegistrationRequest {
3434 // The enrollment ID of the user
3535 private String enrollmentID ;
3636 // Type of identity
37- private String type ;
37+ private String type = "user" ;
3838 // Optional secret
3939 private String secret ;
4040 // Maximum number of enrollments with the secret
41- private int maxEnrollments ;
41+ private Integer maxEnrollments = null ;
4242 // Affiliation for a user
4343 private String affiliation ;
4444 // Array of attribute names and values
45- private Collection <Attribute > attrs ;
45+ private Collection <Attribute > attrs = new ArrayList < Attribute >() ;
4646
4747 private String caName ;
4848
4949 // Constructor
50+
51+ /**
52+ * Register user with certificate authority
53+ *
54+ * @param id The id of the user to register.
55+ * @throws Exception
56+ */
57+ public RegistrationRequest (String id ) throws Exception {
58+ if (id == null ) {
59+ throw new Exception ("id may not be null" );
60+ }
61+ this .enrollmentID = id ;
62+
63+ }
64+
65+ /**
66+ * Register user with certificate authority
67+ *
68+ * @param id The id of the user to register.
69+ * @param affiliation The user's affiliation.
70+ * @throws Exception
71+ */
5072 public RegistrationRequest (String id , String affiliation ) throws Exception {
5173 if (id == null ) {
5274 throw new Exception ("id may not be null" );
5375 }
5476 if (affiliation == null ) {
5577 throw new Exception ("affiliation may not be null" );
5678 }
79+
5780 this .enrollmentID = id ;
5881 this .affiliation = affiliation ;
59- this .type = "user" ;
60- this .attrs = new ArrayList <Attribute >();
82+
6183 }
6284
6385 public String getEnrollmentID () {
@@ -76,7 +98,7 @@ public void setSecret(String secret) {
7698 this .secret = secret ;
7799 }
78100
79- public int getMaxEnrollments () {
101+ public Integer getMaxEnrollments () {
80102 return maxEnrollments ;
81103 }
82104
@@ -113,7 +135,7 @@ void setCAName(String caName) {
113135 }
114136
115137 // Convert the registration request to a JSON string
116- public String toJson () {
138+ String toJson () {
117139 StringWriter stringWriter = new StringWriter ();
118140 JsonWriter jsonWriter = Json .createWriter (new PrintWriter (stringWriter ));
119141 jsonWriter .writeObject (toJsonObject ());
@@ -122,15 +144,21 @@ public String toJson() {
122144 }
123145
124146 // Convert the registration request to a JSON object
125- public JsonObject toJsonObject () {
147+ JsonObject toJsonObject () {
126148 JsonObjectBuilder ob = Json .createObjectBuilder ();
127149 ob .add ("id" , enrollmentID );
128150 ob .add ("type" , type );
129151 if (this .secret != null ) {
130152 ob .add ("secret" , secret );
131153 }
132- ob .add ("max_enrollments" , maxEnrollments );
133- ob .add ("affiliation" , affiliation );
154+ if (null != maxEnrollments ) {
155+
156+ ob .add ("max_enrollments" , maxEnrollments );
157+ }
158+ if (affiliation != null ) {
159+ ob .add ("affiliation" , affiliation );
160+ }
161+
134162 JsonArrayBuilder ab = Json .createArrayBuilder ();
135163 for (Attribute attr : attrs ) {
136164 ab .add (attr .toJsonObject ());
0 commit comments