[Authorization Library]: Add dnet45 parert

master
parent 4dff8c29c3
commit 612cbeafea

@ -2,21 +2,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.dnetlib</groupId>
<parent>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet45-parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>uoa-authorization-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<scm>
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/uoa-authorization-library/trunk</developerConnection>
</scm>
<name>uoa-authorization-library</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -24,7 +22,17 @@
<timestampAuthorizationLibrary>${maven.build.timestamp}</timestampAuthorizationLibrary>
<maven.build.timestamp.format>E MMM dd HH:mm:ss z yyyy</maven.build.timestamp.format>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>

@ -4,10 +4,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.*;
@Configuration
//@PropertySources({
// @PropertySource("classpath:authorization.properties"),
// @PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
//})
@EnableConfigurationProperties({SecurityConfig.class, GlobalVars.class})
@ComponentScan(basePackages = { "eu.dnetlib.uoaauthorizationlibrary" })
public class AuthorizationConfiguration { }

@ -40,8 +40,8 @@ public class AuthorizationLibraryCheckDeployController {
response.put("authorization.security.userInfoUrl", securityConfig.getUserInfoUrl());
response.put("authorization.security.originServer", securityConfig.getOriginServer());
if(globalVars.date != null) {
response.put("Date of deploy", globalVars.date.toString());
if(GlobalVars.date != null) {
response.put("Date of deploy", GlobalVars.date.toString());
}
if(globalVars.getBuildDate() != null) {
response.put("Date of build", globalVars.getBuildDate());

@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component(value = "AuthorizationService")
public class AuthorizationService {
@ -53,19 +54,28 @@ public class AuthorizationService {
return mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
}
public boolean isPortalAdmin() {
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(PORTAL_ADMIN));
}
public boolean isCurator(String type) {
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(curator(type)));
}
public boolean isManager(String type, String id) {
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(manager(type, id)));
}
public boolean isMember(String type, String id) {
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(member(type, id)));
}
public List<String> getRoles() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
if (authorities != null) {
List<String> roles = new ArrayList<>();
authorities.forEach((authority) -> {
roles.add(authority.getAuthority());
});
return roles;
}
return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
}
return null;
return new ArrayList<>();
}
public String getAaiId() {

Loading…
Cancel
Save