|
1 | 1 | package com.docusign.esign.client.auth; |
2 | 2 |
|
3 | | -import com.migcomponents.migbase64.Base64; |
4 | 3 | import java.util.List; |
5 | 4 | import java.util.Map; |
6 | 5 |
|
7 | | -import javax.ws.rs.core.Response.Status.Family; |
8 | | - |
9 | 6 | import org.apache.oltu.oauth2.client.HttpClient; |
10 | 7 | import org.apache.oltu.oauth2.client.OAuthClient; |
11 | 8 | import org.apache.oltu.oauth2.client.request.OAuthClientRequest; |
| 9 | +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; |
12 | 10 | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; |
13 | 11 | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; |
14 | | -import org.apache.oltu.oauth2.client.response.OAuthClientResponse; |
15 | | -import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; |
16 | | -import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; |
17 | | -import org.apache.oltu.oauth2.common.exception.OAuthProblemException; |
18 | | -import org.apache.oltu.oauth2.common.exception.OAuthSystemException; |
19 | 12 | import org.apache.oltu.oauth2.common.message.types.GrantType; |
20 | 13 | import org.apache.oltu.oauth2.common.message.types.ResponseType; |
21 | 14 | import org.apache.oltu.oauth2.common.token.BasicOAuthToken; |
22 | 15 |
|
23 | 16 | import com.docusign.esign.client.Pair; |
24 | 17 | import com.sun.jersey.api.client.Client; |
25 | 18 | import com.sun.jersey.api.client.ClientHandlerException; |
26 | | -import com.sun.jersey.api.client.ClientResponse; |
27 | | -import com.sun.jersey.api.client.WebResource.Builder; |
28 | 19 |
|
29 | 20 | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2017-03-06T16:42:36.211-08:00") |
30 | 21 | public class OAuth implements Authentication { |
@@ -141,103 +132,4 @@ public void setOauthClient(OAuthClient oauthClient) { |
141 | 132 | public void setOauthClient(Client client) { |
142 | 133 | this.oauthClient = new OAuthClient(new OAuthJerseyClient(client)); |
143 | 134 | } |
144 | | - |
145 | | - public static class OAuthJerseyClient implements HttpClient { |
146 | | - |
147 | | - private Client client; |
148 | | - |
149 | | - public OAuthJerseyClient() { |
150 | | - this.client = new Client(null, null); |
151 | | - } |
152 | | - |
153 | | - public OAuthJerseyClient(Client client) { |
154 | | - this.client = client; |
155 | | - } |
156 | | - |
157 | | - public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map<String, String> headers, |
158 | | - String requestMethod, Class<T> responseClass) throws OAuthSystemException, OAuthProblemException { |
159 | | - String contentType = headers.get("Content-Type"); |
160 | | - String url = request.getLocationUri(); |
161 | | - String body = request.getBody(); |
162 | | - Builder builder = this.client.resource(url).getRequestBuilder(); |
163 | | - |
164 | | - for (String key : headers.keySet()) { |
165 | | - builder = builder.header(key, headers.get(key)); |
166 | | - } |
167 | | - |
168 | | - String grantType = null, code = null, clientId = null, clientSecret = null; |
169 | | - for (String entry : body.split("&")) { |
170 | | - String key = entry.split("=")[0]; |
171 | | - String value = entry.split("=")[1]; |
172 | | - if ("grant_type".equals(key)) { |
173 | | - grantType = value; |
174 | | - } else if ("code".equals(key)) { |
175 | | - code = value; |
176 | | - } else if ("client_id".equals(key)) { |
177 | | - clientId = value; |
178 | | - } else if ("client_secret".equals(key)) { |
179 | | - clientSecret = value; |
180 | | - } |
181 | | - } |
182 | | - |
183 | | - if (grantType == null || code == null) { |
184 | | - throw new OAuthSystemException("Missing grant_type/code"); |
185 | | - } else { |
186 | | - body = "grant_type=" + grantType + "&code=" + code; |
187 | | - } |
188 | | - |
189 | | - if (clientId == null || clientSecret == null) { |
190 | | - throw new OAuthSystemException("Missing clientId/secret"); |
191 | | - } else { |
192 | | - byte[] bytes = (clientId + ":" + clientSecret).getBytes(); |
193 | | - builder.header("Authorization", "Basic " + Base64.encodeToString(bytes, false)); |
194 | | - } |
195 | | - |
196 | | - ClientResponse response = null; |
197 | | - |
198 | | - if ("GET".equals(requestMethod)) { |
199 | | - response = (ClientResponse) builder.get(ClientResponse.class); |
200 | | - } else if ("POST".equals(requestMethod)) { |
201 | | - response = builder.type(contentType).post(ClientResponse.class, body); |
202 | | - } else if ("PUT".equals(requestMethod)) { |
203 | | - response = builder.type(contentType).put(ClientResponse.class, body); |
204 | | - } else if ("DELETE".equals(requestMethod)) { |
205 | | - response = builder.type(contentType).delete(ClientResponse.class, body); |
206 | | - } |
207 | | - |
208 | | - if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) { |
209 | | - return null; |
210 | | - } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { |
211 | | - if (responseClass == null) |
212 | | - return null; |
213 | | - else { |
214 | | - String respBody = response.getEntity(String.class); |
215 | | - return OAuthClientResponseFactory.createCustomResponse( |
216 | | - respBody, |
217 | | - contentType, |
218 | | - response.getStatus(), |
219 | | - response.getHeaders(), |
220 | | - responseClass |
221 | | - ); |
222 | | - } |
223 | | - } else { |
224 | | - String message = "error"; |
225 | | - String respBody = null; |
226 | | - if (response.hasEntity()) { |
227 | | - try { |
228 | | - respBody = response.getEntity(String.class); |
229 | | - message = respBody; |
230 | | - System.err.println(message); |
231 | | - } catch (RuntimeException e) { |
232 | | - e.printStackTrace(); |
233 | | - } |
234 | | - } |
235 | | - } |
236 | | - return null; |
237 | | - } |
238 | | - |
239 | | - public void shutdown() { |
240 | | - // Nothing to do here |
241 | | - } |
242 | | - } |
243 | 135 | } |
0 commit comments