CAS 在 tomcat 上获取 Oracle APEX 的属性
CAS getting attributes to Oracle APEX on tomcat
我将我的 Oracle Application Express 配置为具有基于 HTTP Header 变量的身份验证模式。
更具体的说,是在remote_user的基础上,设置为域登录,得益于对接CAS。
现在我需要获取属性。我知道Java中的方法怎么做:
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
final Map attributes = principal.getAttributes();
问题是还有其他方法可以使用 java 接收此属性 w/o(我可以在 Oracle Application Express 中使用的代码),例如Java脚本...
或者可能有一种方法如何在 APEX 中使用 Java 代码?我使用 APEX-ORDS-TOMCAT 系统并且有类似的东西:
.../webapps/${app_name}/WEB-INF/classes and .../webapps/${app_name}/WEB-INF/lib
也许这是我可以放置一些 java 的地方。class 并以某种方式在 Oracle APEX 中使用它?
非常感谢任何帮助
我自己创建了解决方案。
- 创建一个 Java 处理来自 CAS 的属性的 Servlet 和 return 一个 JSON 对象 (doGet):
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
final Map attributes = principal.getAttributes();
JSONObject jsonObj = new JSONObject(attributes);
PrintWriter out = response.getWriter();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
out.print(jsonObj);
将 .java 编译为 .class 并将其放入文件夹:
${TOMCAT_BASE}/webapps/${APP_NAME}/WEB-INF/classes/${PACKAGE_NAME}
- 将 CAS、JSON、Servlet 库放到
${TOMCAT_BASE}/webapps/${APP_NAME}/WEB-INF/lib
库列表(版本可能不同):
json-20190722.jar
javax.servlet-api-4.0.1.jar
cas-client-core-3.6.1.jar
cas-client-support-saml-3.4.1.jar
commons-logging-1.1.1.jar
joda-time-2.10.4.jar
log4j-1.2.17.jar
slf4j-api-1.7.28.jar
slf4j-simple-1.7.25.jar
- 配置 web.xml 以使用此 servlet
<servlet>
<servlet-name>SERVLET_NAME</servlet-name>
<servlet-class>${PACKAGE_NAME}.{CLASS_NAME}</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SERVLET_NAME</servlet-name>
<url-pattern>/{PATH}</url-pattern>
</servlet-mapping>
现在 servlet 在 {host}:{port}/{APP_NAME}/{PATH}
上可用
- 我们可以使用 Java脚本从 APEX 访问它,例如将 json 发送到 item.value
的函数
function loadJSON(itemName) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(itemName).value = this.responseText
}
};
xhttp.open("GET", "{PATH}", true);
xhttp.send();
}
loadJSON("P1_USER_INFO");
我将我的 Oracle Application Express 配置为具有基于 HTTP Header 变量的身份验证模式。
更具体的说,是在remote_user的基础上,设置为域登录,得益于对接CAS。
现在我需要获取属性。我知道Java中的方法怎么做:
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
final Map attributes = principal.getAttributes();
问题是还有其他方法可以使用 java 接收此属性 w/o(我可以在 Oracle Application Express 中使用的代码),例如Java脚本...
或者可能有一种方法如何在 APEX 中使用 Java 代码?我使用 APEX-ORDS-TOMCAT 系统并且有类似的东西:
.../webapps/${app_name}/WEB-INF/classes and .../webapps/${app_name}/WEB-INF/lib
也许这是我可以放置一些 java 的地方。class 并以某种方式在 Oracle APEX 中使用它?
非常感谢任何帮助
我自己创建了解决方案。
- 创建一个 Java 处理来自 CAS 的属性的 Servlet 和 return 一个 JSON 对象 (doGet):
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
final Map attributes = principal.getAttributes();
JSONObject jsonObj = new JSONObject(attributes);
PrintWriter out = response.getWriter();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
out.print(jsonObj);
将 .java 编译为 .class 并将其放入文件夹:
${TOMCAT_BASE}/webapps/${APP_NAME}/WEB-INF/classes/${PACKAGE_NAME}
- 将 CAS、JSON、Servlet 库放到
${TOMCAT_BASE}/webapps/${APP_NAME}/WEB-INF/lib
库列表(版本可能不同):
json-20190722.jar
javax.servlet-api-4.0.1.jar
cas-client-core-3.6.1.jar
cas-client-support-saml-3.4.1.jar
commons-logging-1.1.1.jar
joda-time-2.10.4.jar
log4j-1.2.17.jar
slf4j-api-1.7.28.jar
slf4j-simple-1.7.25.jar
- 配置 web.xml 以使用此 servlet
<servlet>
<servlet-name>SERVLET_NAME</servlet-name>
<servlet-class>${PACKAGE_NAME}.{CLASS_NAME}</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SERVLET_NAME</servlet-name>
<url-pattern>/{PATH}</url-pattern>
</servlet-mapping>
现在 servlet 在 {host}:{port}/{APP_NAME}/{PATH}
上可用- 我们可以使用 Java脚本从 APEX 访问它,例如将 json 发送到 item.value 的函数
function loadJSON(itemName) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(itemName).value = this.responseText
}
};
xhttp.open("GET", "{PATH}", true);
xhttp.send();
}
loadJSON("P1_USER_INFO");