You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.8 KiB
102 lines
2.8 KiB
3 years ago
|
package com.fr.plugin.oauth.utils;
|
||
|
|
||
|
import com.fr.io.utils.ResourceIOUtils;
|
||
|
import com.fr.plugin.oauth.W2Config;
|
||
|
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.sql.Connection;
|
||
|
import java.sql.DriverManager;
|
||
|
import java.sql.PreparedStatement;
|
||
|
import java.sql.ResultSet;
|
||
|
import java.util.Properties;
|
||
|
|
||
|
public class RedirectUtils {
|
||
|
|
||
|
public static String ORACLE;
|
||
|
public static String USER_NAME;
|
||
|
public static String PASSWORD;
|
||
|
|
||
|
public static Properties getProperties() throws IOException {
|
||
|
InputStream is = ResourceIOUtils.read("/resources/oauth2095.properties");
|
||
|
Properties prop = new Properties();
|
||
|
prop.load(is);
|
||
|
|
||
|
ORACLE = prop.getProperty("oracle", "jdbc:oracle:thin:@xx:xx:xx");
|
||
|
USER_NAME = prop.getProperty("username", "xxx");
|
||
|
PASSWORD = prop.getProperty("password", "xxx");
|
||
|
|
||
|
return prop;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 登录成功,跳转至目标页面
|
||
|
*/
|
||
|
public static void redirect(String userName, W2Config config, String token, HttpServletResponse resp) throws IOException {
|
||
|
String url = config.getFrurl();
|
||
|
|
||
|
HtmlUtils.sendRedirect(userName, url, token, resp, "/com/fr/plugin/oauth/web/redirectbyrole.html");
|
||
|
}
|
||
|
|
||
|
private static String getRole(String userName) {
|
||
|
String role = "";
|
||
|
Connection con = null;
|
||
|
PreparedStatement pre = null;
|
||
|
ResultSet result = null;
|
||
|
|
||
|
try {
|
||
|
Class.forName("oracle.jdbc.driver.OracleDriver");
|
||
|
|
||
|
String _result = ORACLE;
|
||
|
String us = USER_NAME;
|
||
|
String pw = PASSWORD;
|
||
|
con = DriverManager.getConnection(_result, us, pw);
|
||
|
String sql = "SELECT ORG_LEVEL FROM HR_MANAGEMENT WHERE USERNAME = ?";
|
||
|
pre = con.prepareStatement(sql);
|
||
|
pre.setString(1, userName);
|
||
|
result = pre.executeQuery();
|
||
|
if (result.next()) {
|
||
|
role = result.getString("ORG_LEVEL");
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
|
||
|
try {
|
||
|
if (result != null) {
|
||
|
result.close();
|
||
|
}
|
||
|
|
||
|
if (pre != null) {
|
||
|
pre.close();
|
||
|
}
|
||
|
|
||
|
if (con != null) {
|
||
|
con.close();
|
||
|
}
|
||
|
} catch (Exception var19) {
|
||
|
var19.printStackTrace();
|
||
|
}
|
||
|
} finally {
|
||
|
try {
|
||
|
if (result != null) {
|
||
|
result.close();
|
||
|
}
|
||
|
|
||
|
if (pre != null) {
|
||
|
pre.close();
|
||
|
}
|
||
|
|
||
|
if (con != null) {
|
||
|
con.close();
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return role;
|
||
|
}
|
||
|
}
|