Search in sources :

Example 11 with SubjectImpl

use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.

the class WorkspaceManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    workspaceManager = new WorkspaceManager(workspaceDao, runtimes, eventService, accountManager, false, false, snapshotDao, sharedPool);
    when(accountManager.getByName(NAMESPACE)).thenReturn(new AccountImpl("accountId", NAMESPACE, "test"));
    when(accountManager.getByName(NAMESPACE_2)).thenReturn(new AccountImpl("accountId2", NAMESPACE_2, "test"));
    when(workspaceDao.create(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    when(workspaceDao.update(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    EnvironmentContext.setCurrent(new EnvironmentContext() {

        @Override
        public Subject getSubject() {
            return new SubjectImpl(NAMESPACE, USER_ID, "token", false);
        }
    });
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with SubjectImpl

use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.

the class EnvironmentInitializationFilter method doFilter.

@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    Subject subject = new SubjectImpl("che", "che", "dummy_token", false);
    HttpSession session = httpRequest.getSession();
    session.setAttribute("codenvy_user", subject);
    final EnvironmentContext environmentContext = EnvironmentContext.getCurrent();
    try {
        environmentContext.setSubject(subject);
        filterChain.doFilter(addUserInRequest(httpRequest, subject), response);
    } finally {
        EnvironmentContext.reset();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) HttpSession(javax.servlet.http.HttpSession) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject)

Aggregations

SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)12 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)5 BeforeMethod (org.testng.annotations.BeforeMethod)4 Test (org.testng.annotations.Test)4 Subject (org.eclipse.che.commons.subject.Subject)3 HashMap (java.util.HashMap)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 AccountImpl (org.eclipse.che.account.spi.AccountImpl)1 AgentKey (org.eclipse.che.api.agent.shared.model.AgentKey)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 CheEnvironmentEngine (org.eclipse.che.api.environment.server.CheEnvironmentEngine)1 DefaultServicesStartStrategy (org.eclipse.che.api.environment.server.DefaultServicesStartStrategy)1 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)1 ProfileImpl (org.eclipse.che.api.user.server.model.impl.ProfileImpl)1 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)1 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)1 ContainerCreated (org.eclipse.che.plugin.docker.client.json.ContainerCreated)1 CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)1