本文整理了Java中org.hswebframework.web.authorization.Authentication
类的一些代码示例,展示了Authentication
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Authentication
类的具体详情如下:
包路径:org.hswebframework.web.authorization.Authentication
类名称:Authentication
[英]用户授权信息,当前登录用户的权限信息,包括用户的基本信息,角色,权限集合等常用信息
获取方式:
代码示例来源: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));
}
内容来源于网络,如有侵权,请联系作者删除!