<commit_before>/*
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id$
 */
package org.gridlab.gridsphere.portlets.core.login;

import org.gridlab.gridsphere.portlet.*;
import org.gridlab.gridsphere.portlet.service.PortletServiceException;
import org.gridlab.gridsphere.provider.event.FormEvent;
import org.gridlab.gridsphere.provider.portlet.ActionPortlet;
import org.gridlab.gridsphere.provider.portletui.beans.CheckBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.FrameBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.portletui.beans.HiddenFieldBean;
import org.gridlab.gridsphere.services.core.security.auth.modules.LoginAuthModule;
import org.gridlab.gridsphere.services.core.security.acl.AccessControlManagerService;
import org.gridlab.gridsphere.services.core.security.acl.GroupRequest;
import org.gridlab.gridsphere.services.core.security.password.InvalidPasswordException;
import org.gridlab.gridsphere.services.core.security.password.PasswordManagerService;
import org.gridlab.gridsphere.services.core.user.LoginService;
import org.gridlab.gridsphere.services.core.user.UserManagerService;
import org.gridlab.gridsphere.services.core.user.AccountRequest;

import javax.servlet.UnavailableException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class LoginPortlet extends ActionPortlet {

    public static final String LOGIN_ERROR_FLAG = "LOGIN_FAILED";
    public static final Integer LOGIN_ERROR_UNKNOWN = new Integer(-1);

    public static final String DO_VIEW_USER_EDIT_LOGIN = "login/createaccount.jsp"; //edit user
    public static final String DO_CONFIGURE = "login/config.jsp"; //edit user

    private static boolean canUserCreateAccount = true;

    private UserManagerService userManagerService = null;
    private AccessControlManagerService aclService = null;
    private PasswordManagerService passwordManagerService = null;

    public void init(PortletConfig config) throws UnavailableException {
        super.init(config);
        try {
            userManagerService = (UserManagerService)getPortletConfig().getContext().getService(UserManagerService.class);
            aclService = (AccessControlManagerService)getPortletConfig().getContext().getService(AccessControlManagerService.class);
            passwordManagerService = (PasswordManagerService)getPortletConfig().getContext().getService(PasswordManagerService.class);
        } catch (PortletServiceException e) {
            throw new UnavailableException("Unable to initialize services");
        }
        DEFAULT_VIEW_PAGE = "doViewUser";
        DEFAULT_CONFIGURE_PAGE = "showConfigure";
    }

    public void initConcrete(PortletSettings settings) throws UnavailableException {
        super.initConcrete(settings);
    }

    public void doViewUser(FormEvent event) throws PortletException {
        log.debug("in LoginPortlet: doViewUser");
        PortletRequest request = event.getPortletRequest();
        User user = request.getUser();
        request.setAttribute("user", user);
        if (user instanceof GuestUser) {
            request.setAttribute("canUserCreateAcct", new Boolean(canUserCreateAccount));
            setNextState(request, "login/login.jsp");
        } else {
            showConfigure(event);
        }
    }<commit_msg>The initial value of the canUserCreateAccount property can be set using an initial portlet parameter of the same name<commit_after>/*
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id$
 */
package org.gridlab.gridsphere.portlets.core.login;

import org.gridlab.gridsphere.portlet.*;
import org.gridlab.gridsphere.portlet.service.PortletServiceException;
import org.gridlab.gridsphere.provider.event.FormEvent;
import org.gridlab.gridsphere.provider.portlet.ActionPortlet;
import org.gridlab.gridsphere.provider.portletui.beans.CheckBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.FrameBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.portletui.beans.HiddenFieldBean;
import org.gridlab.gridsphere.services.core.security.auth.modules.LoginAuthModule;
import org.gridlab.gridsphere.services.core.security.acl.AccessControlManagerService;
import org.gridlab.gridsphere.services.core.security.acl.GroupRequest;
import org.gridlab.gridsphere.services.core.security.password.InvalidPasswordException;
import org.gridlab.gridsphere.services.core.security.password.PasswordManagerService;
import org.gridlab.gridsphere.services.core.user.LoginService;
import org.gridlab.gridsphere.services.core.user.UserManagerService;
import org.gridlab.gridsphere.services.core.user.AccountRequest;

import javax.servlet.UnavailableException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class LoginPortlet extends ActionPortlet {

    public static final String LOGIN_ERROR_FLAG = "LOGIN_FAILED";
    public static final Integer LOGIN_ERROR_UNKNOWN = new Integer(-1);

    public static final String DO_VIEW_USER_EDIT_LOGIN = "login/createaccount.jsp"; //edit user
    public static final String DO_CONFIGURE = "login/config.jsp"; //configure login 

    private boolean canUserCreateAccount = true;

    private UserManagerService userManagerService = null;
    private AccessControlManagerService aclService = null;
    private PasswordManagerService passwordManagerService = null;

    public void init(PortletConfig config) throws UnavailableException {
        super.init(config);
        try {
            userManagerService = (UserManagerService)getPortletConfig().getContext().getService(UserManagerService.class);
            aclService = (AccessControlManagerService)getPortletConfig().getContext().getService(AccessControlManagerService.class);
            passwordManagerService = (PasswordManagerService)getPortletConfig().getContext().getService(PasswordManagerService.class);
            String createAllowed = config.getInitParameter("canUserCreateAccount");
            if (createAllowed != null) {
                    if (createAllowed.equalsIgnoreCase("false")) {
                            canUserCreateAccount = false;
                    }
                    if (createAllowed.equalsIgnoreCase("true")) {
                            canUserCreateAccount = true;
                    }
            }
        } catch (PortletServiceException e) {
            throw new UnavailableException("Unable to initialize services");
        }
        DEFAULT_VIEW_PAGE = "doViewUser";
        DEFAULT_CONFIGURE_PAGE = "showConfigure";
    }

    public void initConcrete(PortletSettings settings) throws UnavailableException {
        super.initConcrete(settings);
    }

    public void doViewUser(FormEvent event) throws PortletException {
        log.debug("in LoginPortlet: doViewUser");
        PortletRequest request = event.getPortletRequest();
        User user = request.getUser();
        request.setAttribute("user", user);
        if (user instanceof GuestUser) {
            request.setAttribute("canUserCreateAcct", new Boolean(canUserCreateAccount));
            setNextState(request, "login/login.jsp");
        } else {
            showConfigure(event);
        }
    }
{'fraction_non_alphanumeric': 0.09277515192437542, 'fraction_numerical': 0.0002700877785280216, 'mean_word_length': 4.179020979020979, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '678087', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1940, 'n_words': 361}