com.alibaba.dubbo.registry.common.domain.User Java Examples

The following examples show how to use com.alibaba.dubbo.registry.common.domain.User. 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: Logs.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public boolean change(Map<String, Object> context) throws Exception {
    String contextLevel = (String)context.get("level");
    if (contextLevel == null || contextLevel.length() == 0) {
        context.put("message", getMessage("MissRequestParameters", "level"));
        return false;
    }
    if (! User.ROOT.equals(role)) {
       context.put("message", getMessage("HaveNoRootPrivilege"));
        return false;
    }
    Level level = Level.valueOf(contextLevel);
    if (level != LoggerFactory.getLevel()) {
        LoggerFactory.setLevel(level);
    }
    context.put("redirect", "/sysinfo/logs");
    return true;
}
 
Example #2
Source File: Logs.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public boolean change(Map<String, Object> context) throws Exception {
    String contextLevel = (String)context.get("level");
    if (contextLevel == null || contextLevel.length() == 0) {
        context.put("message", getMessage("MissRequestParameters", "level"));
        return false;
    }
    if (! User.ROOT.equals(role)) {
       context.put("message", getMessage("HaveNoRootPrivilege"));
        return false;
    }
    Level level = Level.valueOf(contextLevel);
    if (level != LoggerFactory.getLevel()) {
        LoggerFactory.setLevel(level);
    }
    context.put("redirect", "/sysinfo/logs");
    return true;
}
 
Example #3
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private User loginByBase(String authorization) {
    authorization = Coder.decodeBase64(authorization);
    int i = authorization.indexOf(':');
    String username = authorization.substring(0, i);
    if (username != null && username.length() > 0) {
        String password = authorization.substring(i + 1);
        if (password != null && password.length() > 0) {
            String passwordDigest = Coder.encodeMd5(username + ":" + REALM + ":" + password);
            User user = getUser(username);
            if (user != null) {
                String pwd = user.getPassword();
                if (pwd != null && pwd.length() > 0) {
                    if (passwordDigest.equals(pwd)) {
                        return user;
                    }
                }
            }
        }
    }
    return null;
}
 
Example #4
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 #5
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 #6
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private User loginByBase(String authorization) {
    authorization = Coder.decodeBase64(authorization);
    int i = authorization.indexOf(':');
    String username = authorization.substring(0, i);
    if (username != null && username.length() > 0) {
        String password = authorization.substring(i + 1);
        if (password != null && password.length() > 0) {
            String passwordDigest = Coder.encodeMd5(username + ":" + REALM + ":" + password);
            User user = getUser(username);
            if (user != null) {
                String pwd = user.getPassword();
                if (pwd != null && pwd.length() > 0) {
                    if (passwordDigest.equals(pwd)) {
                        return user;
                    }
                }
            }
        }
    }
    return null;
}
 
Example #7
Source File: Tool.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public boolean checkUrl(User user,String uri){
    return true;
    /*if(!User.ROOT.equals(user.getRole())){
        List<String> disabledSysinfo = new ArrayList<String>();
        List<String> disabledSysmanage = new ArrayList<String>();
        Map<String, Boolean> features = daoCache.getFeatures();
        if (features.size() > 0){
            for(Entry<String,Boolean> feature : features.entrySet()){
                if(feature.getKey().startsWith("Sysinfo") && !feature.getValue()){
                    disabledSysinfo.add(feature.getKey().replace(".", "/").toLowerCase());
                }else if(feature.getKey().startsWith("Sysmanage") && !feature.getValue()){
                    disabledSysmanage.add(feature.getKey().replace(".", "/").toLowerCase());
                }
            }
            if(uri.startsWith("/sysinfo")){
                for(String disabled : disabledSysinfo){
                    if (uri.contains(disabled)){
                        return false;
                    }
                }
            }
            if(uri.startsWith("/sysmanage")){
                for(String disabled : disabledSysmanage){
                    if (uri.contains(disabled)){
                        return false;
                    }
                }
            }
        }else{
            return true;
        }
    }
    return true;*/
}
 
Example #8
Source File: ServicePrivilegeCheckValve.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private void invokeCheckServicePrivilege(User user) {
   	TurbineRunData rundata = getTurbineRunData(request);
   	HttpSession session = request.getSession();
   	
   	@SuppressWarnings("unchecked")
   	Map<String, String[]> requestMapping = request.getParameterMap();
   	
   	//记录上次操作到请求中
	String returnURL = "";
	if(session.getAttribute("returnURL")==null){
		returnURL = request.getContextPath();
	}else{
		returnURL = (String)session.getAttribute("returnURL");
	}
   	
   	if(requestMapping.get("service").length>0){
   		String service = ((String[]) requestMapping.get("service"))[0];
   		String method = "index";
   		if(requestMapping.get("_method").length>0){
   			method = requestMapping.get("_method")[0];
   		}
   		
   		boolean exclude = "index".equals(method) || "show".equals(method);
   		if(!exclude){
          	 	if (user != null && !user.hasServicePrivilege(service)) {
          	 		request.setAttribute("returnURL",returnURL);
          	 		redirectToNoRight(rundata);
               }
   		}
   	}
   	String type = requestMapping.get("_type").length == 0 ? null : requestMapping.get("_type")[0];
   	if(!"noServicePrivilege".equals(type)){
   		session.setAttribute("returnURL", request.getRequestURI());
   	}
   	return;
}
 
Example #9
Source File: Infos.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public boolean update(Map<String, Object> context) {
    User user = new User();
    user.setId(currentUser.getId());
    user.setUsername(currentUser.getUsername());
    user.setOperatorAddress(operatorAddress);
    user.setName((String) context.get("name"));
    user.setDepartment((String) context.get("department"));
    user.setEmail((String) context.get("email"));
    user.setPhone((String) context.get("phone"));
    user.setAlitalk((String) context.get("alitalk"));
    user.setLocale((String) context.get("locale"));
    userDAO.modifyUser(user);
    context.put("redirect", "../" + getClass().getSimpleName().toLowerCase());
    return true;
}
 
Example #10
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private User loginByDigest(String value) throws IOException {
    Map<String, String> params = parseParameters(value);
    String username = params.get("username");
    if (username != null && username.length() > 0) {
        String passwordDigest = params.get("response");
        if (passwordDigest != null && passwordDigest.length() > 0) {
            User user = getUser(username);
            if (user != null) {
                String pwd = user.getPassword();
                // 本地User,密码本地
                if (pwd != null && pwd.length() > 0) {
                    String uri = params.get("uri");
                    String nonce = params.get("nonce");
                    String nc = params.get("nc");
                    String cnonce = params.get("cnonce");
                    String qop = params.get("qop");
                    String method = request.getMethod();
                    String a1 = pwd;

                    String a2 = "auth-int".equals(qop)
                        ? Coder.encodeMd5(method + ":" + uri + ":" + Coder.encodeMd5(readToBytes(request.getInputStream())))
                        : Coder.encodeMd5(method + ":" + uri);
                    String digest = "auth".equals(qop) || "auth-int".equals(qop)
                        ? Coder.encodeMd5(a1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + a2)
                        : Coder.encodeMd5(a1 + ":" + nonce + ":" + a2);
                    if (digest.equals(passwordDigest)) {
                        return user;
                    }
                }
            }
        }
    }
    return null;
}
 
Example #11
Source File: Passwds.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public boolean create(Map<String, Object> context) {
    User user = new User();
    user.setOperator(operator);
    user.setOperatorAddress(operatorAddress);
    user.setPassword((String) context.get("newPassword"));
    user.setUsername(operator);

    boolean sucess = userDAO.updatePassword(user, (String) context.get("oldPassword"));
    if (!sucess)
        context.put("message", getMessage("passwd.oldwrong"));
    return sucess;
}
 
Example #12
Source File: ServicePrivilegeCheckValve.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void invokeCheckServicePrivilege(User user) {
   	TurbineRunData rundata = getTurbineRunData(request);
   	HttpSession session = request.getSession();
   	
   	@SuppressWarnings("unchecked")
   	Map<String, String[]> requestMapping = request.getParameterMap();
   	
   	//记录上次操作到请求中
	String returnURL = "";
	if(session.getAttribute("returnURL")==null){
		returnURL = request.getContextPath();
	}else{
		returnURL = (String)session.getAttribute("returnURL");
	}
   	
   	if(requestMapping.get("service").length>0){
   		String service = ((String[]) requestMapping.get("service"))[0];
   		String method = "index";
   		if(requestMapping.get("_method").length>0){
   			method = requestMapping.get("_method")[0];
   		}
   		
   		boolean exclude = "index".equals(method) || "show".equals(method);
   		if(!exclude){
          	 	if (user != null && !user.hasServicePrivilege(service)) {
          	 		request.setAttribute("returnURL",returnURL);
          	 		redirectToNoRight(rundata);
               }
   		}
   	}
   	String type = requestMapping.get("_type").length == 0 ? null : requestMapping.get("_type")[0];
   	if(!"noServicePrivilege".equals(type)){
   		session.setAttribute("returnURL", request.getRequestURI());
   	}
   	return;
}
 
Example #13
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private User loginByDigest(String value) throws IOException {
    Map<String, String> params = parseParameters(value);
    String username = params.get("username");
    if (username != null && username.length() > 0) {
        String passwordDigest = params.get("response");
        if (passwordDigest != null && passwordDigest.length() > 0) {
            User user = getUser(username);
            if (user != null) {
                String pwd = user.getPassword();
                // 本地User,密码本地
                if (pwd != null && pwd.length() > 0) {
                    String uri = params.get("uri");
                    String nonce = params.get("nonce");
                    String nc = params.get("nc");
                    String cnonce = params.get("cnonce");
                    String qop = params.get("qop");
                    String method = request.getMethod();
                    String a1 = pwd;

                    String a2 = "auth-int".equals(qop)
                        ? Coder.encodeMd5(method + ":" + uri + ":" + Coder.encodeMd5(readToBytes(request.getInputStream())))
                        : Coder.encodeMd5(method + ":" + uri);
                    String digest = "auth".equals(qop) || "auth-int".equals(qop)
                        ? Coder.encodeMd5(a1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + a2)
                        : Coder.encodeMd5(a1 + ":" + nonce + ":" + a2);
                    if (digest.equals(passwordDigest)) {
                        return user;
                    }
                }
            }
        }
    }
    return null;
}
 
Example #14
Source File: Infos.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public boolean update(Map<String, Object> context) {
    User user = new User();
    user.setId(currentUser.getId());
    user.setUsername(currentUser.getUsername());
    user.setOperatorAddress(operatorAddress);
    user.setName((String) context.get("name"));
    user.setDepartment((String) context.get("department"));
    user.setEmail((String) context.get("email"));
    user.setPhone((String) context.get("phone"));
    user.setAlitalk((String) context.get("alitalk"));
    user.setLocale((String) context.get("locale"));
    userDAO.modifyUser(user);
    context.put("redirect", "../" + getClass().getSimpleName().toLowerCase());
    return true;
}
 
Example #15
Source File: Infos.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public boolean update(Map<String, Object> context) {
    User user = new User();
    user.setId(currentUser.getId());
    user.setUsername(currentUser.getUsername());
    user.setOperatorAddress(operatorAddress);
    user.setName((String) context.get("name"));
    user.setDepartment((String) context.get("department"));
    user.setEmail((String) context.get("email"));
    user.setPhone((String) context.get("phone"));
    user.setAlitalk((String) context.get("alitalk"));
    user.setLocale((String) context.get("locale"));
    userDAO.modifyUser(user);
    context.put("redirect", "../" + getClass().getSimpleName().toLowerCase());
    return true;
}
 
Example #16
Source File: Passwds.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public boolean create(Map<String, Object> context) {
    User user = new User();
    user.setOperator(operator);
    user.setOperatorAddress(operatorAddress);
    user.setPassword((String) context.get("newPassword"));
    user.setUsername(operator);

    boolean sucess = userDAO.updatePassword(user, (String) context.get("oldPassword"));
    if (!sucess)
        context.put("message", getMessage("passwd.oldwrong"));
    return sucess;
}
 
Example #17
Source File: UserServiceImpl.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public User findById(Long id) {
    // TODO Auto-generated method stub
    return null;
}
 
Example #18
Source File: DubboUser.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static final void setCurrentUser(User user) {
    userHolder.set(user);
}
 
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: Infos.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void index(Map<String, Object> context) {
    User user = userDAO.findById(currentUser.getId());
    context.put("user", user);
}
 
Example #21
Source File: AuthorizationValve.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
private User getUser(String username) {
	return userService.findUser(username);
}
 
Example #22
Source File: DubboUser.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public static final void setCurrentUser(User user) {
    userHolder.set(user);
}
 
Example #23
Source File: UserServiceImpl.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Map<String, User> findAllUsersMap() {
    // TODO Auto-generated method stub
    return null;
}
 
Example #24
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private User getUser(String username) {
	return userService.findUser(username);
}
 
Example #25
Source File: AuthorizationValve.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private User getUser(String username) {
	return userService.findUser(username);
}
 
Example #26
Source File: UserServiceImpl.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public Map<String, User> findAllUsersMap() {
    // TODO Auto-generated method stub
    return null;
}
 
Example #27
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 #28
Source File: Configs.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public boolean update(Map<String, Object> context) {
    @SuppressWarnings("unchecked")
    Map<String, String[]> all = request.getParameterMap();;
    if (all != null && all.size() > 0) {
        if (! User.ROOT.equals(currentUser.getRole())) {
            context.put("message", getMessage("HaveNoRootPrivilege"));
            return false;
        }
        List<Config> configs = new ArrayList<Config>();
        for (Map.Entry<String, String[]> entry : all.entrySet()) {
            String key = entry.getKey();
            String[] values = entry.getValue();
            if (key != null && key.length() > 0 && ! key.startsWith("_")) {
                String value = "";
                if (values != null && values.length > 0
                        && values[0] != null && values[0].length() > 0) {
                    value = values[0];
                }
                Config config = new Config();
                config.setKey(key);
                config.setUsername(currentUser.getUsername());
                config.setOperatorAddress((String) context.get("operatorAddress"));
                config.setValue(value);
                configs.add(config);
            }
        }
        if (configs.size() > 0) {
            configDAO.update(configs);
            
            Set<String> usernames = new HashSet<String>();
            usernames.add(currentUser.getName());
            
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("configs", configs);
        }
        return true;
    } else {
        context.put("message", getMessage("MissRequestParameters", "configKey,configValue"));
        return false;
    }
}
 
Example #29
Source File: UserServiceImpl.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public User findById(Long id) {
    // TODO Auto-generated method stub
    return null;
}
 
Example #30
Source File: DubboUser.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static final void setCurrentUser(User user) {
    userHolder.set(user);
}