List of usage examples for org.springframework.security.oauth.provider.token InvalidOAuthTokenException InvalidOAuthTokenException
public InvalidOAuthTokenException(String msg)
From source file:com.porvak.bracket.social.develop.oauth.OAuthSessionManagerProviderTokenServices.java
public void authorizeRequestToken(String requestToken, String verifier, Authentication authentication) { if (!(authentication.getPrincipal() instanceof Account)) { throw new IllegalArgumentException("Authenticated user principal is not of expected Account type"); }/*from ww w. j a va 2s. co m*/ try { Long authorizingAccountId = Long.valueOf(((Account) authentication.getPrincipal()).getId()); sessionManager.authorize(requestToken, authorizingAccountId, verifier); } catch (InvalidRequestTokenException e) { throw new InvalidOAuthTokenException(e.getMessage()); } }
From source file:com.porvak.bracket.social.develop.oauth.OAuthSessionManagerProviderTokenServices.java
public OAuthAccessProviderToken createAccessToken(String requestToken) { try {/* ww w . j a va 2 s . co m*/ return providerTokenFor(sessionManager.grantAccess(requestToken)); } catch (InvalidRequestTokenException e) { throw new InvalidOAuthTokenException(e.getMessage()); } }
From source file:com.porvak.bracket.social.develop.oauth.OAuthSessionManagerProviderTokenServices.java
public OAuthProviderToken getToken(String tokenValue) { try {/*from w w w. j a va2 s . c om*/ return providerTokenFor(sessionManager.getSession(tokenValue)); } catch (InvalidRequestTokenException e) { try { // TODO return null; // return providerTokenFor(appRepository.findAppConnection(tokenValue)); } catch (Exception ex) { // } catch (NoSuchAccountConnectionException ex) { throw new InvalidOAuthTokenException( "Could not find OAuthSession or AppConnection for provided OAuth request token " + tokenValue); } } }
From source file:org.springframework.security.oauth.provider.token.RandomValueProviderTokenServices.java
public OAuthProviderToken getToken(String token) throws AuthenticationException { OAuthProviderTokenImpl tokenImpl = readToken(token); if (tokenImpl == null) { throw new InvalidOAuthTokenException("Invalid token: " + token); } else if (isExpired(tokenImpl)) { removeToken(token);/* w ww. j a v a 2s . c om*/ onTokenRemoved(tokenImpl); throw new ExpiredOAuthTokenException("Expired token."); } return tokenImpl; }
From source file:org.springframework.security.oauth.provider.token.RandomValueProviderTokenServices.java
public void authorizeRequestToken(String requestToken, String verifier, Authentication authentication) throws AuthenticationException { OAuthProviderTokenImpl tokenImpl = readToken(requestToken); if (tokenImpl == null) { throw new InvalidOAuthTokenException("Invalid token: " + requestToken); } else if (isExpired(tokenImpl)) { removeToken(requestToken);/* ww w . ja va2 s. co m*/ onTokenRemoved(tokenImpl); throw new ExpiredOAuthTokenException("Expired token."); } else if (tokenImpl.isAccessToken()) { throw new InvalidOAuthTokenException("Request to authorize an access token."); } tokenImpl.setUserAuthentication(authentication); tokenImpl.setTimestamp(System.currentTimeMillis());//reset the expiration. tokenImpl.setVerifier(verifier); storeToken(requestToken, tokenImpl); }
From source file:org.springframework.security.oauth.provider.token.RandomValueProviderTokenServices.java
public OAuthAccessProviderToken createAccessToken(String requestToken) throws AuthenticationException { OAuthProviderTokenImpl tokenImpl = readToken(requestToken); if (tokenImpl == null) { throw new InvalidOAuthTokenException("Invalid token: " + requestToken); } else if (isExpired(tokenImpl)) { removeToken(requestToken);// w w w. j av a 2 s . co m onTokenRemoved(tokenImpl); throw new ExpiredOAuthTokenException("Expired token."); } else if (tokenImpl.isAccessToken()) { throw new InvalidOAuthTokenException("Not a request token."); } else if (tokenImpl.getUserAuthentication() == null) { throw new InvalidOAuthTokenException("Request token has not been authorized."); } OAuthProviderTokenImpl requestTokenImpl = removeToken(requestToken); if (requestTokenImpl != null) { onTokenRemoved(requestTokenImpl); } String tokenValue = UUID.randomUUID().toString(); byte[] secretBytes = new byte[getTokenSecretLengthBytes()]; getRandom().nextBytes(secretBytes); String secret = new String(Base64.encodeBase64(secretBytes)); OAuthProviderTokenImpl token = new OAuthProviderTokenImpl(); token.setAccessToken(true); token.setConsumerKey(tokenImpl.getConsumerKey()); token.setUserAuthentication(tokenImpl.getUserAuthentication()); token.setSecret(secret); token.setValue(tokenValue); token.setTimestamp(System.currentTimeMillis()); onTokenCreated(token); storeToken(tokenValue, token); return token; }