Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(4.2.2) Introduced revoke interception script
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Server/src/main/java/org/gluu/oxauth/service/external/ExternalRevokeTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.gluu.oxauth.service.external; | ||
|
||
import org.gluu.model.custom.script.CustomScriptType; | ||
import org.gluu.model.custom.script.conf.CustomScriptConfiguration; | ||
import org.gluu.model.custom.script.type.revoke.RevokeTokenType; | ||
import org.gluu.oxauth.service.external.context.RevokeTokenContext; | ||
import org.gluu.service.custom.script.ExternalScriptService; | ||
import org.slf4j.Logger; | ||
|
||
import javax.ejb.DependsOn; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
/** | ||
* @author Yuriy Zabrovarnyy | ||
*/ | ||
@ApplicationScoped | ||
@DependsOn("appInitializer") | ||
@Named | ||
public class ExternalRevokeTokenService extends ExternalScriptService { | ||
|
||
@Inject | ||
private Logger log; | ||
|
||
public ExternalRevokeTokenService() { | ||
super(CustomScriptType.REVOKE_TOKEN); | ||
} | ||
|
||
public boolean revokeToken(CustomScriptConfiguration script, RevokeTokenContext context) { | ||
try { | ||
log.trace("Executing python 'revokeToken' method, context: {}", context); | ||
context.setScript(script); | ||
RevokeTokenType revokeTokenType = (RevokeTokenType) script.getExternalType(); | ||
final boolean result = revokeTokenType.revoke(context); | ||
log.trace("Finished 'revokeToken' method, result: {}, context: {}", result, context); | ||
return result; | ||
} catch (Exception ex) { | ||
log.error(ex.getMessage(), ex); | ||
saveScriptError(script.getCustomScript(), ex); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public boolean revokeTokenMethods(RevokeTokenContext context) { | ||
for (CustomScriptConfiguration script : this.customScriptConfigurations) { | ||
if (script.getExternalType().getApiVersion() > 1) { | ||
if (!revokeToken(script, context)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
Server/src/main/java/org/gluu/oxauth/service/external/context/RevokeTokenContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.gluu.oxauth.service.external.context; | ||
|
||
import org.gluu.model.custom.script.conf.CustomScriptConfiguration; | ||
import org.gluu.oxauth.model.common.AuthorizationGrant; | ||
import org.gluu.oxauth.model.registration.Client; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* @author Yuriy Zabrovarnyy | ||
*/ | ||
public class RevokeTokenContext extends ExternalScriptContext { | ||
|
||
private final Client client; | ||
private final AuthorizationGrant grant; | ||
private final Response.ResponseBuilder responseBuilder; | ||
private CustomScriptConfiguration script; | ||
|
||
public RevokeTokenContext(HttpServletRequest httpRequest, Client client, AuthorizationGrant grant, Response.ResponseBuilder responseBuilder) { | ||
super(httpRequest); | ||
this.client = client; | ||
this.grant = grant; | ||
this.responseBuilder = responseBuilder; | ||
} | ||
|
||
public Client getClient() { | ||
return client; | ||
} | ||
|
||
public AuthorizationGrant getGrant() { | ||
return grant; | ||
} | ||
|
||
public Response.ResponseBuilder getResponseBuilder() { | ||
return responseBuilder; | ||
} | ||
|
||
public CustomScriptConfiguration getScript() { | ||
return script; | ||
} | ||
|
||
public void setScript(CustomScriptConfiguration script) { | ||
this.script = script; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RevokeTokenContext{" + | ||
"clientId=" + (client != null ? client.getClientId() : "") + | ||
", script=" + (script != null ? script.getName() : "") + | ||
"} " + super.toString(); | ||
} | ||
} |