org.hswebframework.web.authorization.Authentication.current()方法的使用及代码示例

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

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

Authentication.current介绍

[英]获取当前登录的用户权限信息

Authentication auth= Authentication.current().get(); 
//如果权限信息不存在将抛出 
NoSuchElementException建议使用下面的方式获取 
Authentication auth=Authentication.current().orElse(null); 
//或者 
Authentication auth=Authentication.current().orElseThrow(UnAuthorizedException::new);

[中]获取当前登录的用户权限信息

Authentication auth= Authentication.current().get(); 
//如果权限信息不存在将抛出 
NoSuchElementException建议使用下面的方式获取 
Authentication auth=Authentication.current().orElse(null); 
//或者 
Authentication auth=Authentication.current().orElseThrow(UnAuthorizedException::new);

代码示例

代码示例来源: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

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

代码示例来源: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: hs-web/hsweb-framework

@Authorize(merge = false)
@PutMapping(path = "/password")
@ApiOperation("修改当前登录用户的密码")
public ResponseMessage<Void> updateLoginUserPassword(@RequestParam String password,
                           @RequestParam String oldPassword) {
  Authentication authentication = Authentication.current().orElseThrow(UnAuthorizedException::new);
  getService().updatePassword(authentication.getUser().getId(), oldPassword, password);
  return ok();
}

代码示例来源: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

@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

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

代码示例来源: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 ResponseMessage<String> add(@RequestBody DynamicFormEntity data) {
  Authentication authentication = Authentication.current().orElse(null);
  if (null != authentication) {
    data.setCreatorId(authentication.getUser().getId());
  }
  data.setCreateTime(System.currentTimeMillis());
  return SimpleGenericEntityController.super.add(data);
}

代码示例来源: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));
}

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

if (keyExpress.contains("${")) {
  Map<String, Object> params = new HashMap<>();
  params.put("user", Authentication.current().map(Authentication::getUser).orElse(null));
  for (int i = 0; i < args.length; i++) {
    params.put(names.length > i ? names[i] : "arg" + i, args[i]);

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

@Authorize(action = Permission.ACTION_ADD)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "新增")
default ResponseMessage<PK> add(@RequestBody M data) {
  E entity = modelToEntity(data, getService().createEntity());
  //自动添加创建人和创建时间
  if (entity instanceof RecordCreationEntity) {
    RecordCreationEntity creationEntity = (RecordCreationEntity) entity;
    creationEntity.setCreateTimeNow();
    creationEntity.setCreatorId(Authentication.current()
        .map(Authentication::getUser)
        .map(User::getId)
        .orElse(null));
  }
  //修改人和修改时间
  if (entity instanceof RecordModifierEntity) {
    RecordModifierEntity creationEntity = (RecordModifierEntity) entity;
    creationEntity.setModifyTimeNow();
    creationEntity.setModifierId(Authentication.current()
        .map(Authentication::getUser)
        .map(User::getId)
        .orElse(null));
  }
  return ok(getService().insert(entity));
}

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

@PatchMapping
@Authorize(action = Permission.ACTION_UPDATE)
@ApiOperation(value = "保存客户端", notes = "如果客户端不存在则自动新增")
public ResponseMessage<OAuth2Client> saveOrUpdate(@RequestBody OAuth2ClientEntity clientEntity) {
  Authentication authentication = Authentication.current().orElse(null);
  if (null != authentication) {
    clientEntity.setCreatorId(authentication.getUser().getId());
  }
  clientEntity.setCreateTimeNow();
  return ResponseMessage.ok(repository.save(clientEntity));
}

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

@PatchMapping("/bind")
@ApiOperation("同时保存表单和字段")
@Authorize(action = {Permission.ACTION_ADD, Permission.ACTION_UPDATE}, logical = Logical.OR)
public ResponseMessage<String> saveOrUpdateFormAndColumn(@RequestBody DynamicFormColumnBindEntity bindEntity) {
  Authentication authentication = Authentication.current().orElse(null);
  Objects.requireNonNull(bindEntity.getForm(), "form can not be null");
  Objects.requireNonNull(bindEntity.getColumns(), "columns can not be null");
  if (null != authentication) {
    bindEntity.getForm().setCreatorId(authentication.getUser().getId());
  }
  bindEntity.getForm().setCreateTime(System.currentTimeMillis());
  return ResponseMessage.ok(dynamicFormService.saveOrUpdate(bindEntity));
}

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

@Authorize(action = {Permission.ACTION_UPDATE, Permission.ACTION_ADD}, logical = Logical.AND)
@PatchMapping
@ApiOperation("新增或者修改")
default ResponseMessage<PK> saveOrUpdate(@RequestBody M data) {
  E entity = modelToEntity(data, getService().createEntity());
  //自动添加创建人和创建时间
  if (entity instanceof RecordCreationEntity) {
    RecordCreationEntity creationEntity = (RecordCreationEntity) entity;
    creationEntity.setCreateTimeNow();
    creationEntity.setCreatorId(Authentication.current()
        .map(Authentication::getUser)
        .map(User::getId)
        .orElse(null));
  }
  //修改人和修改时间
  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().saveOrUpdate(entity));
}

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

@GetMapping(params = "response_type=code")
@ApiOperation("获取当前登录用户OAuth2.0授权码")
@Authorize
@ApiImplicitParam(paramType = "query",name =  OAuth2Constants.client_id,required = true)
public AuthorizationCodeModel requestCode(
    @RequestParam("redirect_uri") String redirectUri,
    @RequestParam(value = "state", required = false) String state,
    HttpServletRequest request) {
  Authentication authentication = Authentication.current().orElseThrow(UnAuthorizedException::new);
  AuthorizationCodeRequest codeRequest = new HttpAuthorizationCodeRequest(authentication.getUser().getId(), request);
  String code = authorizationCodeService.createAuthorizationCode(codeRequest);
  AuthorizationCodeModel model = new AuthorizationCodeModel();
  model.setCode(code);
  model.setRedirectUri(redirectUri);
  model.setState(state);
  return model;
}

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

@Authorize(action = "upload", description = "上传文件")
public ResponseMessage<FileInfoEntity> upload(@RequestPart("file") MultipartFile file) {
  Authentication authentication = Authentication.current().orElse(null);
  String creator = authentication == null ? null : authentication.getUser().getId();
  if (file.isEmpty()) {

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

@Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
      HandlerMethod method = ((HandlerMethod) handler);
      TwoFactor factor = method.getMethodAnnotation(TwoFactor.class);
      if (factor == null || factor.ignore()) {
        return true;
      }
      String userId = Authentication.current()
          .map(Authentication::getUser)
          .map(User::getId)
          .orElse(null);
      TwoFactorValidator validator = validatorManager.getValidator(userId, factor.value(), factor.provider());
      if (!validator.expired()) {
        return true;
      }
      String code = request.getParameter(factor.parameter());
      if (code == null) {
        code = request.getHeader(factor.parameter());
      }
      if (StringUtils.isEmpty(code)) {
        throw new NeedTwoFactorException(factor.message(), factor.provider());
      } else if (!validator.verify(code, factor.timeout())) {
        throw new NeedTwoFactorException("验证码错误", factor.provider());
      }
    }
    return super.preHandle(request, response, handler);
  }
}

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

Authentication.current().map(Authentication::getUser)
    .map(User::getId).orElse(null)
, event.getProcessDefinitionId()

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

boolean isControl = false;
if (null != definition) {
  Authentication authentication = Authentication.current().orElseThrow(UnAuthorizedException::new);

相关文章