Add property for session id
This commit is contained in:
parent
e95c9a6468
commit
f8c80fad37
2
pom.xml
2
pom.xml
|
@ -7,7 +7,7 @@
|
|||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>uoa-authorization-library</artifactId>
|
||||
<version>2.0.4-SNAPSHOT</version>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<scm>
|
||||
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/uoa-authorization-library/trunk</developerConnection>
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
public class SecurityConfig {
|
||||
|
||||
private String userInfoUrl;
|
||||
private String session;
|
||||
|
||||
public String getUserInfoUrl() {
|
||||
return userInfoUrl;
|
||||
|
@ -15,8 +16,11 @@ public class SecurityConfig {
|
|||
this.userInfoUrl = userInfoUrl;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
public boolean isDeprecated() {
|
||||
return userInfoUrl.contains("accessToken");
|
||||
public String getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(String session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ public class AuthorizationLibraryCheckDeployController {
|
|||
public Map<String, String> checkEverything() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("authorization.security.userInfoUrl", securityConfig.getUserInfoUrl());
|
||||
response.put("authorization.security.session", securityConfig.getSession());
|
||||
if(GlobalVars.date != null) {
|
||||
response.put("Date of deploy", GlobalVars.date.toString());
|
||||
}
|
||||
|
|
|
@ -17,37 +17,23 @@ import java.util.Collections;
|
|||
public class AuthorizationUtils {
|
||||
private final Logger log = Logger.getLogger(this.getClass());
|
||||
private final SecurityConfig securityConfig;
|
||||
private final static String TOKEN = "AccessToken";
|
||||
private final static String SESSION = "OpenAIRESession";
|
||||
|
||||
@Autowired
|
||||
AuthorizationUtils(SecurityConfig securityConfig) {
|
||||
this.securityConfig = securityConfig;
|
||||
}
|
||||
|
||||
private String getToken(HttpServletRequest request) {
|
||||
if (request.getCookies() == null) {
|
||||
return null;
|
||||
}
|
||||
for (Cookie c : request.getCookies()) {
|
||||
if (c.getName().equals(TOKEN)) {
|
||||
return c.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo(HttpServletRequest request) {
|
||||
String url = securityConfig.getUserInfoUrl() + (securityConfig.isDeprecated()?getToken(request):"");
|
||||
String url = securityConfig.getUserInfoUrl();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
try {
|
||||
if(hasCookie(request)) {
|
||||
ResponseEntity<UserInfo> response = restTemplate.exchange(url, HttpMethod.GET, createHeaders(request), UserInfo.class);
|
||||
return response.getBody();
|
||||
return response.getBody();
|
||||
}
|
||||
return null;
|
||||
} catch (RestClientException e) {
|
||||
log.error(url + ":" + e.getMessage());
|
||||
log.error(url + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -55,11 +41,7 @@ public class AuthorizationUtils {
|
|||
private boolean hasCookie(HttpServletRequest request) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if(cookies != null) {
|
||||
if (securityConfig.isDeprecated()) {
|
||||
return Arrays.stream(cookies).anyMatch(cookie -> cookie.getName().equalsIgnoreCase(TOKEN));
|
||||
} else {
|
||||
return Arrays.stream(cookies).anyMatch(cookie -> cookie.getName().equalsIgnoreCase(SESSION));
|
||||
}
|
||||
return Arrays.stream(cookies).anyMatch(cookie -> cookie.getName().equalsIgnoreCase(this.securityConfig.getSession()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#dev
|
||||
authorization.security.userInfoUrl = http://mpagasas.di.uoa.gr:8080/login-service/userInfo
|
||||
authorization.security.session=openAIRESession
|
||||
authorization.globalVars.buildDate=@timestampAuthorizationLibrary@
|
||||
authorization.globalVars.version=@project.version@
|
||||
|
|
Loading…
Reference in New Issue