PathSegmentImpl(final String path, final boolean decode) { this(path, decode, new MultivaluedStringMap()); }
public final <A> A getFirst(String key, Class<A> type) { String value = getFirst(key); if (value == null) { return null; } Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = null; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; }
@POST @Produces(MediaType.APPLICATION_JSON) public Response exchangeAuthorizationCode( @PathParam(value = "identity") String identity, @Valid @NotNull final Payload payload, @Context final HttpServletResponse servletResponse) throws IOException { SocialIdentityProviderEntity identityProvider = socialIdentityProviderService.findById(identity); if (identityProvider != null) { // Step 1. Exchange authorization code for access token. final MultivaluedStringMap accessData = new MultivaluedStringMap(); accessData.add(CLIENT_ID_KEY, payload.getClientId()); accessData.add(REDIRECT_URI_KEY, payload.getRedirectUri()); accessData.add(CLIENT_SECRET, identityProvider.getClientSecret()); accessData.add(CODE_KEY, payload.getCode()); accessData.add(GRANT_TYPE_KEY, AUTH_CODE); Response response = client.target(identityProvider.getTokenEndpoint()) .request(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) .post(Entity.form(accessData)); accessData.clear(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { final String accessToken = (String) getResponseEntity(response).get(ACCESS_TOKEN_PROPERTY); return authenticateUser(identityProvider, servletResponse, accessToken); } return Response .status(Response.Status.UNAUTHORIZED) .build(); } return Response.status(Response.Status.NOT_FOUND).build(); }
/** * Based on <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465407.aspx">http://msdn.microsoft.com/en-us/library/windows/apps/hh465407.aspx</a> * * @throws WnsException when authentication fails */ public void refreshAccessToken() throws WnsException { WebTarget target = client.target(getAuthenticationUri()); MultivaluedStringMap formData = new MultivaluedStringMap(); formData.add("grant_type", GRANT_TYPE_CLIENT_CREDENTIALS); formData.add("client_id", this.sid); formData.add("client_secret", this.clientSecret); formData.add("scope", SCOPE); Response response = target.request(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData)); if (response.getStatus() != 200) { throw new WnsException("Authentication failed. HTTP error code: " + response.getStatus()); } this.token = response.readEntity(WnsOAuthToken.class); }
@POST @Produces(MediaType.APPLICATION_JSON) public Response exchangeAuthorizationCode( @PathParam(value = "identity") String identity, @Valid @NotNull final Payload payload, @Context final HttpServletResponse servletResponse) throws IOException { SocialIdentityProviderEntity identityProvider = socialIdentityProviderService.findById(identity); if (identityProvider != null) { // Step 1. Exchange authorization code for access token. final MultivaluedStringMap accessData = new MultivaluedStringMap(); accessData.add(CLIENT_ID_KEY, payload.getClientId()); accessData.add(REDIRECT_URI_KEY, payload.getRedirectUri()); accessData.add(CLIENT_SECRET, identityProvider.getClientSecret()); accessData.add(CODE_KEY, payload.getCode()); accessData.add(GRANT_TYPE_KEY, AUTH_CODE); Response response = client.target(identityProvider.getTokenEndpoint()) .request(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) .post(Entity.form(accessData)); accessData.clear(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { final String accessToken = (String) getResponseEntity(response).get(ACCESS_TOKEN_PROPERTY); return authenticateUser(identityProvider, servletResponse, accessToken); } return Response .status(Response.Status.UNAUTHORIZED) .build(); } return Response.status(Response.Status.NOT_FOUND).build(); }
PathSegmentImpl(final String path, final boolean decode) { this(path, decode, new MultivaluedStringMap()); }
if (identityProvider.getTokenIntrospectionEndpoint() != null) { final MultivaluedStringMap introspectData = new MultivaluedStringMap(); introspectData.add(TOKEN, token); Response response = client (identityProvider.getClientId() + ':' + identityProvider.getClientSecret()).getBytes()))) .post(Entity.form(introspectData)); introspectData.clear();
public final <A> A getFirst(String key, Class<A> type) { String value = getFirst(key); if (value == null) { return null; } Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = null; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; }
private JerseyUriBuilder(final JerseyUriBuilder that) { this.scheme = that.scheme; this.ssp = that.ssp; this.authority = that.authority; this.userInfo = that.userInfo; this.host = that.host; this.port = that.port; this.path = new StringBuilder(that.path); this.matrixParams = that.matrixParams == null ? null : new MultivaluedStringMap(that.matrixParams); this.query = new StringBuilder(that.query); this.queryParams = that.queryParams == null ? null : new MultivaluedStringMap(that.queryParams); this.fragment = that.fragment; }
if (identityProvider.getTokenIntrospectionEndpoint() != null) { final MultivaluedStringMap introspectData = new MultivaluedStringMap(); introspectData.add(TOKEN, token); Response response = client (identityProvider.getClientId() + ':' + identityProvider.getClientSecret()).getBytes()))) .post(Entity.form(introspectData)); introspectData.clear();
@SuppressWarnings("unchecked") public final <A> A getFirst(String key, A defaultValue) { String value = getFirst(key); if (value == null) { return defaultValue; } Class<A> type = (Class<A>) defaultValue.getClass(); Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = defaultValue; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; } }
private JerseyUriBuilder(final JerseyUriBuilder that) { this.scheme = that.scheme; this.ssp = that.ssp; this.authority = that.authority; this.userInfo = that.userInfo; this.host = that.host; this.port = that.port; this.path = new StringBuilder(that.path); this.matrixParams = that.matrixParams == null ? null : new MultivaluedStringMap(that.matrixParams); this.query = new StringBuilder(that.query); this.queryParams = that.queryParams == null ? null : new MultivaluedStringMap(that.queryParams); this.fragment = that.fragment; }
@SuppressWarnings("unchecked") public final <A> A getFirst(String key, A defaultValue) { String value = getFirst(key); if (value == null) { return defaultValue; } Class<A> type = (Class<A>) defaultValue.getClass(); Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = defaultValue; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; } }
/** * Decode the matrix component of a URI path segment. * * @param pathSegment the path segment component in encoded form. * @param decode true if the matrix parameters of the path segment component * should be in decoded form. * @return the multivalued map of matrix parameters. */ public static MultivaluedMap<String, String> decodeMatrix(final String pathSegment, final boolean decode) { final MultivaluedMap<String, String> matrixMap = new MultivaluedStringMap(); // Skip over path segment int s = pathSegment.indexOf(';') + 1; if (s == 0 || s == pathSegment.length()) { return matrixMap; } do { final int e = pathSegment.indexOf(';', s); if (e == -1) { decodeMatrixParam(matrixMap, pathSegment.substring(s), decode); } else if (e > s) { decodeMatrixParam(matrixMap, pathSegment.substring(s, e), decode); } s = e + 1; } while (s > 0 && s < pathSegment.length()); return matrixMap; }
public final <A> A getFirst(String key, Class<A> type) { String value = getFirst(key); if (value == null) { return null; } Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = null; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; }
/** * Decode the matrix component of a URI path segment. * * @param pathSegment the path segment component in encoded form. * @param decode true if the matrix parameters of the path segment component * should be in decoded form. * @return the multivalued map of matrix parameters. */ public static MultivaluedMap<String, String> decodeMatrix(final String pathSegment, final boolean decode) { final MultivaluedMap<String, String> matrixMap = new MultivaluedStringMap(); // Skip over path segment int s = pathSegment.indexOf(';') + 1; if (s == 0 || s == pathSegment.length()) { return matrixMap; } do { final int e = pathSegment.indexOf(';', s); if (e == -1) { decodeMatrixParam(matrixMap, pathSegment.substring(s), decode); } else if (e > s) { decodeMatrixParam(matrixMap, pathSegment.substring(s, e), decode); } s = e + 1; } while (s > 0 && s < pathSegment.length()); return matrixMap; }
public final <A> A getFirst(String key, Class<A> type) { String value = getFirst(key); if (value == null) { return null; } Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = null; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; }
final MultivaluedMap<String, String> queryParameters = new MultivaluedStringMap();
public final <A> A getFirst(String key, Class<A> type) { String value = getFirst(key); if (value == null) { return null; } Constructor<A> c = null; try { c = type.getConstructor(String.class); } catch (Exception ex) { throw new IllegalArgumentException(type.getName() + " has no String constructor", ex); } A retVal = null; try { retVal = c.newInstance(value); } catch (Exception ex) { } return retVal; }
final MultivaluedMap<String, String> queryParameters = new MultivaluedStringMap();