Search in sources :

Example 1 with ScaleSingleRequestUser

use of com.tremolosecurity.scalejs.singlerequest.data.ScaleSingleRequestUser in project OpenUnison by TremoloSecurity.

the class ScaleSingleRequest method doFilter.

@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
    Gson gson = new Gson();
    request.getServletRequest().setAttribute("com.tremolosecurity.unison.proxy.noRedirectOnError", "com.tremolosecurity.unison.proxy.noRedirectOnError");
    if (request.getRequestURI().endsWith("/singlerequest/config")) {
        response.setContentType("application/json");
        ScaleSingleRequestUser ssru = new ScaleSingleRequestUser();
        ssru.setConfig(scaleConfig);
        AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
        Attribute displayNameAttribute = userData.getAttribs().get(this.scaleConfig.getDisplayNameAttribute());
        if (displayNameAttribute != null) {
            ssru.setDisplayName(displayNameAttribute.getValues().get(0));
        } else {
            ssru.setDisplayName("Unknown");
        }
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().println(gson.toJson(ssru).trim());
    } else if (request.getMethod().equalsIgnoreCase("POST") && request.getRequestURI().endsWith("/singlerequest/submit")) {
        AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
        String json = new String((byte[]) request.getAttribute(ProxySys.MSG_BODY));
        SingleRequest sr = gson.fromJson(json, SingleRequest.class);
        ScaleError errors = new ScaleError();
        if (sr.getReason() == null || sr.getReason().isEmpty()) {
            errors.getErrors().add("Reason is required");
        } else {
            ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
            WFCall wfCall = new WFCall();
            wfCall.setName(this.scaleConfig.getWorkflowName());
            wfCall.setReason(sr.getReason());
            wfCall.setUidAttributeName(this.scaleConfig.getUidAttribute());
            TremoloUser tu = new TremoloUser();
            tu.setUid(userData.getAttribs().get(this.scaleConfig.getUidAttribute()).getValues().get(0));
            tu.getAttributes().add(new Attribute(this.scaleConfig.getUidAttribute(), userData.getAttribs().get(this.scaleConfig.getUidAttribute()).getValues().get(0)));
            if (this.scaleConfig.isUseAttributesFromAuthentication()) {
                for (String key : userData.getAttribs().keySet()) {
                    Attribute fromUser = userData.getAttribs().get(key);
                    if (!key.equalsIgnoreCase(this.scaleConfig.getUidAttribute())) {
                        Attribute forwf = new Attribute(key);
                        forwf.getValues().addAll(fromUser.getValues());
                        tu.getAttributes().add(forwf);
                    }
                }
            }
            wfCall.setUser(tu);
            try {
                com.tremolosecurity.provisioning.workflow.ExecuteWorkflow exec = new com.tremolosecurity.provisioning.workflow.ExecuteWorkflow();
                exec.execute(wfCall, GlobalEntries.getGlobalEntries().getConfigManager());
            } catch (Exception e) {
                logger.error("Could not update user", e);
                errors.getErrors().add("Please contact your system administrator");
            }
        }
        if (errors.getErrors().size() > 0) {
            response.setStatus(500);
            response.getWriter().print(gson.toJson(errors).trim());
            response.getWriter().flush();
        }
    }
}
Also used : SingleRequest(com.tremolosecurity.scalejs.singlerequest.data.SingleRequest) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) WFCall(com.tremolosecurity.provisioning.service.util.WFCall) Attribute(com.tremolosecurity.saml.Attribute) Gson(com.google.gson.Gson) ScaleSingleRequestUser(com.tremolosecurity.scalejs.singlerequest.data.ScaleSingleRequestUser) ScaleError(com.tremolosecurity.scalejs.data.ScaleError) AuthController(com.tremolosecurity.proxy.auth.AuthController) ConfigManager(com.tremolosecurity.config.util.ConfigManager) TremoloUser(com.tremolosecurity.provisioning.service.util.TremoloUser)

Aggregations

Gson (com.google.gson.Gson)1 ConfigManager (com.tremolosecurity.config.util.ConfigManager)1 TremoloUser (com.tremolosecurity.provisioning.service.util.TremoloUser)1 WFCall (com.tremolosecurity.provisioning.service.util.WFCall)1 AuthController (com.tremolosecurity.proxy.auth.AuthController)1 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)1 Attribute (com.tremolosecurity.saml.Attribute)1 ScaleError (com.tremolosecurity.scalejs.data.ScaleError)1 ScaleSingleRequestUser (com.tremolosecurity.scalejs.singlerequest.data.ScaleSingleRequestUser)1 SingleRequest (com.tremolosecurity.scalejs.singlerequest.data.SingleRequest)1