Add health properties check method. Add remove admin role method. Add git info and maven spring-boot plugin in pom
This commit is contained in:
parent
d11ef469c6
commit
95d146228a
20
pom.xml
20
pom.xml
|
@ -15,6 +15,12 @@
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
<scm>
|
||||||
|
<url>https://code-repo.d4science.org/MaDgIK/dnet-role-management</url>
|
||||||
|
<connection>scm:git:gitea@code-repo.d4science.org:MaDgIK/dnet-role-management.git</connection>
|
||||||
|
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/dnet-role-management.git</developerConnection>
|
||||||
|
<tag>dnet-role-management-1.0.0</tag>
|
||||||
|
</scm>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -95,6 +101,20 @@
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>eu.dnetlib.dnetrolemanagement.DnetRoleManagementApplication</mainClass>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.6</version>
|
<version>2.6</version>
|
||||||
|
|
|
@ -1,17 +1,51 @@
|
||||||
package eu.dnetlib.dnetrolemanagement.controllers;
|
package eu.dnetlib.dnetrolemanagement.controllers;
|
||||||
|
|
||||||
|
import eu.dnetlib.dnetrolemanagement.config.properties.APIProperties;
|
||||||
|
import eu.dnetlib.dnetrolemanagement.config.properties.RedisProperties;
|
||||||
|
import eu.dnetlib.dnetrolemanagement.config.properties.RegistryProperties;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class HealthController {
|
public class HealthController {
|
||||||
private final Logger log = Logger.getLogger(this.getClass());
|
private final Logger log = Logger.getLogger(this.getClass());
|
||||||
|
private final APIProperties apiProperties;
|
||||||
|
private final RedisProperties redisProperties;
|
||||||
|
private final RegistryProperties registryProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public HealthController(APIProperties apiProperties, RedisProperties redisProperties, RegistryProperties registryProperties) {
|
||||||
|
this.apiProperties = apiProperties;
|
||||||
|
this.redisProperties = redisProperties;
|
||||||
|
this.registryProperties = registryProperties;
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
||||||
public String hello() {
|
public String hello() {
|
||||||
log.debug("Hello from role management!");
|
log.debug("Hello from role management!");
|
||||||
return "Hello from Role management!";
|
return "Hello from Role management!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority('PORTAL_ADMINISTRATOR')")
|
||||||
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
||||||
|
public Map<String, String> checkEverything() {
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
response.put("api.title", apiProperties.getTitle());
|
||||||
|
response.put("api.description", apiProperties.getDescription());
|
||||||
|
response.put("api.version", apiProperties.getVersion());
|
||||||
|
response.put("registry.coid", registryProperties.getCoid());
|
||||||
|
response.put("registry.issuer", registryProperties.getIssuer());
|
||||||
|
response.put("registry.user", registryProperties.getUser());
|
||||||
|
response.put("registry.password", registryProperties.getPassword());
|
||||||
|
response.put("registry.version", registryProperties.getVersion());
|
||||||
|
response.put("redis.host", redisProperties.getHost());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUpdater;
|
||||||
import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUtils;
|
import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
@ -70,4 +69,26 @@ public class SuperAdminController {
|
||||||
}
|
}
|
||||||
throw new ResourceNotFoundException("User has not been found");
|
throw new ResourceNotFoundException("User has not been found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove portal admin role from logged in user or user with @email
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/remove", method = RequestMethod.DELETE)
|
||||||
|
public ResponseEntity<Response> removeRole( @RequestParam(required = false) String email) {
|
||||||
|
List<Integer> coPersonIds = registryService.getCoPersonIdsByEmail(email);
|
||||||
|
if (coPersonIds.size() > 0) {
|
||||||
|
Integer couId = registryService.getCouId(AuthoritiesUtils.portalAdminRole());
|
||||||
|
if (couId != null) {
|
||||||
|
coPersonIds.forEach(coPersonId -> {
|
||||||
|
String identifier = registryService.getIdentifierByCoPersonId(coPersonId);
|
||||||
|
Integer role = registryService.getRoleId(coPersonId, couId);
|
||||||
|
registryService.removeMemberRole(coPersonId, couId, role);
|
||||||
|
authoritiesUpdater.removeRole(identifier, new SimpleGrantedAuthority(AuthoritiesUtils.portalAdminRole()));
|
||||||
|
});
|
||||||
|
return ResponseEntity.ok(new Response("Role has been revoked successfully"));
|
||||||
|
}
|
||||||
|
throw new ResourceNotFoundException("Role has not been found");
|
||||||
|
}
|
||||||
|
throw new ResourceNotFoundException("User has not been found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ import java.util.Map;
|
||||||
@Component
|
@Component
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(eu.dnetlib.dnetrolemanagement.utils.HttpUtils.class);
|
private static final Logger logger = Logger.getLogger(HttpUtils.class);
|
||||||
|
|
||||||
private RegistryProperties registryProperties;
|
private final RegistryProperties registryProperties;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public HttpUtils(RegistryProperties registryProperties) {
|
public HttpUtils(RegistryProperties registryProperties) {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
Loading…
Reference in New Issue