Beispiel #1
0
 private void handleRedirectPath(String internalPath) {
   if (internalPath.equals(this.service_.getRedirectInternalPath())) {
     WApplication app = WApplication.getInstance();
     WEnvironment env = app.getEnvironment();
     if (!env.hasAjax()) {
       String stateE = env.getParameter("state");
       if (!(stateE != null) || !stateE.equals(this.oAuthState_)) {
         this.setError(WString.tr("Wt.Auth.OAuthService.invalid-state"));
       } else {
         String errorE = env.getParameter("error");
         if (errorE != null) {
           this.setError(WString.tr("Wt.Auth.OAuthService." + errorE));
         } else {
           String codeE = env.getParameter("code");
           if (!(codeE != null)) {
             this.setError(WString.tr("Wt.Auth.OAuthService.missing-code"));
           } else {
             this.requestToken(codeE);
           }
         }
       }
       this.onOAuthDone();
     }
   }
 }
Beispiel #2
0
 /**
  * Constructor.
  *
  * <p>
  *
  * @see OAuthService#createProcess(String scope)
  */
 protected OAuthProcess(OAuthService service, String scope) {
   super();
   this.service_ = service;
   this.scope_ = scope;
   this.authenticate_ = false;
   this.authorized_ = new Signal1<OAuthAccessToken>(this);
   this.authenticated_ = new Signal1<Identity>(this);
   this.redirected_ = new JSignal(this, "redirected");
   this.oAuthState_ = "";
   this.token_ = new OAuthAccessToken();
   this.error_ = new WString();
   this.startInternalPath_ = "";
   this.redirectEndpoint_ = new OAuthRedirectEndpoint(this);
   WApplication app = WApplication.getInstance();
   PopupWindow.loadJavaScript(app);
   String url = app.makeAbsoluteUrl(this.redirectEndpoint_.getUrl());
   this.oAuthState_ = this.service_.encodeState(url);
   this.redirected_.addListener(
       this,
       new Signal.Listener() {
         public void trigger() {
           OAuthProcess.this.onOAuthDone();
         }
       });
   if (!app.getEnvironment().hasJavaScript()) {
     app.internalPathChanged()
         .addListener(
             this,
             new Signal1.Listener<String>() {
               public void trigger(String e1) {
                 OAuthProcess.this.handleRedirectPath(e1);
               }
             });
   }
 }
Beispiel #3
0
 /**
  * Starts an authorization process.
  *
  * <p>This starts an authorization process to request an accesstoken to access protected
  * information within the process scope.
  *
  * <p>The authorization process ends with the {@link OAuthProcess#authorized() authorized()}
  * signal which signals the obtained token.
  *
  * <p>
  *
  * <p><i><b>Note: </b>To be able to use a popup (instead of a page redirect), you should connect
  * this method directly to an, since popup windows are blocked in most web browsers unless they
  * are the direct consequence of an event. </i>
  */
 public void startAuthorize() {
   WApplication app = WApplication.getInstance();
   if (!app.getEnvironment().hasJavaScript()) {
     this.startInternalPath_ = app.getInternalPath();
     app.redirect(this.getAuthorizeUrl());
   } else {
     this.redirectEndpoint_.getUrl();
   }
 }
Beispiel #4
0
 private void handleToken(Exception err, HttpMessage response) {
   if (err == null) {
     this.doParseTokenResponse(response);
   } else {
     logger.error(
         new StringWriter().append("handleToken(): ").append(err.getMessage()).toString());
     this.setError(new WString(err.getMessage()));
   }
   WApplication app = WApplication.getInstance();
   if (app.getEnvironment().hasAjax()) {
   } else {
     this.onOAuthDone();
     app.redirect(app.url(this.startInternalPath_));
   }
 }
 DomElement createDomElement(WApplication app) {
   boolean withIds = !app.getEnvironment().agentIsSpiderBot();
   DomElement table = DomElement.createNew(this.getDomElementType());
   this.setId(table, app);
   DomElement thead = null;
   if (this.headerRowCount_ != 0) {
     thead = DomElement.createNew(DomElementType.DomElement_THEAD);
     if (withIds) {
       thead.setId(this.getId() + "th");
     }
   }
   DomElement tbody = DomElement.createNew(DomElementType.DomElement_TBODY);
   if (withIds) {
     tbody.setId(this.getId() + "tb");
   }
   for (int col = 0; col < this.columns_.size(); ++col) {
     DomElement c = DomElement.createNew(DomElementType.DomElement_COL);
     if (withIds) {
       c.setId(this.columns_.get(col).getId());
     }
     this.columns_.get(col).updateDom(c, true);
     table.addChild(c);
   }
   this.flags_.clear(BIT_COLUMNS_CHANGED);
   for (int row = 0; row < (int) this.getRowCount(); ++row) {
     for (int col = 0; col < (int) this.getColumnCount(); ++col) {
       this.itemAt(row, col).overSpanned = false;
     }
   }
   for (int row = 0; row < (int) this.getRowCount(); ++row) {
     DomElement tr = this.createRow(row, withIds, app);
     if (row < (int) this.headerRowCount_) {
       thead.addChild(tr);
     } else {
       tbody.addChild(tr);
     }
   }
   this.rowsAdded_ = 0;
   if (thead != null) {
     table.addChild(thead);
   }
   table.addChild(tbody);
   this.updateDom(table, true);
   this.flags_.clear(BIT_GRID_CHANGED);
   ;
   this.rowsChanged_ = null;
   return table;
 }
Beispiel #6
0
 DomElement createDomElement(WApplication app) {
   DomElement result = null;
   if (this.isInLayout()) {
     this.setJavaScriptMember(WT_RESIZE_JS, "function() {}");
   }
   if (app.getEnvironment().agentIsIElt(9)
       || app.getEnvironment().getAgent() == WEnvironment.UserAgent.MobileWebKitAndroid) {
     result = DomElement.createNew(DomElementType.DomElement_DIV);
     if (this.alternative_ != null) {
       result.addChild(this.alternative_.createSDomElement(app));
     }
   } else {
     DomElement media = this.createMediaDomElement();
     DomElement wrap = null;
     if (this.isInLayout()) {
       media.setProperty(Property.PropertyStylePosition, "absolute");
       media.setProperty(Property.PropertyStyleLeft, "0");
       media.setProperty(Property.PropertyStyleRight, "0");
       wrap = DomElement.createNew(DomElementType.DomElement_DIV);
       wrap.setProperty(Property.PropertyStylePosition, "relative");
     }
     result = wrap != null ? wrap : media;
     if (wrap != null) {
       this.mediaId_ = this.getId() + "_media";
       media.setId(this.mediaId_);
     } else {
       this.mediaId_ = this.getId();
     }
     this.updateMediaDom(media, true);
     for (int i = 0; i < this.sources_.size(); ++i) {
       DomElement src = DomElement.createNew(DomElementType.DomElement_SOURCE);
       src.setId(this.mediaId_ + "s" + String.valueOf(i));
       this.renderSource(src, this.sources_.get(i), i + 1 >= this.sources_.size());
       media.addChild(src);
     }
     this.sourcesRendered_ = this.sources_.size();
     this.sourcesChanged_ = false;
     if (wrap != null) {
       wrap.addChild(media);
     }
   }
   if (this.isInLayout()) {
     StringWriter ss = new StringWriter();
     ss.append("function(self, w, h) {");
     if (this.mediaId_.length() != 0) {
       ss.append(
           "v="
               + this.getJsMediaRef()
               + ";if(v){v.setAttribute('width', w);v.setAttribute('height', h);}");
     }
     if (this.alternative_ != null) {
       ss.append("a=" + this.alternative_.getJsRef() + ";if(a && a.")
           .append(WT_RESIZE_JS)
           .append(")a.")
           .append(WT_RESIZE_JS)
           .append("(a, w, h);");
     }
     ss.append("}");
     this.setJavaScriptMember(WT_RESIZE_JS, ss.toString());
   }
   this.setId(result, app);
   this.updateDom(result, true);
   if (this.isInLayout()) {
     result.setEvent(PLAYBACKSTARTED_SIGNAL, "");
     result.setEvent(PLAYBACKPAUSED_SIGNAL, "");
     result.setEvent(ENDED_SIGNAL, "");
     result.setEvent(TIMEUPDATED_SIGNAL, "");
     result.setEvent(VOLUMECHANGED_SIGNAL, "");
   }
   this.setJavaScriptMember("mediaId", "'" + this.mediaId_ + "'");
   return result;
 }