Package org.apache.openmeetings.db.entity.server

Examples of org.apache.openmeetings.db.entity.server.OAuthServer


    log.debug("All languages are imported");
  }

  public void loadInitialOAuthServers() throws Exception {
    // Yandex
    OAuthServer yandexServer = new OAuthServer();
    yandexServer.setName("Yandex");
    yandexServer.setIconUrl("http://yandex.st/morda-logo/i/favicon.ico");
    yandexServer.setClientId("<put your client_id>");
    yandexServer.setClientSecret("<put your client_secret>");
    yandexServer.setEmailParamName("default_email");
    yandexServer.setEnabled(false);
    yandexServer.setLoginParamName("default_email");
    yandexServer.setRequestInfoUrl("https://login.yandex.ru/info?format=json&oauth_token={$access_token}");
    yandexServer.setRequestTokenUrl("https://oauth.yandex.ru/token");
    yandexServer.setRequestKeyUrl("https://oauth.yandex.ru/authorize?response_type=code&client_id={$client_id}");
    yandexServer.setRequestTokenAttributes("grant_type=authorization_code&code={$code}&client_id={$client_id}&client_secret={$client_secret}");
    yandexServer.setRequestTokenMethod(RequestMethod.POST);
    oauthDao.update(yandexServer, null);
   
    // Google
    OAuthServer googleServer = new OAuthServer();
    googleServer.setName("Google");
    googleServer.setIconUrl("https://www.google.ru/images/google_favicon_128.png");
    googleServer.setEnabled(false);
    googleServer.setClientId("<put your client_id>");
    googleServer.setClientSecret("<put your client_secret>");
    googleServer.setRequestKeyUrl("https://accounts.google.com/o/oauth2/auth?redirect_uri={$redirect_uri}&response_type=code&client_id={$client_id}"
        + "&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile");
    googleServer.setRequestTokenUrl("https://accounts.google.com/o/oauth2/token");
    googleServer.setRequestTokenMethod(RequestMethod.POST);
    googleServer.setRequestTokenAttributes("code={$code}&client_id={$client_id}&client_secret={$client_secret}&redirect_uri={$redirect_uri}&grant_type=authorization_code");
    googleServer.setRequestInfoUrl("https://www.googleapis.com/oauth2/v1/userinfo?access_token={$access_token}");
    googleServer.setLoginParamName("email");
    googleServer.setEmailParamName("email");
    googleServer.setFirstnameParamName("given_name");
    googleServer.setLastnameParamName("family_name");
    oauthDao.update(googleServer, null);
   
    // Facebook
    OAuthServer facebookServer = new OAuthServer();
    facebookServer.setName("Facebook");
    facebookServer.setIconUrl("https://www.facebook.com/images/fb_icon_325x325.png");
    facebookServer.setEnabled(false);
    facebookServer.setClientId("<put your client_id>");
    facebookServer.setClientSecret("<put your client_secret>");
    facebookServer.setRequestKeyUrl("https://www.facebook.com/dialog/oauth?client_id={$client_id}&redirect_uri={$redirect_uri}&scope=email");
    facebookServer.setRequestTokenUrl("https://graph.facebook.com/oauth/access_token");
    facebookServer.setRequestTokenMethod(RequestMethod.POST);
    facebookServer.setRequestTokenAttributes("client_id={$client_id}&redirect_uri={$redirect_uri}&client_secret={$client_secret}&code={$code}");
    facebookServer.setRequestInfoUrl("https://graph.facebook.com/me?access_token={$access_token}&fields=username,first_name,last_name,email");
    facebookServer.setLoginParamName("username");
    facebookServer.setEmailParamName("email");
    facebookServer.setFirstnameParamName("first_name");
    facebookServer.setLastnameParamName("last_name");
    oauthDao.update(facebookServer, null);
  }
View Full Code Here


  }
 
  public OAuthServer get(long id) {
    TypedQuery<OAuthServer> query = em.createNamedQuery("getOAuthServerById", OAuthServer.class);
    query.setParameter("id", id);
    OAuthServer result = null;
    try {
      result = query.getSingleResult();
    } catch (NoResultException e) {}
    return result;
  }
View Full Code Here

  @Override
  protected void onSaveSubmit(AjaxRequestTarget target, Form<?> form) {
    OAuth2Dao oAuth2Dao = Application.getBean(OAuth2Dao.class);
    oAuth2Dao.update(getModelObject(), WebSession.getUserId());
    OAuthServer oauthServer = oAuth2Dao.get(getModelObject().getId());
    this.setModelObject(oauthServer);
    hideNewRecord();
    target.add(this);
    target.add(listContainer);
    target.appendJavaScript("oauthPanelInit();");
View Full Code Here

    target.appendJavaScript("oauthPanelInit();");
  }

  @Override
  protected void onNewSubmit(AjaxRequestTarget target, Form<?> form) {
    this.setModelObject(new OAuthServer());
    target.add(this);
    target.appendJavaScript("oauthPanelInit();");
  }
View Full Code Here

    target.appendJavaScript("oauthPanelInit();");
  }

  @Override
  protected void onRefreshSubmit(AjaxRequestTarget target, Form<?> form) {
    OAuthServer server = this.getModelObject();
    if (server.getId() <= 0) {
      server = Application.getBean(OAuth2Dao.class).get(getModelObject().getId());
    } else {
      server = new OAuthServer();
    }
    this.setModelObject(server);
    target.add(this);
    target.appendJavaScript("oauthPanelInit();");
  }
View Full Code Here

  }

  @Override
  protected void onDeleteSubmit(AjaxRequestTarget target, Form<?> form) {
    Application.getBean(OAuth2Dao.class).delete(getModelObject(), WebSession.getUserId());
    this.setModelObject(new OAuthServer());
    target.add(listContainer);
    target.add(this);
    target.appendJavaScript("oauthPanelInit();");
  }
View Full Code Here

      private static final long serialVersionUID = -7701640237947383416L;

      @Override
      protected void populateItem(Item<OAuthServer> item) {
        final OAuthServer server = item.getModelObject();
        item.add(new Label("oauthServerId", String.valueOf(server.getId())));
        item.add(new Label("name", server.getName()));
        item.add(new AjaxEventBehavior("onclick") {

          private static final long serialVersionUID = 7380727643346943181L;

          @Override
          protected void onEvent(AjaxRequestTarget target) {
            form.setModelObject(server);
            form.hideNewRecord();
            target.add(form, listContainer);
            target.appendJavaScript("oauthPanelInit();");
          }
        });
        item.add(AttributeModifier.replace("class", "clickable "
            + (item.getIndex() % 2 == 1 ? "even" : "odd")
            + (server.getId().equals(form.getModelObject().getId()) ? " selected" : "")));
      }
     
    };
   
    add(listContainer.add(dataView).setOutputMarkupId(true));
    PagedEntityListPanel navigator = new PagedEntityListPanel("navigator", dataView) {
      private static final long serialVersionUID = -1L;

      @Override
      protected void onEvent(AjaxRequestTarget target) {
        target.add(listContainer);
      }
    };
    DataViewContainer<OAuthServer> container = new DataViewContainer<OAuthServer>(listContainer, dataView, navigator);
    container.setLinks(new OmOrderByBorder<OAuthServer>("orderById", "oauthServerId", container),
               new OmOrderByBorder<OAuthServer>("orderByName", "name", container));
    add(container.orderLinks);
    add(navigator);
   
    form = new OAuthForm("form", listContainer, new OAuthServer());
    form.showNewRecord();
        add(form);
  }
View Full Code Here

    super();
    if (p != null) {
      if (p.get("oauthid").toString() != null) { // oauth2 login
        try {
          long serverId = Long.valueOf(p.get("oauthid").toString());
          OAuthServer server = getBean(OAuth2Dao.class).get(serverId);
          log.debug("OAuthServer=" + server);
          if (server == null) {
            log.warn("OAuth server id=" + serverId + " not found");
            return;
          }
         
          if (p.get("code").toString() != null) { // got code
            String code = p.get("code").toString();
            log.debug("OAuth response code=" + code);
             AuthInfo authInfo = getToken(code, server);
             if (authInfo == null) return;
             log.debug("OAuthInfo=" + authInfo);
             Map<String, String> authParams = getAuthParams(authInfo.accessToken, code, server);
             if (authParams != null) {
               loginViaOAuth2(authParams, serverId);
             }
          } else { // redirect to get code
            String redirectUrl = prepareUrlParams(server.getRequestKeyUrl(), server.getClientId(),
                null, null, getRedirectUri(server, this), null);
            log.debug("redirectUrl=" + redirectUrl);
            throw new RedirectToUrlException(redirectUrl);
          }
        } catch (IOException e) {
View Full Code Here

    log.debug("All languages are imported");
  }

  public void loadInitialOAuthServers() throws Exception {
    // Yandex
    OAuthServer yandexServer = new OAuthServer();
    yandexServer.setName("Yandex");
    yandexServer.setIconUrl("http://yandex.st/morda-logo/i/favicon.ico");
    yandexServer.setClientId("<put your client_id>");
    yandexServer.setClientSecret("<put your client_secret>");
    yandexServer.setEmailParamName("default_email");
    yandexServer.setEnabled(false);
    yandexServer.setLoginParamName("default_email");
    yandexServer.setRequestInfoUrl("https://login.yandex.ru/info?format=json&oauth_token={$access_token}");
    yandexServer.setRequestTokenUrl("https://oauth.yandex.ru/token");
    yandexServer.setRequestKeyUrl("https://oauth.yandex.ru/authorize?response_type=code&client_id={$client_id}");
    yandexServer.setRequestTokenAttributes("grant_type=authorization_code&code={$code}&client_id={$client_id}&client_secret={$client_secret}");
    yandexServer.setRequestTokenMethod(RequestMethod.POST);
    oauthDao.update(yandexServer, null);
   
    // Google
    OAuthServer googleServer = new OAuthServer();
    googleServer.setName("Google");
    googleServer.setIconUrl("https://www.google.ru/images/google_favicon_128.png");
    googleServer.setEnabled(false);
    googleServer.setClientId("<put your client_id>");
    googleServer.setClientSecret("<put your client_secret>");
    googleServer.setRequestKeyUrl("https://accounts.google.com/o/oauth2/auth?redirect_uri={$redirect_uri}&response_type=code&client_id={$client_id}"
        + "&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile");
    googleServer.setRequestTokenUrl("https://accounts.google.com/o/oauth2/token");
    googleServer.setRequestTokenMethod(RequestMethod.POST);
    googleServer.setRequestTokenAttributes("code={$code}&client_id={$client_id}&client_secret={$client_secret}&redirect_uri={$redirect_uri}&grant_type=authorization_code");
    googleServer.setRequestInfoUrl("https://www.googleapis.com/oauth2/v1/userinfo?access_token={$access_token}");
    googleServer.setLoginParamName("email");
    googleServer.setEmailParamName("email");
    googleServer.setFirstnameParamName("given_name");
    googleServer.setLastnameParamName("family_name");
    oauthDao.update(googleServer, null);
   
    // Facebook
    OAuthServer facebookServer = new OAuthServer();
    facebookServer.setName("Facebook");
    facebookServer.setIconUrl("https://www.facebook.com/images/fb_icon_325x325.png");
    facebookServer.setEnabled(false);
    facebookServer.setClientId("<put your client_id>");
    facebookServer.setClientSecret("<put your client_secret>");
    facebookServer.setRequestKeyUrl("https://www.facebook.com/dialog/oauth?client_id={$client_id}&redirect_uri={$redirect_uri}&scope=email");
    facebookServer.setRequestTokenUrl("https://graph.facebook.com/oauth/access_token");
    facebookServer.setRequestTokenMethod(RequestMethod.POST);
    facebookServer.setRequestTokenAttributes("client_id={$client_id}&redirect_uri={$redirect_uri}&client_secret={$client_secret}&code={$code}");
    facebookServer.setRequestInfoUrl("https://graph.facebook.com/me?access_token={$access_token}&fields=username,first_name,last_name,email");
    facebookServer.setLoginParamName("username");
    facebookServer.setEmailParamName("email");
    facebookServer.setFirstnameParamName("first_name");
    facebookServer.setLastnameParamName("last_name");
    oauthDao.update(facebookServer, null);
  }
View Full Code Here

    super();
    StringValue oauthid = p.get("oauthid");
    if (!oauthid.isEmpty()) { // oauth2 login
      try {
        long serverId = oauthid.toLong(-1);
        OAuthServer server = getBean(OAuth2Dao.class).get(serverId);
        log.debug("OAuthServer=" + server);
        if (server == null) {
          log.warn("OAuth server id=" + serverId + " not found");
          return;
        }
       
        if (p.get("code").toString() != null) { // got code
          String code = p.get("code").toString();
          log.debug("OAuth response code=" + code);
           AuthInfo authInfo = getToken(code, server);
           if (authInfo == null) return;
           log.debug("OAuthInfo=" + authInfo);
           Map<String, String> authParams = getAuthParams(authInfo.accessToken, code, server);
           if (authParams != null) {
             loginViaOAuth2(authParams, serverId);
           }
        } else { // redirect to get code
          String redirectUrl = prepareUrlParams(server.getRequestKeyUrl(), server.getClientId(),
              null, null, getRedirectUri(server, this), null);
          log.debug("redirectUrl=" + redirectUrl);
          throw new RedirectToUrlException(redirectUrl);
        }
      } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.openmeetings.db.entity.server.OAuthServer

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.