Search in sources :

Example 1 with SubjectImpl

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

the class DashboardRedirectionFilterTest method shouldRedirectIfRequestWithoutNamespace.

@Test(dataProvider = "nonNamespacePathProvider")
public void shouldRedirectIfRequestWithoutNamespace(String uri, String url) throws Exception {
    //given
    when(request.getMethod()).thenReturn("GET");
    when(request.getRequestURI()).thenReturn(uri);
    when(request.getRequestURL()).thenReturn(new StringBuffer(url));
    EnvironmentContext context = new EnvironmentContext();
    context.setSubject(new SubjectImpl("id123", "name", "token123", false));
    EnvironmentContext.setCurrent(context);
    //when
    filter.doFilter(request, response, chain);
    //then
    verify(response).sendRedirect(eq("/dashboard/"));
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Test(org.testng.annotations.Test)

Example 2 with SubjectImpl

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

the class ProjectServiceTest method testGetProjectCheckUserPermissions.

@Test
public void testGetProjectCheckUserPermissions() throws Exception {
    // Without roles Collections.<String>emptySet() should get default set of permissions
    env.setSubject(new SubjectImpl(vfsUser, vfsUser, "dummy_token", false));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/my_project", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    ProjectConfigDto result = (ProjectConfigDto) response.getEntity();
    assertNotNull(result);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Test(org.testng.annotations.Test)

Example 3 with SubjectImpl

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

the class MachineProviderImplTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    when(dockerConnectorConfiguration.getDockerHostIp()).thenReturn("123.123.123.123");
    provider = spy(new MachineProviderBuilder().build());
    EnvironmentContext envCont = new EnvironmentContext();
    envCont.setSubject(new SubjectImpl(USER_NAME, "userId", USER_TOKEN, false));
    EnvironmentContext.setCurrent(envCont);
    when(recipeRetriever.getRecipe(any(MachineConfig.class))).thenReturn(new RecipeImpl().withType(DOCKER_FILE_TYPE).withScript("FROM codenvy"));
    when(dockerMachineFactory.createNode(anyString(), anyString())).thenReturn(dockerNode);
    when(dockerConnector.createContainer(any(CreateContainerParams.class))).thenReturn(new ContainerCreated(CONTAINER_ID, new String[0]));
    when(dockerConnector.inspectContainer(any(InspectContainerParams.class))).thenReturn(containerInfo);
    when(containerInfo.getState()).thenReturn(containerState);
    when(containerState.isRunning()).thenReturn(false);
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ContainerCreated(org.eclipse.che.plugin.docker.client.json.ContainerCreated) InspectContainerParams(org.eclipse.che.plugin.docker.client.params.InspectContainerParams) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with SubjectImpl

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

the class TestUtils method createTestUser.

/**
     * Creates a user and makes that user be the current user.
     *
     * @param userProfileDao
     *         the User Profile DAO
     * @throws Exception
     *         if anything goes wrong
     */
public static void createTestUser(final ProfileDao userProfileDao) throws Exception {
    // set current user
    EnvironmentContext.getCurrent().setSubject(new SubjectImpl("codenvy", "codenvy", null, false));
    // rules for mock
    final Map<String, String> profileAttributes = new HashMap<>();
    profileAttributes.put("firstName", "Codenvy");
    profileAttributes.put("lastName", "Codenvy");
    profileAttributes.put("email", "che@eclipse.org");
    Mockito.when(userProfileDao.getById("codenvy")).thenReturn(new ProfileImpl("codenvy", profileAttributes));
}
Also used : HashMap(java.util.HashMap) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl)

Example 5 with SubjectImpl

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

the class WorkspaceRuntimeIntegrationTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    CheEnvironmentEngine environmentEngine = new CheEnvironmentEngine(snapshotDao, machineInstanceProviders, "/tmp", 2000, eventService, environmentParser, new DefaultServicesStartStrategy(), instanceProvider, infrastructureProvisioner, "http://localhost:8080/api", recipeDownloader, containerNameGenerator, agentRegistry, sharedPool);
    runtimes = new WorkspaceRuntimes(eventService, environmentEngine, agentSorter, launcherFactory, agentRegistry, snapshotDao, sharedPool);
    executor = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setNameFormat(this.getClass().toString() + "-%d").build());
    EnvironmentContext.getCurrent().setSubject(new SubjectImpl("name", "id", "token", false));
}
Also used : CheEnvironmentEngine(org.eclipse.che.api.environment.server.CheEnvironmentEngine) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DefaultServicesStartStrategy(org.eclipse.che.api.environment.server.DefaultServicesStartStrategy) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

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