public Client getClient(String clientId) throws OAuthServiceException { return client == null || !client.getConsumerKey().equals(clientId) ? null : client; }
public MemoryOAuthDataProvider() { Client client = new Client(OAuthTestUtils.CLIENT_ID, OAuthTestUtils.CLIENT_SECRET, OAuthTestUtils.APPLICATION_NAME, OAuthTestUtils.CALLBACK); clientAuthInfo.put(OAuthTestUtils.CLIENT_ID, client); }
protected void validateCallbackURL(Client client, String oauthCallback) throws OAuthProblemException { // the callback must not be empty or null, and it should either match // the registered callback URI or have the common root with the // the registered application URI (but only if no callback was registered) if (!StringUtils.isEmpty(oauthCallback)) { boolean registeredCallbackIsEmpty = StringUtils.isEmpty(client.getCallbackURI()); if (!registeredCallbackIsEmpty && oauthCallback.equals(client.getCallbackURI())) { return; } if (registeredCallbackIsEmpty && !StringUtils.isEmpty(client.getApplicationURI()) && oauthCallback.startsWith(client.getApplicationURI())) { return; } } OAuthProblemException problemEx = new OAuthProblemException( OAuth.Problems.PARAMETER_REJECTED + " - " + OAuth.OAUTH_CALLBACK); problemEx .setParameter(OAuthProblemException.HTTP_STATUS_CODE, HttpServletResponse.SC_BAD_REQUEST); throw problemEx; }
protected OAuthAuthorizationData addAdditionalParams(OAuthAuthorizationData secData, OAuthDataProvider dataProvider, RequestToken token) throws OAuthProblemException { secData.setOauthToken(token.getTokenKey()); secData.setApplicationName(token.getClient().getApplicationName()); secData.setApplicationURI(token.getClient().getApplicationURI()); secData.setCallbackURI(getCallbackValue(token)); secData.setApplicationDescription(token.getClient().getApplicationDescription()); secData.setLogoUri(token.getClient().getLogoUri()); secData.setPermissions(token.getScopes()); return secData; }
String clientSecret = generateClientSecret(); Client newClient = new Client(clientId, clientSecret, appName, appURI); newClient.setApplicationDescription(appDesc); newClient.setLogoUri(logoURI.toString());
public static void validateMessage(OAuthMessage oAuthMessage, Client client, Token token, OAuthDataProvider provider, OAuthValidator validator) throws Exception { OAuthConsumer consumer = new OAuthConsumer(null, client.getConsumerKey(), client.getSecretKey(), null); OAuthAccessor accessor = new OAuthAccessor(consumer); if (token != null) { if (token instanceof RequestToken) { accessor.requestToken = token.getTokenKey(); } else { accessor.accessToken = token.getTokenKey(); } accessor.tokenSecret = token.getTokenSecret(); } try { validator.validateMessage(oAuthMessage, accessor); } catch (Exception ex) { if (token != null) { provider.removeToken(token); } throw ex; } if (token != null && validator instanceof DefaultOAuthValidator) { ((DefaultOAuthValidator)validator).validateToken(token, provider); } }
if (consumerSecret != null && !consumerSecret.equals(client.getSecretKey())) { LOG.warning("Client secret is invalid"); throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN); accessToken = client.getPreAuthorizedToken(); if (accessToken == null || !accessToken.isPreAuthorized()) { LOG.warning("Preauthorized access token is unavailable");
protected String getCallbackValue(RequestToken token) throws OAuthProblemException { String callback = token.getCallback(); if (callback == null) { callback = token.getClient().getApplicationURI(); } if (callback == null) { throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED); } return callback; }
public Principal getUserPrincipal() { String login = AbstractAuthFilter.this.useUserSubject ? (theSubject != null ? theSubject.getLogin() : null) : info.getToken().getClient().getLoginName(); return new SimplePrincipal(login); }
public void removeToken(Token t) { for (Token token : oauthTokens.values()) { Client authNInfo = token.getClient(); if (t.getClient().getConsumerKey().equals(authNInfo.getConsumerKey())) { oauthTokens.remove(token.getTokenKey()); break; } } }
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/") public ConsumerRegistration registerForm(@FormParam("appName") String appName, @FormParam("appURI") String appURI) { String clientId = generateClientId(appName, appURI); String clientSecret = generateClientSecret(); Client newClient = new Client(clientId, clientSecret, appName, appURI); manager.registerClient(newClient); return new ConsumerRegistration(clientId, clientSecret); }
public AccessToken createAccessToken(AccessTokenRegistration reg) throws OAuthServiceException { RequestToken requestToken = reg.getRequestToken(); Client client = requestToken.getClient(); requestToken = getRequestToken(requestToken.getTokenKey()); String accessTokenString = generateToken(); String tokenSecretString = generateToken(); AccessToken accessToken = new AccessToken(client, accessTokenString, tokenSecretString, 3600, System.currentTimeMillis() / 1000); accessToken.setScopes(requestToken.getScopes()); synchronized (oauthTokens) { oauthTokens.remove(requestToken.getTokenKey()); oauthTokens.put(accessTokenString, accessToken); synchronized (userAuthorizedClients) { userAuthorizedClients.add(client.getConsumerKey(), client.getConsumerKey()); } } return accessToken; }