use of org.drools.RuleBase in project oxTrust by GluuFederation.
the class SsoLoginAction method start.
public String start() {
if (initialized) {
return OxTrustConstants.RESULT_SUCCESS;
}
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
relyingPartyId = request.getHeader("relyingPartyId");
setActionUrl(request.getHeader("actionUrl"));
log.debug("relyingPartyId is" + relyingPartyId);
log.debug("actionUrl is" + actionUrl);
if (StringHelper.isEmpty(relyingPartyId)) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Direct access to this page is not supported");
// return Configuration.RESULT_FAILURE;
}
try {
log.debug("Getting SSL HTTP Client");
// Create HTTP local context
// Bind cookie store to the local context
// Add user cookies
log.debug("Setting HTTP Client cookies from user session");
} catch (Exception ex) {
log.error("Failed to initialize HTTP Client", ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to prepare login form");
// return Configuration.RESULT_FAILURE;
}
initialized = true;
RuleBase ruleBase = null;
try {
log.info("Checking for customized login pages");
InputStream is = getClass().getClassLoader().getResourceAsStream("selection.drl");
if (is != null) {
log.info("Login page customization rules found.");
Reader reader = new InputStreamReader(is);
try {
ruleBase = RuleBaseLoader.getInstance().loadFromReader(reader);
WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(relyingPartyId);
// workingMemory.insert(contextKey);
// workingMemory.insert(relayState);
// workingMemory.insert(relayStateValue);
// workingMemory.insert(requestedSessionId);
List<String> viewId = new ArrayList<String>();
workingMemory.insert(viewId);
workingMemory.fireAllRules();
if (viewId.size() > 0) {
log.info("Login page customization rules fired: " + viewId.get(0));
facesService.redirect(viewId.get(0));
}
} finally {
IOUtils.closeQuietly(reader);
}
}
} catch (CheckedDroolsException e) {
e.printStackTrace();
} catch (IOException e) {
log.warn("There were error reading selection.drl");
}
return OxTrustConstants.RESULT_SUCCESS;
}
Aggregations