@Override public OauthToken validateToken(String token) throws OauthClientException { return client.validateToken(token); } };
public TokenRequest withScopes(String... scopes) { for (String scope : scopes) { withScope(scope); } return this; }
public TokenRequest withNote(String note) { return withNote(note,null); }
@Override public OauthToken createToken(TokenRequest r) throws OauthClientException { OauthToken t = new OauthToken(); t.accessToken = "account="+r.getAccountName()+",scope="+ join(r.getScopes(), " "); return t; }
String pack(TokenRequest req) throws OauthClientException { try { return CREATE_TOKEN + MAPPER.writeValueAsString(req); } catch (IOException e) { throw new OauthClientException("Failed to marshal TokenRequest",e); } }
public OauthToken validateToken(String token, String... scopes) throws OauthClientException { OauthToken oauthToken = validateToken(token); if (oauthToken==null) return null; if (oauthToken.validateScopes(scopes)) return oauthToken; else return null; }
@Override public void serialize(GrantType o, JsonGenerator gen, SerializerProvider serializer) throws IOException { gen.writeString(o.toLowerCase()); } }
@Override public GrantType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return parse(jp.getText()); } }
private GrantType() { lowerCase = name().toLowerCase(Locale.ENGLISH); }
@Override public OauthToken createOAuthClientToken(Collection<String> scopes) throws OauthClientException { if (LOGGER.isLoggable(FINE)) { LOGGER.log(FINE, "Creating an OAuth client token: "+scopes); } return client.createOAuthClientToken(scopes); } };
public void deleteToken(String oauthTokenId) throws OauthClientException { try { bees.jsonPOJORequest(gcUrl + "/api/v2/authorizations/"+oauthTokenId, null, null, "DELETE"); } catch (IOException e) { throw new OauthClientException("Failed to delete OAuth token",e); } }
public OauthToken validateToken(String token, String... scopes) throws OauthClientException { OauthToken oauthToken = validateToken(token); if (oauthToken==null) return null; if (oauthToken.validateScopes(scopes)) return oauthToken; else return null; }
public TokenRequest withScopes(String... scopes) { for (String scope : scopes) { withScope(scope); } return this; }
public TokenRequest withNote(String note) { return withNote(note,null); }
@Override public void serialize(GrantType o, JsonGenerator gen, SerializerProvider serializer) throws IOException { gen.writeString(o.toLowerCase()); } }
@Override public GrantType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return parse(jp.getText()); } }
public void deleteApplication(String clientId) throws OauthClientException { try { bees.jsonPOJORequest(gcUrl + "/api/v2/applications/"+clientId, null, null, "DELETE"); } catch (IOException e) { throw new OauthClientException("Failed to delete OAuth application",e); } }
/** * * Create a Json serializable Oauth token request. * * @param note optional. Tells something about the oauth application * @param noteUrl optional. Your application URL * @param refreshToken optional. Refresh token that should be used to generate a new token. * @param accountName required. Name of the account * @param scopes Optional. array of scopes to be granted with this token. The default scope is https://api.cloudbees.com/v2/users/user, * which is user read and write scope. If you are creating token to crete other tokens with specific scopes you must ask for * https://api.cloudbees.com/v2/users/user/generate_token scope scope. * * @throws IllegalArgumentException In case there is an error */ public TokenRequest(String note, String noteUrl, String refreshToken, String accountName, String... scopes) { this.note = note; this.noteUrl = noteUrl; this.accountName = accountName; this.refreshToken = refreshToken; for(String scope: scopes) withScope(scope); }