本文整理汇总了Java中org.eclipse.che.commons.env.EnvironmentContext.setCurrent方法的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentContext.setCurrent方法的具体用法?Java EnvironmentContext.setCurrent怎么用?Java EnvironmentContext.setCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.che.commons.env.EnvironmentContext
的用法示例。
在下文中一共展示了EnvironmentContext.setCurrent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldRedirectIfRequestWithoutNamespace
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@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/"));
}
示例2: shouldAddPermissions
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@Test
public void shouldAddPermissions() throws Exception {
final EnvironmentContext ctx = new EnvironmentContext();
ctx.setSubject(new SubjectImpl("test-user-name", "test-user-id", "test-token", false));
EnvironmentContext.setCurrent(ctx);
final StackImpl stack = createStack();
permProvider.onEvent(new StackPersistedEvent(stack));
final ArgumentCaptor<StackPermissionsImpl> captor =
ArgumentCaptor.forClass(StackPermissionsImpl.class);
verify(permManager).storePermission(captor.capture());
final StackPermissionsImpl perm = captor.getValue();
assertEquals(perm.getInstanceId(), stack.getId());
assertEquals(perm.getUserId(), "test-user-id");
assertEquals(perm.getDomainId(), StackDomain.DOMAIN_ID);
assertEquals(perm.getActions(), StackDomain.getActions());
}
示例3: shouldSkipRequestToProject
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@Test
public void shouldSkipRequestToProject() throws Exception {
// given
when(request.getMethod()).thenReturn("GET");
when(request.getRequestURI()).thenReturn("/ws/ws-id");
EnvironmentContext context = spy(EnvironmentContext.getCurrent());
EnvironmentContext.setCurrent(context);
// when
filter.doFilter(request, response, chain);
// then
verify(chain).doFilter(eq(request), eq(response));
verify(context).setSubject(eq(new SubjectImpl("che", "che", "dummy_token", false)));
// after reset
assertNotEquals(EnvironmentContext.getCurrent(), context);
}
示例4: setUp
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
workspaceManager =
new WorkspaceManager(workspaceDao, runtimes, eventService, accountManager, validator);
when(accountManager.getByName(NAMESPACE_1))
.thenReturn(new AccountImpl("accountId", NAMESPACE_1, "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_1, USER_ID, "token", false);
}
});
}
示例5: setUp
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
keysInjector = new KeysInjector(sshManager, workspaceManager, execAgentClientFactory);
when(execAgentClientFactory.create(anyString())).thenReturn(client);
when(client.startProcess(anyString(), anyString(), anyString(), anyString()))
.thenReturn(newDto(ProcessStartResponseDto.class).withPid(100));
when(client.getProcess(anyString(), anyInt()))
.thenReturn(
newDto(GetProcessResponseDto.class).withAlive(false).withPid(100).withExitCode(0));
prepareAndMockServers();
EnvironmentContext context = new EnvironmentContext();
context.setSubject(new SubjectImpl("name", OWNER, "token123", false));
EnvironmentContext.setCurrent(context);
}
示例6: DummyProjectManager
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
public DummyProjectManager(String workspacePath, EventService eventService) {
EnvironmentContext context = new EnvironmentContext();
context.setSubject(new SubjectImpl(vfsUser, "", "", false));
EnvironmentContext.setCurrent(context);
// localFileSystemProvider = new LocalFileSystemProvider("", new LocalFSMountStrategy() {
// @Override
// public File getMountPath(String workspaceId) throws ServerException {
// return new File(workspacePath);
// }
//
// @Override
// public File getMountPath() throws ServerException {
// return new File(workspacePath);
// }
// }, eventService, null, SystemPathsFilter.ANY, null);
}
示例7: setup
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setup() throws Exception {
publicPermissionsRemoveChecker = new PublicPermissionsRemoveChecker(defaultChecker, manager);
final EnvironmentContext ctx = new EnvironmentContext();
ctx.setSubject(subj);
EnvironmentContext.setCurrent(ctx);
}
示例8: setup
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setup() throws Exception {
stackSetPermChecker = new StackDomainSetPermissionsChecker(defaultChecker);
final EnvironmentContext ctx = new EnvironmentContext();
ctx.setSubject(subj);
EnvironmentContext.setCurrent(ctx);
}
示例9: setUp
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(request.getScheme()).thenReturn("http");
when(request.getSession()).thenReturn(session);
EnvironmentContext context = spy(EnvironmentContext.getCurrent());
EnvironmentContext.setCurrent(context);
filter =
new KeycloakEnvironmentInitalizationFilter(userManager, tokenExtractor, permissionChecker);
}
示例10: shouldRefreshSubjectWhenTokensNotMatch
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@Test
public void shouldRefreshSubjectWhenTokensNotMatch() throws Exception {
Subject existingSubject = new SubjectImpl("name", "id1", "token", false);
UserImpl user = new UserImpl("id2", "[email protected]", "username2");
Subject expectedSubject = new SubjectImpl(user.getName(), user.getId(), "token2", false);
ArgumentCaptor<AuthorizedSubject> captor = ArgumentCaptor.forClass(AuthorizedSubject.class);
// given
when(tokenExtractor.getToken(any(HttpServletRequest.class))).thenReturn("token2");
when(request.getAttribute("token")).thenReturn(createJwt());
when(session.getAttribute(eq("che_subject"))).thenReturn(existingSubject);
when(userManager.getById(anyString())).thenReturn(user);
EnvironmentContext context = spy(EnvironmentContext.getCurrent());
EnvironmentContext.setCurrent(context);
// when
filter.doFilter(request, response, chain);
// then
verify(session).setAttribute(eq("che_subject"), captor.capture());
verify(context).setSubject(captor.capture());
assertEquals(expectedSubject.getToken(), captor.getAllValues().get(0).getToken());
assertEquals(expectedSubject.getToken(), captor.getAllValues().get(1).getToken());
assertEquals(expectedSubject.getUserId(), captor.getAllValues().get(0).getUserId());
assertEquals(expectedSubject.getUserId(), captor.getAllValues().get(1).getUserId());
assertEquals(expectedSubject.getUserName(), captor.getAllValues().get(0).getUserName());
assertEquals(expectedSubject.getUserName(), captor.getAllValues().get(1).getUserName());
}
示例11: invokeMethod
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@Override
public Object invokeMethod(
Object resource, GenericResourceMethod genericMethodResource, ApplicationContext context) {
WSConnection wsConnection =
(WSConnection)
org.everrest.core.impl.EnvironmentContext.getCurrent().get(WSConnection.class);
if (wsConnection != null) {
EnvironmentContext environmentContext =
(EnvironmentContext) wsConnection.getAttribute(ENVIRONMENT_CONTEXT);
if (environmentContext != null) {
try {
EnvironmentContext.setCurrent(environmentContext);
LOG.debug(
"Websocket {} in http session {}",
wsConnection.getId(),
wsConnection.getHttpSession());
return super.invokeMethod(resource, genericMethodResource, context);
} finally {
EnvironmentContext.reset();
}
} else {
LOG.warn("EnvironmentContext is null");
}
}
return super.invokeMethod(resource, genericMethodResource, context);
}
示例12: shouldUseTokenFromCurrentContextForAuthorization
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@Test
public void shouldUseTokenFromCurrentContextForAuthorization(ITestContext ctx) throws Exception {
final EnvironmentContext context = new EnvironmentContext();
context.setSubject(TEST_SUBJECT);
EnvironmentContext.setCurrent(context);
new DefaultHttpJsonRequest(getUrl(ctx) + "/token").usePostMethod().request();
}
示例13: setUp
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
EnvironmentContext customEnvironment = mock(EnvironmentContext.class);
doReturn(new SubjectImpl(vfsUser, "", "", false)).when(customEnvironment).getSubject();
EnvironmentContext.setCurrent(customEnvironment);
fJProject1 = Java18ProjectTestSetup.getProject();
fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
}
示例14: setUp
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
// let tests pass faster
HostedMachineProviderImpl.SWARM_WAIT_BEFORE_REPEAT_WORKAROUND_TIME_MS = 10;
when(dockerConnectorProviderMock.get()).thenReturn(dockerConnector);
when(dockerConnectorConfiguration.getDockerHostIp()).thenReturn("123.123.123.123");
EnvironmentContext envCont = new EnvironmentContext();
envCont.setSubject(new SubjectImpl(USER_NAME, "userId", USER_TOKEN, false));
EnvironmentContext.setCurrent(envCont);
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(dockerConnector.inspectContainer(anyString())).thenReturn(containerInfo);
when(containerState.getStatus()).thenReturn("running");
when(dockerConnector.inspectImage(anyString())).thenReturn(imageInfo);
when(imageInfo.getConfig()).thenReturn(imageConfig);
when(imageConfig.getCmd()).thenReturn(new String[] {"tail", "-f", "/dev/null"});
provider =
new HostedMachineProviderImpl(
dockerConnectorProviderMock,
credentialsReader,
dockerMachineFactory,
dockerInstanceStopDetector,
windowsPathEscaper,
requestTransmitter,
endpointIdsHolder,
emptySet(),
emptySet(),
emptySet(),
emptySet(),
false,
false,
securityOptProvider,
-1,
emptySet(),
emptySet(),
SNAPSHOT_USE_REGISTRY,
MEMORY_SWAP_MULTIPLIER,
machineTokenRegistry,
emptySet(),
null,
null,
null,
0,
0,
emptySet(),
null,
emptyMap());
}
示例15: setUp
import org.eclipse.che.commons.env.EnvironmentContext; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() throws Throwable {
Module module =
new AbstractModule() {
public void configure() {
// Bind manager and his dep-s. To bind interceptor, guice must create intercepted class
// by himself.
bind(WorkspaceDao.class).toInstance(mock(WorkspaceDao.class));
bind(EventService.class).toInstance(mock(EventService.class));
bind(EntityManagerFactory.class).toInstance(mock(EntityManagerFactory.class));
bind(DBInitializer.class).toInstance(mock(DBInitializer.class));
bind(WorkspaceSharedPool.class)
.toInstance(new WorkspaceSharedPool("cached", null, null));
bindConstant().annotatedWith(Names.named("che.api")).to("localhost");
bind(MachineTokenRegistry.class).toInstance(tokenRegistry);
bind(RuntimeInfrastructure.class).toInstance(mock(RuntimeInfrastructure.class));
MapBinder.newMapBinder(binder(), String.class, InternalEnvironmentFactory.class);
MapBinder.newMapBinder(binder(), String.class, InternalEnvironmentFactory.class);
bind(WorkspaceRuntimes.class);
// Main injection
install(new MachineAuthModule());
// To prevent real methods of manager calling
bindInterceptor(
subclassesOf(WorkspaceRuntimes.class), names("startAsync"), invocation -> null);
bindConstant().annotatedWith(Names.named("che.workspace.probe_pool_size")).to(1);
}
};
injector = Guice.createInjector(module);
workspaceRuntimes = injector.getInstance(WorkspaceRuntimes.class);
EnvironmentContext.setCurrent(
new EnvironmentContext() {
@Override
public Subject getSubject() {
return new SubjectImpl(USER_NAME, USER_ID, "token", false);
}
});
}