use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class AuthorizationValve method loginByBase.
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;
}
use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class AuthorizationValve method loginByDigest.
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();
// A valid user, validate password
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;
}
use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class Menu method execute.
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);
}
use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class UserServiceImpl method findUser.
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;
}
Aggregations