Package org.brickred.socialauth

Examples of org.brickred.socialauth.SocialAuthManager


      url = "http://opensource.brickred.com/socialauth-struts-filter-demo/SAF/SocialAuth?id="
          + id;
      return "forward";

    } else if ("signout".equals(mode)) {
      SocialAuthManager manager = null;
      if (helper != null) {
        manager = helper.getAuthManager();
        if (manager != null) {
          manager.disconnectProvider(id);
        }
      }
      return "home";
    }
    return "home";
View Full Code Here


  }

  private void getAccessToken() throws Exception {
    SocialAuthConfig config = SocialAuthConfig.getDefault();
    config.load();
    SocialAuthManager manager = new SocialAuthManager();
    manager.setSocialAuthConfig(config);

    URL aURL = new URL(successURL);
    host = aURL.getHost();
    port = aURL.getPort();
    port = port == -1 ? 80 : port;
    callbackPath = aURL.getPath();

    if (tokenFilePath == null) {
      tokenFilePath = System.getProperty("user.home");
    }
    String url = manager.getAuthenticationUrl(providerId, successURL);
    startServer();

    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(Action.BROWSE)) {
        try {
          desktop.browse(URI.create(url));
          // return;
        } catch (IOException e) {
          // handled below
        }
      }
    }

    lock.lock();
    try {
      while (paramsMap == null && error == null) {
        gotAuthorizationResponse.awaitUninterruptibly();
      }
      if (error != null) {
        throw new IOException("User authorization failed (" + error
            + ")");
      }
    } finally {
      lock.unlock();
    }
    stop();

    AccessGrant accessGrant = manager.createAccessGrant(providerId,
        paramsMap, successURL);

    Exporter.exportAccessGrant(accessGrant, tokenFilePath);

    LOG.info("Access Grant Object saved in a file  :: " + tokenFilePath
View Full Code Here

   */

  @Action(value = "/socialAuth")
  public String execute() throws Exception {
    LOG.info("Given provider id :: " + id);
    SocialAuthManager manager;
    if (userSession.get("socialAuthManager") != null) {
      manager = (SocialAuthManager) userSession.get("socialAuthManager");
      if ("signout".equals(mode)) {
        manager.disconnectProvider(id);
        return "home";
      }
    } else {
      InputStream in = SocialAuthenticationAction.class.getClassLoader()
          .getResourceAsStream("oauth_consumer.properties");
      SocialAuthConfig conf = SocialAuthConfig.getDefault();
      conf.load(in);
      manager = new SocialAuthManager();
      manager.setSocialAuthConfig(conf);
      userSession.put("socialAuthManager", manager);
    }

    String returnToUrl = RequestUtils.getServletPath(request);
    System.out.println(returnToUrl);
    // returnToUrl =
    // "http://opensource.brickred.com/socialauth-struts-demo/socialAuthSuccessAction.do";
    returnToUrl = UrlHelper.buildUrl("socialAuthSuccessAction.do", request,
        response, null, null, true, true, true);
    url = manager.getAuthenticationUrl(id, returnToUrl);
    LOG.info("Redirecting to: " + url);
    if (url != null) {
      return "redirect";
    }
    return "failure";
View Full Code Here

    if (statusMessage == null || statusMessage.trim().length() == 0) {
      request.setAttribute("Message", "Status can't be left blank.");
      return "failure";
    }
   
    SocialAuthManager manager = null;
    if (userSession.get("socialAuthManager") != null) {
      manager = (SocialAuthManager)userSession.get("socialAuthManager");
    }
    AuthProvider provider = null;
    if(manager!=null){
      provider = manager.getCurrentAuthProvider();
    }
    if (provider != null) {
      try {
        provider.updateStatus(statusMessage);
        request.setAttribute("Message", "Status Updated successfully");
View Full Code Here

   */
  @Action(value="/socialAuthUploadPhotoAction")
  public String execute() throws Exception {

   
    SocialAuthManager manager = null;
    if (userSession.get("socialAuthManager") != null) {
      manager = (SocialAuthManager)userSession.get("socialAuthManager");
    }
    AuthProvider provider = null;
    if(manager!=null){
      provider = manager.getCurrentAuthProvider();
    }
    if (provider != null) {
      try {
        provider.uploadImage(statusMessage,
            imageFileFileName, new FileInputStream(imageFile));
View Full Code Here

    callback(request);
    return "redirect:/" + successPageURL;
  }

  private void callback(final HttpServletRequest request) {
    SocialAuthManager m = socialAuthTemplate.getSocialAuthManager();
    if (m != null) {
      try {
        AuthProvider provider = m.connect(SocialAuthUtil
            .getRequestParametersMap(request));
        LOG.debug("Connected Provider : " + provider.getProviderId());
      } catch (Exception e) {
        e.printStackTrace();
      }
View Full Code Here

    id = null;
    provider = null;
    config = new SocialAuthConfig();
    try {
      config.load();
      manager = new SocialAuthManager();
      manager.setSocialAuthConfig(config);
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

   *             if an error occurs
   */
  @Action(value = "/socialAuthSuccessAction")
  public String execute() throws Exception {

    SocialAuthManager manager = null;
    if (userSession.get("socialAuthManager") != null) {
      manager = (SocialAuthManager) userSession.get("socialAuthManager");
    }

    if (manager != null) {
      List<Contact> contactsList = new ArrayList<Contact>();
      Profile profile = null;
      try {
        Map<String, String> paramsMap = SocialAuthUtil
            .getRequestParametersMap(request);
        AuthProvider provider = manager.connect(paramsMap);
        profile = provider.getUserProfile();
        contactsList = provider.getContactList();
        if (contactsList != null && contactsList.size() > 0) {
          for (Contact p : contactsList) {
            if (StringUtils.isEmpty(p.getFirstName())
View Full Code Here

    }
 
  @Override
  protected void doAuthGet(HttpServletRequest req, HttpServletResponse resp, String openid) throws ServletException, IOException {
   
      SocialAuthManager manager = (SocialAuthManager) req.getSession().getAttribute(SOCIAL_AUTH_MANAGER);
     
      if(manager == null) {
          /*
           * then either the session expired or the user is getting the
           * link they were posted to.
           */
          resp.sendRedirect(req.getContextPath()+"/connect");
          return;
      }
     
      Map<String, String> paramsMap = SocialAuthUtil.getRequestParametersMap(req);
     
      AuthProvider provider;
        try {
            provider = manager.connect(paramsMap);
        } catch (Exception e) {
            throw new ScriptusRuntimeException(e);
        }

        String tokenKey = provider.getAccessGrant().getKey();
View Full Code Here

  }

  @Override
  protected void doAuthPost(HttpServletRequest req, HttpServletResponse resp, String openid) throws ServletException, IOException {

        SocialAuthManager manager = new SocialAuthManager();
        try {
           
            manager.setSocialAuthConfig(socialAuthConfig);
           
            String successURL = req.getRequestURL().toString();
           
            String url = manager.getAuthenticationUrl(TransportType.Twitter.toString().toLowerCase(), successURL);
           
            req.getSession().setAttribute(SOCIAL_AUTH_MANAGER, manager);

            resp.sendRedirect(url);
           
View Full Code Here

TOP

Related Classes of org.brickred.socialauth.SocialAuthManager

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.