Search in sources :

Example 46 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class CurrentUserProfileAction method edit.

@Override
public String edit() {
    try {
        IUserProfile userProfile = null;
        UserDetails currentUser = this.getCurrentUser();
        Object object = currentUser.getProfile();
        if (null != object && object instanceof IUserProfile) {
            // String username = currentUser.getUsername();
            // this.getUserProfileManager().getProfile(username);
            userProfile = (IUserProfile) object;
            this.checkTypeLabels(userProfile);
        } else {
            return "currentUserWithoutProfile";
        }
        IUserProfile currentProfile = this.getUserProfile();
        if (null == currentProfile || !currentProfile.getUsername().equals(currentUser.getUsername())) {
            userProfile.disableAttributes(SystemConstants.USER_PROFILE_ATTRIBUTE_DISABLING_CODE_ON_EDIT);
            this.getRequest().getSession().setAttribute(SESSION_PARAM_NAME_CURRENT_PROFILE, userProfile);
        }
    } catch (Throwable t) {
        _logger.error("error in edit", t);
        // ApsSystemUtils.logThrowable(t, this, "edit");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 47 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class UserShortcutsConfigTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    try {
        UserConfigBean config = (UserConfigBean) request.getSession().getAttribute(MyShortcutConfigAction.SESSION_PARAM_MY_SHORTCUTS);
        UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        if (null == config || !currentUser.getUsername().equals(config.getUsername())) {
            request.getSession().removeAttribute(MyShortcutConfigAction.SESSION_PARAM_MY_SHORTCUTS);
            IShortcutManager shortcutManager = (IShortcutManager) ApsWebApplicationUtils.getBean(ApsAdminSystemConstants.SHORTCUT_MANAGER, this.pageContext);
            config = shortcutManager.getUserConfigBean(currentUser);
        }
        if (null != this.getVar()) {
            ValueStack stack = this.getStack();
            stack.getContext().put(this.getVar(), config);
            stack.setValue("#attr['" + this.getVar() + "']", config, false);
        }
    } catch (Throwable t) {
        _logger.error("Error on doStartTag", t);
        throw new JspException("Error on doStartTag", t);
    }
    return super.doEndTag();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ValueStack(com.opensymphony.xwork2.util.ValueStack) IShortcutManager(org.entando.entando.apsadmin.system.services.shortcut.IShortcutManager) UserConfigBean(org.entando.entando.apsadmin.system.services.shortcut.model.UserConfigBean)

Example 48 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class DispatchAction method validate.

@Override
public void validate() {
    super.validate();
    if (this.hasFieldErrors())
        return;
    _logger.debug("Authentication : user {} - password ******** ", this.getUsername());
    UserDetails user = null;
    try {
        user = this.getAuthenticationProvider().getUser(this.getUsername(), this.getPassword());
    } catch (Throwable t) {
        _logger.error("error in LoginAction ", t);
        throw new RuntimeException("Login error : username " + this.getUsername(), t);
    }
    if (null == user) {
        _logger.debug("Login failed : username {} - password ******** ", this.getUsername());
        this.addActionError(this.getText("error.user.login.loginFailed"));
    } else {
        // UTENTE RICONOSCIUTO ED ATTIVO
        if (!user.isAccountNotExpired()) {
            this.addActionError(this.getText("error.user.login.accountExpired"));
            this.getSession().removeAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
            return;
        }
        this.getSession().setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);
        if (!user.isCredentialsNotExpired()) {
            this.addActionError(this.getText("error.user.login.credentialsExpired"));
            return;
        }
        if (this.getAuthorizationManager().isAuthOnPermission(user, Permission.SUPERUSER) || this.getAuthorizationManager().isAuthOnPermission(user, Permission.BACKOFFICE)) {
            _logger.info("User - {} logged", user.getUsername());
        } else {
            this.addActionError(this.getText("error.user.login.userNotAbilitated"));
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 49 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class PageFinderAction method getAllowedGroupCodes.

private List<String> getAllowedGroupCodes() {
    List<String> allowedGroups = new ArrayList<String>();
    UserDetails currentUser = this.getCurrentUser();
    List<Group> userGroups = this.getAuthorizationManager().getUserGroups(currentUser);
    Iterator<Group> iter = userGroups.iterator();
    while (iter.hasNext()) {
        Group group = iter.next();
        allowedGroups.add(group.getName());
    }
    return allowedGroups;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList)

Example 50 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class PagePreviewAction method preview.

public String preview() {
    try {
        String ERR_RESULT = "apslogin";
        if (null == this.getCurrentUser()) {
            UserDetails guest = this.getUserManager().getGuestUser();
            this.getRequest().getSession().setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, guest);
        }
        if (StringUtils.isBlank(this.getPageCode())) {
            _logger.info("Null page code");
            this.addActionError(this.getText("error.page.invalidPageCode"));
            return ERR_RESULT;
        }
        if (!isCurrentUserAdmin()) {
            boolean isValidToken = this.checkToken(this.getToken(), this.getPageCode());
            if (!isValidToken) {
                _logger.info("Invalid token");
                this.addActionError(this.getText("error.page.invalidPreviewToken"));
                return ERR_RESULT;
            }
        }
        IPage page = this.getPage(this.getPageCode());
        if (!this.getAuthorizationManager().isAuth(this.getCurrentUser(), page)) {
            _logger.info("Curent user not allowed");
            this.addActionError(this.getText("error.page.userNotAllowed"));
            return ERR_RESULT;
        }
        if (null == page) {
            _logger.info("Null page code");
            this.addActionError(this.getText("error.page.invalidPageCode"));
            return ERR_RESULT;
        }
        if (null == this.getLangManager().getLang(this.getLang())) {
            String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
            _logger.warn("Invalid lang '{}' detected. Defaulting to '{}'", this.getLang(), defaultLangCode);
            this.setLang(defaultLangCode);
        }
    } catch (Exception e) {
        _logger.error("error in preview", e);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7