1
|
package eu.dnetlib.uoaauthorizationlibrary.security;
|
2
|
|
3
|
import org.springframework.beans.factory.annotation.Autowired;
|
4
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
5
|
import org.springframework.security.core.Authentication;
|
6
|
import org.springframework.security.core.userdetails.UserDetails;
|
7
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
8
|
import org.springframework.stereotype.Component;
|
9
|
|
10
|
@Component
|
11
|
public class AuthorizationProvider {
|
12
|
|
13
|
private UserDetailsServiceImpl userDetailsService;
|
14
|
|
15
|
@Autowired
|
16
|
AuthorizationProvider(UserDetailsServiceImpl userDetailsService) {
|
17
|
this.userDetailsService = userDetailsService;
|
18
|
}
|
19
|
|
20
|
public Authentication getAuthentication(String token) {
|
21
|
try {
|
22
|
UserDetails userDetails = userDetailsService.loadUserByUsername(token);
|
23
|
return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities());
|
24
|
} catch (UsernameNotFoundException e) {
|
25
|
return null;
|
26
|
}
|
27
|
}
|
28
|
}
|