让我们考虑一个相当简单的假设应用程序,用户可以在其中阅读或撰写帖子.
有些用户可以阅读和撰写文章,而有些用户只能阅读.使用Spring Security(3.2.1),我通过两个角色对此进行了建模:
使用Spring安全性实现这一点非常简单......
现在,我想通过使用Spring Security OAuth(版本2.0.0.M3 ATM)实现OAuth2提供程序,允许第三方应用程序代表用户读写帖子.
在授权步骤期间,应用程序询问用户是否愿意代表他们授予阅读和/或撰写帖子的权利.这里的用户在这里授予范围(不是角色).
然后,当OAuth2使用者调用我的REST API时,Spring Sec OAuth会授权所授予的令牌并创建一个身份验证,其中包含具有所有角色的用户以及仅授予的作用域.
问题(和问题)是我现在必须编写不同的安全逻辑,具体取决于API是否由正常身份验证的用户调用(只检查角色)或是否通过OAuth2调用(检查角色+范围).
是否可以在Spring Security OAuth2中"合并"角色和范围的概念,以便在授权步骤中,用户向应用程序授予他们拥有的角色的子集(并且让OAuth2身份验证仅在授予的权限中报告这些角色) ?这样,当第三方应用程序进行API调用时,身份验证中的角色是授予的角色?这样我就不必编写任何特定于OAuth2的安全逻辑.
spring oauth spring-security oauth-2.0 spring-security-oauth2
我正在从Java程序中调用来自Delphi编译的*.so文件的函数.经过一些研究,似乎JNA是他的出路.在深入研究一些复杂的Delphi代码之前,我正在尝试使用一些"Hello World"代码,但是在获取Delphi函数返回的字符串时遇到了麻烦.
Delphi代码(helloworld.pp):
library HelloWorldLib;
function HelloWorld(const myString: string): string; stdcall;
begin
WriteLn(myString);
Result := myString;
end;
exports HelloWorld;
begin
end.
Run Code Online (Sandbox Code Playgroud)
我使用" fpc -Mdelphi helloworld.pp " 从命令行编译它,生成libhelloworld.so.
现在我的Java类:
import com.sun.jna.Library;
import com.sun.jna.Native;
public class HelloWorld {
public interface HelloWorldLibrary extends Library {
HelloWorldLibrary INSTANCE = (HelloWorldLibrary) Native.loadLibrary("/full/path/to/libhelloworld.so", HelloWorldLibrary.class);
String HelloWorld(String test);
}
public static void main(String[] args) {
System.out.println(HelloWorldLibrary.INSTANCE.HelloWorld("QWERTYUIOP"));
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个Java代码时,我得到:
# A fatal error has been detected by the Java Runtime Environment:
#
# …Run Code Online (Sandbox Code Playgroud) 我使用带有 Redis/JDK 序列化的 Spring Cache 作为缓存后端。我有一个方法,它的结果被缓存,缓存中填充了一些值。在我的应用程序的更新中,我正在以一种破坏 Java 反序列化的方式更改缓存对象的类(将成员的类型从 aList更改为 a Set)。现在对我的缓存方法的任何调用都失败了org.springframework.data.redis.serializer.SerializationException。
@Cacheable(cacheNames = "myCache", cacheManager = "myCacheManager)
public SomeObject myCachedMethod(String param) {
return ...;
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Caused by: org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.lang.ClassCastException: cannot assign instance of java.util.ArrayList to field SomeObject.foo of type java.util.Set in instance of SomeObject
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:41) ~[spring-data-redis-1.6.4.RELEASE.jar:na]
at org.springframework.data.redis.cache.RedisCache$CacheValueAccessor.deserializeIfNecessary(RedisCache.java:378) ~[spring-data-redis-1.6.4.RELEASE.jar:na] …Run Code Online (Sandbox Code Playgroud)