Here are the examples of the java api @org.springframework.lang.NonNull taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
810 Examples
19
View Source File : VerifyAuthFunction.java
License : Apache License 2.0
Project Creator : zuihou
License : Apache License 2.0
Project Creator : zuihou
/**
* 远程查询当前登录的用户拥有那些权限
*
* @return
*/
@NonNull
private Set<String> getAllResources() {
// 查询当前用户拥有的所有资源
Set<String> resources = new HashSet<>();
R<SysUser> result = userResolverService.getById(UserQuery.buildResource());
if (result.getIsSuccess() && result.getData() != null && result.getData().getResources() != null) {
SysUser sysUser = result.getData();
resources = new HashSet<>(sysUser.getResources());
}
return resources;
}
19
View Source File : VerifyAuthFunction.java
License : Apache License 2.0
Project Creator : zuihou
License : Apache License 2.0
Project Creator : zuihou
@NonNull
private Set<String> getAllRoles() {
// 查询当前用户拥有的所有角色
Set<String> roles = new HashSet<>();
R<SysUser> result = userResolverService.getById(UserQuery.buildRoles());
if (result.getIsSuccess() && result.getData() != null && result.getData().getRoles() != null) {
SysUser sysUser = result.getData();
roles = sysUser.getRoles().stream().map(SysRole::getCode).collect(Collectors.toSet());
}
return roles;
}
19
View Source File : MyRedisCacheManager.java
License : Apache License 2.0
Project Creator : Zoctan
License : Apache License 2.0
Project Creator : Zoctan
@NonNull
@Override
protected Collection<RedisCache> loadCaches() {
final List<RedisCache> caches = new LinkedList<>();
for (final Map.Entry<String, RedisCacheConfiguration> entry : this.initialCacheConfiguration.entrySet()) {
caches.add(super.createRedisCache(entry.getKey(), entry.getValue()));
}
return caches;
}
19
View Source File : BeanUtils.java
License : MIT License
Project Creator : zidoshare
License : MIT License
Project Creator : zidoshare
/**
* Gets null names set of property.
*
* @param source object data must not be null
* @return null name set of property
*/
@NonNull
private static Set<String> getNullPropertyNameSet(@NonNull Object source) {
replacedert.notNull(source, "source object must not be null");
BeanWrapperImpl beanWrapper = new BeanWrapperImpl(source);
PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String propertyName = propertyDescriptor.getName();
Object propertyValue = beanWrapper.getPropertyValue(propertyName);
// if property value is equal to null, add it to empty name set
if (propertyValue == null) {
emptyNames.add(propertyName);
}
}
return emptyNames;
}
19
View Source File : BeanUtils.java
License : MIT License
Project Creator : zidoshare
License : MIT License
Project Creator : zidoshare
/**
* Gets null names array of property.
*
* @param source object data must not be null
* @return null name array of property
*/
@NonNull
private static String[] getNullPropertyNames(@NonNull Object source) {
return getNullPropertyNameSet(source).toArray(new String[0]);
}
19
View Source File : BeanUtils.java
License : MIT License
Project Creator : zidoshare
License : MIT License
Project Creator : zidoshare
/**
* Transforms from source data collection in batch.
*
* @param sources source data collection
* @param targetClreplaced target clreplaced must not be null
* @param <T> target clreplaced type
* @return target collection transforming from source data collection.
* @throws BeanUtilsException if newing target instance failed or copying failed
*/
@NonNull
public static <T> List<T> transformFromInBatch(Collection<?> sources, @NonNull Clreplaced<T> targetClreplaced) {
if (CollectionUtils.isEmpty(sources)) {
return Collections.emptyList();
}
// Transform in batch
return sources.stream().map(source -> transformFrom(source, targetClreplaced)).collect(Collectors.toList());
}
19
View Source File : SimpleSliderCodeFactory.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 根据抠图后的源图片绝对路径, 获取抠图图片的绝对路径
* @param srcImageAbsPath 抠图后的源图片绝对路径
* @return 抠图图片的绝对路径
*/
@NonNull
private String getMarkImageAbsPath(@NonNull String srcImageAbsPath) {
return srcImageAbsPath.substring(0, srcImageAbsPath.length() - SRC_SUFFIX.length()).concat(MARK_SUFFIX);
}
19
View Source File : SimpleSliderCodeFactory.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
private SliderCode getSliderCode(byte[] srcImageBytes, byte[] markImageBytes, String srcImageFileName) {
// 0 1 2 3 4
// x_y_w_h_token.temp
final String[] split = srcImageFileName.split(IMAGE_NAME_DELIMITER, IMAGE_NAME_SPLIT_LIMIT);
if (split.length != IMAGE_NAME_SPLIT_LIMIT) {
throw new ValidateCodeException(ErrorCodeEnum.GET_VALIDATE_CODE_FAILURE, null, null);
}
// 获取 token
String token = split[4];
token = token.substring(0, token.lastIndexOf("."));
int locationX = Integer.parseInt(split[0]);
int locationY = Integer.parseInt(split[1]);
int width = Integer.parseInt(split[2]);
int height = Integer.parseInt(split[3]);
return new SliderCode(null, expireIn, token, new String(markImageBytes, StandardCharsets.UTF_8), new String(srcImageBytes, StandardCharsets.UTF_8), locationX, locationY, width, height);
}
19
View Source File : UmsAuthenticationSuccessHandler.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
private RedisConnection getConnection() {
return this.redisConnectionFactory.getConnection();
}
19
View Source File : DefaultUriAuthorizeService.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Map<String, Map<String, Set<String>>> getRolesAuthoritiesOfTenant(String tenantAuthority) {
log.error("使用 多租户 权限服务必须实现此接口 AbstractUriAuthorizeService 或 UriAuthorizeService.");
throw new RuntimeException("未实现获取多租户的所有角色的 uri(资源) 的权限的接口 AbstractUriAuthorizeService 或 UriAuthorizeService");
}
19
View Source File : DefaultUriAuthorizeService.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Map<String, Map<String, Set<String>>> getScopeAuthoritiesOfScope(Set<String> scopeSet) {
log.error("使用 SCOPE 权限服务必须实现此接口 AbstractUriAuthorizeService 或 UriAuthorizeService.");
throw new RuntimeException("未实现获取 SCOPE 的所有角色的 uri(资源) 的权限的接口 AbstractUriAuthorizeService 或 UriAuthorizeService");
}
19
View Source File : DefaultUriAuthorizeService.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Map<String, Map<String, Set<String>>> getRolesAuthorities() {
log.error("使用基于 角色 的权限服务必须实现此接口 AbstractUriAuthorizeService 或 UriAuthorizeService.");
throw new RuntimeException("未实现获取所有角色的 uri(资源) 的权限的接口 AbstractUriAuthorizeService 或 UriAuthorizeService");
}
19
View Source File : AbstractUriAuthorizeService.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 获取用户角色的 uri 权限 Map
* @param rolesAuthoritiesMap 所有角色 uri(资源) 权限 Map(role, map(uri, Set(permission)))
* @param userRoleSet 用户所拥有的角色集合
* @return 用户角色的 uri 权限 Map(uri, Set(permission))
*/
@NonNull
private Map<String, Set<String>> getUriAuthoritiesOfUserRole(@NonNull Map<String, Map<String, Set<String>>> rolesAuthoritiesMap, @NonNull final Set<String> userRoleSet) {
// Map<uri, Set<permission>>
Map<String, Set<String>> uriAuthoritiesMap = new HashMap<>(rolesAuthoritiesMap.size());
rolesAuthoritiesMap.entrySet().stream().filter(entry -> userRoleSet.contains(entry.getKey())).map(Map.Entry::getValue).forEach(map2mapConsumer(uriAuthoritiesMap));
return uriAuthoritiesMap;
}
19
View Source File : AbstractUriAuthorizeService.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 根据 authentication 获取用户所拥有的角色与 scope 的 uri(资源) 权限. 这里包含了多租户 与 SCOPE 逻辑. <br>
* <pre>
* Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
* // 此 authorities 可以包含: [ROLE_A, ROLE_B, TENANT_110110, SCOPE_read, SCOPE_write]
* // authorities 要求:
* // 1. 角色数量 >= 0
* // 2. SCOPE 数量 >= 0
* // 3. 多租户数量 1 或 0
* // 4. 角色数量 + SCOPE 数量 >= 1
* </pre>
* @param authentication {@link Authentication}
* @return 用户所拥有的角色与 scope 的 uri(资源) 权限 Map(uri, Set(permission))
*/
@Override
@NonNull
public Map<String, Set<String>> getUriAuthoritiesOfUser(@NonNull Authentication authentication) {
// 获取角色权限集合
Set<String> authoritySet = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
int size = authoritySet.size();
// 存储用户角色的集合
final Set<String> roleSet = new HashSet<>(size, 1.F);
// 存储多组户 ID
final String[] tenantAuthority = new String[] { null };
// 存储 SCOPE 的集合
final Set<String> scopeAuthoritySet = new HashSet<>(size, 1.F);
groupByRoleOrTenantOrScope(authoritySet, roleSet, tenantAuthority, scopeAuthoritySet);
// 用户所拥有的所有角色的 uri(资源) 权限 Map(uri, Set(permission))
final Map<String, Map<String, Set<String>>> rolesAuthorities;
if (null != tenantAuthority[0]) {
// 获取此租户 ID 的所有角色的资源权限的 Map
rolesAuthorities = getRolesAuthoritiesOfTenant(tenantAuthority[0]);
} else if (roleSet.size() > 0) {
// 获取所有角色的资源权限的 Map
rolesAuthorities = getRolesAuthorities();
} else {
rolesAuthorities = new HashMap<>(0);
}
// 基于用户 roleSet 的 Map<uri, Set<permission>>
final Map<String, Set<String>> uriPermissionsOfUserRole = getUriAuthoritiesOfUserRole(rolesAuthorities, roleSet);
if (scopeAuthoritySet.size() > 0) {
// 获取此 scopeAuthoritySet 的所有角色的资源权限的 Map<role, Map<uri, Set<permission>>>
final Map<String, Map<String, Set<String>>> uriPermissionsOfScope = getScopeAuthoritiesOfScope(scopeAuthoritySet);
// 把 scope 的资源权限与 role 资源权限合并
if (!uriPermissionsOfScope.isEmpty()) {
uriPermissionsOfScope.values().forEach(map2mapConsumer(uriPermissionsOfUserRole));
}
}
return uriPermissionsOfUserRole;
}
19
View Source File : AbstractUriAuthorizeService.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
private Consumer<Map<String, Set<String>>> map2mapConsumer(@NonNull final Map<String, Set<String>> uriAuthoritiesMap) {
return map -> map.forEach((key, value) -> uriAuthoritiesMap.compute(key, (k, v) -> {
if (v == null) {
v = new HashSet<>();
}
v.addAll(value);
return v;
}));
}
19
View Source File : Auth2Jackson2ModuleHolder.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public SimpleModule getSimpleModule() {
return auth2Jackson2Module;
}
19
View Source File : Auth2RequestHolder.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 根据传入的字符串数组转换为类名格式的字符串, 另外 DingTalk -> DingTalk, WECHAT -> WeChat.
* @param splits 字符串数组, 例如: [WECHAT, OPEN]
* @return 返回类名格式的字符串, 如传入的数组是: [STACK, OVERFLOW] 那么返回 AuthStackOverflowRequest
*/
@NonNull
private static String toAuthRequestClreplacedName(String[] splits) {
StringBuilder sb = new StringBuilder();
sb.append(AUTH_REQUEST_PREFIX);
for (String split : splits) {
split = split.toLowerCase();
if (AuthDefaultSource.DINGTALK.name().equalsIgnoreCase(split)) {
sb.append("DingTalk");
continue;
}
if ("wechat".equalsIgnoreCase(split)) {
sb.append("WeChat");
continue;
}
if ("enterprise".equalsIgnoreCase(split) && splits.length == 2 && "wechat".equalsIgnoreCase(splits[0])) {
sb.append("EnterpriseQrcode");
continue;
}
if (split.length() > 1) {
sb.append(split.substring(0, 1).toUpperCase()).append(split.substring(1));
} else {
sb.append(split.toUpperCase());
}
}
sb.append(AUTH_REQUEST_SUFFIX);
return sb.toString();
}
19
View Source File : Auth2RequestHolder.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 根据传入的字符串数组转换为驼峰格式的字符串
* @param splits 字符串数组, 例如: [WECHAT, OPEN]
* @return 驼峰格式的字符串, 如传入的数组是: [WECHAT, OPEN] 那么返回 wechatOpen
*/
@NonNull
private static String toProviderId(String[] splits) {
if (splits.length == 1) {
return splits[0].trim().toLowerCase();
}
StringBuilder sb = new StringBuilder();
for (String split : splits) {
split = split.toLowerCase();
if (split.length() > 1) {
sb.append(split.substring(0, 1).toUpperCase()).append(split.substring(1));
} else {
sb.append(split.toUpperCase());
}
}
String firstChar = String.valueOf(sb.charAt(0)).toLowerCase();
sb.replace(0, 1, firstChar);
return sb.toString();
}
19
View Source File : Auth2RequestHolder.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 根据 {@link AuthSource} 获取对应的 {@link AuthDefaultRequest} 子类的 Clreplaced
* @param source {@link AuthSource}
* @return 返回 {@link AuthSource} 对应的 {@link AuthDefaultRequest} 子类的 Clreplaced
*/
@NonNull
public static Clreplaced<?> getAuthRequestClreplacedBySource(@NonNull AuthSource source) throws ClreplacedNotFoundException {
if (source instanceof AuthCustomizeSource) {
if (Auth2RequestHolder.authCustomizeSource == null) {
throw new RuntimeException("必须实现 top.dcenter.ums.security.core.api.oauth.customize.AuthCustomizeSource 且注入 IOC 容器");
}
return Auth2RequestHolder.authCustomizeSource.getCustomizeRequestClreplaced();
}
if (source instanceof AuthGitlabPrivateSource) {
if (Auth2RequestHolder.authGitlabPrivateSource == null) {
throw new RuntimeException("必须实现 top.dcenter.ums.security.core.oauth.justauth.source.AuthCustomizeSource 且注入 IOC 容器");
}
return Auth2RequestHolder.authGitlabPrivateSource.getCustomizeRequestClreplaced();
}
if (!(source instanceof AuthDefaultSource)) {
throw new RuntimeException("AuthSource 必须是 me.zhyd.oauth.config.AuthDefaultSource 或 top.dcenter.ums.security.core.api.oauth.customize.AuthCustomizeSource 子类");
}
String[] splits = ((AuthDefaultSource) source).name().split(FIELD_SEPARATOR);
String authRequestClreplacedName = AUTH_REQUEST_PACKAGE + toAuthRequestClreplacedName(splits);
return Clreplaced.forName(authRequestClreplacedName);
}
19
View Source File : MdcUtil.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 装饰 task, 如没有日志链路追踪 ID, 生成日志链路追踪 ID.
* @param task 任务
* @param idType MDC id 类型
* @param idGenerator mdc id 生成器
* @return 返回装饰后的 task
*/
@NonNull
public static Runnable decorateTasks(@NonNull Runnable task, @NonNull MdcIdType idType, @Nullable MdcIdGenerator idGenerator) {
return () -> {
Map<String, String> contextMap = MDC.getCopyOfContextMap();
boolean isRemoveMdcId = false;
if (contextMap == null) {
MDC.put(MDC_KEY, getMdcId(idType, idGenerator));
isRemoveMdcId = true;
}
task.run();
if (isRemoveMdcId) {
MDC.remove(MDC_KEY);
}
};
}
19
View Source File : MdcUtil.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 获取基于 SLF4J MDC 机制实现日志链路追踪 ID
* @param type MDC id 类型
* @param idGenerator MDC id 生成器.
* @return 返回 MDC 日志链路追踪 ID
*/
@NonNull
public static String getMdcId(@NonNull MdcIdType type, @Nullable MdcIdGenerator idGenerator) {
if (MdcIdType.CUSTOMIZE_ID.equals(type) && idGenerator != null) {
return idGenerator.getMdcId();
}
return type.getMdcId();
}
19
View Source File : MdcUtil.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 获取当前线程的 MDC 日志链路追踪 ID; 如没有日志链路追踪 ID, 生成日志链路追踪 ID.
* @param type MDC id 类型
* @param idGenerator MDC id 生成器.
* @return 返回 MDC 日志链路追踪 ID, 如果不存在, 返回 null
*/
@NonNull
public static String getMdcTraceId(@NonNull MdcIdType type, @Nullable MdcIdGenerator idGenerator) {
try {
String id = MDC.get(MDC_KEY);
if (hasText(id)) {
return id;
}
return getMdcId(type, idGenerator);
} catch (Exception e) {
return getMdcId(type, idGenerator);
}
}
19
View Source File : Oauth2TokenAuthenticationTokenToUserConverter.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public UserDetails convert(@NonNull AbstractOAuth2TokenAuthenticationToken<OAuth2AccessToken> token) {
User user = new User(token.getName(), "", token.getAuthorities());
user.eraseCredentials();
return user;
}
19
View Source File : UmsJwtGrantedAuthoritiesConverterSupplier.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Converter<Jwt, Collection<GrantedAuthority>> getConverter() {
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
jwtGrantedAuthoritiesConverter.setAuthorityPrefix("");
jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName(JwtCustomClaimNames.AUTHORITIES.getClaimName());
return jwtGrantedAuthoritiesConverter;
}
19
View Source File : JwtJackson2ModuleHolder.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public SimpleModule getSimpleModule() {
return jwtJackson2Module;
}
19
View Source File : UmsGenerateClaimsSetServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public JWTClaimsSet generateClaimsSet(@NonNull Authentication authentication, @Nullable Jwt refreshTokenJwt) {
String tenantId = null;
if (nonNull(tenantContextHolder)) {
tenantId = tenantContextHolder.getTenantId(authentication);
}
// Prepare JWT with claims set
final JWTClaimsSet.Builder builder = getJwtClaimsSetBuilder(tenantId, authentication.getName(), refreshTokenJwt);
if (nonNull(customClaimsSetService)) {
JWTClaimsSet jwtClaimsSet = customClaimsSetService.toClaimsSet(authentication);
jwtClaimsSet.getClaims().forEach(builder::claim);
}
return builder.build();
}
19
View Source File : UmsGenerateClaimsSetServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public JWTClaimsSet generateClaimsSet(@NonNull UserDetails userDetails, @Nullable Jwt refreshTokenJwt) {
String tenantId = null;
if (nonNull(tenantContextHolder)) {
tenantId = tenantContextHolder.getTenantId(userDetails);
}
// Prepare JWT with claims set
final JWTClaimsSet.Builder builder = getJwtClaimsSetBuilder(tenantId, userDetails.getUsername(), refreshTokenJwt);
if (nonNull(refreshTokenJwt)) {
builder.claim(JwtCustomClaimNames.REFRESH_TOKEN_JTI.getClaimName(), refreshTokenJwt.getId());
}
if (nonNull(customClaimsSetService)) {
JWTClaimsSet jwtClaimsSet = customClaimsSetService.toClaimsSet(userDetails);
jwtClaimsSet.getClaims().forEach(builder::claim);
}
return builder.build();
}
19
View Source File : UmsGenerateClaimsSetServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public JwtAuthenticationConverter getJwtAuthenticationConverter() {
return this.jwtAuthenticationConverter;
}
19
View Source File : UmsAuthoritiesClaimsSetServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public JWTClaimsSet toClaimsSet(@NonNull Authentication authentication) {
// Prepare JWT with claims set
JWTClaimsSet.Builder builder = getJwtClaimsSetBuilderWithAuthorities(authentication.getAuthorities());
return builder.build();
}
19
View Source File : UmsAuthoritiesClaimsSetServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public JWTClaimsSet toClaimsSet(@NonNull UserDetails userDetails) {
// Prepare JWT with claims set
JWTClaimsSet.Builder builder = getJwtClaimsSetBuilderWithAuthorities(userDetails.getAuthorities());
return builder.build();
}
19
View Source File : UmsJwtCacheTransformServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Clreplaced<JwtAuthenticationToken> getClazz() {
return JwtAuthenticationToken.clreplaced;
}
19
View Source File : UmsJwtCacheTransformServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public byte[] serialize(@NonNull Authentication authentication) throws SerializationException {
if (authentication instanceof JwtAuthenticationToken) {
byte[] result = redisSerializer.serialize(((JwtAuthenticationToken) authentication));
if (nonNull(result)) {
return result;
}
}
throw new SerializationException("序列化错误");
}
19
View Source File : DemoUriAuthorizeServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Map<String, Map<String, Set<String>>> getRolesAuthorities() {
// do nothing 具体看 permission-example 的 demo.permission.service.impl.UriAuthorizeServiceImpl
return new HashMap<>(0);
}
19
View Source File : UmsUriAuthorizeServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Map<String, Map<String, Set<String>>> getRolesAuthoritiesOfTenant(String tenantAuthority) {
// 多租户应用必须实现此方法. 才能根据租户 id 进行相应的授权.
// do nothing 具体看 permission-example 的 demo.permission.service.impl.UriAuthorizeServiceImpl
return new HashMap<>(0);
}
19
View Source File : UriAuthorizeServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* 获取角色的 uri 的权限 map.<br>
* 返回值为: Map(role, Map(uri, UriResourcesDTO))
* @return Map(String, Map(String, String)) 的 key 为必须包含"ROLE_"前缀的角色名称(如: ROLE_ADMIN), value 为 UriResourcesDTO map
* (key 为 uri, 此 uri 可以为 antPath 通配符路径,如 /user/**; value 为 UriResourcesDTO).
*/
@Override
@NonNull
public Map<String, Map<String, Set<String>>> getRolesAuthorities() {
if (this.rolesAuthoritiesMap != null) {
return this.rolesAuthoritiesMap;
}
synchronized (lock) {
if (this.rolesAuthoritiesMap != null) {
return this.rolesAuthoritiesMap;
}
// 更新并缓存所有角色 uri(资源) 权限 Map<role, Map<uri, Set<permission>>>
return new ConcurrentHashMap<>(updateRolesAuthorities());
}
}
19
View Source File : RolePermissionServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public Clreplaced<SysResources> getUpdateResourcesClreplaced() {
return SysResources.clreplaced;
}
19
View Source File : RolePermissionServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public List<SysResources> findAllResourcesByRoleId(@NonNull Long roleId) {
// 1. 获取角色
Optional<SysRole> sysRoleOptional = sysRoleService.findById(roleId);
// 角色不存在
if (!sysRoleOptional.isPresent()) {
return new ArrayList<>();
}
SysRole sysRole = sysRoleOptional.get();
// start: 判断是否有权限获取此角色
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return new ArrayList<>();
}
// 根据角色的 authorities 获取所有的继承角色, 包含本角色
final Collection<? extends GrantedAuthority> authorities = roleHierarchy.getReachableGrantedAuthorities(authentication.getAuthorities());
// 是否包含在权限继承链中.
final boolean isInclude = authorities.stream().anyMatch(authority -> authority.getAuthority().equals(sysRole.getName()));
if (!isInclude) {
return new ArrayList<>();
}
// end: 判断是否有权限获取此角色
// 2. 获取角色 uri 的对应权限资源,
return sysResourcesService.findByRoleId(sysRole.getId());
}
19
View Source File : DemoJwkSetUriConfig.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Map<String, Object> headers() {
HashMap<String, Object> resultMap = new HashMap<>(2);
resultMap.put("appId", "111");
resultMap.put("appCode", "111");
return resultMap;
}
19
View Source File : UserDetailsServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/**
* {@link #existedByUsernames(String...)} usernames 生成规则.
* 如需自定义重新实现此逻辑
* @param authUser 第三方用户信息
* @return 返回一个 username 数组
*/
@NonNull
@Override
public String[] generateUsernames(@NonNull AuthUser authUser) {
return new String[] { authUser.getUsername(), // providerId = authUser.getSource()
authUser.getUsername() + "_" + authUser.getSource(), // providerUserId = authUser.getUuid()
authUser.getUsername() + "_" + authUser.getSource() + "_" + authUser.getUuid() };
}
19
View Source File : LoginSocialUserDetailsServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public List<Boolean> existedByUsernames(@NonNull String... usernames) throws UsernameNotFoundException {
// TODO
return null;
}
19
View Source File : LoginSocialUserDetailsServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public String[] generateUsernames(@NonNull AuthUser authUser) {
return new String[] { authUser.getUsername(), // providerId = authUser.getSource()
authUser.getUsername() + "_" + authUser.getSource(), // providerUserId = authUser.getUuid()
authUser.getUsername() + "_" + authUser.getSource() + "_" + authUser.getUuid() };
}
19
View Source File : LoginSocialUserDetailsServiceImpl.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public UserDetails loadUserByUserId(@NonNull String userId) throws UsernameNotFoundException {
// TODO
return null;
}
19
View Source File : AuthJackson2ModuleHolder.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public SimpleModule getSimpleModule() {
return authJackson2Module;
}
19
View Source File : RemoveConnectionsByConnectionKeyWithUserIdKeyGenerator.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
@Override
public Object generate(@NonNull Object target, @NonNull Method method, Object... params) {
String userId = (String) params[0];
ConnectionKey key = (ConnectionKey) params[1];
return "h:" + userId + RedisCacheAutoConfiguration.REDIS_CACHE_KEY_SEPARATE + key.getProviderId() + RedisCacheAutoConfiguration.REDIS_CACHE_HASH_KEY_SEPARATE + key.getProviderUserId();
}
19
View Source File : RedisHashCacheManager.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
/*
* (non-Javadoc)
* @see org.springframework.cache.support.AbstractCacheManager#loadCaches()
*/
@NonNull
@Override
protected Collection<RedisCache> loadCaches() {
List<RedisCache> caches = new LinkedList<>();
for (Map.Entry<String, RedisCacheConfiguration> entry : initialCacheConfiguration.entrySet()) {
caches.add(createRedisCache(entry.getKey(), entry.getValue()));
}
return caches;
}
19
View Source File : MdcThreadPoolTaskExecutor.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
private <V> Callable<V> decorateCallable(@NonNull Callable<V> task, @Nullable Map<String, String> context) {
return () -> call(task, context);
}
19
View Source File : MdcThreadPoolTaskExecutor.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public <T> Future<T> submit(Runnable task, T result) {
// 获取父线程 MDC 中的内容
final Map<String, String> context = MDC.getCopyOfContextMap();
final Runnable r = decorateRunnable(task, context);
return super.submit(r, result);
}
19
View Source File : MdcThreadPoolTaskExecutor.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
// 获取父线程 MDC 中的内容
final Map<String, String> context = MDC.getCopyOfContextMap();
return super.invokeAny(tasks.stream().map(task -> decorateCallable(task, context)).collect(Collectors.toList()));
}
19
View Source File : MdcThreadPoolTaskExecutor.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@Override
@NonNull
public Future<?> submit(@NonNull Runnable task) {
// 获取父线程 MDC 中的内容
final Map<String, String> context = MDC.getCopyOfContextMap();
final Runnable r = decorateRunnable(task, context);
return super.submit(r);
}
19
View Source File : MdcThreadPoolTaskExecutor.java
License : MIT License
Project Creator : ZeroOrInfinity
License : MIT License
Project Creator : ZeroOrInfinity
@NonNull
private Runnable decorateRunnable(@NonNull Runnable runnable, @Nullable Map<String, String> context) {
return () -> run(runnable, context);
}
See More Examples