Package com.ibm.sbt.security.authentication.oauth.consumer

Examples of com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler


  private static final Logger logger = Logger.getLogger(sourceClass);

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
     Context context = Context.get();
    OAuth2Handler oAuthHandler = (OAuth2Handler)context.getSessionMap().get(Configuration.OAUTH2_HANDLER);
    if (oAuthHandler == null) {
        // this can happen if you access the application using a different hostname
        // to the one registered as the OAuth2.0 redirect URI
        StringBuffer requestUrl = request.getRequestURL();
        String msg = "Unable to retrieve OAuth2.0 handler for redirect request to {0}. Please check you are accessing the application using the same hostname used in the OAuth 2.0 redirect URI.";
        logger.info(MessageFormat.format(msg, requestUrl));
        return;
    }
   
    String authcode = extractAuthorizationToken(request);
    oAuthHandler.setAuthorization_code(authcode);
    try {
      oAuthHandler.getAccessTokenForAuthorizedUser(); // This retrieves and sets all authentication information in OAuth2Handler
      AccessToken token = oAuthHandler.createToken(oAuthHandler.getAppId(),oAuthHandler.getServiceName());
            // Store the new key
      oAuthHandler.setAccessTokenObject(token);
          if(!context.isCurrentUserAnonymous()) {
            CredentialStore credStore = CredentialStoreFactory.getCredentialStore(oAuthHandler.getCredentialStore());
            if(credStore!=null) {
              credStore.store(oAuthHandler.getServiceName(), OAuth2Handler.ACCESS_TOKEN_STORE_TYPE, context.getCurrentUserId(), token);
              }
            } else {
              // Store the token for anonymous user
              AnonymousCredentialStore.storeCredentials(context, token, oAuthHandler.getAppId(), oAuthHandler.getServiceName());
            }
      Context.get().sendRedirect(oAuthHandler.getApplicationPage());
    } catch (Exception e) {
      e.printStackTrace();
    }
    }
View Full Code Here


public class OAuth2Endpoint extends AbstractEndpoint {

  protected OAuth2Handler  oAuthHandler;

  public OAuth2Endpoint(){
    this.oAuthHandler = new OAuth2Handler();
  }
View Full Code Here

TOP

Related Classes of com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.