Package com.ibm.commons.runtime

Examples of com.ibm.commons.runtime.Context


     * When parameter force is True, we reperform the Oauth Dance.
     * When login is True, we reperform the Oauth dance only when tokens are not available in store or bean
     */
   
    public AccessToken _acquireToken(boolean login, boolean force) throws OAuthException {
      Context context = Context.get();
      AccessToken tk;
     
        // If force is used, then login must be requested
        if(force) {
            login = true;
        }

        String userId = getUserId();

        // Look for a token in the store
      // If the user is anonymous, then the token might had been stored in the session
        if(!force) {
         
          if (getAccessTokenObject() != null) {
          // read from the local bean if accesstoken is present
          tk = getAccessTokenObject();
        }else{
              tk = context.isCurrentUserAnonymous()
          ? (AccessToken)AnonymousCredentialStore.loadCredentials(context,getAppId(),getServiceName())
          : findTokenFromStore(context, userId);
        }

          // check if token needs to be renewed
View Full Code Here


            acquireToken(true, true); // Failed to renew token, get a new one
                  return null;
        } else {
          setOAuthData(responseBody);
          renewedtoken = createToken(getAppId(),getServiceName()); // Now create a new token and save that in the store       
          Context context = Context.get();
          setAccessTokenObject(renewedtoken);
          try {
                if(!context.isCurrentUserAnonymous()) {
                  CredentialStore credStore = findCredentialStore();
                  if (credStore != null) {
                // if the token is already present, and was expired due to which we have fetched a new
                // token, then we remove the token from the store first and then add this new token.
                deleteToken();
View Full Code Here

   4. Interceptor from endpoint then takes care of inserting the required security headers
   */
  public synchronized void performOAuth2Dance(){
   
    setApplicationPage();
    Context context = Context.get();
   
    String callbackurl="";
    try {
      callbackurl = getCallbackUrl(context);
    } catch (OAuthException e1) {
      Platform.getInstance().log(e1);
    }
    setClient_uri(callbackurl);
   
    // Store the Oauth handler in session object
    context.getSessionMap().put(Configuration.OAUTH2_HANDLER, this);
   
    Object resp = Context.get().getHttpResponse();
    try {
        Context.get().sendRedirect(getAuthorizationNetworkUrl());
    } catch (Exception e) {
View Full Code Here

      token = acquireToken();
      if (token == null) {
        throw new OAuthException(null, "No user token is available");
      }
    }
    Context context = Context.get();
    try {
      getAccessTokenFromServer();

      token = createToken(getAppId(), getServiceName(), this, token.getUserId());
      setAccessTokenObject(token);
View Full Code Here

  public String getUserId() {
    if (this.userId != null) {
      return this.userId;
    }
    Context context = Context.getUnchecked();
    return (context == null) ? null : context.getCurrentUserId();
  }
View Full Code Here

  // Mode where an HTTP session exists
  //
  // =========================================================================================

  public void execHttpSession() throws ServletException, IOException {
    Context context = Context.get();

    // Find the OAuth dance object being used
    OAuth1Handler oAuthHandler = (OAuth1Handler)context.getSessionMap().get(Configuration.OAUTH1_HANDLER);
    if (oAuthHandler == null) {
      throw new ServletException(
          "Internal Error: Cannot find the OAuth object back from the request");
    }

    // Read the oauth parameters
    try {
      String oauth_token = (String) context.getRequestParameterMap().get(OAConstants.OAUTH_TOKEN);
      String oauth_verifier = (String) context.getRequestParameterMap().get(OAConstants.OAUTH_VERIFIER);
     
      oAuthHandler.setAccessToken(oauth_token);
      oAuthHandler.setVerifierCode(oauth_verifier);
     
      AccessToken tk = oAuthHandler.readToken(oauth_token, oauth_verifier);
      if (tk == null) {
        // should not happen
        throw new ServletException("Missing OAuth token");
      }
      // Store the new key
      oAuthHandler.setAccessTokenObject(tk);
      if (!context.isCurrentUserAnonymous()) {
        CredentialStore cs = CredentialStoreFactory.getCredentialStore(oAuthHandler.getCredentialStore());
        if (cs != null) {
          // But we store it uniquely if the current user is not anonymous
          cs.store(oAuthHandler.getServiceName(), OAuth1Handler.ACCESS_TOKEN_STORE_TYPE, context.getCurrentUserId(), tk);
        }
      } else {
        AnonymousCredentialStore.storeCredentials(context, tk,
            oAuthHandler.getAppId(), oAuthHandler.getServiceName());
      }

      // redirect to the initial page
      String applicationPage = oAuthHandler.getApplicationPage();
      if (StringUtil.isNotEmpty(applicationPage)) {
        context.sendRedirect(applicationPage);
      }
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
View Full Code Here

  private static final String sourceClass = OA2Callback.class.getName();
  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());
            }
View Full Code Here

   */
  @Override
  public void getRequestTokenFromServer() throws OAuthException {

    int responseCode = HttpStatus.SC_OK;
    Context context = Context.get();
    String responseBody = "";
    try {
      HttpClient client = new DefaultHttpClient();
      if (getForceTrustSSLCertificate()) {
        client = SSLUtil.wrapHttpClient((DefaultHttpClient) client);
View Full Code Here

  public void getRequestTokenFromServer() throws Exception {
    HttpGet method = null;
    int responseCode = HttpStatus.SC_OK;
    String responseBody = null;
    InputStream content = null;
    Context context = Context.get();
    try {
      HttpClient client = new DefaultHttpClient();
      if (getForceTrustSSLCertificate()) {
        client = SSLUtil.wrapHttpClient((DefaultHttpClient) client);
      }
View Full Code Here

      return _acquireToken(login, force);
    }
  }

  public AccessToken _acquireToken(boolean login, boolean force) throws OAuthException {
      Context context = Context.get();
      AccessToken tk;

    // If force is used, then login must be requested
    if (force) {
      login = true;
    }

    String userId = getUserId();

    // Look for a token in the store
    // If the user is anonymous, then the token might had been stored in the session
    if (!force) {
      if (getAccessTokenObject() != null) {
              // if cred store is not defined in end point return from bean
              tk = getAccessTokenObject();
            }else{
       tk = context.isCurrentUserAnonymous() ? (AccessToken) AnonymousCredentialStore
          .loadCredentials(context, getAppId(), getServiceName()) : findTokenFromStore(context,
              userId);
            }
         
      // check if token needs to be renewed
View Full Code Here

TOP

Related Classes of com.ibm.commons.runtime.Context

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.