Package com.adito.security.forms

Examples of com.adito.security.forms.UserAccountForm


     * @return forward
     * @throws Exception on any error
     */
    public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        UserAccountForm account = (UserAccountForm) form;
        PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
        SessionInfo info = this.getSessionInfo(request);
        UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(getSessionInfo(request).getUser().getRealm());
        User user = null;
        if(udb.supportsAccountCreation()) {
            PropertyList roleList = account.getRolesList();
            int idx = 0;
            Role[] roles = new Role[roleList.size()];
            for(Iterator i = roleList.iterator(); i.hasNext(); ) {
                roles[idx++] = udb.getRole((String)i.next());
            }

            if (account.getEditing()) {
                user = udb.getAccount(account.getUsername());
                try {
                    udb.updateAccount(user, account.getEmail(), account.getFullname(), roles);
                    CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_EDITED, user, info)
                        .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 (GroupsRequiredForUserException e) {
                    saveError(request, "createAccount.error.groupsRequired");
                    return mapping.findForward("display");
                } catch (UserDatabaseException e) {
                    if(UserDatabaseException.INTERNAL_ERROR == e.getCode()) {
                        handleException(CoreEventConstants.USER_CREATED, account, info, roles, e);
                        throw e;
                    } else {
                        saveError(request, e.getBundleActionMessage());
                        return mapping.findForward("display");
                    }
                } catch (Exception e) {
                    handleException(CoreEventConstants.USER_EDITED, account, info, roles, e);
                  throw e;
                }
            } else {
              try {
                    user = udb.createAccount(account.getUsername(), String.valueOf((int) (Math.random() * 100000)),
                    // Set a random password
                         account.getEmail(), account.getFullname(), roles);
                    CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_CREATED, null, info, CoreEvent.STATE_SUCCESSFUL)
                    .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, account.getUsername())
                    .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, account.getFullname())
                    .addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, account.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 (GroupsRequiredForUserException e) {
                    saveError(request, "createAccount.error.groupsRequired");
                    return mapping.findForward("display");
              } catch (UserDatabaseException e) {
                    if(UserDatabaseException.INTERNAL_ERROR == e.getCode()) {
                        handleException(CoreEventConstants.USER_CREATED, account, info, roles, e);
                        throw e;
                    } else {
                        saveError(request, e.getBundleActionMessage());
                        return mapping.findForward("display");
                    }
              } catch (Exception e) {
                    handleException(CoreEventConstants.USER_CREATED, account, info, roles, e);
                throw e;
              }
            }
        }
        else {
            user = udb.getAccount(account.getUsername());
        }

        // Update the attributes
        for(Iterator i = account.getAttributeValueItems().iterator(); i.hasNext(); ) {
           AttributeValueItem v = (AttributeValueItem)i.next();
           if(v.getDefinition().getVisibility() != AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
               Property.setProperty(new UserAttributeKey(user, v.getDefinition().getName()), v.getDefinition().formatAttributeValue(v.getValue()), info);
           }
        }
        // XXX HACK to ensure user attributes in memory are the same as persisted
        for(Iterator j = LogonControllerFactory.getInstance().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);
    }

        // we need to reset the menu items as they could have changed here.
        LogonControllerFactory.getInstance().applyMenuItemChanges(request);

        // Go to the set password page if this is a new account and set password was selected
        if (udb.supportsPasswordChange() && (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");
View Full Code Here


     * @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_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
        for(Iterator i = account.getAttributeValueItems().iterator(); i.hasNext(); ) {
            AttributeValueItem v = (AttributeValueItem)i.next();
            v.setValue(v.getDefinition().parseValue(v.getDefinition().getDefaultValue()));
        }
        return mapping.findForward("display");
    }
View Full Code Here

TOP

Related Classes of com.adito.security.forms.UserAccountForm

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.