Browse Source

fix

feature/10.0
Lanlan 3 years ago
parent
commit
fd3364a299
  1. 59
      designer-base/src/main/java/com/fr/design/login/AbstractDesignerSSO.java

59
designer-base/src/main/java/com/fr/design/login/AbstractDesignerSSO.java

@ -2,21 +2,12 @@ package com.fr.design.login;
import com.fr.design.DesignerEnvManager;
import com.fr.design.actions.UpdateAction;
import com.fr.design.login.utils.DesignerLoginUtils;
import com.fr.design.os.impl.SupportOSImpl;
import com.fr.design.utils.BrowseUtils;
import com.fr.general.CloudCenter;
import com.fr.general.log.MessageFormatter;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.third.org.bouncycastle.util.encoders.Hex;
import java.awt.event.ActionEvent;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
* @author Lanlan
@ -25,30 +16,19 @@ import javax.crypto.spec.SecretKeySpec;
*/
public abstract class AbstractDesignerSSO extends UpdateAction {
private static final String PRODUCT_FINEREPORT = "product-finereport";
private static final String KEY = "i7hP48WAcuTrmxfN";
@Override
public void actionPerformed(ActionEvent event) {
String url = getJumpUrl();
if (!SupportOSImpl.DESIGNER_LOGIN.support()) {
BrowseUtils.browser(url);
return;
}
DesignerEnvManager manager = DesignerEnvManager.getEnvManager();
int uid = manager.getDesignerLoginUid();
if (uid > 0) {
String ssoUrl = CloudCenter.getInstance().acquireUrlByKind("designer.sso.api", "https://id.fanruan.com/api/app/?code={}&referrer={}");
try {
String code = generateLoginCode();
MessageFormatter.FormattingTuple tuple = MessageFormatter.arrayFormat(ssoUrl, new String[]{code, url});
BrowseUtils.browser(tuple.getMessage());
} catch (Exception e) {
String ssoUrl = DesignerLoginUtils.generateDesignerSSOUrl(url);
BrowseUtils.browser(ssoUrl);
} else {
if (!SupportOSImpl.DESIGNER_LOGIN.support()) {
BrowseUtils.browser(url);
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return;
}
} else {
boolean loginRemindBeforeJumpBBS = manager.isLoginRemindBeforeJumpBBS();
if (loginRemindBeforeJumpBBS) {
Map<String, String> params = new HashMap<>();
@ -61,32 +41,5 @@ public abstract class AbstractDesignerSSO extends UpdateAction {
}
}
private String generateLoginCode() throws Exception {
DesignerEnvManager manager = DesignerEnvManager.getEnvManager();
JSONObject jo = JSONObject.create();
jo.put("uid", manager.getDesignerLoginUid());
jo.put("username", manager.getDesignerLoginUsername());
jo.put("source", PRODUCT_FINEREPORT);
byte[] iv = randomIv();
return new String(Hex.encode(iv)) + encrypt(jo.toString(), KEY.getBytes(), iv);
}
private static byte[] randomIv() {
byte[] salt = new byte[16];
SecureRandom secureRandom = new SecureRandom();
secureRandom.setSeed(System.currentTimeMillis());
secureRandom.nextBytes(salt);
return salt;
}
public static String encrypt(String content, byte[] key, byte[] iv) throws Exception {
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/CTR/PKCS5Padding");
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
byte[] resultBytes = cipher.doFinal(content.getBytes());
return new String(Hex.encode(resultBytes));
}
public abstract String getJumpUrl();
}

Loading…
Cancel
Save