Revision 61752
Added by Konstantinos Triantafyllou over 2 years ago
AuthorizationProvider.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaauthorizationlibrary.security; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaauthorizationlibrary.utils.AuthorizationUtils; |
|
4 |
import eu.dnetlib.uoaauthorizationlibrary.utils.UserInfo; |
|
3 | 5 |
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 | 6 |
import org.springframework.stereotype.Component; |
9 | 7 |
|
8 |
import javax.servlet.http.HttpServletRequest; |
|
9 |
|
|
10 | 10 |
@Component |
11 | 11 |
public class AuthorizationProvider { |
12 | 12 |
|
13 |
private UserDetailsServiceImpl userDetailsService;
|
|
13 |
private final AuthorizationUtils utils;
|
|
14 | 14 |
|
15 | 15 |
@Autowired |
16 |
AuthorizationProvider(UserDetailsServiceImpl userDetailsService) {
|
|
17 |
this.userDetailsService = userDetailsService;
|
|
16 |
AuthorizationProvider(AuthorizationUtils utils) {
|
|
17 |
this.utils = utils;
|
|
18 | 18 |
} |
19 | 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 |
} |
|
20 |
public OpenAIREAuthentication getAuthentication(HttpServletRequest request) { |
|
21 |
UserInfo user = utils.getUserInfo(request); |
|
22 |
if(user != null) { |
|
23 |
return new OpenAIREAuthentication(user); |
|
24 |
} |
|
25 |
return new OpenAIREAuthentication(); |
|
27 | 26 |
} |
28 | 27 |
} |
Also available in: Unified diff
Create OpenAIREAuthentication object. Get user Info supports new login service user Info implementation