Skip to content

Commit 19eb99d

Browse files
committed
added remote call interfaces and handling
1 parent 966766c commit 19eb99d

6 files changed

Lines changed: 157 additions & 4 deletions

File tree

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@
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>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Abstract remote handler implementation, based on this doc:
3+
* https://developers.staffbase.com/api/plugin-sso/
4+
*
5+
* @category Authentication
6+
* @copyright 2018 Staffbase, GmbH.
7+
* @author Stefan Staude
8+
* @license http://www.apache.org/licenses/LICENSE-2.0
9+
* @link https://github.com/staffbase/plugins-sdk-java
10+
*/
11+
package com.staffbase.plugins.sdk.RemoteCall;
12+
13+
/**
14+
* class AbstractRemoteCallHandler
15+
*
16+
* An Abstract RemoteCallHandler implementation
17+
* which can be used in conjunction with all
18+
* remote call interfaces
19+
*/
20+
public abstract class AbstractRemoteCallHandler implements RemoteCallInterface{
21+
@Override
22+
public void exitSuccess() {
23+
24+
}
25+
26+
@Override
27+
public void exitFailure() {
28+
29+
}
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Delete remote handler interface, based on this doc:
3+
* https://developers.staffbase.com/api/plugin-sso/
4+
*
5+
* @category Authentication
6+
* @copyright 2018 Staffbase, GmbH.
7+
* @author Stefan Staude
8+
* @license http://www.apache.org/licenses/LICENSE-2.0
9+
* @link https://github.com/staffbase/plugins-sdk-java
10+
*/
11+
package com.staffbase.plugins.sdk.RemoteCall;
12+
13+
/**
14+
* Interface DeleteInstanceCallHandlerInterface
15+
*/
16+
public interface DeleteInstanceCallHandlerInterface extends RemoteCallInterface {
17+
18+
/**
19+
* Method to remove and cleanup every plugin related data of the given identifier.
20+
*
21+
* @param instanceId Plugin Instance identifier
22+
* @return <code>false</code> if the deletion goes wrong and should be retried later.
23+
*/
24+
public boolean deleteInstance(String instanceId);
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Remote call interface, based on this doc:
3+
* https://developers.staffbase.com/api/plugin-sso/
4+
*
5+
* @category Authentication
6+
* @copyright 2018 Staffbase, GmbH.
7+
* @author Stefan Staude
8+
* @license http://www.apache.org/licenses/LICENSE-2.0
9+
* @link https://github.com/staffbase/plugins-sdk-java
10+
*/
11+
package com.staffbase.plugins.sdk.RemoteCall;
12+
13+
/**
14+
* Interface RemoteCallInterface
15+
*
16+
* A generic interface describing the protocol with the
17+
* Staffbase Backend after a Remote SSO cal was issued.
18+
*/
19+
public interface RemoteCallInterface {
20+
21+
/**
22+
* Stop the execution by providing a 2XX HTTP response
23+
*
24+
* This will tell Staffbase that everything went OK.
25+
*/
26+
public void exitSuccess();
27+
28+
/**
29+
* Stop the execution by providing a 5XX HTTP response
30+
*
31+
* This will tell Staffbase that it should try again later.
32+
*/
33+
public void exitFailure();
34+
}

src/main/java/com/staffbase/plugins/sdk/sso/SSOData.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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

src/main/java/com/staffbase/plugins/sdk/sso/SSOFacade.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.util.Objects;
1717

1818

19+
import com.staffbase.plugins.sdk.RemoteCall.DeleteInstanceCallHandlerInterface;
20+
import com.staffbase.plugins.sdk.RemoteCall.RemoteCallInterface;
1921
import org.apache.logging.log4j.LogManager;
2022
import org.apache.logging.log4j.Logger;
2123

@@ -67,6 +69,11 @@ public static SSOFacade create(final RSAPublicKey rsaPublicKey) {
6769
*/
6870
private JwtConsumer jwtConsumer;
6971

72+
/**
73+
* An instance handling remote calls
74+
*/
75+
private RemoteCallInterface remoteCallHandler;
76+
7077

7178
/**********************************************
7279
* Constructors
@@ -83,15 +90,19 @@ public static SSOFacade create(final RSAPublicKey rsaPublicKey) {
8390
* Initialization
8491
**********************************************/
8592

93+
SSOFacade initialize(final RSAPublicKey rsaPublicKey) {
94+
return this.initialize(rsaPublicKey, null);
95+
}
96+
8697
/**
8798
* Initialize this component by building up the consumer for JWT using the
8899
* pre-configured secret
89100
*
90101
* @param rsaPublicKey the RSA public key to be used for verification.
91-
*
102+
* @param remoteCallHandler a class handling remote calls
92103
* @return Fluent interface.
93104
*/
94-
SSOFacade initialize(final RSAPublicKey rsaPublicKey) {
105+
SSOFacade initialize(final RSAPublicKey rsaPublicKey, final RemoteCallInterface remoteCallHandler) {
95106

96107
if (logger.isDebugEnabled()) {
97108
logger.debug("Initializing single-sign-on manager SSOFacade. ");
@@ -112,6 +123,8 @@ SSOFacade initialize(final RSAPublicKey rsaPublicKey) {
112123
.setRequireIssuedAt()
113124
.build();
114125

126+
this.remoteCallHandler = remoteCallHandler;
127+
115128
return this;
116129
}
117130

@@ -152,7 +165,7 @@ public SSOData verify(final String raw) throws SSOException {
152165
+ "[instance_id=" + instanceId + "]");
153166
}
154167

155-
throw new SSOException("Missing or malformed instnance_id.");
168+
throw new SSOException("Missing or malformed instance_id.");
156169
}
157170

158171
if (logger.isDebugEnabled()) {
@@ -162,7 +175,23 @@ public SSOData verify(final String raw) throws SSOException {
162175
}
163176

164177
// Parse and return the container data.
165-
return new SSOData(jwtClaims);
178+
SSOData ssoData = new SSOData(jwtClaims);
179+
if(ssoData.isDeleteInstanceCall() && this.remoteCallHandler != null) {
180+
boolean result = true;
181+
if (this.remoteCallHandler instanceof DeleteInstanceCallHandlerInterface){
182+
result = ((DeleteInstanceCallHandlerInterface) this.remoteCallHandler).deleteInstance(instanceId);
183+
} else {
184+
logger.warn("Warning: An instance deletion call for instance $instanceId was not handled.");
185+
}
186+
187+
if(result){
188+
this.remoteCallHandler.exitSuccess();
189+
} else {
190+
this.remoteCallHandler.exitFailure();
191+
}
192+
exitRemoteCall();
193+
}
194+
return ssoData;
166195
} catch (final MalformedClaimException malformationException) {
167196
if (logger.isFatalEnabled()) {
168197
logger.fatal("Encountered malformed sso attempt.", malformationException);
@@ -177,4 +206,14 @@ public SSOData verify(final String raw) throws SSOException {
177206
throw new SSOException(invalidJwtException.getMessage(), invalidJwtException);
178207
}
179208
}
209+
210+
211+
/**
212+
* @throws SSOException if a remote call was not handled by the user
213+
*/
214+
private void exitRemoteCall() throws SSOException {
215+
String message = "Warning: The exit procedure for a remote call was not properly handled.";
216+
logger.warn(message);
217+
throw new SSOException(message);
218+
}
180219
}

0 commit comments

Comments
 (0)