├── .gitignore
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
└── main
└── java
└── com
└── peoplesoft
└── pt
└── custom
└── filter
└── PortalServletFilter.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build #
2 | #########
3 | MANIFEST.MF
4 | dependency-reduced-pom.xml
5 |
6 | # Compiled #
7 | ############
8 | bin
9 | build
10 | dist
11 | lib
12 | out
13 | run
14 | target
15 | *.com
16 | *.class
17 | *.dll
18 | *.exe
19 | *.o
20 | *.so
21 |
22 | # Databases #
23 | #############
24 | *.db
25 | *.sql
26 | *.sqlite
27 |
28 | # Packages #
29 | ############
30 | *.7z
31 | *.dmg
32 | *.gz
33 | *.iso
34 | *.rar
35 | *.tar
36 | *.zip
37 |
38 | # Repository #
39 | ##############
40 | .git
41 |
42 | # Logging #
43 | ###########
44 | /logs
45 | *.log
46 |
47 | # Misc #
48 | ########
49 | *.bak
50 |
51 | # System #
52 | ##########
53 | .DS_Store
54 | ehthumbs.db
55 | Thumbs.db
56 |
57 | # Project #
58 | ###########
59 | .classpath
60 | .externalToolBuilders
61 | .gradle
62 | .idea
63 | .project
64 | .settings
65 | .checkstyle
66 | .factorypath
67 | run
68 | ./eclipse
69 | nbproject
70 | atlassian-ide-plugin.xml
71 | build.xml
72 | nb-configuration.xml
73 | *.iml
74 | *.ipr
75 | *.iws
76 | /.apt_generated/
77 | *.launch
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PortalServletFilter
2 |
3 | * [Source]
4 | * [Issues]
5 | * [Downloads]
6 |
7 | Provides additional logging for PeopleSoft applications.
8 |
9 | ## Available Headers
10 | * `X-PS-APPSERVER` : Displays the appserver host with port (Enabled by default)
11 | * `X-PS-APPSTATUS` : Displays the appserver's status (running/stopped)
12 | * `X-PS-AUTHTOKEN`: Displays the authtoken of PIA
13 | * `X-PS-CLIENTIP` : Displays the client's ip address (Enabled by default)
14 | * `X-PS-COOKIE` : Displays all cookies associated with request
15 | * `X-PS-MENU` : Displays the current menu being accessed
16 | * `X-PS-PWDDAYSLEFT` : Displays the user's remaining days before password expires
17 | * `X-PS-ROLES` : Displays the client's PS roles
18 | * `X-PS-SESSION-COOKIE` : Displays the session cookie
19 | * `X-PS-SESSION-COUNT` : Displays the current total open sessions to PIA
20 | * `X-PS-SITE` : Displays the PIA site name
21 | * `X-PS-SRID` : Displays the SRID for the user's session
22 | * `X-PS-USERID` : Displays the client's user id (Enabled by default)
23 |
24 | ## Prerequisites
25 | * [Java 7]
26 | * BEA Library - You can normally find this library in your PIA install under `domain/applications/peoplesoft/lib/bea.jar`
27 | * PIA Common Library - You can normally find this library in your PIA install under `domain/applications/peoplesoft/pspc.war/WEB-INF/lib/piacommon.jar`
28 | * WebLogic Server Library API - You can normally find this library in your WLS install under `ORACLE_HOME/wlserver/server/lib/wls-api.jar`
29 | **Note: BEA, PIA Common, and WLS API libs need to be copied to the libs folder of this project or it will not build properly.**
30 |
31 | ## Cloning
32 |
33 | `git clone https://github.com/bloodmc/PortalServletFilter.git`
34 |
35 | ## Building
36 | In order to build PortalServletFilter you simply need to run the `gradlew` command. On Windows systems you should run `gradlew.bat` instead of `./gradlew` to invoke the Gradle wrapper. You can find the compiled JAR file in `./build/libs` named `portalservlet-x.x.jar`.
37 |
38 | ## Installation
39 | * Copy the portalservlet-x.x.jar to your `domain/applications/peoplesoft/PORTAL.war/WEB-INF/lib` folder.
40 | * Edit `web.xml` under `domain/applications/peoplesoft/PORTAL.war/WEB-INF` to use the new filter.
41 | Here is an example of how it should look
42 | ```
43 |
44 | PortalServletFilter
45 | com.peoplesoft.pt.custom.filter.PortalServletFilter
46 | true
47 |
48 |
49 | PortalServletFilter
50 | /psp/*
51 | /psc/*
52 | /cs/*
53 |
54 | ```
55 | * Login to your weblogic console
56 | * Open `http://server:port/console` and login.
57 | * Go to `Environment > Servers > PIA > Logging > HTTP`.
58 | * Click `Lock & Edit`.
59 | * Select the checkbox for `HTTP access log file enabled`.
60 | * Save the changes.
61 | * Expand the `Advanced` section.
62 | * Change the Format to Extended.
63 | * Add each sc(HEADER) to the Extended Logging Format Fields. Replace `HEADER` with what you want to use.
64 | * (Optional) Set the Log File Buffer to 0 if you are debugging and need to see entries immediately.
65 | * Save the changes.
66 | * Click the `Release Configuration` button.
67 | * Restart the web server.
68 |
69 | ## Configuration
70 | You can find the PortalServletFilter configuration in your PIA install under `domain/piaconfig/properties/PortalServletFilter.properties`.
71 | This config allows you to customize what headers you wanted added to responses. After making changes, you will need to restart the PIA server.
72 |
73 | ## IMPORTANT
74 | All headers are added to the client response. If you do NOT want these headers to appear on client side then you will have to strip them.
75 | If you are using a load balancer, here is how you can strip them from the response :
76 |
77 | 1. **[F5]**
78 | * [remove-x-headers-from-web-server-response](https://devcentral.f5.com/codeshare/remove-x-headers-from-web-server-response)
79 |
80 | 2. **[KEMP]**
81 | * Create a Content Rule with type `Delete Header` and set the pattern to `/X-PS.*/`
82 |
83 | 3. **[HAProxy]** (credit to coryfazzini for this one)
84 | * Add the following to your frontend or backend section haproxy.cfg : `rspidel ^X-PS-.*`
85 |
86 | [Source]: https://github.com/bloodmc/PortalServletFilter
87 | [Issues]: https://github.com/bloodmc/PortalServletFilter/issues
88 | [Downloads]: https://github.com/bloodmc/PortalServletFilter/releases
89 | [Java 7]: http://java.oracle.com
90 | [F5]: https://f5.com/glossary/load-balancer
91 | [KEMP]: https://kemptechnologies.com/load-balancer/
92 | [HAProxy]: https://www.haproxy.org/
93 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | }
6 |
7 | plugins {
8 | id 'maven'
9 | }
10 |
11 | // Environment variables for the build set by the build server
12 | ext.buildNumber = System.env.BUILD_NUMBER ?: '0'
13 |
14 | defaultTasks 'clean', 'build'
15 |
16 | allprojects {
17 | apply plugin: 'java'
18 | sourceCompatibility = 1.7
19 | targetCompatibility = 1.7
20 | }
21 |
22 | archivesBaseName = project.name.toLowerCase()
23 |
24 | version = "0.4"
25 |
26 | project.ext.getGitHash = {
27 | def command = Runtime.getRuntime().exec("git rev-parse --short HEAD")
28 | def result = command.waitFor()
29 | return (result == 0) ? command.inputStream.text.trim() : "nogit"
30 | }
31 |
32 | repositories {
33 | mavenCentral()
34 | maven {
35 | url = 'https://maven.oracle.com'
36 | }
37 | }
38 |
39 | dependencies {
40 | compileOnly "javax.servlet:javax.servlet-api:3.0.1"
41 | compile files('libs/piacommon.jar')
42 | compile files('libs/wls-api.jar')
43 | compile files('libs/bea.jar')
44 | }
45 |
46 | jar {
47 | manifest.attributes('Implementation-Title': 'PortalServletFilter')
48 | manifest.attributes('Implementation-Version': "$version")
49 | manifest.attributes('Git-Hash': project.ext.getGitHash())
50 | classifier = ''
51 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/psadmin-io/PortalServletFilter/31cc4b3c32fca448c292017342f7e19217870980/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Apr 09 18:35:47 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/src/main/java/com/peoplesoft/pt/custom/filter/PortalServletFilter.java:
--------------------------------------------------------------------------------
1 | package com.peoplesoft.pt.custom.filter;
2 |
3 | import psft.pt8.jb.JBEntry;
4 | import psft.pt8.net.NetSession;
5 | import psft.pt8.util.PSSessionProp;
6 | import weblogic.management.runtime.WebAppComponentRuntimeMBean;
7 |
8 | import java.io.FileInputStream;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 | import java.nio.file.Files;
13 | import java.nio.file.Path;
14 | import java.nio.file.Paths;
15 | import java.util.Collections;
16 | import java.util.Enumeration;
17 | import java.util.Hashtable;
18 | import java.util.Properties;
19 | import java.util.Vector;
20 |
21 | import javax.servlet.Filter;
22 | import javax.servlet.FilterChain;
23 | import javax.servlet.FilterConfig;
24 | import javax.servlet.ServletException;
25 | import javax.servlet.ServletRequest;
26 | import javax.servlet.ServletResponse;
27 | import javax.servlet.http.Cookie;
28 | import javax.servlet.http.HttpServletRequest;
29 | import javax.servlet.http.HttpServletResponse;
30 | import javax.servlet.http.HttpSession;
31 |
32 | public class PortalServletFilter implements Filter {
33 |
34 | private FilterConfig config;
35 | private Path propertiesPath;
36 | private WebAppComponentRuntimeMBean peoplesoftRuntimeBean;
37 | public static final String CONFIG_HEADER = "Portal Servlet Filter 0.2\n"
38 | + "# The following headers can be used\n"
39 | + "# X-PS-APPSERVER : Displays the appserver host with port\n"
40 | + "# X-PS-APPSTATUS : Displays the appserver's status\n"
41 | + "# X-PS-AUTHTOKEN : Displays the authtoken of PIA\n"
42 | + "# X-PS-CLIENTIP : Displays the client's ip address\n"
43 | + "# X-PS-COOKIE : Displays all cookies associated with request\n"
44 | + "# X-PS-MENU : Displays the current menu being accessed\n"
45 | + "# X-PS-PWDDAYSLEFT : Displays the user's remaining days before password expires\n"
46 | + "# X-PS-ROLES : Displays the client's PS roles\n"
47 | + "# X-PS-SESSION-COOKIE : Displays the session cookie\n"
48 | + "# X-PS-SESSION-COUNT : Displays the current total open sessions to PIA\n"
49 | + "# X-PS-SITE : Displays the PIA site name\n"
50 | + "# X-PS-SRID : Displays the SRID for the user's session\n"
51 | + "# X-PS-USERID : Displays the client's user id\n";
52 | private boolean isEnabled = true;
53 | private boolean prop_appServer = true;
54 | private boolean prop_appStatus = false;
55 | private boolean prop_authToken = false;
56 | private boolean prop_clientIp = true;
57 | private boolean prop_cookie = false;
58 | private boolean prop_menu = false;
59 | private boolean prop_pwdDaysLeft = false;
60 | private boolean prop_roles = false;
61 | private boolean prop_sessionCookie = false;
62 | private boolean prop_sessionCount = false;
63 | private boolean prop_site = false;
64 | private boolean prop_srid = true;
65 | private boolean prop_userId = true;
66 | private boolean checkSessionProps = false;
67 |
68 | public PortalServletFilter() {
69 | this.config = null;
70 | this.loadProperties();
71 | }
72 |
73 | private void loadProperties() {
74 | Properties prop = new Properties() {
75 | private static final long serialVersionUID = -1414273837759328933L;
76 |
77 | @SuppressWarnings({ "unchecked", "rawtypes" })
78 | @Override
79 | public Enumeration keys() {
80 | Enumeration keysEnum = super.keys();
81 | Vector keyList = new Vector();
82 | while(keysEnum.hasMoreElements()){
83 | keyList.add((String)keysEnum.nextElement());
84 | }
85 | Collections.sort(keyList);
86 | return keyList.elements();
87 | }
88 | };
89 | try {
90 | this.propertiesPath = Paths.get("piaconfig", "properties", "PortalServletFilter.properties");
91 | if (!Files.exists(this.propertiesPath)) {
92 | Files.createDirectories(propertiesPath.getParent());
93 | Files.createFile(propertiesPath);
94 | prop.setProperty("appserver", "true");
95 | prop.setProperty("appstatus", "false");
96 | prop.setProperty("authtoken", "false");
97 | prop.setProperty("clientip", "true");
98 | prop.setProperty("cookie", "false");
99 | prop.setProperty("menu", "false");
100 | prop.setProperty("pwddaysleft", "false");
101 | prop.setProperty("roles", "false");
102 | prop.setProperty("sessioncookie", "false");
103 | prop.setProperty("sessioncount", "false");
104 | prop.setProperty("site", "false");
105 | prop.setProperty("srid", "true");
106 | prop.setProperty("userid", "true");
107 | prop.store(new FileOutputStream(this.propertiesPath.toFile()), CONFIG_HEADER);
108 | this.checkSessionProps = true;
109 | } else {
110 | InputStream is = new FileInputStream(this.propertiesPath.toFile());
111 | prop.load(is);
112 | this.prop_appServer = Boolean.parseBoolean(prop.getProperty("appserver", "true"));
113 | this.prop_appStatus = Boolean.parseBoolean(prop.getProperty("appstatus", "false"));
114 | this.prop_authToken = Boolean.parseBoolean(prop.getProperty("authtoken", "false"));
115 | this.prop_clientIp = Boolean.parseBoolean(prop.getProperty("clientip", "true"));
116 | this.prop_cookie = Boolean.parseBoolean(prop.getProperty("cookie", "false"));
117 | this.prop_menu = Boolean.parseBoolean(prop.getProperty("menu", "false"));
118 | this.prop_pwdDaysLeft = Boolean.parseBoolean(prop.getProperty("pwddaysleft", "false"));
119 | this.prop_roles = Boolean.parseBoolean(prop.getProperty("roles", "false"));
120 | this.prop_sessionCookie = Boolean.parseBoolean(prop.getProperty("sessioncookie", "false"));
121 | this.prop_sessionCount = Boolean.parseBoolean(prop.getProperty("sessioncount", "false"));
122 | this.prop_site = Boolean.parseBoolean(prop.getProperty("site", "false"));
123 | this.prop_srid = Boolean.parseBoolean(prop.getProperty("srid", "true"));
124 | this.prop_userId = Boolean.parseBoolean(prop.getProperty("userid", "true"));
125 | if (this.prop_appServer || this.prop_appStatus || this.prop_authToken || this.prop_menu || this.prop_pwdDaysLeft || this.prop_srid) {
126 | this.checkSessionProps = true;
127 | }
128 | if (!this.checkSessionProps && !this.prop_userId && !this.prop_clientIp && !this.prop_roles && !this.prop_cookie && !this.prop_site) {
129 | this.isEnabled = false;
130 | }
131 | }
132 | } catch (IOException e) {
133 | e.printStackTrace();
134 | }
135 | }
136 |
137 | public void init(final FilterConfig config) throws ServletException {
138 | this.config = config;
139 | }
140 |
141 | public void destroy() {
142 | this.config = null;
143 | }
144 |
145 | @SuppressWarnings("unchecked")
146 | public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
147 | if (!this.isEnabled || !(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
148 | chain.doFilter(request, response);
149 | return;
150 | }
151 |
152 | final HttpServletRequest servletRequest = (HttpServletRequest) request;
153 | final HttpServletResponse servletResponse = (HttpServletResponse) response;
154 | final HttpSession session = servletRequest.getSession(false);
155 | if (session == null) {
156 | chain.doFilter(request, response);
157 | return;
158 | }
159 |
160 | if (this.prop_cookie) {
161 | final Cookie[] reqCookies = servletRequest.getCookies();
162 | if (reqCookies != null) {
163 | String cookies = "";
164 | for (Cookie cookie : reqCookies) {
165 | cookies += cookie.getName() + "|";
166 | }
167 | servletResponse.addHeader("X-PS-COOKIE", cookies);
168 | }
169 | }
170 |
171 | final String userInfo = (String) session.getAttribute("USERID");
172 | if (userInfo == null) {
173 | chain.doFilter(request, response);
174 | return;
175 | }
176 |
177 | final int slashIndex = userInfo.indexOf("/");
178 | final int atIndex = userInfo.indexOf("@");
179 | if (userInfo == null || slashIndex == -1 || atIndex == -1) {
180 | // no data
181 | chain.doFilter(request, response);
182 | return;
183 | }
184 |
185 | final String userId = userInfo.substring(0, atIndex);
186 | if (this.prop_userId) {
187 | servletResponse.addHeader("X-PS-USERID", userId);
188 | }
189 | final String site = userInfo.substring(slashIndex + 1, userInfo.length());
190 | if (this.prop_clientIp) {
191 | final String clientIp = userInfo.substring(atIndex + 1, slashIndex);
192 | servletResponse.addHeader("X-PS-CLIENTIP", clientIp);
193 | }
194 | if (this.prop_site) {
195 | servletResponse.addHeader("X-PS-SITE", site);
196 | }
197 | if (this.prop_roles) {
198 | final Hashtable roleMap = (Hashtable) session.getAttribute("ROLES");
199 | String roles = "";
200 | for (String role : roleMap.keySet()) {
201 | roles = role + "|";
202 | }
203 | servletResponse.addHeader("X-PS-ROLES", roles);
204 | }
205 |
206 | if (this.prop_authToken || this.prop_sessionCookie || this.prop_sessionCount) {
207 | if (this.peoplesoftRuntimeBean == null) {
208 | this.peoplesoftRuntimeBean = (WebAppComponentRuntimeMBean) session.getServletContext().getAttribute("weblogic.servlet.WebAppComponentRuntimeMBean");
209 | if (this.peoplesoftRuntimeBean == null) {
210 | chain.doFilter(request, response);
211 | return;
212 | }
213 | }
214 |
215 | if (this.prop_authToken) {
216 | servletResponse.addHeader("X-PS-AUTHTOKEN", this.peoplesoftRuntimeBean.getSessionCookieDomain());
217 | }
218 | if (this.prop_sessionCookie) {
219 | servletResponse.addHeader("X-PS-SESSION-COOKIE", this.peoplesoftRuntimeBean.getSessionCookieName());
220 | }
221 | if (this.prop_sessionCount) {
222 | servletResponse.addHeader("X-PS-SESSION-COUNT", Integer.toString(this.peoplesoftRuntimeBean.getAllServletSessions().size()));
223 | }
224 | }
225 |
226 | if (!this.checkSessionProps) {
227 | chain.doFilter(request, response);
228 | return;
229 | }
230 |
231 | PSSessionProp sessionProps = (PSSessionProp) session.getAttribute("portalSessionProps/" + site);
232 | if (sessionProps == null) {
233 | // check icSessionProps
234 | sessionProps = (PSSessionProp) session.getAttribute("icSessionProp/" + site);
235 | }
236 | if (sessionProps != null) {
237 | if (this.prop_srid) {
238 | final String SRID = (String) sessionProps.get("SRID");
239 | if (SRID != null) {
240 | servletResponse.addHeader("X-PS-SRID", SRID);
241 | }
242 | }
243 |
244 | JBEntry jbe = (JBEntry) sessionProps.get("JBridge");
245 | if (jbe != null) {
246 | NetSession ns = (psft.pt8.net.NetSession) jbe.getSession();
247 | if (ns != null) {
248 | if (this.prop_appStatus) {
249 | try {
250 | if (ns.isAlive()) {
251 | servletResponse.addHeader("X-PS-APPSTATUS", "running");
252 | } else {
253 | servletResponse.addHeader("X-PS-APPSTATUS", "stopped");
254 | }
255 | } catch (Exception e) {
256 | servletResponse.addHeader("X-PS-APPSTATUS", "stopped");
257 | }
258 | }
259 | if (this.prop_appServer) {
260 | servletResponse.addHeader("X-PS-APPSERVER", ns.getCurrentAppServer());
261 | }
262 | if (this.prop_menu) {
263 | servletResponse.addHeader("X-PS-MENU", ns.getLoginInfo().getCurrentMenuName());
264 | }
265 | if (this.prop_pwdDaysLeft) {
266 | servletResponse.addHeader("X-PS-PWDDAYSLEFT", Integer.toString(ns.getPwdDaysLeft()));
267 | }
268 | }
269 | }
270 | }
271 |
272 | chain.doFilter(request, response);
273 | }
274 | }
275 |
--------------------------------------------------------------------------------