Search in sources :

Example 36 with UserDetails

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

the class TestActivityStream method testLastUpdate.

public void testLastUpdate() throws Throwable {
    // "coach" group
    Content content = this._contentManager.loadContent("EVN41", false);
    String contentOnSessionMarker = AbstractContentAction.buildContentOnSessionMarker(content, ApsAdminSystemConstants.ADD);
    content.setId(null);
    String contentId = null;
    Thread.sleep(1000);
    try {
        this.getRequest().getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_PREXIX + contentOnSessionMarker, content);
        this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
        this.setUserOnSession("admin");
        String result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        contentId = content.getId();
        assertNotNull(this._contentManager.loadContent(contentId, false));
        super.waitThreads(IActionLogManager.LOG_APPENDER_THREAD_NAME_PREFIX);
        ActionLogRecordSearchBean searchBean = this._helper.createSearchBean("admin", null, null, null, null, null);
        List<Integer> ids = this._actionLoggerManager.getActionRecords(searchBean);
        assertEquals(1, ids.size());
        Thread.sleep(1000);
        this.getRequest().getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_PREXIX + contentOnSessionMarker, content);
        this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
        this.setUserOnSession("admin");
        result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        contentId = content.getId();
        assertNotNull(this._contentManager.loadContent(contentId, false));
        super.waitThreads(IActionLogManager.LOG_APPENDER_THREAD_NAME_PREFIX);
        List<Integer> actionRecords = this._actionLoggerManager.getActionRecords(null);
        assertNotNull(actionRecords);
        assertEquals(2, actionRecords.size());
        ActionLogRecord actionRecord = this._actionLoggerManager.getActionRecord(actionRecords.get(1));
        UserDetails adminUser = this.getUser("admin", "admin");
        Date lastUpdateDate = this._actionLoggerManager.lastUpdateDate(adminUser);
        assertEquals(actionRecord.getUpdateDate(), lastUpdateDate);
    } catch (Throwable t) {
        throw t;
    } finally {
        this._contentManager.deleteContent(content);
        assertNull(this._contentManager.loadContent(contentId, false));
    }
}
Also used : ActionLogRecord(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecord) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ActionLogRecordSearchBean(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecordSearchBean) Date(java.util.Date)

Example 37 with UserDetails

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

the class TestActivityStream method testSaveNewContent_1.

// ----------------------------------------------
public void testSaveNewContent_1() throws Throwable {
    Content content = this._contentManager.loadContent("ART1", false);
    String contentOnSessionMarker = AbstractContentAction.buildContentOnSessionMarker(content, ApsAdminSystemConstants.ADD);
    content.setId(null);
    String contentId = null;
    try {
        this.getRequest().getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_PREXIX + contentOnSessionMarker, content);
        this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
        this.setUserOnSession("admin");
        String result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        contentId = content.getId();
        assertNotNull(this._contentManager.loadContent(contentId, false));
        super.waitThreads(IActionLogManager.LOG_APPENDER_THREAD_NAME_PREFIX);
        ActionLogRecordSearchBean searchBean = this._helper.createSearchBean("admin", null, null, null, null, null);
        List<Integer> ids = this._actionLoggerManager.getActionRecords(searchBean);
        assertEquals(1, ids.size());
        UserDetails currentUser = (UserDetails) super.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        List<Integer> activityStream = this._actionLoggerManager.getActivityStream(currentUser);
        assertEquals(activityStream.size(), ids.size());
        assertEquals(activityStream.get(0), ids.get(0));
        ActionLogRecord record = this._actionLoggerManager.getActionRecord(ids.get(0));
        assertEquals("/do/jacms/Content", record.getNamespace());
        assertEquals("save", record.getActionName());
        ActivityStreamInfo asi = record.getActivityStreamInfo();
        assertNotNull(asi);
        assertEquals(1, asi.getActionType());
        assertEquals(Permission.CONTENT_EDITOR, asi.getLinkAuthPermission());
        assertEquals(content.getMainGroup(), asi.getLinkAuthGroup());
        assertEquals("edit", asi.getLinkActionName());
        assertEquals("/do/jacms/Content", asi.getLinkNamespace());
        // assertEquals(1, asi.getLinkParameters().size());
        Properties parameters = asi.getLinkParameters();
        assertEquals(1, parameters.size());
        assertEquals(contentId, parameters.getProperty("contentId"));
    } catch (Throwable t) {
        throw t;
    } finally {
        this._contentManager.deleteContent(content);
        assertNull(this._contentManager.loadContent(contentId, false));
    }
}
Also used : ActionLogRecord(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecord) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ActivityStreamInfo(org.entando.entando.aps.system.services.actionlog.model.ActivityStreamInfo) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ActionLogRecordSearchBean(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecordSearchBean) Properties(java.util.Properties)

Example 38 with UserDetails

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

the class TestUserAction method testFailureDisableAdminUser.

public void testFailureDisableAdminUser() throws Throwable {
    String username = SystemConstants.ADMIN_USER_NAME;
    UserDetails adminUser = this._userManager.getUser(username);
    try {
        this.setUserOnSession("admin");
        this.initAction("/do/User", "save");
        this.addParameter("strutsAction", String.valueOf(ApsAdminSystemConstants.EDIT));
        this.addParameter("username", username);
        this.addParameter("active", "false");
        String result = this.executeAction();
        assertEquals(Action.INPUT, result);
        Map<String, List<String>> fieldErrors = this.getAction().getFieldErrors();
        assertEquals(1, fieldErrors.size());
        List<String> errors = fieldErrors.get("active");
        assertEquals(1, errors.size());
    } catch (Throwable t) {
        this._userManager.updateUser(adminUser);
        throw t;
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) List(java.util.List)

Example 39 with UserDetails

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

the class TestUserAction method testAddNew_1.

public void testAddNew_1() throws Throwable {
    String username = "usernameForTest";
    String password = "password";
    try {
        this.setUserOnSession("admin");
        this.initAction("/do/User", "save");
        this.addParameter("strutsAction", String.valueOf(ApsAdminSystemConstants.ADD));
        this.addParameter("username", username);
        this.addParameter("password", password);
        this.addParameter("passwordConfirm", password);
        this.addParameter("active", "true");
        this.addParameter("profileTypeCode", SystemConstants.DEFAULT_PROFILE_TYPE_CODE);
        String result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        UserDetails extracted = this._userManager.getUser(username, password);
        assertNotNull(extracted);
        assertFalse(extracted.isDisabled());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._userManager.removeUser(username);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 40 with UserDetails

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

the class TestUserAction method testAddNew_2.

public void testAddNew_2() throws Throwable {
    // the dot '.' is accepted in the username as well as the underscore '_'
    String username = "user.name_for_test";
    String password = "password";
    try {
        this.setUserOnSession("admin");
        this.initAction("/do/User", "save");
        this.addParameter("strutsAction", String.valueOf(ApsAdminSystemConstants.ADD));
        this.addParameter("username", username);
        this.addParameter("password", password);
        this.addParameter("passwordConfirm", password);
        this.addParameter("active", "true");
        this.addParameter("profileTypeCode", SystemConstants.DEFAULT_PROFILE_TYPE_CODE);
        String result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        UserDetails extracted = this._userManager.getUser(username, password);
        assertNotNull(extracted);
        assertFalse(extracted.isDisabled());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._userManager.removeUser(username);
        assertNull(this._userManager.getUser(username));
    }
}
Also used : 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