当前位置: 首页>>代码示例>>Java>>正文


Java EnvironmentContext类代码示例

本文整理汇总了Java中org.eclipse.che.commons.env.EnvironmentContext的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentContext类的具体用法?Java EnvironmentContext怎么用?Java EnvironmentContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EnvironmentContext类属于org.eclipse.che.commons.env包,在下文中一共展示了EnvironmentContext类的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/"));
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:17,代码来源:DashboardRedirectionFilterTest.java

示例2: store

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
/**
 * Stores (create or updates) invite.
 *
 * <p>It also send email invite on initial invite creation.
 *
 * @param invite invite to store
 * @throws ConflictException when user is specified email is already registered
 * @throws ServerException when any other error occurs during invite storing
 */
@Transactional(rollbackOn = {RuntimeException.class, ServerException.class})
public void store(Invite invite) throws NotFoundException, ConflictException, ServerException {
  requireNonNull(invite, "Required non-null invite");
  String domainId = invite.getDomainId();
  if (!OrganizationDomain.DOMAIN_ID.equals(domainId)
      && !WorkspaceDomain.DOMAIN_ID.equals(domainId)) {
    throw new ConflictException("Invitations for specified domain are not supported");
  }
  permissionsManager.checkActionsSupporting(domainId, invite.getActions());

  try {
    userManager.getByEmail(invite.getEmail());
    throw new ConflictException("User with specified id is already registered");
  } catch (NotFoundException ignored) {
  }

  Optional<InviteImpl> existingInvite = inviteDao.store(new InviteImpl(invite));
  if (!existingInvite.isPresent()) {
    Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
    eventService.publish(
        new InviteCreatedEvent(
            currentSubject.isAnonymous() ? null : currentSubject.getUserId(), invite));
  }
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:34,代码来源:InviteManager.java

示例3: filter

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
@Override
protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments)
    throws ApiException {

  final String methodName = genericMethodResource.getMethod().getName();
  switch (methodName) {
    case "getAddNodeScript":
    case "registerNode":
      {
        final Subject subject = EnvironmentContext.getCurrent().getSubject();
        subject.checkPermission(SystemDomain.DOMAIN_ID, null, SystemDomain.MANAGE_SYSTEM_ACTION);
        return;
      }
    default:
      throw new ForbiddenException("The user does not have permission to perform this operation");
  }
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:18,代码来源:NodeServicePermissionFilter.java

示例4: filter

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
@Override
protected void filter(GenericResourceMethod genericResourceMethod, Object[] arguments)
    throws ApiException {
  final String methodName = genericResourceMethod.getMethod().getName();

  final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
  String action;
  String workspaceId;

  switch (methodName) {
    case "getFactoryJson":
      {
        workspaceId = ((String) arguments[0]);
        action = WorkspaceDomain.READ;
        break;
      }
    default:
      // public methods
      return;
  }
  currentSubject.checkPermission(WorkspaceDomain.DOMAIN_ID, workspaceId, action);
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:FactoryPermissionsFilter.java

示例5: onEvent

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
@Override
public void onEvent(WorkspaceCreatedEvent event) {
  try {
    workerDao.store(
        new WorkerImpl(
            event.getWorkspace().getId(),
            EnvironmentContext.getCurrent().getSubject().getUserId(),
            new ArrayList<>(new WorkspaceDomain().getAllowedActions())));
  } catch (ServerException e) {
    LOG.error(
        "Can't add creator's permissions for workspace with id '"
            + event.getWorkspace().getId()
            + "'",
        e);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:WorkspaceCreatorPermissionsProvider.java

示例6: 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());
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:StackCreatorPermissionsProviderTest.java

示例7: 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);
        }
      });
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:WorkspaceManagerTest.java

示例8: filter

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
@Override
protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments)
    throws ApiException {
  switch (genericMethodResource.getMethod().getName()) {
    case STORE_FREE_RESOURCES_LIMIT_METHOD:
    case GET_FREE_RESOURCES_LIMITS_METHOD:
    case GET_FREE_RESOURCES_LIMIT_METHOD:
    case REMOVE_FREE_RESOURCES_LIMIT_METHOD:
      final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
      if (currentSubject.hasPermission(
          SystemDomain.DOMAIN_ID, null, SystemDomain.MANAGE_SYSTEM_ACTION)) {
        return;
      }
      // fall through
      // user doesn't have permissions and request should not be processed
    default:
      throw new ForbiddenException("The user does not have permission to perform this operation");
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:FreeResourcesLimitServicePermissionsFilter.java

示例9: remove

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
/**
 * Removes permissions of userId related to the particular instanceId of specified domainId
 *
 * @param userId user id
 * @param domainId domain id
 * @param instanceId instance id
 * @throws NotFoundException when given domainId is unsupported
 * @throws ConflictException when removes last 'setPermissions' of given instanceId
 * @throws ServerException when any other error occurs during permissions removing
 */
public void remove(String userId, String domainId, String instanceId)
    throws ConflictException, ServerException, NotFoundException {
  final PermissionsDao<? extends AbstractPermissions> permissionsDao =
      getPermissionsDao(domainId);
  Permissions permissions;
  try (@SuppressWarnings("unused")
      Unlocker unlocker = updateLocks.writeLock(firstNonNull(instanceId, domainId))) {
    if (userHasLastSetPermissions(permissionsDao, userId, instanceId)) {
      throw new ConflictException(
          "Can't remove permissions because there is not any another user "
              + "with permission 'setPermissions'");
    }
    permissions = permissionsDao.get(userId, instanceId);
    permissionsDao.remove(userId, instanceId);
  }
  final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
  eventService.publish(new PermissionsRemovedEvent(initiator, permissions));
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:PermissionsManager.java

示例10: 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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:KeysInjectorTest.java

示例11: 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);
  }
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:DummyProjectManager.java

示例12: remove

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
/**
 * Removes organization with given id
 *
 * @param organizationId organization id
 * @throws NullPointerException when {@code organizationId} is null
 * @throws ServerException when any other error occurs during organization removing
 */
@Transactional(rollbackOn = {RuntimeException.class, ApiException.class})
public void remove(String organizationId) throws ServerException {
  requireNonNull(organizationId, "Required non-null organization id");
  try {
    OrganizationImpl organization = organizationDao.getById(organizationId);
    eventService
        .publish(new BeforeAccountRemovedEvent(organization.getAccount()))
        .propagateException();
    eventService.publish(new BeforeOrganizationRemovedEvent(organization)).propagateException();
    removeSuborganizations(organizationId);
    final List<Member> members = removeMembers(organizationId);
    organizationDao.remove(organizationId);
    final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
    eventService.publish(new OrganizationRemovedEvent(initiator, organization, members));
  } catch (NotFoundException e) {
    // organization is already removed
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:OrganizationManager.java

示例13: getByKey

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
private WorkspaceImpl getByKey(String key) throws NotFoundException, ServerException {

    int lastColonIndex = key.indexOf(":");
    int lastSlashIndex = key.lastIndexOf("/");
    if (lastSlashIndex == -1 && lastColonIndex == -1) {
      // key is id
      return workspaceDao.get(key);
    }

    final String namespace;
    final String wsName;
    if (lastColonIndex == 0) {
      // no namespace, use current user namespace
      namespace = EnvironmentContext.getCurrent().getSubject().getUserName();
      wsName = key.substring(1);
    } else if (lastColonIndex > 0) {
      wsName = key.substring(lastColonIndex + 1);
      namespace = key.substring(0, lastColonIndex);
    } else {
      namespace = key.substring(0, lastSlashIndex);
      wsName = key.substring(lastSlashIndex + 1);
    }
    return workspaceDao.get(wsName, namespace);
  }
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:WorkspaceManager.java

示例14: getById

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
@Override
public ProfileImpl getById(String userId) throws NotFoundException, ServerException {
  requireNonNull(userId, "Required non-null id");
  String currentUserId = EnvironmentContext.getCurrent().getSubject().getUserId();
  if (!userId.equals(currentUserId)) {
    throw new ServerException(
        "It's not allowed to get foreign profile on current configured storage.");
  }

  Map<String, String> keycloakUserAttributes;
  // Retrieving own profile
  try {
    keycloakUserAttributes =
        requestFactory.fromUrl(keyclockCurrentUserInfoUrl).request().asProperties();
  } catch (IOException | ApiException e) {
    LOG.warn("Exception during retrieval of the Keycloak user profile", e);
    throw new ServerException("Exception during retrieval of the Keycloak user profile", e);
  }

  return new ProfileImpl(userId, mapAttributes(keycloakUserAttributes));
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:KeycloakProfileDao.java

示例15: filter

import org.eclipse.che.commons.env.EnvironmentContext; //导入依赖的package包/类
@Override
protected void filter(GenericResourceMethod genericResourceMethod, Object[] arguments)
    throws ApiException {
  final String methodName = genericResourceMethod.getMethod().getName();

  final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
  String action;
  String workspaceId;

  switch (methodName) {
    case "active":
      {
        workspaceId = ((String) arguments[0]);
        action = USE;
        break;
      }
    default:
      throw new ForbiddenException("The user does not have permission to perform this operation");
  }
  currentSubject.checkPermission(DOMAIN_ID, workspaceId, action);
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:ActivityPermissionsFilter.java


注:本文中的org.eclipse.che.commons.env.EnvironmentContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。