Revision 59787
Added by Konstantinos Triantafyllou over 3 years ago
modules/uoa-authorization-library/trunk/src/main/java/eu/dnetlib/uoaauthorizationlibrary/security/AuthorizationFilter.java | ||
---|---|---|
38 | 38 |
String token = utils.getToken(request); |
39 | 39 |
if (token != null) { |
40 | 40 |
Authentication auth = authorizationProvider.getAuthentication(token); |
41 |
SecurityContextHolder.getContext().setAuthentication(auth); |
|
41 |
if(auth != null) { |
|
42 |
SecurityContextHolder.getContext().setAuthentication(auth); |
|
43 |
} |
|
42 | 44 |
} |
43 | 45 |
filterChain.doFilter(req, res); |
44 | 46 |
} |
modules/uoa-authorization-library/trunk/src/main/java/eu/dnetlib/uoaauthorizationlibrary/security/AuthorizationProvider.java | ||
---|---|---|
4 | 4 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
5 | 5 |
import org.springframework.security.core.Authentication; |
6 | 6 |
import org.springframework.security.core.userdetails.UserDetails; |
7 |
import org.springframework.security.core.userdetails.UsernameNotFoundException; |
|
7 | 8 |
import org.springframework.stereotype.Component; |
8 | 9 |
|
9 | 10 |
@Component |
... | ... | |
17 | 18 |
} |
18 | 19 |
|
19 | 20 |
public Authentication getAuthentication(String token) { |
20 |
UserDetails userDetails = userDetailsService.loadUserByUsername(token); |
|
21 |
return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); |
|
21 |
try { |
|
22 |
UserDetails userDetails = userDetailsService.loadUserByUsername(token); |
|
23 |
return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); |
|
24 |
} catch (UsernameNotFoundException e) { |
|
25 |
return null; |
|
26 |
} |
|
22 | 27 |
} |
23 | 28 |
} |
modules/uoa-authorization-library/trunk/pom.xml | ||
---|---|---|
34 | 34 |
</exclusion> |
35 | 35 |
</exclusions> |
36 | 36 |
</dependency> |
37 |
<dependency> |
|
38 |
<groupId>org.springframework.boot</groupId> |
|
39 |
<artifactId>spring-boot-starter-tomcat</artifactId> |
|
40 |
<scope>provided</scope> |
|
41 |
</dependency> |
|
42 |
<dependency> |
|
43 |
<groupId>org.springframework.boot</groupId> |
|
44 |
<artifactId>spring-boot-starter-test</artifactId> |
|
45 |
<scope>test</scope> |
|
46 |
</dependency> |
|
47 | 37 |
<!-- Starter for using Spring Security --> |
48 | 38 |
<dependency> |
49 | 39 |
<groupId>org.springframework.boot</groupId> |
Also available in: Unified diff
[Authorization Library | Trunk]: Fix invalid token error