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; }
public AccessToken createAccessToken(AccessTokenRegistration reg) throws OAuthServiceException { RequestToken rt = reg.getRequestToken(); String tokenId = UUID.randomUUID().toString(); String tokenSecret = UUID.randomUUID().toString(); at = new AccessToken(rt.getClient(), tokenId, tokenSecret); at.setSubject(rt.getSubject()); at.setScopes(rt.getScopes()); rt = null; return at; }
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 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; }
public String finalizeAuthorization(AuthorizationInput input) throws OAuthServiceException { RequestToken rt = input.getToken(); if (rt.getScopes().containsAll(input.getApprovedScopes())) { rt.setScopes(input.getApprovedScopes()); } String verifier = UUID.randomUUID().toString(); rt.setVerifier(verifier); return verifier; }
public RequestToken createRequestToken(RequestTokenRegistration reg) throws OAuthServiceException { String tokenId = UUID.randomUUID().toString(); String tokenSecret = UUID.randomUUID().toString(); rt = new RequestToken(reg.getClient(), tokenId, tokenSecret); rt.setScopes(getPermissionsInfo(reg.getScopes())); rt.setCallback(reg.getCallback()); return rt; }
public RequestToken createRequestToken(RequestTokenRegistration reg) throws OAuthServiceException { String token = generateToken(); String tokenSecret = generateToken(); RequestToken reqToken = new RequestToken(reg.getClient(), token, tokenSecret, reg.getLifetime(), reg.getIssuedAt()); reqToken.setScopes(getPermissionsInfo(reg.getScopes())); oauthTokens.put(token, reqToken); return reqToken; }
public String finalizeAuthorization(AuthorizationInput input) throws OAuthServiceException { RequestToken requestToken = input.getToken(); requestToken.setVerifier(generateToken()); return requestToken.getVerifier(); }
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; } } }
public Principal getUserPrincipal() { String login = AbstractAuthFilter.this.useUserSubject ? (theSubject != null ? theSubject.getLogin() : null) : info.getToken().getClient().getLoginName(); return new SimplePrincipal(login); }
private OAuthContext getOAuthContext() { OAuthContext oauth = mc.getContent(OAuthContext.class); if (oauth == null || oauth.getSubject() == null || oauth.getSubject().getLogin() == null) { throw new WebApplicationException(403); } return oauth; }
public RequestToken getRequestToken(String tokenId) throws OAuthServiceException { return rt == null || !rt.getTokenKey().equals(tokenId) ? null : rt; }
public Client getClient(String clientId) throws OAuthServiceException { return client == null || !client.getConsumerKey().equals(clientId) ? null : client; }
public AccessToken getAccessToken(String tokenId) throws OAuthServiceException { return at == null || !at.getTokenKey().equals(tokenId) ? null : at; }
protected OAuthContext createOAuthContext(OAuthInfo info) { UserSubject subject = null; if (info.getToken() != null) { subject = info.getToken().getSubject(); } return new OAuthContext(subject, info.getMatchedPermissions()); }
public MemoryOAuthDataProvider() { Client client = new Client(OAuthTestUtils.CLIENT_ID, OAuthTestUtils.CLIENT_SECRET, OAuthTestUtils.APPLICATION_NAME, OAuthTestUtils.CALLBACK); clientAuthInfo.put(OAuthTestUtils.CLIENT_ID, client); }
private Form getAuthorizationResult(OAuthAuthorizationData data) { Form form = new Form(); form.param("oauth_token", data.getOauthToken()); // TODO: get the user confirmation, using a popup window or a blocking cmd input form.param("oauthDecision", "allow"); form.param("session_authenticity_token", data.getAuthenticityToken()); return form; }
public List<String> getRoles() { List<String> authorities = new ArrayList<>(); for (OAuthPermission permission : permissions) { authorities.addAll(permission.getRoles()); } return authorities; }
public boolean isUserInRole(String role) { List<String> roles = null; if (AbstractAuthFilter.this.useUserSubject && theSubject != null) { roles = theSubject.getRoles(); } else { roles = info.getRoles(); } return roles.contains(role); }
@GET public Calendar getUserCalendar() { OAuthContext oauth = getOAuthContext(); String userName = oauth.getSubject().getLogin(); return accounts.getAccount(userName).getCalendar(); }