Search in sources :

Example 1 with CheckedDroolsException

use of org.drools.CheckedDroolsException 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;
}
Also used : FacesContext(javax.faces.context.FacesContext) InputStreamReader(java.io.InputStreamReader) CheckedDroolsException(org.drools.CheckedDroolsException) InputStream(java.io.InputStream) WorkingMemory(org.drools.WorkingMemory) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IOException(java.io.IOException) CheckedDroolsException(org.drools.CheckedDroolsException) HttpServletRequest(javax.servlet.http.HttpServletRequest) RuleBase(org.drools.RuleBase)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 FacesContext (javax.faces.context.FacesContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 CheckedDroolsException (org.drools.CheckedDroolsException)1 RuleBase (org.drools.RuleBase)1 WorkingMemory (org.drools.WorkingMemory)1