@@ -124,8 +124,16 @@ public void postEnrollment(Enrollment enrollment) {
124124 String path = "/api/classes/{classSourcedId}/enrollments" ;
125125 String url = this .baseUrl + StringUtils .replace (path , "{classSourcedId}" , enrollment .getKlass ().getSourcedId ());
126126
127- restTemplate
128- .exchange (url , HttpMethod .POST , he , JsonObject .class );
127+ ResponseEntity <JsonObject > response =
128+ restTemplate
129+ .exchange (url , HttpMethod .POST , he , JsonObject .class );
130+
131+ if (response != null && response .getStatusCode () == HttpStatus .UNAUTHORIZED ) {
132+ httpHeaders .add ("Authorization" , "Bearer " + getToken ());
133+ restTemplate
134+ .exchange (url , HttpMethod .POST , he , JsonObject .class );
135+ }
136+
129137 }
130138
131139 public void postUser (User user ) {
@@ -139,7 +147,7 @@ public void postUser(User user) {
139147 .exchange (url , HttpMethod .POST , he , JsonObject .class );
140148
141149
142- if (response != null && response .getStatusCode () == HttpStatus .FORBIDDEN ) {
150+ if (response != null && response .getStatusCode () == HttpStatus .UNAUTHORIZED ) {
143151 httpHeaders .add ("Authorization" , "Bearer " + getToken ());
144152 restTemplate
145153 .exchange (url , HttpMethod .POST , he , JsonObject .class );
@@ -153,9 +161,16 @@ public void postUserMapping(UserMapping userMapping) {
153161 String path = "/api/users/mapping" ;
154162 String url = this .baseUrl + path ;
155163
156- restTemplate
164+ ResponseEntity <JsonObject > response =
165+ restTemplate
157166 .exchange (url , HttpMethod .POST , he , JsonObject .class );
158167
168+ if (response != null && response .getStatusCode () == HttpStatus .UNAUTHORIZED ) {
169+ httpHeaders .add ("Authorization" , "Bearer " + getToken ());
170+ restTemplate
171+ .exchange (url , HttpMethod .POST , he , JsonObject .class );
172+ }
173+
159174 }
160175
161176 public void postLineItem (LineItem lineItem ) {
0 commit comments