org.hswebframework.web.authorization.Authentication类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中org.hswebframework.web.authorization.Authentication类的一些代码示例,展示了Authentication类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Authentication类的具体详情如下:
包路径:org.hswebframework.web.authorization.Authentication
类名称:Authentication

Authentication介绍

[英]用户授权信息,当前登录用户的权限信息,包括用户的基本信息,角色,权限集合等常用信息
获取方式:

  • springmvc 入参方式: ResponseMessage myTest(Authorization auth){}
  • 静态方法方式:AuthorizationHolder.get();
    [中]用户授权信息,当前登录用户的权限信息,包括用户的基本信息,角色,权限集合等常用信息
    获取方式:
    *springmvc入参方式: 响应消息myTest(授权验证){}
  • 静态方法方式:授权持有人。get();

代码示例

代码示例来源:origin: hs-web/hsweb-framework

@Override
public ResponseMessage<String> add(@RequestBody BindRoleUserEntity data) {
  Authentication authentication = Authentication.current().orElse(null);
  if (null != authentication) {
    data.setCreatorId(authentication.getUser().getId());
  }
  return CreateController.super.add(data);
}

代码示例来源:origin: hs-web/hsweb-framework

actionsDef);
List<Permission> permissions = authentication.getPermissions().stream()
    .filter(permission -> {
    ? authentication.getRoles().stream()::anyMatch
    : authentication.getRoles().stream()::allMatch;
access = func.apply(role -> rolesDef.contains(role.getId()));
    ? usersDef.stream()::anyMatch
    : usersDef.stream()::allMatch;
access = func.apply(authentication.getUser().getUsername()::equals);

代码示例来源:origin: hs-web/hsweb-framework

String[] permissionAndActions = conf.split("[:]", 2);
if (permissionAndActions.length < 2) {
  temp = authentication -> !authentication.getPermissions().isEmpty();
} else {
  String[] real = permissionAndActions[1].split("[:]");
String[] real = conf.split("[:]", 2);
if (real.length < 2) {
  temp = authentication -> !authentication.getRoles().isEmpty();
} else {
  temp = AuthenticationPredicate.role(real[1]);

代码示例来源:origin: hs-web/hsweb-framework

.getMethod().getName());
String userId = context.getAuthentication().getUser().getId();
boolean allow;
allow = Optional.ofNullable(allows.get("users"))
    .getRoles()
    .stream()
    .map(role -> allows.getOrDefault("roles", Collections.emptyMap()).get(role.getId()))

代码示例来源:origin: hs-web/hsweb-framework

@Override
public Authentication sync(Authentication authentication) {
  authentications.put(authentication.getUser().getId(), authentication);
  return authentication;
}

代码示例来源:origin: hs-web/hsweb-framework

@Override
  public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    return Authentication.current().orElseThrow(UnAuthorizedException::new);
  }
}

代码示例来源:origin: hs-web/hsweb-framework

/**
 * 根据权限id获取权限信息,权限不存在则返回null
 *
 * @param id 权限id
 * @return 权限信息
 */
default Optional<Permission> getPermission(String id) {
  if (null == id) {
    return Optional.empty();
  }
  return getPermissions().stream()
      .filter(permission -> permission.getId().equals(id))
      .findAny();
}

代码示例来源:origin: hs-web/hsweb-framework

/**
 * 根据id获取角色,角色不存在则返回null
 *
 * @param id 角色id
 * @return 角色信息
 */
default Optional<Role> getRole(String id) {
  if (null == id) {
    return Optional.empty();
  }
  return getRoles().stream()
      .filter(role -> role.getId().equals(id))
      .findAny();
}

代码示例来源:origin: hs-web/hsweb-framework

@Override
public String getUserId() {
  return authentication.getUser().getId();
}

代码示例来源:origin: hs-web/hsweb-framework

default boolean test() {
  return Authentication.current()
      .map(this::test)
      .orElse(false);
}

代码示例来源:origin: org.hswebframework.web/hsweb-authorization-basic

.getMethod().getName());
String userId = context.getAuthentication().getUser().getId();
boolean allow;
allow = Optional.ofNullable(allows.get("users"))
    .getRoles()
    .stream()
    .map(role -> allows.getOrDefault("roles", Collections.emptyMap()).get(role.getId()))

代码示例来源:origin: hs-web/hsweb-framework

List<Permission> permission = context.getAuthentication().getPermissions()
    .stream()
    .filter(per -> context.getDefinition().getPermissions().contains(per.getId()))

代码示例来源:origin: hs-web/hsweb-framework

@Override
  public PersonnelAuthentication get() {
    //TreadLocal Cache
    return ThreadLocalUtils.get(threadLocalCacheKey, () ->
        Authentication.current().map(authentication -> getByUserId(authentication.getUser().getId()))
            .orElse(null));
  }
}

代码示例来源:origin: hs-web/hsweb-framework

@Override
public boolean canClaim(Task task, String userId) {
  return getCandidateInfo(task)
      .stream()
      .map(CandidateInfo::user)
      .anyMatch(user -> user.getUser().getId().equals(userId));
}

代码示例来源:origin: hs-web/hsweb-framework

@GetMapping("{id}/execute")
  @Authorize(merge = false)
  @ApiOperation("执行仪表盘配置")
  public ResponseMessage<Object> execute(@PathVariable String id) {
    return ResponseMessage.ok(dashBoardExecutor.execute(dashBoardService.selectByPk(id), Authentication.current().orElse(null)));
  }
}

代码示例来源:origin: org.hswebframework.web/hsweb-authorization-basic

actionsDef);
List<Permission> permissions = authentication.getPermissions().stream()
    .filter(permission -> {
    ? authentication.getRoles().stream()::anyMatch
    : authentication.getRoles().stream()::allMatch;
access = func.apply(role -> rolesDef.contains(role.getId()));
    ? usersDef.stream()::anyMatch
    : usersDef.stream()::allMatch;
access = func.apply(authentication.getUser().getUsername()::equals);

代码示例来源:origin: org.hswebframework.web/hsweb-authorization-basic

List<Permission> permission = context.getAuthentication().getPermissions()
    .stream()
    .filter(per -> context.getDefinition().getPermissions().contains(per.getId()))

代码示例来源:origin: hs-web/hsweb-framework

@Override
public ResponseMessage<String> add(@RequestBody DashBoardConfigEntity data) {
  Authentication.current().ifPresent(a -> data.setCreatorId(a.getUser().getId()));
  return SimpleGenericEntityController.super.add(data);
}

代码示例来源:origin: hs-web/hsweb-framework

@GetMapping("/me/{key}")
@Authorize(merge = false)
@ApiOperation("获取当前用户的配置列表")
public ResponseMessage<List<UserSettingEntity>> get(Authentication authentication,
                          @PathVariable String key) {
  return ResponseMessage.ok(userSettingService
      .selectByUser(authentication.getUser().getId(), key)
      .stream()
      .filter(setting -> setting.hasPermission(R, RW))
      .collect(Collectors.toList()));
}

代码示例来源:origin: hs-web/hsweb-framework

@Authorize(action = Permission.ACTION_UPDATE)
@PutMapping(path = "/{id}")
@ApiOperation("修改数据")
default ResponseMessage<Integer> updateByPrimaryKey(@PathVariable PK id, @RequestBody M data) {
  E entity = modelToEntity(data, getService().createEntity());
  if (entity instanceof RecordModifierEntity) {
    RecordModifierEntity creationEntity = (RecordModifierEntity) entity;
    creationEntity.setModifyTimeNow();
    creationEntity.setModifierId(Authentication.current()
        .map(Authentication::getUser)
        .map(User::getId)
        .orElse(null));
  }
  return ResponseMessage.ok(getService().updateByPk(id, entity));
}

相关文章