/** * @return the name of the service */ public String getServiceName() { return AgoravaContext.getQualifierToService().get(getServiceQualifier()); }
@Override public OAuthService getCurrentService() { return services.select(getCurrentSession().getServiceQualifier()).get(); }
@Override public UserProfileService getCurrentUserProfileService() { return userProfileServices.select(getCurrentSession().getServiceQualifier()).get(); }
@Override public OAuthSession getForProvider(Annotation qual) { if (getCurrent().getServiceQualifier().equals(qual)) { return getCurrent(); } else { for (OAuthSession session : activeSessions) { if (session.getServiceQualifier().equals(qual)) { return session; } } } return OAuthSession.NULL; }
@Produces @PicketLink @RequestScoped public Authenticator authenticatorProducer() { Annotation qualifier; if (session != OAuthSession.NULL) { qualifier = session.getServiceQualifier(); } else if (AgoravaContext.getListOfServices().contains(provider)) { qualifier = AgoravaContext.getServicesToQualifier().get(provider); } else { throw new AgoravaException("Current OAuthSession is NULL and Request doesn't contain " + AgoravaConstants .PROVIDER_PARAM + " parameter"); } if (qualifier == null) { throw new AgoravaException("No qualifier found for the following provider " + provider); } return authenticators.select(qualifier).get(); } }
@Override public OAuthSession resolveSessionForQualifier(Annotation qualifier) { OAuthSession current = getCurrentSession(); if (current.getServiceQualifier().equals(qualifier)) { return current; } if (getCurrentRepository().getCurrent().equals(OAuthSession.NULL)) { buildSessionFor(qualifier); } else if (!getCurrentRepository().getCurrent().getServiceQualifier().equals(qualifier)) { throw new ProviderMismatchException("Inconsistent state between repo and service. In repo Session provider is " + getCurrentRepository().getCurrent().getServiceName() + " while service provider is " + qualifier); } return getCurrentRepository().getCurrent(); }
@Override public synchronized void endDance() { OAuthSession currentSession = getCurrentSession(); System.out.println("Verifier ("+ getVerifierParamName() + ") : " + currentSession.getVerifier()); // FIXME replace with logger or disable if (currentSession.getAccessToken() == null) { currentSession.setAccessToken(getCurrentService().getAccessToken(currentSession.getRequestToken(), currentSession.getVerifier())); } if (currentSession.getAccessToken() != null) { currentSession.setRequestToken(null); currentSession.setUserProfile(getCurrentUserProfileService().getUserProfile()); currentSession.getRepo().add(currentSession); completeEvt.select(currentSession.getServiceQualifier()).fire(new OAuthComplete(SocialEvent.Status.SUCCESS, "", currentSession)); //TODO: reactivate logger } else { // FIXME Launch an exception !! } }
/** * Configure this builder with an existing {@link org.agorava.api.oauth.OAuthSession}. Convenient to clone a session * or to create an unproxified version of a session * * @param session the session to read values from * @return this builder */ public Builder readFromOAuthSession(OAuthSession session) { qualifier(session.getServiceQualifier()) .requestToken(session.getRequestToken()) .accessToken(session.getAccessToken()) .verifier(session.getVerifier()) .userProfile(session.getUserProfile()) .repo(session.getRepo()) .id(session.getId()); return this; }