Package org.apdplat.module.security.model

Examples of org.apdplat.module.security.model.User


     * 根据会话ID获取在线用户的用户名
     * @param sessionID 会话ID
     * @return 用户名
     */
    public String getUsername(String sessionID) {
        User user = getUser(sessionID);
        String username = "匿名用户";
        if (user != null) {
            username = user.getUsername();
        }
        LOG.debug("获取会话为:"+sessionID+" 的用户名:"+username);
        return username;
    }
View Full Code Here


        SessionInformation info=sessionRegistry.getSessionInformation(sessionID);
        if(info == null){
            LOG.debug("没有获取到会话ID为:"+sessionID+" 的在线用户");
            return null;
        }
        User user = (User)info.getPrincipal();
        LOG.debug("获取到会话ID为:"+sessionID+" 的在线用户 "+user.getUsername());
       
        return user;
    }
View Full Code Here

     */
    private List<User> getAllUsers(){
        List<User> result=new ArrayList<>();
        List<Object> users = sessionRegistry.getAllPrincipals();
        for(Object obj : users){
            User user = (User)obj;
            result.add(user);
            LOG.debug("获取到会话ID为:"+sessionRegistry.getAllSessions(obj, false).get(0).getSessionId() +" 的在线用户");
        }
        return result;
    }
View Full Code Here

        List<Object> users = sessionRegistry.getAllPrincipals();
        List<Integer> ids = OrgService.getChildIds(org);
        ids.add(org.getId());
        LOG.debug("特定组织架构及其所有子机构:"+ids);
        for(Object obj : users){
            User user = (User)obj;
            if(ids.contains(user.getOrg().getId())){
                result.add(user);
                LOG.info("获取到会话ID为:"+sessionRegistry.getAllSessions(obj, false).get(0).getSessionId() +" 的在线用户");
            }
        }
        return result;
View Full Code Here

        }
        List<Object> users = sessionRegistry.getAllPrincipals();
        List<Integer> roleIds=RoleService.getChildIds(role);
        roleIds.add(role.getId());
        for(Object obj : users){
            User user=(User)obj;
            for(Role r : user.getRoles()){
                if(roleIds.contains(r.getId())){
                    result.add(user);
                    LOG.info("获取到会话ID为:"+sessionRegistry.getAllSessions(obj, false).get(0).getSessionId() +" 的在线用户");
                    break;
                }
View Full Code Here

        roleIds.add(role.getId());
        LOG.debug("特定组织架构及其所有子组织架构:"+orgIds);
        LOG.debug("特定角色及其所有子角色:"+orgIds);
        //遍历所有的用户
        for(Object obj : users){
            User user=(User)obj;
            //用户的ID在指定组织架构范围内
            if(orgIds.contains(user.getOrg().getId())){
                for(Role r : user.getRoles()){
                    //用户的ID在指定角色范围内
                    if(roleIds.contains(r.getId())){
                        result.add(user);
                        LOG.debug("获取到会话ID为:"+sessionRegistry.getAllSessions(obj, false).get(0).getSessionId() +" 的在线用户");
                        break;
View Full Code Here

    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        if (se.getValue() instanceof SecurityContextImpl && loginMonitor) {
            User user=UserHolder.getCurrentLoginUser();
            if (null != user) {
                String sessioId=se.getSession().getId();
                LOG.info("用户 "+user.getUsername()+" 登录成功,会话ID:"+sessioId);

                if(logs.get(user.getUsername())==null){
                    LOG.info("开始记录用户 "+user.getUsername()+" 的登录日志");
                    String ip=UserHolder.getCurrentUserLoginIp();
                    UserLogin userLogin=new UserLogin();
                    userLogin.setAppName(SystemListener.getContextPath());
                    userLogin.setLoginIP(ip);
                    userLogin.setUserAgent(se.getSession().getAttribute("userAgent").toString());
                    userLogin.setLoginTime(new Date());
                    try {
                        userLogin.setServerIP(InetAddress.getLocalHost().getHostAddress());
                    } catch (UnknownHostException e) {
                        LOG.error("记录登录日志出错",e);
                    }
                    userLogin.setUsername(user.getUsername());
                    //保存用户登陆日志
                    BufferLogCollector.collect(userLogin);
                    logs.put(user.getUsername(), userLogin);
                }else{
                    LOG.info("用户 "+user.getUsername()+" 的登录日志已经被记录过,用户在未注销前又再次登录,忽略此登录");
                }
            }else{
                LOG.info("在登录的时候获得User失败");
            }
        }
View Full Code Here

            SecurityContext context=(SecurityContext)se.getValue();
            Authentication authentication=context.getAuthentication();
            if (authentication != null) {
                Object principal = authentication.getPrincipal();
                if (principal instanceof User) {
                    User user = (User) principal;
                    if (null != user) {
                        String sessioId=se.getSession().getId();
                        LOG.info("用户 "+user.getUsername()+" 注销成功,会话ID:"+sessioId);

                        UserLogin userLogin=logs.get(user.getUsername());
                        if(userLogin!=null){
                            LOG.info("开始记录用户 "+user.getUsername()+" 的注销日志");
                            userLogin.setLogoutTime(new Date());
                            userLogin.setOnlineTime(userLogin.getLogoutTime().getTime()-userLogin.getLoginTime().getTime());
                            //更新userLogin
                            ServiceFacade serviceFacade = SpringContextUtils.getBean("serviceFacadeForLog");
                            serviceFacade.update(userLogin);
                            logs.remove(user.getUsername());
                        }else{
                            LOG.info("无法记录用户 "+user.getUsername()+" 的注销日志,因为用户的登录日志不存在");
                        }
                    }else{
                        LOG.info("在注销的时候获得User失败");
                    }
                }
View Full Code Here

     * 设置创建时间
     * @param model
     */
    @Override
    public void prePersist(Model model) {       
        User user=UserHolder.getCurrentLoginUser();
        if(model instanceof SimpleModel){
            SimpleModel simpleModel = (SimpleModel)model;
            if(user!=null && simpleModel.getOwnerUser()==null && !model.getClass().isAnnotationPresent(IgnoreUser.class)){
                //设置数据的拥有者
                simpleModel.setOwnerUser(user);
                LOG.debug("设置模型"+model+"的拥有者为:"+user.getUsername());
            }
        }
        //设置创建时间
        model.setCreateTime(new Date());
        LOG.debug("设置模型"+model+"的创建时间");
View Full Code Here

     * @param type
     */
    private void saveLog(Model model, String type){
        //判断模型是否已经指定忽略记录增删改日志
        if(!model.getClass().isAnnotationPresent(IgnoreBusinessLog.class)){
            User user=UserHolder.getCurrentLoginUser();
            String ip=UserHolder.getCurrentUserLoginIp();
            OperateLog operateLog=new OperateLog();
            if(user != null){
                operateLog.setUsername(user.getUsername());
            }
            operateLog.setLoginIP(ip);
            try {
                operateLog.setServerIP(InetAddress.getLocalHost().getHostAddress());
            } catch (UnknownHostException ex) {
View Full Code Here

TOP

Related Classes of org.apdplat.module.security.model.User

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.