public void execute(Map<String, Object> context) throws Exception { Result result = new Result(); if (request.getParameter("url") != null) { url = URL.valueOf(URL.decode(request.getParameter("url"))); } if (context.get(WebConstants.CURRENT_USER_KEY) != null) { User user = (User) context.get(WebConstants.CURRENT_USER_KEY); currentUser = user; operator = user.getUsername(); role = user.getRoles(); context.put(WebConstants.CURRENT_USER_KEY, user); } operatorAddress = (String) context.get("clientid"); if (operatorAddress == null || operatorAddress.isEmpty()) { operatorAddress = (String) context.get("request.remoteHost"); } context.put("operator", operator); context.put("operatorAddress", operatorAddress); String jsonResult = null; try { result = doExecute(context); result.setStatus("OK"); } catch (IllegalArgumentException t) { result.setStatus("ERROR"); result.setCode(3); result.setMessage(t.getMessage()); } // catch (InvalidRequestException t) { // result.setStatus("ERROR"); // result.setCode(2); // result.setMessage(t.getMessage()); // } catch (Throwable t) { result.setStatus("ERROR"); result.setCode(1); result.setMessage(t.getMessage()); } response.setContentType("application/javascript"); ServletOutputStream os = response.getOutputStream(); try { jsonResult = JSON.toJSONString(result); os.print(jsonResult); } catch (Exception e) { response.setStatus(500); os.print(e.getMessage()); } finally { os.flush(); } }
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); }
public User findUser(String username) { if ("guest".equals(username)) { User user = new User(); user.setUsername(username); user.setPassword(Coder.encodeMd5(username + ":" + User.REALM + ":" + guestPassword)); user.setName(username); user.setRole(User.GUEST); user.setEnabled(true); user.setLocale("zh"); user.setServicePrivilege(""); return user; } else if ("root".equals(username)) { User user = new User(); user.setUsername(username); user.setPassword(Coder.encodeMd5(username + ":" + User.REALM + ":" + rootPassword)); user.setName(username); user.setRole(User.ROOT); user.setEnabled(true); user.setLocale("zh"); user.setServicePrivilege("*"); return user; } return null; }