use of org.gluu.model.custom.script.conf.CustomScriptConfiguration in project oxAuth by GluuFederation.
the class ExternalSpontaneousScopeService method getScriptsToExecute.
private Set<CustomScriptConfiguration> getScriptsToExecute(Client client) {
Set<CustomScriptConfiguration> result = Sets.newHashSet();
if (this.customScriptConfigurations == null) {
return result;
}
List<String> scriptDns = client.getAttributes().getSpontaneousScopeScriptDns();
for (CustomScriptConfiguration script : this.customScriptConfigurations) {
if (scriptDns.contains(script.getCustomScript().getDn())) {
result.add(script);
}
}
return result;
}
use of org.gluu.model.custom.script.conf.CustomScriptConfiguration in project oxAuth by GluuFederation.
the class ExternalUmaRptClaimsService method externalModify.
public boolean externalModify(JSONObject rptAsJson, ExternalUmaRptClaimsContext context) {
final List<CustomScriptConfiguration> scripts = getCustomScriptConfigurationsByDns(context.getClient().getAttributes().getRptClaimsScripts());
if (scripts.isEmpty()) {
return false;
}
log.trace("Found {} RPT Claims scripts.", scripts.size());
for (CustomScriptConfiguration script : scripts) {
if (!externalModify(rptAsJson, script, context)) {
return false;
}
}
log.debug("ExternalModify returned 'true'.");
return true;
}
use of org.gluu.model.custom.script.conf.CustomScriptConfiguration in project oxAuth by GluuFederation.
the class UmaNeedsInfoService method checkNeedsInfo.
public Map<UmaScriptByScope, UmaAuthorizationContext> checkNeedsInfo(Claims claims, Map<Scope, Boolean> requestedScopes, List<UmaPermission> permissions, UmaPCT pct, HttpServletRequest httpRequest, Client client) {
Map<UmaScriptByScope, UmaAuthorizationContext> scriptMap = new HashMap<UmaScriptByScope, UmaAuthorizationContext>();
Map<String, String> ticketAttributes = new HashMap<String, String>();
List<ClaimDefinition> missedClaims = new ArrayList<ClaimDefinition>();
UmaAuthorizationContextBuilder contextBuilder = new UmaAuthorizationContextBuilder(appConfiguration, attributeService, resourceService, permissions, requestedScopes, claims, httpRequest, sessionService, userService, permissionService, client);
for (Scope scope : requestedScopes.keySet()) {
List<String> authorizationPolicies = scope.getUmaAuthorizationPolicies();
if (authorizationPolicies != null && !authorizationPolicies.isEmpty()) {
for (String scriptDN : authorizationPolicies) {
// log.trace("Loading UMA script: " + scriptDN + ", scope: " + scope + " ...");
CustomScriptConfiguration script = policyService.getScriptByDn(scriptDN);
if (script != null) {
UmaAuthorizationContext context = contextBuilder.build(script);
scriptMap.put(new UmaScriptByScope(scope, script), context);
List<ClaimDefinition> requiredClaims = policyService.getRequiredClaims(script, context);
if (requiredClaims != null && !requiredClaims.isEmpty()) {
for (ClaimDefinition definition : requiredClaims) {
if (!claims.has(definition.getName())) {
missedClaims.add(definition);
}
}
}
String claimsGatheringScriptName = policyService.getClaimsGatheringScriptName(script, context);
if (StringUtils.isNotBlank(claimsGatheringScriptName)) {
ticketAttributes.put(UmaConstants.GATHERING_ID, constructGatheringScriptNameValue(ticketAttributes.get(UmaConstants.GATHERING_ID), claimsGatheringScriptName));
} else {
log.debug("External 'getClaimsGatheringScriptName' script method return null or blank value, script: " + script.getName());
}
} else {
log.error("Unable to load UMA script dn: '{}'", scriptDN);
}
}
} else {
log.trace("No policies defined for scope: " + scope.getId() + ", scopeDn: " + scope.getDn());
}
}
if (!missedClaims.isEmpty()) {
ticketAttributes.put(UmaPermission.PCT, pct.getCode());
String newTicket = permissionService.changeTicket(permissions, ticketAttributes);
UmaNeedInfoResponse needInfoResponse = new UmaNeedInfoResponse();
needInfoResponse.setTicket(newTicket);
needInfoResponse.setError("need_info");
needInfoResponse.setRedirectUser(buildClaimsGatheringRedirectUri(scriptMap.values(), client, newTicket));
needInfoResponse.setRequiredClaims(missedClaims);
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(ServerUtil.asJsonSilently(needInfoResponse)).build());
}
return scriptMap;
}
use of org.gluu.model.custom.script.conf.CustomScriptConfiguration in project oxAuth by GluuFederation.
the class UmaGatherer method prepareForStep.
public String prepareForStep() {
try {
final HttpServletRequest httpRequest = (HttpServletRequest) externalContext.getRequest();
final HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
final SessionId session = umaSessionService.getSession(httpRequest, httpResponse);
if (session == null || session.getSessionAttributes().isEmpty()) {
log.error("Invalid session.");
return result(Constants.RESULT_EXPIRED);
}
CustomScriptConfiguration script = getScript(session);
UmaGatherContext context = new UmaGatherContext(script.getConfigurationAttributes(), httpRequest, session, umaSessionService, umaPermissionService, umaPctService, pageClaims, userService, facesService, appConfiguration);
int step = umaSessionService.getStep(session);
if (step < 1) {
log.error("Invalid step: {}", step);
return result(Constants.RESULT_INVALID_STEP);
}
if (script == null) {
log.error("Failed to load script, step: '{}'", step);
return result(Constants.RESULT_FAILURE);
}
if (!umaSessionService.isPassedPreviousSteps(session, step)) {
log.error("There are claims-gathering steps not marked as passed. scriptName: '{}', step: '{}'", script.getName(), step);
return result(Constants.RESULT_FAILURE);
}
boolean result = external.prepareForStep(script, step, context);
if (result) {
context.persist();
return result(Constants.RESULT_SUCCESS);
} else {
String redirectToExternalUrl = context.getRedirectToExternalUrl();
if (StringUtils.isNotBlank(redirectToExternalUrl)) {
log.debug("Redirect to : " + redirectToExternalUrl);
facesService.redirectToExternalURL(redirectToExternalUrl);
return redirectToExternalUrl;
}
}
} catch (Exception e) {
log.error("Failed to prepareForStep()", e);
}
return result(Constants.RESULT_FAILURE);
}
use of org.gluu.model.custom.script.conf.CustomScriptConfiguration in project oxAuth by GluuFederation.
the class UmaGatherer method gather.
public boolean gather() {
try {
final HttpServletRequest httpRequest = (HttpServletRequest) externalContext.getRequest();
final HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
final SessionId session = umaSessionService.getSession(httpRequest, httpResponse);
CustomScriptConfiguration script = getScript(session);
UmaGatherContext context = new UmaGatherContext(script.getConfigurationAttributes(), httpRequest, session, umaSessionService, umaPermissionService, umaPctService, pageClaims, userService, facesService, appConfiguration);
int step = umaSessionService.getStep(session);
if (!umaSessionService.isPassedPreviousSteps(session, step)) {
log.error("There are claims-gathering steps not marked as passed. scriptName: '{}', step: '{}'", script.getName(), step);
return false;
}
boolean gatheredResult = external.gather(script, step, context);
log.debug("Claims-gathering result for script '{}', step: '{}', gatheredResult: '{}'", script.getName(), step, gatheredResult);
int overridenNextStep = external.getNextStep(script, step, context);
if (!gatheredResult && overridenNextStep == -1) {
return false;
}
if (overridenNextStep != -1) {
umaSessionService.resetToStep(session, overridenNextStep, step);
step = overridenNextStep;
}
int stepsCount = external.getStepsCount(script, context);
if (step < stepsCount || overridenNextStep != -1) {
int nextStep;
if (overridenNextStep != -1) {
nextStep = overridenNextStep;
} else {
nextStep = step + 1;
umaSessionService.markStep(session, step, true);
}
umaSessionService.setStep(nextStep, session);
context.persist();
String page = external.getPageForStep(script, nextStep, context);
log.trace("Redirecting to page: '{}'", page);
facesService.redirect(page);
return true;
}
if (step == stepsCount) {
context.persist();
onSuccess(session, context);
return true;
}
} catch (Exception e) {
log.error("Exception during gather() method call.", e);
}
log.error("Failed to perform gather() method successfully.");
return false;
}
Aggregations