use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.
the class ApplicationsController method updateExtendAttr.
@ResponseBody
@RequestMapping(value = { "/updateExtendAttr" })
public Message updateExtendAttr(@ModelAttribute("application") Apps application, @ModelAttribute("extraAttrs") ExtraAttr extraAttr) {
if (extraAttr.getAttr() != null) {
String[] attributes = extraAttr.getAttr().split(",");
String[] attributeType = extraAttr.getType().split(",");
String[] attributeValue = extraAttr.getValue().split(",");
ExtraAttrs extraAttrs = new ExtraAttrs();
for (int i = 0; i < attributes.length; i++) {
extraAttrs.put(attributes[i], attributeType[i], attributeValue[i]);
}
application.setExtendAttr(extraAttrs.toJsonString());
}
if (appsService.updateExtendAttr(application)) {
return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS), MessageType.success);
} else {
return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error);
}
}
use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.
the class ExtendApiZentaoAdapter method authorize.
@Override
public ModelAndView authorize(ModelAndView modelAndView) {
Apps details = (Apps) app;
// extraAttrs from Applications
ExtraAttrs extraAttrs = null;
if (details.getIsExtendAttr() == 1) {
extraAttrs = new ExtraAttrs(details.getExtendAttr());
}
_logger.trace("Extra Attrs " + extraAttrs);
String code = details.getPrincipal();
String key = details.getCredentials();
String time = "" + Instant.now().getEpochSecond();
String token = DigestUtils.md5Hex(code + key + time);
_logger.debug("" + token);
String account = userInfo.getUsername();
String redirect_uri = details.getLoginUrl();
if (redirect_uri.indexOf("api.php?") < 0) {
if (redirect_uri.endsWith("/")) {
redirect_uri += String.format(login_url_template, account, code, time, token);
} else {
redirect_uri += "/" + String.format(login_url_template, account, code, time, token);
}
} else if (redirect_uri.endsWith("&")) {
redirect_uri += String.format(login_url_m_template, account, code, time, token);
} else {
redirect_uri += "&" + String.format(login_url_m_template, account, code, time, token);
}
_logger.debug("redirect_uri : " + redirect_uri);
modelAndView = new ModelAndView("authorize/redirect_sso_submit");
modelAndView.addObject("redirect_uri", redirect_uri);
return modelAndView;
}
use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.
the class ExtendApiCndnsApiMailAdapter method authorize.
@SuppressWarnings("unchecked")
@Override
public ModelAndView authorize(ModelAndView modelAndView) {
HttpsTrusts.beforeConnection();
Apps details = (Apps) app;
// extraAttrs from Applications
ExtraAttrs extraAttrs = null;
String action = "getWebMailUrl";
String domain = null;
if (details.getIsExtendAttr() == 1) {
extraAttrs = new ExtraAttrs(details.getExtendAttr());
if (extraAttrs.get("action") == null || extraAttrs.get("action").equalsIgnoreCase("getWebMailUrl")) {
action = "getWebMailUrl";
} else if (extraAttrs.get("action").equalsIgnoreCase("getDomailUrl")) {
action = "getDomailUrl";
domain = extraAttrs.get("domain");
}
}
String timestamp = "" + Instant.now().getEpochSecond();
String tokenMd5 = DigestUtils.md5Hex(details.getCredentials());
HashMap<String, Object> requestParamenter = new HashMap<String, Object>();
String redirect_uri = "";
if (action.equalsIgnoreCase("getDomailUrl")) {
String sign = DigestUtils.md5Hex(String.format(SIGN_STRING, details.getPrincipal(), timestamp, tokenMd5));
requestParamenter.put("domain", domain);
String responseBody = new HttpRequestAdapter().post(String.format(ADMIN_AUTHKEY_URI, details.getPrincipal(), sign, timestamp), requestParamenter);
HashMap<String, String> authKey = JsonUtils.gson2Object(responseBody, HashMap.class);
redirect_uri = authKey.get("adminUrl");
} else {
String sign = DigestUtils.md5Hex(String.format(SIGN_EMAIL_STRING, details.getPrincipal(), userInfo.getEmail(), timestamp, tokenMd5));
requestParamenter.put("email", userInfo.getWorkEmail());
String responseBody = new HttpRequestAdapter().post(String.format(AUTHKEY_URI, details.getPrincipal(), sign, timestamp), requestParamenter);
HashMap<String, String> authKey = JsonUtils.gson2Object(responseBody, HashMap.class);
redirect_uri = authKey.get("webmailUrl");
}
_logger.debug("redirect_uri : " + redirect_uri);
modelAndView.addObject("redirect_uri", redirect_uri);
return modelAndView;
}
use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.
the class ExtendApiTimestampSignAdapter method authorize.
@Override
public ModelAndView authorize(ModelAndView modelAndView) {
Apps details = (Apps) app;
String code = details.getPrincipal();
String key = details.getCredentials();
String timestamp = "" + Instant.now().getEpochSecond();
String token = DigestUtils.md5Hex(code + key + timestamp);
// extraAttrs from Applications
ExtraAttrs extraAttrs = null;
if (details.getIsExtendAttr() == 1) {
extraAttrs = new ExtraAttrs(details.getExtendAttr());
if (extraAttrs.get("sign") == null || extraAttrs.get("sign").equalsIgnoreCase("md5")) {
} else if (extraAttrs.get("sign").equalsIgnoreCase("sha") || extraAttrs.get("sign").equalsIgnoreCase("sha1")) {
token = DigestUtils.shaHex(code + key + timestamp);
} else if (extraAttrs.get("sign").equalsIgnoreCase("sha256")) {
token = DigestUtils.sha256Hex(code + key + timestamp);
} else if (extraAttrs.get("sign").equalsIgnoreCase("sha384")) {
token = DigestUtils.sha384Hex(code + key + timestamp);
} else if (extraAttrs.get("sign").equalsIgnoreCase("sha512")) {
token = DigestUtils.sha512Hex(code + key + timestamp);
}
}
_logger.debug("" + token);
String account = userInfo.getUsername();
String redirect_uri = String.format(details.getLoginUrl(), account, code, timestamp, token);
_logger.debug("redirect_uri : " + redirect_uri);
modelAndView.addObject("redirect_uri", redirect_uri);
return modelAndView;
}
use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.
the class ExtendApiQQExmailAdapter method authorize.
@Override
public ModelAndView authorize(ModelAndView modelAndView) {
HttpsTrusts.beforeConnection();
Apps details = (Apps) app;
// extraAttrs from Applications
ExtraAttrs extraAttrs = null;
if (details.getIsExtendAttr() == 1) {
extraAttrs = new ExtraAttrs(details.getExtendAttr());
}
_logger.debug("Extra Attrs " + extraAttrs);
String responseBody = new HttpRequestAdapter().get(String.format(TOKEN_URI, details.getPrincipal(), details.getCredentials()), null);
Token token = JsonUtils.gson2Object(responseBody, Token.class);
_logger.debug("token {}", token);
String authKeyBody = new HttpRequestAdapter().get(String.format(AUTHKEY_URI, token.getAccess_token(), userInfo.getUsername()), null);
LoginUrl loginUrl = JsonUtils.gson2Object(authKeyBody, LoginUrl.class);
_logger.debug("LoginUrl {} ", loginUrl);
modelAndView.addObject("redirect_uri", loginUrl.getLogin_url());
return modelAndView;
}
Aggregations