一、系统默认方式
二、自定义相关实现
三、OAUTH2实现
一、SSO配置
先正常完成O2OA系统启动,使用xadmin登录系统,点击左上角系统菜单-系统设置,如下图:
在基础配置中点击“系统SSO配置”,点击“添加SSO配置”,如下图:
注意:xadmin帐号不能用于单点登入
二、数据加密工具类(Java)
Crypto.java
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
/ encrypt and decrypt utils @author O2OA/public class Crypto {
private static final String utf8 = "UTF-8";
private final static String DES = "DES";
private final static String cipher_init = "DES";
public static String encrypt(String data, String key) throws Exception {
byte[] bt = encrypt(data.getBytes(), key.getBytes());
String str = Base64.encodeBase64URLSafeString(bt);
return URLEncoder.encode( str, utf8 );
}
public static byte[] encrypt(byte[] data, byte[] key) throws Exception {
// 生成一个可信任的随机数源 SecureRandom sr = new SecureRandom();
// 从原始密钥数据创建DESKeySpec对象 DESKeySpec dks = new DESKeySpec(key);
// 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher对象实际完成加密操作 Cipher cipher = Cipher.getInstance(cipher_init);
// 用密钥初始化Cipher对象 cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return cipher.doFinal(data);
}
public static String decrypt(String data, String key) throws IOException, Exception {
if (StringUtils.isEmpty(data)) {
return null;
}
String str = URLDecoder.decode(data, utf8);
byte[] buf = Base64.decodeBase64(str);
byte[] bt = decrypt(buf, key.getBytes());
return new String(bt);
}
public static byte[] decrypt(byte[] data, byte[] key) throws Exception {
// 生成一个可信任的随机数源 SecureRandom sr = new SecureRandom();
// 从原始密钥数据创建DESKeySpec对象 DESKeySpec dks = new DESKeySpec(key);
// 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher对象实际完成解密操作 Cipher cipher = Cipher.getInstance(cipher_init);
// 用密钥初始化Cipher对象 cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
return cipher.doFinal(data);
}
}
三、O2OA相关修改(sso.html)
文件路径:o2server/servers/webServer/x_desktop/sso.html修改登录相关的代码