File tree Expand file tree Collapse file tree 5 files changed +51
-6
lines changed
main/java/com/staffbase/plugins/sdk/sso
test/java/com/staffbase/plugins/sdk/sso Expand file tree Collapse file tree 5 files changed +51
-6
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,13 @@ You can try to create a token from the received jwt.
4444 try {
4545 final SSOFacade ssoFac = SSOFacade . create(rsaPublicKey);
4646 final SSOData ssoData = ssoFac. verify(jwToken);
47-
47+
48+ // If the plugin instance was deleted in Staffbase
49+ if (ssoData. isDeleteInstanceCall()){
50+ this . handleSsoDeletionCall();
51+ return ;
52+ }
53+
4854 request. setAttribute(" instanceID" , ssoData. getInstanceID());
4955
5056 return this . forward(" /index.jsp" );
Original file line number Diff line number Diff line change 182182 <autoReleaseAfterClose >true</autoReleaseAfterClose >
183183 </configuration >
184184 </plugin >
185+ <plugin >
186+ <groupId >org.apache.maven.plugins</groupId >
187+ <artifactId >maven-compiler-plugin</artifactId >
188+ <configuration >
189+ <source >8</source >
190+ <target >8</target >
191+ </configuration >
192+ </plugin >
185193 </plugins >
186194 </build >
187195 <profiles >
Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ public class SSOData {
3737 */
3838 public static final String ROLE_EDITOR = "editor" ;
3939
40+ /**
41+ * The user id/subject to identify if the SSO call is an instance deletion call.
42+ */
43+ public static final String REMOTE_CALL_DELETE = "delete" ;
44+
4045 /**
4146 * The key in the JWT claims for fetching the requested plugin instance's
4247 * unique id.
@@ -410,6 +415,18 @@ public boolean isEditor() {
410415 return ROLE_EDITOR .equals (this .userRole );
411416 }
412417
418+ /**
419+ * Check if the SSO call is an instance deletion call.
420+ *
421+ * If an editor deletes a plugin instance in Staffbase,
422+ * this will be true.
423+ *
424+ * @return <code>true</code> if the SSO call is an instance deletion call
425+ */
426+ public boolean isDeleteInstanceCall () {
427+ return REMOTE_CALL_DELETE .equals (this .userID );
428+ }
429+
413430 /**
414431 * Get the tags of the user in regards of the requested {@link #instanceID}.
415432 * If the requesting user does have admin permissions, this value is set to
Original file line number Diff line number Diff line change @@ -67,7 +67,6 @@ public static SSOFacade create(final RSAPublicKey rsaPublicKey) {
6767 */
6868 private JwtConsumer jwtConsumer ;
6969
70-
7170 /**********************************************
7271 * Constructors
7372 **********************************************/
@@ -88,7 +87,6 @@ public static SSOFacade create(final RSAPublicKey rsaPublicKey) {
8887 * pre-configured secret
8988 *
9089 * @param rsaPublicKey the RSA public key to be used for verification.
91- *
9290 * @return Fluent interface.
9391 */
9492 SSOFacade initialize (final RSAPublicKey rsaPublicKey ) {
@@ -111,11 +109,9 @@ SSOFacade initialize(final RSAPublicKey rsaPublicKey) {
111109 .setRequireNotBefore ()
112110 .setRequireIssuedAt ()
113111 .build ();
114-
115112 return this ;
116113 }
117114
118-
119115 /**********************************************
120116 * Methods
121117 **********************************************/
@@ -152,7 +148,7 @@ public SSOData verify(final String raw) throws SSOException {
152148 + "[instance_id=" + instanceId + "]" );
153149 }
154150
155- throw new SSOException ("Missing or malformed instnance_id ." );
151+ throw new SSOException ("Missing or malformed instance_id ." );
156152 }
157153
158154 if (logger .isDebugEnabled ()) {
Original file line number Diff line number Diff line change 1111
1212package com .staffbase .plugins .sdk .sso ;
1313
14+ import static org .junit .Assert .assertTrue ;
1415import static org .junit .Assert .fail ;
1516import static org .junit .Assert .assertEquals ;
1617import static org .mockito .Mockito .mock ;
2829public class SSODataTest {
2930
3031 private static final String ROLE_EDITOR = "editor" ;
32+ private static final String REMOTE_CALL_DELETE = "delete" ;
3133
3234 public static final String DATA_INSTANCE_ID = "55c79b6ee4b06c6fb19bd1e2" ;
3335 public static final String DATA_USER_ID = "541954c3e4b08bbdce1a340a" ;
@@ -104,4 +106,20 @@ public void createWithJwtClaims() throws MalformedClaimException {
104106
105107 assertEquals (Locale .US , ssoData .getUserLocale ().get ());
106108 }
109+
110+ /**
111+ * Test deletion claim accessor.
112+ * @throws MalformedClaimException
113+ */
114+ @ Test
115+ public void testWithDeleteJWTClaims () throws MalformedClaimException {
116+
117+ final JwtClaims claims = mock (JwtClaims .class );
118+
119+ when (claims .getClaimValue (SSOData .KEY_INSTANCE_ID , String .class )).thenReturn (DATA_INSTANCE_ID );
120+ when (claims .getClaimValue (SSOData .KEY_USER_ID , String .class )).thenReturn (REMOTE_CALL_DELETE );
121+
122+ final SSOData ssoData = new SSOData (claims );
123+ assertTrue (ssoData .isDeleteInstanceCall ());
124+ }
107125}
You can’t perform that action at this time.
0 commit comments