com.alibaba.dubbo.governance.web.util.WebConstants Java Examples

The following examples show how to use com.alibaba.dubbo.governance.web.util.WebConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Shell.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void execute(Map<String,Object> context) throws Exception {
    if(context.get(WebConstants.CURRENT_USER_KEY)!=null){
           User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
           currentUser = user;
           operator = user.getUsername();
           role = user.getRole();
           context.put(WebConstants.CURRENT_USER_KEY, user);
       }
       operatorAddress = (String)context.get("request.remoteHost");
       context.put("operator", operator);
       context.put("operatorAddress", operatorAddress);
	try {
		String message = doExecute(context);
		context.put("message", "OK: " + filterERROR(message));
	} catch (Throwable t) {
       	context.put("message", "ERROR: " + filterOK(t.getMessage()));
       }
	PrintWriter writer = response.getWriter();
	writer.print(context.get("message"));
	writer.flush();
}
 
Example #2
Source File: Menu.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void execute(HttpSession session, Context context, CookieParser parser) {
    
    User user = (User) session.getAttribute(WebConstants.CURRENT_USER_KEY);
    if (user != null) context.put("operator", user.getUsername());
    
    RootContextPath rootContextPath = new RootContextPath(request.getContextPath());
    context.put("rootContextPath", rootContextPath);
    if (! context.containsKey("bucLogoutAddress")) {
    	context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
    }
    if (! context.containsKey("helpUrl")) {
    	context.put("helpUrl", "https://github.com/dangdangdotcom/dubbox/wiki");
    }
    context.put(WebConstants.CURRENT_USER_KEY, user);
    context.put("language", parser.getString("locale"));
    context.put("registryServerSync", registryServerSync);
}
 
Example #3
Source File: Menu.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void execute(HttpSession session, Context context, CookieParser parser) {
    
    User user = (User) session.getAttribute(WebConstants.CURRENT_USER_KEY);
    if (user != null) context.put("operator", user.getUsername());
    
    RootContextPath rootContextPath = new RootContextPath(request.getContextPath());
    context.put("rootContextPath", rootContextPath);
    if (! context.containsKey("bucLogoutAddress")) {
    	context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
    }
    if (! context.containsKey("helpUrl")) {
    	context.put("helpUrl", "https://github.com/dangdangdotcom/dubbox/wiki");
    }
    context.put(WebConstants.CURRENT_USER_KEY, user);
    context.put("language", parser.getString("locale"));
    context.put("registryServerSync", registryServerSync);
}
 
Example #4
Source File: Shell.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void execute(Map<String,Object> context) throws Exception {
    if(context.get(WebConstants.CURRENT_USER_KEY)!=null){
           User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
           currentUser = user;
           operator = user.getUsername();
           role = user.getRole();
           context.put(WebConstants.CURRENT_USER_KEY, user);
       }
       operatorAddress = (String)context.get("request.remoteHost");
       context.put("operator", operator);
       context.put("operatorAddress", operatorAddress);
	try {
		String message = doExecute(context);
		context.put("message", "OK: " + filterERROR(message));
	} catch (Throwable t) {
       	context.put("message", "ERROR: " + filterOK(t.getMessage()));
       }
	PrintWriter writer = response.getWriter();
	writer.print(context.get("message"));
	writer.flush();
}
 
Example #5
Source File: Shell.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void execute(Map<String,Object> context) throws Exception {
    if(context.get(WebConstants.CURRENT_USER_KEY)!=null){
           User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
           currentUser = user;
           operator = user.getUsername();
           role = user.getRole();
           context.put(WebConstants.CURRENT_USER_KEY, user);
       }
       operatorAddress = (String)context.get("request.remoteHost");
       context.put("operator", operator);
       context.put("operatorAddress", operatorAddress);
	try {
		String message = doExecute(context);
		context.put("message", "OK: " + filterERROR(message));
	} catch (Throwable t) {
       	context.put("message", "ERROR: " + filterOK(t.getMessage()));
       }
	PrintWriter writer = response.getWriter();
	writer.print(context.get("message"));
	writer.flush();
}
 
Example #6
Source File: Menu.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void execute(HttpSession session, Context context, CookieParser parser) {
    
    User user = (User) session.getAttribute(WebConstants.CURRENT_USER_KEY);
    if (user != null) context.put("operator", user.getUsername());
    
    RootContextPath rootContextPath = new RootContextPath(request.getContextPath());
    context.put("rootContextPath", rootContextPath);
    if (! context.containsKey("bucLogoutAddress")) {
    	context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
    }
    if (! context.containsKey("helpUrl")) {
    	context.put("helpUrl", "http://code.alibabatech.com/wiki/display/dubbo");
    }
    context.put(WebConstants.CURRENT_USER_KEY, user);
    context.put("language", parser.getString("locale"));
    context.put("registryServerSync", registryServerSync);
}
 
Example #7
Source File: Menu.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void execute(HttpSession session, Context context, CookieParser parser) {
    
    User user = (User) session.getAttribute(WebConstants.CURRENT_USER_KEY);
    if (user != null) context.put("operator", user.getUsername());
    
    RootContextPath rootContextPath = new RootContextPath(request.getContextPath());
    context.put("rootContextPath", rootContextPath);
    if (! context.containsKey("bucLogoutAddress")) {
    	context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
    }
    if (! context.containsKey("helpUrl")) {
    	context.put("helpUrl", "http://code.alibabatech.com/wiki/display/dubbo");
    }
    context.put(WebConstants.CURRENT_USER_KEY, user);
    context.put("language", parser.getString("locale"));
    context.put("registryServerSync", registryServerSync);
}
 
Example #8
Source File: Shell.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void execute(Map<String,Object> context) throws Exception {
    if(context.get(WebConstants.CURRENT_USER_KEY)!=null){
           User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
           currentUser = user;
           operator = user.getUsername();
           role = user.getRole();
           context.put(WebConstants.CURRENT_USER_KEY, user);
       }
       operatorAddress = (String)context.get("request.remoteHost");
       context.put("operator", operator);
       context.put("operatorAddress", operatorAddress);
	try {
		String message = doExecute(context);
		context.put("message", "OK: " + filterERROR(message));
	} catch (Throwable t) {
       	context.put("message", "ERROR: " + filterOK(t.getMessage()));
       }
	PrintWriter writer = response.getWriter();
	writer.print(context.get("message"));
	writer.flush();
}
 
Example #9
Source File: Menu.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void execute(HttpSession session, Context context, CookieParser parser) {
    
    User user = (User) session.getAttribute(WebConstants.CURRENT_USER_KEY);
    if (user != null) context.put("operator", user.getUsername());
    
    RootContextPath rootContextPath = new RootContextPath(request.getContextPath());
    context.put("rootContextPath", rootContextPath);
    if (! context.containsKey("bucLogoutAddress")) {
    	context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
    }
    if (! context.containsKey("helpUrl")) {
    	context.put("helpUrl", "http://code.alibabatech.com/wiki/display/dubbo");
    }
    context.put(WebConstants.CURRENT_USER_KEY, user);
    context.put("language", parser.getString("locale"));
    context.put("registryServerSync", registryServerSync);
}
 
Example #10
Source File: Shell.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void execute(Map<String,Object> context) throws Exception {
    if(context.get(WebConstants.CURRENT_USER_KEY)!=null){
           User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
           currentUser = user;
           operator = user.getUsername();
           role = user.getRole();
           context.put(WebConstants.CURRENT_USER_KEY, user);
       }
       operatorAddress = (String)context.get("request.remoteHost");
       context.put("operator", operator);
       context.put("operatorAddress", operatorAddress);
	try {
		String message = doExecute(context);
		context.put("message", "OK: " + filterERROR(message));
	} catch (Throwable t) {
       	context.put("message", "ERROR: " + filterOK(t.getMessage()));
       }
	PrintWriter writer = response.getWriter();
	writer.print(context.get("message"));
	writer.flush();
}
 
Example #11
Source File: ServicePrivilegeCheckValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
    User user = (User) request.getSession().getAttribute(WebConstants.CURRENT_USER_KEY);
    invokeCheckServicePrivilege(user);
    pipelineContext.invokeNext();
}
 
Example #12
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
      if (logger.isInfoEnabled()) {
          logger.info("AuthorizationValve of uri: " + request.getRequestURI());
      }
      String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (contextPath != null && contextPath.length() > 0  && ! "/".equals(contextPath)) {
    uri = uri.substring(contextPath.length());
}
      if (uri.equals(logout)) {
    if (! isLogout()) {
        setLogout(true);
  		    showLoginForm();
    } else {
        setLogout(false);
        response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
    }
          return;
}
      //FIXME
      if(! uri.startsWith("/status/")){
      	User user = null;
          String authType = null;
          String authorization = request.getHeader("Authorization");
          if (authorization != null && authorization.length() > 0) {
              int i = authorization.indexOf(' ');
              if (i >= 0) {
                  authType = authorization.substring(0, i);
                  String authPrincipal = authorization.substring(i + 1);
                  if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByBase(authPrincipal);
                  } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByDigest(authPrincipal);
                  }
              }
          }
          if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
              showLoginForm();
              pipelineContext.breakPipeline(1);
          }
          if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
              request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
              pipelineContext.invokeNext();
          }
      }else{
          pipelineContext.invokeNext();
      }
  }
 
Example #13
Source File: ServicePrivilegeCheckValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
    User user = (User) request.getSession().getAttribute(WebConstants.CURRENT_USER_KEY);
    invokeCheckServicePrivilege(user);
    pipelineContext.invokeNext();
}
 
Example #14
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
      if (logger.isInfoEnabled()) {
          logger.info("AuthorizationValve of uri: " + request.getRequestURI());
      }
      String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (contextPath != null && contextPath.length() > 0  && ! "/".equals(contextPath)) {
    uri = uri.substring(contextPath.length());
}
      if (uri.equals(logout)) {
    if (! isLogout()) {
        setLogout(true);
  		    showLoginForm();
    } else {
        setLogout(false);
        response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
    }
          return;
}
      //FIXME
      if(! uri.startsWith("/status/")){
      	User user = null;
          String authType = null;
          String authorization = request.getHeader("Authorization");
          if (authorization != null && authorization.length() > 0) {
              int i = authorization.indexOf(' ');
              if (i >= 0) {
                  authType = authorization.substring(0, i);
                  String authPrincipal = authorization.substring(i + 1);
                  if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByBase(authPrincipal);
                  } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByDigest(authPrincipal);
                  }
              }
          }
          if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
              showLoginForm();
              pipelineContext.breakPipeline(1);
          }
          if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
              request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
              pipelineContext.invokeNext();
          }
      }else{
          pipelineContext.invokeNext();
      }
  }
 
Example #15
Source File: ServicePrivilegeCheckValve.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
    User user = (User) request.getSession().getAttribute(WebConstants.CURRENT_USER_KEY);
    invokeCheckServicePrivilege(user);
    pipelineContext.invokeNext();
}
 
Example #16
Source File: AuthorizationValve.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
      if (logger.isInfoEnabled()) {
          logger.info("AuthorizationValve of uri: " + request.getRequestURI());
      }
      String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (contextPath != null && contextPath.length() > 0  && ! "/".equals(contextPath)) {
    uri = uri.substring(contextPath.length());
}
      if (uri.equals(logout)) {
    if (! isLogout()) {
        setLogout(true);
  		    showLoginForm();
    } else {
        setLogout(false);
        response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
    }
          return;
}
      //FIXME
      if(! uri.startsWith("/status/")){
      	User user = null;
          String authType = null;
          String authorization = request.getHeader("Authorization");
          if (authorization != null && authorization.length() > 0) {
              int i = authorization.indexOf(' ');
              if (i >= 0) {
                  authType = authorization.substring(0, i);
                  String authPrincipal = authorization.substring(i + 1);
                  if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByBase(authPrincipal);
                  } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByDigest(authPrincipal);
                  }
              }
          }
          if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
              showLoginForm();
              pipelineContext.breakPipeline(1);
          }
          if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
              request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
              pipelineContext.invokeNext();
          }
      }else{
          pipelineContext.invokeNext();
      }
  }
 
Example #17
Source File: ServicePrivilegeCheckValve.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
    User user = (User) request.getSession().getAttribute(WebConstants.CURRENT_USER_KEY);
    invokeCheckServicePrivilege(user);
    pipelineContext.invokeNext();
}
 
Example #18
Source File: AuthorizationValve.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
      if (logger.isInfoEnabled()) {
          logger.info("AuthorizationValve of uri: " + request.getRequestURI());
      }
      String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (contextPath != null && contextPath.length() > 0  && ! "/".equals(contextPath)) {
    uri = uri.substring(contextPath.length());
}
      if (uri.equals(logout)) {
    if (! isLogout()) {
        setLogout(true);
  		    showLoginForm();
    } else {
        setLogout(false);
        response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
    }
          return;
}
      //FIXME
      if(! uri.startsWith("/status/")){
      	User user = null;
          String authType = null;
          String authorization = request.getHeader("Authorization");
          if (authorization != null && authorization.length() > 0) {
              int i = authorization.indexOf(' ');
              if (i >= 0) {
                  authType = authorization.substring(0, i);
                  String authPrincipal = authorization.substring(i + 1);
                  if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByBase(authPrincipal);
                  } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByDigest(authPrincipal);
                  }
              }
          }
          if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
              showLoginForm();
              pipelineContext.breakPipeline(1);
          }
          if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
              request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
              pipelineContext.invokeNext();
          }
      }else{
          pipelineContext.invokeNext();
      }
  }
 
Example #19
Source File: ServicePrivilegeCheckValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
    User user = (User) request.getSession().getAttribute(WebConstants.CURRENT_USER_KEY);
    invokeCheckServicePrivilege(user);
    pipelineContext.invokeNext();
}
 
Example #20
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
      if (logger.isInfoEnabled()) {
          logger.info("AuthorizationValve of uri: " + request.getRequestURI());
      }
      String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (contextPath != null && contextPath.length() > 0  && ! "/".equals(contextPath)) {
    uri = uri.substring(contextPath.length());
}
      if (uri.equals(logout)) {
    if (! isLogout()) {
        setLogout(true);
  		    showLoginForm();
    } else {
        setLogout(false);
        response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
    }
          return;
}
      //FIXME
      if(! uri.startsWith("/status/")){
      	User user = null;
          String authType = null;
          String authorization = request.getHeader("Authorization");
          if (authorization != null && authorization.length() > 0) {
              int i = authorization.indexOf(' ');
              if (i >= 0) {
                  authType = authorization.substring(0, i);
                  String authPrincipal = authorization.substring(i + 1);
                  if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByBase(authPrincipal);
                  } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByDigest(authPrincipal);
                  }
              }
          }
          if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
              showLoginForm();
              pipelineContext.breakPipeline(1);
          }
          if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
              request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
              pipelineContext.invokeNext();
          }
      }else{
          pipelineContext.invokeNext();
      }
  }