我是Spring安全的新手,正在开发具有OAuth2身份验证和授权的Spring REST API。一切正常,但是当我请求刷新令牌时,却收到错误消息,指出:
org.springframework.security.oauth2.provider.endpoint.TokenEndpoint handleException IllegalStateException,需要UserDetailsService。
注意:我使用自定义身份验证提供程序来验证数据库中的用户凭据。
这是我的代码:
Web安全配置适配器:
@Configuration
@EnableWebSecurity
public class OAuth2SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
private CustomAuthenticationProvider authProvider;
@Override
protected void configure(
AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.anonymous().disable()
.authorizeRequests()
.antMatchers("/oauth/token").permitAll();
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public TokenStore tokenStore() {
return new InMemoryTokenStore();
}
@Bean
@Autowired
public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore){
TokenStoreUserApprovalHandler handler = …Run Code Online (Sandbox Code Playgroud) java spring spring-mvc spring-security spring-security-oauth2
func getThumbnailFrom(path: URL?, withCompletionHandler completion:@escaping ((UIImage)-> Void)){
var thumbnail = UIImage(named: "name of Dummy Image")
if let url = path{
DispatchQueue.global(qos: .background).async {
do{
let asset = AVURLAsset(url: url , options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(value: 500,timescale: 30), actualTime: nil)
thumbnail = UIImage(cgImage: cgImage)
completion(thumbnail!)
}catch let error{
print(error.localizedDescription)
}
}
}
completion(thumbnail!)
}
Used it as
getThumbnailFrom(path: URL(string: "https://p-events-delivery.akamaized.net/18oijbasfvuhbfsdvoijhbsdfvljkb6/m3u8/hls_vod_mvp.m3u8")!, withCompletionHandler: { (image) in DispatchQueue.main.async(execute: { self.imagePreview.image = image }) …Run Code Online (Sandbox Code Playgroud) 我开发的Spring REST API将作为后端.它将由Web应用程序和移动应用程序访问.为了使这个API安全,我使用了Spring的oAuth2身份验证.我知道通过使用这种架构,我的API是安全的,但是,有没有办法检查access_token是否来自发出它的同一个客户端(应用程序)?
我是 Python 和 Django 新手。我创建了 ViewSet,如下所示:
api/views.py
class UserDetails(ViewSet):
"""
CREATE, SELECT, UPDATE OR DELETE
"""
def retrive(self, request, pk):
user = self.get_object(pk)
print(user.query)
user = TestSerializer(user)
return Response(user.data)
def list(self, request):
users = TestTB.objects.all()
print(users.query)
serializer = TestSerializer(users, many=True)
return Response(serializer.data)
def create(self, request):
serializer = TestSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def update(self, request, pk):
user = self.get_object(pk)
serializer = TestSerializer(user, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def destroy(self, request, pk): …Run Code Online (Sandbox Code Playgroud)