我正在基于实验性 Spring 项目Spring Authorization Server构建 OAuth2 授权服务器
我的用例非常简单,从数据库中获取用户,并根据用户的某些属性,在正在生成的 JWT 中设置一些自定义声明。我还没有找到使用 Spring Authorization Server 的方法,我能解决的唯一方法是注入一个jwtCustomizer对象作为JwtEncoderbean 定义的一部分:
@Bean
public JwtEncoder jwtEncoder(CryptoKeySource keySource) {
NimbusJwsEncoder jwtEncoder = new NimbusJwsEncoder(keySource);
jwtEncoder.setJwtCustomizer((headersBuilder, claimsBuilder) -> {
// Inject some headers and claims...
});
return jwtEncoder;
}
Run Code Online (Sandbox Code Playgroud)
这显然不允许我访问用户信息,因此我目前无法设置我需要的声明。有人设法解决这个问题吗?
我很难将 0.0.1-SNAPSHOT 版本的 Java 库发布到 GitHub Packages。该库是一个 Gradle 项目。看起来,当版本不在 GitHub 上时,它会成功创建,但此后,它永远不会被更新/覆盖,发布新快照版本的唯一方法是物理删除现有版本。我的build.gradle:
plugins {
id 'java'
id 'maven-publish'
}
version = '0.0.1-SNAPSHOT'
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = "https://maven.pkg.github.com/myOrg/myRepo"
credentials {
username = "myUsername"
password = "myPassword"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时gradle publish(无论是本地还是通过 GitHub 操作),日志都干净整洁
> Task :compileJava UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :javadoc UP-TO-DATE
> Task …Run Code Online (Sandbox Code Playgroud) gradle maven maven-publish github-actions github-package-registry
假设我想执行以下操作:
代码看起来有点像这样:
Stream<Reader> stream = Files.list(Paths.get("myFolder")) // Returns a stream of Path
.callback(Files::delete) // This would have to be called after the reader has been consumed
.map(Files::newBufferedReader); // Maps every path into a Reader
Run Code Online (Sandbox Code Playgroud)
如果我peek()用来删除文件,那么当需要将文件映射到Reader时,文件就不会存在,所以我需要在使用流后运行的东西.任何的想法?
我有一个User对象列表,定义如下:
public class User {
private String userId; // Unique identifier
private String name;
private String surname;
private String otherPersonalInfo;
private int versionNumber;
}
public User(String userId, String name, String surname, String otherPersonalInfo, int version) {
super();
this.name = name;
this.surname = surname;
this.otherPersonalInfo = otherPersonalInfo;
this.version = version;
}
}
Run Code Online (Sandbox Code Playgroud)
示例列表:
List<User> users = Arrays.asList(
new User("JOHNSMITH", "John", "Smith", "Some info", 1),
new User("JOHNSMITH", "John", "Smith", "Updated info", 2),
new User("JOHNSMITH", "John", "Smith", "Latest info", 3),
new User("BOBDOE", "Bob", …Run Code Online (Sandbox Code Playgroud) 我有以下对象:
class Event {
private LocalDateTime when;
private String what;
public Event(LocalDateTime when, String what) {
super();
this.when = when;
this.what = what;
}
public LocalDateTime getWhen() {
return when;
}
public void setWhen(LocalDateTime when) {
this.when = when;
}
public String getWhat() {
return what;
}
public void setWhat(String what) {
this.what = what;
}
Run Code Online (Sandbox Code Playgroud)
}
我需要按年/月(yyyy-mm)和事件类型聚合,然后计数。例如下面的列表
List<Event> events = Arrays.asList(
new Event(LocalDateTime.parse("2017-03-03T09:01:16.111"), "EVENT1"),
new Event(LocalDateTime.parse("2017-03-03T09:02:11.222"), "EVENT1"),
new Event(LocalDateTime.parse("2017-04-03T09:04:11.333"), "EVENT1"),
new Event(LocalDateTime.parse("2017-04-03T09:04:11.333"), "EVENT2"),
new Event(LocalDateTime.parse("2017-04-03T09:06:16.444"), "EVENT2"),
new Event(LocalDateTime.parse("2017-05-03T09:01:26.555"), "EVENT3") …Run Code Online (Sandbox Code Playgroud)