Skip to content

Commit

Permalink
feat(jans-auth-server): added ability to return error out of introspe…
Browse files Browse the repository at this point in the history
…ction and update_token custom script #3255
  • Loading branch information
yuriyz committed Dec 19, 2022
1 parent 41740bd commit ef87ba7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import io.jans.model.custom.script.conf.CustomScriptConfiguration;
import io.jans.model.custom.script.type.introspection.IntrospectionType;
import io.jans.service.custom.script.ExternalScriptService;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;

import jakarta.ejb.DependsOn;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.WebApplicationException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;

import java.util.List;

/**
Expand Down Expand Up @@ -93,7 +94,10 @@ private boolean executeExternalModifyResponse(CustomScriptConfiguration scriptCo
final boolean result = script.modifyResponse(responseAsJsonObject, context);
log.trace("Finished external 'executeExternalModifyResponse' method, script name: {}, responseAsJsonObject: {} , context: {}, result: {}",
scriptConf.getName(), responseAsJsonObject, context, result);
context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(scriptConf.getCustomScript(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import io.jans.model.custom.script.conf.CustomScriptConfiguration;
import io.jans.model.custom.script.type.token.UpdateTokenType;
import io.jans.service.custom.script.ExternalScriptService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.WebApplicationException;
import org.jetbrains.annotations.NotNull;

import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
import java.util.function.Function;

Expand All @@ -42,7 +43,10 @@ public boolean modifyIdTokenMethod(CustomScriptConfiguration script, JsonWebResp
final boolean result = updateTokenType.modifyIdToken(jsonWebResponse, context);
log.trace("Finished 'updateToken' method, script name: {}, jsonWebResponse: {}, context: {}, result: {}", script.getName(), jsonWebResponse, context, result);

context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(script.getCustomScript(), ex);
Expand Down Expand Up @@ -84,7 +88,10 @@ public int getRefreshTokenLifetimeInSeconds(CustomScriptConfiguration script, Ex
final int result = updateTokenType.getRefreshTokenLifetimeInSeconds(context);
log.trace("Finished 'getRefreshTokenLifetimeInSeconds' method, script name: {}, context: {}, result: {}", script.getName(), context, result);

context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(script.getCustomScript(), ex);
Expand Down Expand Up @@ -133,7 +140,10 @@ public boolean modifyRefreshToken(CustomScriptConfiguration script, RefreshToken
final boolean result = updateTokenType.modifyRefreshToken(refreshToken, context);
log.trace("Finished 'modifyRefreshToken' method, script name: {}, context: {}, result: {}", script.getName(), context, result);

context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(script.getCustomScript(), ex);
Expand Down Expand Up @@ -167,7 +177,10 @@ public boolean modifyAccessToken(CustomScriptConfiguration script, AccessToken a
final boolean result = updateTokenType.modifyAccessToken(accessToken, context);
log.trace("Finished 'modifyAccessToken' method, script name: {}, context: {}, result: {}", script.getName(), context, result);

context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(script.getCustomScript(), ex);
Expand Down Expand Up @@ -201,7 +214,10 @@ public int getAccessTokenLifetimeInSeconds(CustomScriptConfiguration script, Ext
final int result = updateTokenType.getAccessTokenLifetimeInSeconds(context);
log.trace("Finished 'getAccessTokenLifetimeInSeconds' method, script name: {}, context: {}, result: {}", script.getName(), context, result);

context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(script.getCustomScript(), ex);
Expand Down Expand Up @@ -235,7 +251,10 @@ public int getIdTokenLifetimeInSeconds(CustomScriptConfiguration script, Externa
final int result = updateTokenType.getIdTokenLifetimeInSeconds(context);
log.trace("Finished 'getIdTokenLifetimeInSeconds' method, script name: {}, context: {}, result: {}", script.getName(), context, result);

context.throwWebApplicationExceptionIfSet();
return result;
} catch (WebApplicationException e) {
throw e;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
saveScriptError(script.getCustomScript(), ex);
Expand Down

0 comments on commit ef87ba7

Please sign in to comment.