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


Java IdentityService.setAuthenticatedUserId方法代码示例

本文整理汇总了Java中org.camunda.bpm.engine.IdentityService.setAuthenticatedUserId方法的典型用法代码示例。如果您正苦于以下问题:Java IdentityService.setAuthenticatedUserId方法的具体用法?Java IdentityService.setAuthenticatedUserId怎么用?Java IdentityService.setAuthenticatedUserId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.camunda.bpm.engine.IdentityService的用法示例。


在下文中一共展示了IdentityService.setAuthenticatedUserId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAuthenticationData

import org.camunda.bpm.engine.IdentityService; //导入方法依赖的package包/类
private void createAuthenticationData() {
  IdentityService identityService = engineRule.getIdentityService();
  Group group = identityService.newGroup("group");
  identityService.saveGroup(group);
  User user = identityService.newUser("user");
  User user2 = identityService.newUser("user2");
  identityService.saveUser(user);
  identityService.saveUser(user2);
  Tenant tenant = identityService.newTenant("tenant");
  identityService.saveTenant(tenant);
  Tenant tenant2 = identityService.newTenant("tenant2");
  identityService.saveTenant(tenant2);
  identityService.createMembership("user", "group");
  identityService.createTenantUserMembership("tenant", "user");
  identityService.createTenantUserMembership("tenant2", "user2");


  TestResource resource1 = new TestResource("resource1", 100);
  // create global authorization which grants all permissions to all users (on resource1):
  AuthorizationService authorizationService = engineRule.getAuthorizationService();
  Authorization globalAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
  globalAuth.setResource(resource1);
  globalAuth.setResourceId(ANY);
  globalAuth.addPermission(ALL);
  authorizationService.saveAuthorization(globalAuth);

  //grant user read auth on resource2
  TestResource resource2 = new TestResource("resource2", 200);
  Authorization userGrant = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
  userGrant.setUserId("user");
  userGrant.setResource(resource2);
  userGrant.setResourceId(ANY);
  userGrant.addPermission(READ);
  authorizationService.saveAuthorization(userGrant);

  identityService.setAuthenticatedUserId("user");
}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:38,代码来源:PurgeDatabaseTest.java

示例2: doFilter

import org.camunda.bpm.engine.IdentityService; //导入方法依赖的package包/类
/**
 * Sets currently authenticated user to BPM component in every request.
 * @param request incoming http request
 * @param response outgoing http response
 * @param filterChain next filter in line
 * @throws IOException bubble up exception from next filter
 * @throws ServletException bubble up exception from next filter
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    IdentityService identityService = context.getBean(IdentityService.class);
    Map<String, UserDetails> beans = context.getBeansOfType(UserDetails.class);
    if (beans.size() > 0) {
        UserDetails user = unwrap(beans.values().iterator().next());

        if (user != null) {
            List<String> authorities = user.getAuthorities().stream()
                                           .map(GrantedAuthority::getAuthority)
                                           .collect(Collectors.toList());

            String tenantId = user.getTenantId();

            if (tenantId != null) {
                identityService.setAuthentication(user.getId(), authorities, asList(tenantId));
            } else {
                identityService.setAuthentication(user.getId(), authorities);
            }
        }
    }

    filterChain.doFilter(request, response);

    identityService.setAuthenticatedUserId(null);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:37,代码来源:BpmAuthenticationFilter.java


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