Package org.joget.directory.model.service

Examples of org.joget.directory.model.service.UserSecurity


                // don't store authentication in session for json calls
                SecurityContextHolder.getContext().setAuthentication(null);
            }           
            */

            UserSecurity us = DirectoryUtil.getUserSecurity();
            if (us != null) {
                us.requestPostProcessing();
            }
           
            // clear current user
            workflowUserManager.clearCurrentThreadUser();
            LocaleContextHolder.resetLocaleContext();
View Full Code Here


        if (pathParamIndex > 0) {
            // strip everything after the first semi-colon
            uri = uri.substring(0, pathParamIndex);
        }

        UserSecurity us = DirectoryUtil.getUserSecurity();
        if ((super.obtainUsername(request) != null)) {
            // request contains j_username, force authentication
            requiresAuth = true;
        } else if (us != null) {
            uri = uri.substring(request.getContextPath().length());
            if (us.getAuthenticateAllApi() && uri.startsWith("/web/json/") && (!uri.startsWith("/web/json/plugin") || uri.startsWith("/web/json/plugin/list")) && !uri.startsWith("/web/json/directory/user/sso") && !uri.startsWith("/web/json/workflow/currentUsername") && !uri.startsWith("/web/json/apps/published/userviews") && isAnonymous) {
                // authenticateAllApi flag is true, so force authentication for all json calls except for plugin, sso, and published userview calls
                requiresAuth = true;
            } else if (us.getForceSessionTimeout() && !isAnonymous) {
                // logged in, but timed out
                requiresAuth = true;
            }
        }
       
View Full Code Here

    protected Authentication authenticate(HttpServletRequest request) throws AuthenticationException {
        RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
       
        boolean isAnonymous = workflowUserManager.isCurrentUserAnonymous();
        UserSecurity us = DirectoryUtil.getUserSecurity();
        if (us != null && us.getForceSessionTimeout() && !isAnonymous) {
            throw new BadCredentialsException(ResourceBundleUtil.getMessage("authentication.failed.sessionTimeOut"));
        }
       
        Authentication auth = null;

        // check for username/password in request
        String username = super.obtainUsername(request);
        String password = super.obtainPassword(request);

        String loginAs = request.getParameter("loginAs");
        String loginHash = request.getParameter("hash");
       
        // Place the last username attempted into HttpSession for views
        HttpSession session = request.getSession(false);

        if (session != null || getAllowSessionCreation()) {
            request.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY, TextUtils.escapeEntities(username));
        }

        if (username != null && (password != null || loginHash != null)) {
            User currentUser = null;

            //diable master login based on UserSecurity
            if (us != null && us.getDisableHashLogin()) {
                loginAs = null;
            }
           
            if (loginAs != null) {
                String masterLoginUsername = getSetupManager().getSettingValue("masterLoginUsername");
                String masterLoginPassword = getSetupManager().getSettingValue("masterLoginPassword");
               
                //decryt masterLoginPassword
                masterLoginPassword = SecurityUtil.decrypt(masterLoginPassword);

                if ((masterLoginUsername != null && masterLoginUsername.trim().length() > 0) &&
                        (masterLoginPassword != null && masterLoginPassword.trim().length() > 0)) {

                    User master = new User();
                    master.setUsername(masterLoginUsername.trim());
                    master.setPassword(StringUtil.md5Base16(masterLoginPassword.trim()));

                    if (username.trim().equals(master.getUsername()) &&
                            ((password != null && StringUtil.md5Base16(password.trim()).equalsIgnoreCase(master.getPassword())) ||
                            (loginHash != null && loginHash.trim().equalsIgnoreCase(master.getLoginHash())))) {
                        currentUser = directoryManager.getUserByUsername(loginAs);
                        if (currentUser != null) {
                            WorkflowUserDetails user = new WorkflowUserDetails(currentUser);
                           
                            auth = new UsernamePasswordAuthenticationToken(user, user.getUsername(), user.getAuthorities());
                            super.setDetails(request, (UsernamePasswordAuthenticationToken) auth);
                        } else {
                            LogUtil.info(getClass().getName(), "Authentication for user " + loginAs + ": " + false);
           
                            WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                            workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + loginAs + ": " + false);
                       
                            throw new BadCredentialsException("");
                        }
                    }
                }
            } else {
                if (loginHash != null) {
                    password = loginHash;
                }
                if (password != null) {
                    // use existing authentication manager
                    try {
                        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username.trim(), password.trim());
                        super.setDetails(request, authRequest);

                        auth = getAuthenticationManager().authenticate(authRequest);

                        // no direct way in Spring Security 2, so use reflection to clear password in token
                        Field field = null;
                        try {
                            field = auth.getClass().getDeclaredField("credentials");
                            field.setAccessible(true);
                            field.set(auth, null);
                        } catch (Exception ex) {
                            LogUtil.error(getClass().getName(), ex, "Error clearing credentials in token");
                        } finally {
                            if (field != null) {
                                field.setAccessible(false);
                            }
                        }
                       
                        if (auth.isAuthenticated()) {
                            currentUser = directoryManager.getUserByUsername(username);
                        }
                    } catch (BadCredentialsException be) {
                        LogUtil.info(getClass().getName(), "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + false);
           
                        WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                        workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + false);
           
                        throw be;
                    }
                }
            }

            if (currentUser != null) {
                workflowUserManager.setCurrentThreadUser(currentUser.getUsername());
            }

            if (!"/WEB-INF/jsp/unauthorized.jsp".equals(request.getServletPath())) {
                LogUtil.info(getClass().getName(), "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + true);
                WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + true);
            }
        } else {
            if (us != null && us.getAuthenticateAllApi()) {
                throw new BadCredentialsException("");
            }
        }

        return auth;
View Full Code Here

        Map<String, String> status = new HashMap<String, String>();
        status.put("1", "Active");
        status.put("0", "Inactive");
        model.addAttribute("status", status);
       
        UserSecurity us = DirectoryUtil.getUserSecurity();
        if (us != null) {
            model.addAttribute("userFormFooter", us.getUserCreationFormFooter());
        } else {
            model.addAttribute("userFormFooter", "");
        }

        User user = new User();
View Full Code Here

                //remove trailing comma
                roles = roles.substring(0, roles.length() - 2);
            }
            model.addAttribute("roles", roles);
           
            UserSecurity us = DirectoryUtil.getUserSecurity();
            if (us != null) {
                model.addAttribute("addOnButtons", us.getUserDetailsButtons(user));
            }
        }

        model.addAttribute("isCustomDirectoryManager", DirectoryUtil.isCustomDirectoryManager());
View Full Code Here

        model.addAttribute("employeeGrade", employment.getGradeId());
        model.addAttribute("employeeStartDate", employment.getStartDate());
        model.addAttribute("employeeEndDate", employment.getEndDate());
        model.addAttribute("employeeDepartmentHod", (employment.getHods() != null && employment.getHods().size() > 0) ? "yes" : "no");
       
        UserSecurity us = DirectoryUtil.getUserSecurity();
        if (us != null) {
            model.addAttribute("userFormFooter", us.getUserEditingFormFooter(user));
        } else {
            model.addAttribute("userFormFooter", "");
        }
       
        return "console/directory/userEdit";
View Full Code Here

            @RequestParam(value = "employeeDepartmentHod", required = false) String employeeDepartmentHod, @RequestParam(value = "employeeGrade", required = false) String employeeGrade,
            @RequestParam(value = "employeeStartDate", required = false) String employeeStartDate, @RequestParam(value = "employeeEndDate", required = false) String employeeEndDate) {
        // validate ID
        validator.validate(user, result);

        UserSecurity us = DirectoryUtil.getUserSecurity();

        boolean invalid = result.hasErrors();
        if (!invalid) {
            // check error
            Collection<String> errors = new ArrayList<String>();
           
            if ("create".equals(action)) {
                // check username exist
                if (directoryManager.getUserByUsername(user.getUsername()) != null || (us != null && us.isDataExist(user.getUsername()))) {
                    errors.add(ResourceBundleUtil.getMessage("console.directory.user.error.label.usernameExists"));
                }
               
                if (us != null) {
                    Collection<String> validationErrors = us.validateUserOnInsert(user);
                    if (validationErrors != null && !validationErrors.isEmpty()) {
                        errors.addAll(validationErrors);
                    }
                }
               
                errors.addAll(validateEmploymentDate(employeeStartDate, employeeEndDate));

                if (errors.isEmpty()) {
                    user.setId(user.getUsername());
                    if (user.getPassword() != null && !user.getPassword().trim().isEmpty()) {
                        user.setConfirmPassword(user.getPassword());
                        if (us != null) {
                            user.setPassword(us.encryptPassword(user.getUsername(), user.getPassword()));
                        } else {
                            //md5 password
                            user.setPassword(StringUtil.md5Base16(user.getPassword()));
                        }
                    }

                    //set roles
                    if (user.getRoles() != null && user.getRoles().size() > 0) {
                        Set roles = new HashSet();
                        for (String roleId : (Set<String>) user.getRoles()) {
                            roles.add(roleDao.getRole(roleId));
                        }
                        user.setRoles(roles);
                    }

                    invalid = !userDao.addUser(user);

                    if (us != null && !invalid) {
                        us.insertUserPostProcessing(user);
                    }
                }
            } else {
                user.setUsername(user.getId());
               
                if (us != null) {
                    Collection<String> validationErrors = us.validateUserOnUpdate(user);
                    if (validationErrors != null && !validationErrors.isEmpty()) {
                        errors.addAll(validationErrors);
                    }
                }
               
                errors.addAll(validateEmploymentDate(employeeStartDate, employeeEndDate));
               
                if (errors.isEmpty()) {
                    boolean passwordReset = false;

                    User u = userDao.getUserById(user.getId());
                    u.setFirstName(user.getFirstName());
                    u.setLastName(user.getLastName());
                    u.setEmail(user.getEmail());
                    if (user.getPassword() != null && !user.getPassword().trim().isEmpty()) {
                        u.setConfirmPassword(user.getPassword());
                        if (us != null) {
                            passwordReset = true;
                            u.setPassword(us.encryptPassword(user.getUsername(), user.getPassword()));
                        } else {
                            //md5 password
                            u.setPassword(StringUtil.md5Base16(user.getPassword()));
                        }
                    }
                    //set roles
                    if (user.getRoles() != null && user.getRoles().size() > 0) {
                        Set roles = new HashSet();
                        for (String roleId : (Set<String>) user.getRoles()) {
                            roles.add(roleDao.getRole(roleId));
                        }
                        u.setRoles(roles);
                    }
                    u.setTimeZone(user.getTimeZone());
                    u.setActive(user.getActive());

                    invalid = !userDao.updateUser(u);
                    if (us != null && !invalid) {
                        us.updateUserPostProcessing(u);
                        if (passwordReset) {
                            us.passwordResetPostProcessing(u);
                        }
                    }
                }
            }

            if (!errors.isEmpty()) {
                model.addAttribute("errors", errors);
                invalid = true;
            }
        }

        if (invalid) {
            Collection<Organization> organizations = organizationDao.getOrganizationsByFilter(null, "name", false, null, null);
            model.addAttribute("organizations", organizations);
            model.addAttribute("roles", roleDao.getRoles(null, "name", false, null, null));
            model.addAttribute("timezones", TimeZoneUtil.getList());

            Map<String, String> status = new HashMap<String, String>();
            status.put("1", "Active");
            status.put("0", "Inactive");
            model.addAttribute("status", status);

            model.addAttribute("user", user);

            model.addAttribute("employeeCode", employeeCode);
            model.addAttribute("employeeRole", employeeRole);
            model.addAttribute("employeeOrganization", employeeOrganization);
            model.addAttribute("employeeDepartment", employeeDepartment);
            model.addAttribute("employeeGrade", employeeGrade);
            model.addAttribute("employeeStartDate", employeeStartDate);
            model.addAttribute("employeeEndDate", employeeEndDate);
            model.addAttribute("employeeDepartmentHod", employeeDepartmentHod);
           
            if (us != null) {
                if ("create".equals(action)) {
                    model.addAttribute("userFormFooter", us.getUserCreationFormFooter());
                } else {
                    model.addAttribute("userFormFooter", us.getUserEditingFormFooter(user));
                }
            } else {
                model.addAttribute("userFormFooter", "");
            }
           
View Full Code Here

            String id = (String) strToken.nextElement();
           
            if (id != null && !id.equals(currentUsername)) {
                userDao.deleteUser(id);

                UserSecurity us = DirectoryUtil.getUserSecurity();
                if (us != null) {
                    us.deleteUserPostProcessing(id);
                }
            }
        }
        return "console/directory/userList";
    }
View Full Code Here

                    localeStringList.put(code, code + " - " +localeList[x].getDisplayName(localeResolver.resolveLocale(WorkflowUtil.getHttpServletRequest())));
                }
            }
        }
       
        UserSecurity us = DirectoryUtil.getUserSecurity();
        if (us != null) {
            map.addAttribute("policies", us.passwordPolicies());
            map.addAttribute("userProfileFooter", us.getUserProfileFooter(user));
        } else {
            map.addAttribute("policies", "");
            map.addAttribute("userProfileFooter", "");
        }
View Full Code Here

            } catch (Exception e) {
            }
        }
       
       
        UserSecurity us = DirectoryUtil.getUserSecurity();

        if (!authenticated) {
            if (errors == null) {
                errors = new ArrayList<String>();
            }
            errors.add(ResourceBundleUtil.getMessage("console.directory.user.error.label.authenticationFailed"));
        } else {
            if (us != null) {
                errors = us.validateUserOnProfileUpdate(user);
            }

            if (user.getPassword() != null && !user.getPassword().isEmpty() && us != null) {
                passwordErrors = us.validatePassword(user.getUsername(), user.getOldPassword(), user.getPassword(), user.getConfirmPassword());  
            }
        }

        if (!authenticated || (passwordErrors != null && !passwordErrors.isEmpty()) || (errors != null && !errors.isEmpty())) {
            model.addAttribute("passwordErrors", passwordErrors);
            model.addAttribute("errors", errors);
            model.addAttribute("user", user);
            model.addAttribute("timezones", TimeZoneUtil.getList());

            String enableUserLocale = setupManager.getSettingValue("enableUserLocale");
            Map<String, String> localeStringList = new TreeMap<String, String>();
            if (enableUserLocale != null && enableUserLocale.equalsIgnoreCase("true")) {
                String userLocale = setupManager.getSettingValue("userLocale");
                Collection<String> locales = new HashSet();
                locales.addAll(Arrays.asList(userLocale.split(",")));

                Locale[] localeList = Locale.getAvailableLocales();
                for (int x = 0; x < localeList.length; x++) {
                    String code = localeList[x].toString();
                    if (locales.contains(code)) {
                        localeStringList.put(code, code + " - " + localeList[x].getDisplayName(localeResolver.resolveLocale(WorkflowUtil.getHttpServletRequest())));
                    }
                }
            }
            model.addAttribute("enableUserLocale", enableUserLocale);
            model.addAttribute("localeStringList", localeStringList);
           
            if (us != null) {
                model.addAttribute("policies", us.passwordPolicies());
                model.addAttribute("userProfileFooter", us.getUserProfileFooter(currentUser));
            } else {
                model.addAttribute("policies", "");
                model.addAttribute("userProfileFooter", "");
            }

            return "console/profile";
        } else {
            if (currentUser.getUsername().equals(user.getUsername())) {
                currentUser.setFirstName(user.getFirstName());
                currentUser.setLastName(user.getLastName());
                currentUser.setEmail(user.getEmail());
                currentUser.setTimeZone(user.getTimeZone());
                currentUser.setLocale(user.getLocale());
                if (user.getPassword() != null && user.getConfirmPassword() != null && user.getPassword().length() > 0 && user.getPassword().equals(user.getConfirmPassword())) {
                    if (us != null) {
                        currentUser.setPassword(us.encryptPassword(user.getUsername(), user.getPassword()));
                    } else {
                        currentUser.setPassword(StringUtil.md5Base16(user.getPassword()));
                    }
                    currentUser.setConfirmPassword(user.getPassword());
                }
                userDao.updateUser(currentUser);

                if (us != null) {
                    us.updateUserProfilePostProcessing(currentUser);
                }
            }
        }

        return "console/dialogClose";
View Full Code Here

TOP

Related Classes of org.joget.directory.model.service.UserSecurity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.