1 |
54525
|
panagiotis
|
package eu.dnetlib.repo.manager.service;
|
2 |
50372
|
panagiotis
|
|
3 |
51239
|
panagiotis
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
4 |
50372
|
panagiotis
|
import org.springframework.beans.factory.annotation.Value;
|
5 |
51239
|
panagiotis
|
import org.springframework.http.HttpStatus;
|
6 |
|
|
import org.springframework.http.ResponseEntity;
|
7 |
|
|
import org.springframework.security.core.GrantedAuthority;
|
8 |
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
9 |
54525
|
panagiotis
|
import org.springframework.stereotype.Service;
|
10 |
50372
|
panagiotis
|
|
11 |
51239
|
panagiotis
|
import java.util.HashMap;
|
12 |
|
|
import java.util.List;
|
13 |
|
|
import java.util.Map;
|
14 |
|
|
import java.util.stream.Collectors;
|
15 |
50372
|
panagiotis
|
|
16 |
54525
|
panagiotis
|
@Service("userService")
|
17 |
54690
|
panagiotis
|
public class UserServiceImpl implements UserService {
|
18 |
50372
|
panagiotis
|
|
19 |
|
|
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
20 |
54690
|
panagiotis
|
.getLogger(UserServiceImpl.class);
|
21 |
50372
|
panagiotis
|
|
22 |
|
|
@Value("${oidc.issuer}")
|
23 |
|
|
private String oidc_issuer;
|
24 |
|
|
|
25 |
|
|
@Override
|
26 |
51239
|
panagiotis
|
public ResponseEntity<Object> login() {
|
27 |
|
|
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
28 |
|
|
LOGGER.debug("User authentication : " + authentication);
|
29 |
|
|
Map<String,Object> body = new HashMap<>();
|
30 |
|
|
body.put("sub",authentication.getSub());
|
31 |
51525
|
panagiotis
|
if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals(""))
|
32 |
51239
|
panagiotis
|
body.put("name",authentication.getUserInfo().getGivenName() + " " + authentication.getUserInfo().getFamilyName());
|
33 |
51525
|
panagiotis
|
else
|
34 |
51239
|
panagiotis
|
body.put("name",authentication.getUserInfo().getName());
|
35 |
51525
|
panagiotis
|
|
36 |
51239
|
panagiotis
|
body.put("email",authentication.getUserInfo().getEmail());
|
37 |
|
|
List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
|
38 |
|
|
body.put("role",roles);
|
39 |
51911
|
panagiotis
|
|
40 |
51239
|
panagiotis
|
return new ResponseEntity<>(body, HttpStatus.OK);
|
41 |
50372
|
panagiotis
|
}
|
42 |
|
|
}
|