File tree Expand file tree Collapse file tree 7 files changed +87
-8
lines changed
Expand file tree Collapse file tree 7 files changed +87
-8
lines changed Original file line number Diff line number Diff line change 11{
2- "authenticators" : [],
2+ "authenticators" : [
3+ {
4+ "name" : " User Enabled Authenticator" ,
5+ "fileName" : " user-enabled-authenticator.js" ,
6+ "description" : " Allow only enabled users"
7+ },
8+ {
9+ "name" : " CSM Authenticator" ,
10+ "fileName" : " csm-authenticator.js" ,
11+ "description" : " CSM EmployeeStatus Authenticator"
12+ },
13+ {
14+ "name" : " Authorization Authenticator" ,
15+ "fileName" : " authz-authenticator.js" ,
16+ "description" : " Authorization Authenticator"
17+ }
18+ ],
319 "policies" : [],
420 "mappers" : [],
521 "saml-mappers" : [
Original file line number Diff line number Diff line change 1+ AuthenticationFlowError = Java . type ( "org.keycloak.authentication.AuthenticationFlowError" ) ;
2+
3+ function authenticate ( context ) {
4+
5+ if ( ! authenticationSession . getClient ( ) ) {
6+ context . failure ( AuthenticationFlowError . CLIENT_NOT_FOUND ) ;
7+ return ;
8+ }
9+ var client = authenticationSession . getClient ( ) . getClientId ( ) ;
10+ LOG . info ( script . name + " evalute authorization for user=" + user . username + " client=" + client ) ;
11+ /*
12+ Use employeeStatus verification for service-now which allows some disabled
13+ states to still authenticate.
14+ Also allow class-dev for testing purposes.
15+ */
16+ if ( client && ( client . contains ( "service-now" ) || client . contains ( "class-dev" ) ) ) {
17+ var allowed = / ( R E Q A P P R O V A L | A C T I V E | W E B O N L Y | R E S T R I C T E D ) / ;
18+ var employeeStatus = user . getFirstAttribute ( "employeeStatus" ) ;
19+ if ( employeeStatus && ! allowed . test ( employeeStatus ) ) {
20+ context . failure ( AuthenticationFlowError . INVALID_USER ) ;
21+ return ;
22+ }
23+ } else {
24+ /*
25+ All other clients will authorize if the user account is not disabled or locked
26+ */
27+ if ( user . getFirstAttribute ( "nsAccountLock" ) == "TRUE" || user . getFirstAttribute ( "loginDisabled" ) == "TRUE" ) {
28+ context . failure ( AuthenticationFlowError . INVALID_USER ) ;
29+ return ;
30+ }
31+ }
32+
33+ context . success ( ) ;
34+ }
Original file line number Diff line number Diff line change 11FROM rockylinux:8
2- RUN dnf -y install java-17 -openjdk-devel maven && yum clean all && rm -rf /var/cache/yum/*
3- RUN alternatives --set java $(alternatives --display java | grep 'family java-17 -openjdk' | cut -d' ' -f1)
4- RUN alternatives --set javac $(alternatives --display javac | grep 'family java-17 -openjdk' | cut -d' ' -f1)
2+ RUN dnf -y install java-21 -openjdk-devel maven && yum clean all && rm -rf /var/cache/yum/*
3+ RUN alternatives --set java $(alternatives --display java | grep 'family java-21 -openjdk' | cut -d' ' -f1)
4+ RUN alternatives --set javac $(alternatives --display javac | grep 'family java-21 -openjdk' | cut -d' ' -f1)
55RUN mkdir /build
6+ ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk
Original file line number Diff line number Diff line change @@ -12,6 +12,5 @@ From root of repo:
1212
1313```
1414docker run --rm -it -v $(pwd):/build -w /build \
15- -e JAVA_HOME=/usr/lib/jvm/java-17-openjdk \
1615osc-keycloak-scripts-build:latest mvn clean package
1716```
Original file line number Diff line number Diff line change 1+ AuthenticationFlowError = Java . type ( "org.keycloak.authentication.AuthenticationFlowError" ) ;
2+
3+ function authenticate ( context ) {
4+
5+ LOG . info ( script . name + " --> trace auth for: " + user . username ) ;
6+
7+ const allowed = / ( R E Q A P P R O V A L | A C T I V E | W E B O N L Y | R E S T R I C T E D ) / ;
8+ if ( user . getFirstAttribute ( "employeeStatus" ) && allowed . test ( user . getFirstAttribute ( "employeeStatus" ) ) ) {
9+ context . success ( ) ;
10+ } else {
11+ context . failure ( AuthenticationFlowError . INVALID_USER ) ;
12+ return ;
13+ }
14+
15+ context . success ( ) ;
16+ }
Original file line number Diff line number Diff line change 66
77 <groupId >edu.osc</groupId >
88 <artifactId >osc-keycloak-scripts</artifactId >
9- <version >1.0 .0</version >
9+ <version >1.1 .0</version >
1010 <packaging >jar</packaging >
1111
1212 <properties >
1313 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
14- <java .version>17 .0.0</java .version>
14+ <java .version>21 .0.0</java .version>
1515 </properties >
1616
1717 <dependencies >
2323 </dependencies >
2424
2525 <build >
26- <finalName >osc-keycloak-scripts</finalName >
26+ <finalName >osc-keycloak-scripts- ${project.version} </finalName >
2727 <resources >
2828 <resource >
2929 <directory >.</directory >
Original file line number Diff line number Diff line change 1+ AuthenticationFlowError = Java . type ( "org.keycloak.authentication.AuthenticationFlowError" ) ;
2+
3+ function authenticate ( context ) {
4+
5+ LOG . info ( script . name + " --> trace auth for: " + user . username ) ;
6+
7+ if ( user . getFirstAttribute ( "nsAccountLock" ) == "TRUE" || user . getFirstAttribute ( "loginDisabled" ) == "TRUE" ) {
8+ context . failure ( AuthenticationFlowError . INVALID_USER ) ;
9+ return ;
10+ }
11+
12+ context . success ( ) ;
13+ }
You can’t perform that action at this time.
0 commit comments