⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showaccountaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_EDITED, user, this.getSessionInfo())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())
                    	.addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, user.getEmail());

                    if(roles.length != 0) {
                        for(int i = 0; i < roles.length; i++ ) {
                            coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_GROUP + Integer.toString(i+1), roles[i].getPrincipalName()); 
                        }
                    }
                    CoreServlet.getServlet().fireCoreEvent(coreEvent);
                } catch (Exception e) {
                    CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_EDITED, null, info, e)
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())
                    	.addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, user.getEmail());

                    if(roles.length != 0) {
                        for(int i = 0; i < roles.length; i++ ) {
                            coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_GROUP + Integer.toString(i+1), roles[i].getPrincipalName()); 
                        }
                    }
                    CoreServlet.getServlet().fireCoreEvent(coreEvent);
                	throw e;
                }
            } else {
            	try {
                    user = udb.createAccount(account.getUsername(), String.valueOf((int) (Math.random() * 100000)),
                    // Set a random password
                         account.getEmail(), account.getFullname(), roles, new Properties());
                    CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_CREATED, null, info, CoreEvent.STATE_SUCCESSFUL)
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())
                    	.addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, user.getEmail());

                    if(roles.length != 0) {
                        for(int i = 0; i < roles.length; i++ ) {
                            coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_GROUP + Integer.toString(i+1), roles[i].getPrincipalName()); 
                        }
                    }
                    CoreServlet.getServlet().fireCoreEvent(coreEvent);
            	} catch (Exception e) {
                    CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_CREATED, null, info, CoreEvent.STATE_UNSUCCESSFUL)
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
                        .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())
                    	.addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, user.getEmail());

                    if(roles.length != 0) {
                        for(int i = 0; i < roles.length; i++ ) {
                            coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_GROUP + Integer.toString(i+1), roles[i].getPrincipalName()); 
                        }
                    }
                    CoreServlet.getServlet().fireCoreEvent(coreEvent);
            		throw e;
            	}
            }
        }
        else {
            user = udb.getAccount(account.getUsername());
        }

        // Update the attributes
        for(Iterator i = account.getUserAttributeValueItems().iterator(); i.hasNext(); ) {
           UserAttributeValueItem v = (UserAttributeValueItem)i.next();
           if(v.getDefinition().getVisibility() != UserAttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
               CoreUtil.setUserAttribute(getSessionInfo(), v.getDefinition(), v.getValue(), user);
           }
        }
        // XXX HACK to ensure user attributes in memory are the same as persisted
        for(Iterator j = CoreServlet.getServlet().getLogonController().getActiveSessions().entrySet().iterator(); j.hasNext(); ) {
            Map.Entry e = (Map.Entry)j.next();
            SessionInfo sinfo = (SessionInfo)e.getValue();
            if(sinfo.getUser().getPrincipalName().equals(user.getPrincipalName())) {
                sinfo.setUser(user);
            }
        }

        // Reset the enabled state if it is different
        if (PolicyUtil.isEnabled(user) != account.isEnabled()) {
            PolicyUtil.setEnabled(user, account.isEnabled(), null, null);
		}
        
        // Go to the set password page if this is a new account and set password was selected
        if (account.isSetPassword() || !account.getEditing()) {
            request.getSession().setAttribute("setPassword.user", user);
            ActionMessages msgs = new ActionMessages();
            msgs.add(Globals.MESSAGE_KEY, new ActionMessage("createAccount.message.accountSaved"));
            saveMessages(request, msgs);
            return mapping.findForward("setPassword");
        } else {
            return mapping.findForward("success");
        }
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
    }

    /**
     * Reset all user attributes.
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return forward
     * @throws Exception
     */
    public ActionForward resetUserAttributes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        UserAccountForm account = (UserAccountForm) form;
        PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_RESOURCE_TYPE, account.getEditing() ? PolicyConstants.PERM_EDIT : PolicyConstants.PERM_CREATE, request);
        for(Iterator i = account.getUserAttributeValueItems().iterator(); i.hasNext(); ) {
            UserAttributeValueItem v = (UserAttributeValueItem)i.next();
            v.setValue(v.getDefinition().getDefaultValue());
        }
        return mapping.findForward("display");
    }

    /**
     * Send a message.
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return forward
     * @throws Exception
     */
    public ActionForward sendMessage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        UserAccountForm account = (UserAccountForm) form;
        return CoreUtil.addParameterToForward(mapping.findForward("message"), "users", account.getUsername());
    }

    /**
     * Confirm the reset of a users private key.
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return forward
     * @throws Exception
     */
    public ActionForward confirmResetPrivateKey(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        UserAccountForm account = (UserAccountForm) form;
        request.getSession().setAttribute(Constants.EDITING_ITEM, CoreServlet.getServlet().getUserDatabase().getAccount(account.getUsername()));
        return mapping.findForward("confirmResetPrivateKey");
    }

    /**
     * Reset of a users private key.
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return forward
     * @throws Exception
     */
    public ActionForward resetPrivateKey(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        UserAccountForm account = (UserAccountForm) form;
        User u = (User)request.getSession().getAttribute(Constants.EDITING_ITEM); 
        PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_RESOURCE_TYPE, account.getEditing() ? PolicyConstants.PERM_EDIT : PolicyConstants.PERM_CREATE, request);
        for(Iterator i = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinitions().iterator(); i.hasNext(); ) {
            UserAttributeDefinition def = (UserAttributeDefinition)i.next();
            if(def.getVisibility() == UserAttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
                u.getAttributes().remove(def.getName());
            }
        }
        PublicKeyStore.getInstance().removeKeys(u.getPrincipalName());
        CoreServlet.getServlet().getUserDatabase().updateAttributes(u.getPrincipalName(), u.getAttributes());
        return mapping.findForward("display");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -