[Admin Tools | Trunk]: Add get managers method. Delete no needed files.

This commit is contained in:
Konstantinos Triantafyllou 2021-02-25 19:00:05 +00:00
parent 6c452b5433
commit 6484343d2f
24 changed files with 254 additions and 714 deletions

11
pom.xml
View File

@ -80,12 +80,11 @@
<artifactId>uoa-admin-tools-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>eu.dnetlib</groupId>-->
<!-- <artifactId>uoa-authorization-library</artifactId>-->
<!-- <version>1.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-authorization-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

View File

@ -1,5 +1,7 @@
package eu.dnetlib.uoaadmintools;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig;
//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
//import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
@ -7,21 +9,32 @@ import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfigurati
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoaadmintools", "eu.dnetlib.uoaadmintoolslibrary"})
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoaadmintools", "eu.dnetlib.uoaadmintoolslibrary", "eu.dnetlib.uoanotificationservice"})
@PropertySources({
@PropertySource("classpath:admintools.properties"),
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
})
//SecurityConfig.class,
@EnableConfigurationProperties({MongoConfig.class})
@EnableConfigurationProperties({MongoConfig.class, ManagersApiConfig.class})
@Import(AuthorizationConfiguration.class)
public class UoaAdminToolsApplication {
public static void main(String[] args) {
SpringApplication.run(UoaAdminToolsApplication.class, args);
}
@Bean
RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(new ObjectMapper());
restTemplate.getMessageConverters().add(converter);
return restTemplate;
}
}

View File

@ -1,37 +0,0 @@
package eu.dnetlib.uoaadmintools;
//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
//import eu.dnetlib.uoaadmintools.handlers.AuthorizationHandler;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* Created by argirok on 23/2/2018.
*/
@Configuration
public class UoaAdminToolsConfiguration extends WebMvcConfigurerAdapter {
private final Logger log = Logger.getLogger(this.getClass());
// @Autowired
// private SecurityConfig securityConfig;
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// registry.addInterceptor(new AuthorizationHandler(securityConfig.getUserInfoUrl(), securityConfig.getOriginServer(), securityConfig.getPostsAllowed()))
// .addPathPatterns("/**");
//
// }
}

View File

@ -0,0 +1,26 @@
package eu.dnetlib.uoaadmintools.configuration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("admintool.managers.api")
public class ManagersApiConfig {
private String id;
private String email;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View File

@ -1,40 +0,0 @@
//package eu.dnetlib.uoaadmintools.configuration.properties;
//
//import org.springframework.boot.context.properties.ConfigurationProperties;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@ConfigurationProperties("admintool.security")
//public class SecurityConfig {
//
// private String userInfoUrl;
// private String originServer;
// private List<String> postsAllowed = new ArrayList<>();
//
// public void setUserInfoUrl(String userInfoUrl) {
// this.userInfoUrl = userInfoUrl;
// }
//
// public void setOriginServer(String originServer) {
// this.originServer = originServer;
// }
//
//
// public void setPostsAllowed(List<String> posts) {
// this.postsAllowed = posts;
// }
//
// public String getUserInfoUrl() {
// return userInfoUrl;
// }
//
// public String getOriginServer() {
// return originServer;
// }
//
// public List<String> getPostsAllowed() {
// return postsAllowed;
// }
//
//}

View File

@ -6,18 +6,17 @@ import eu.dnetlib.uoaadmintools.services.NotificationsService;
import eu.dnetlib.uoaadmintools.services.StatisticsService;
import eu.dnetlib.uoaadmintools.services.SubscriberService;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/community")
@ -26,7 +25,7 @@ public class CommunityController {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private RolesUtils rolesUtils;
private AuthorizationService authorizationService;
@Autowired
private LayoutService layoutService;
@ -96,7 +95,7 @@ public class CommunityController {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Boolean deleteCommunities(@RequestBody List<String> portals) {
List<String> roles = rolesUtils.getRoles();
List<String> roles = authorizationService.getRoles();
for (String id: portals) {
Portal portal = portalService.getPortalById(id);

View File

@ -1,18 +1,17 @@
package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.entities.Layout;
import eu.dnetlib.uoaadmintools.services.LayoutService;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
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.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
import java.util.List;
@RestController
@RequestMapping("/connect")
@ -29,16 +28,16 @@ public class ConnectController {
@RequestMapping(value = "/update", method = RequestMethod.POST)
public PortalResponse updateConnect(@RequestBody Portal portal) {
if(!portal.getType().equals("connect")) {
if (!portal.getType().equals("connect")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Update Connect: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of connect");
throw new MismatchingContentException("Update Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
}
PortalResponse portalResponse = portalService.updatePortal(portal);
String old_pid = portalResponse.getPid();
String new_pid = portal.getPid();
if(!old_pid.equals(new_pid)) {
if (!old_pid.equals(new_pid)) {
layoutService.updatePid(old_pid, new_pid);
}
@ -47,9 +46,9 @@ public class ConnectController {
@RequestMapping(value = "/save", method = RequestMethod.POST)
public PortalResponse insertConnect(@RequestBody Portal portal) {
if(!portal.getType().equals("connect")) {
if (!portal.getType().equals("connect")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Save Connect: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of connect");
throw new MismatchingContentException("Save Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
}
PortalResponse portalResponse = portalService.insertPortal(portal);
@ -58,15 +57,15 @@ public class ConnectController {
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Boolean deleteConnect(@RequestBody List<String> portals) {
for (String id: portals) {
for (String id : portals) {
Portal portal = portalService.getPortalById(id);
if(portal == null) {
if (portal == null) {
// EXCEPTION - Entity Not Found
throw new ContentNotFoundException("Delete connect: Portal with id: " + id + " not found");
}
if(!portal.getType().equals("connect")) {
if (!portal.getType().equals("connect")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Delete Connect: Portal with id: "+id+" has type: "+portal.getType()+" instead of connect");
throw new MismatchingContentException("Delete Connect: Portal with id: " + id + " has type: " + portal.getType() + " instead of connect");
}
String pid = portalService.deletePortal(id);

View File

@ -1,17 +1,15 @@
package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.dao.CuratorDAO;
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoaadmintools.services.CuratorService;
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@RestController
@CrossOrigin(origins = "*")
@ -19,34 +17,20 @@ public class CuratorController {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private CuratorDAO curatorDAO;
private CuratorService curatorService;
@Autowired
private RolesUtils rolesUtils;
private AuthorizationService authorizationService;
/**
* Return a list with curator. If list of emails does not existed return all curators, else return
* curators based on given list.
* Return a list with curator for a specific community
*
* @param emails
* @param pid
* @return
*/
@RequestMapping(value = "/curator", method = RequestMethod.GET)
public List<CuratorResponse> getCurators(@RequestParam(required = false) Optional<String> emails) {
List<CuratorResponse> curators = new ArrayList<>();
if(emails.isPresent()) {
for(String email: emails.get().split(",")) {
Curator curator = curatorDAO.findByEmail(email);
if(curator != null) {
curators.add(new CuratorResponse(curator));
}
}
} else {
for(Curator curator: curatorDAO.findAll()) {
curators.add(new CuratorResponse(curator));
}
}
return curators;
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET)
public List<CuratorResponse> getCurators(@PathVariable String pid) {
return curatorService.getCurators(pid);
}
/**
@ -58,7 +42,7 @@ public class CuratorController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/curator/{id}", method = RequestMethod.GET)
public Curator getCuratorById(@PathVariable String id) {
return curatorDAO.findById(id);
return curatorService.findById(id);
}
/**
@ -70,30 +54,21 @@ public class CuratorController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/curator", method = RequestMethod.POST)
public Curator insertCurator(@RequestBody Curator curator) {
String aaiId = rolesUtils.getAaiId();
curator.setId(aaiId);
return curatorDAO.save(curator);
String aaiId = authorizationService.getAaiId();
curator.setId(aaiId.substring(0, aaiId.indexOf("@")));
return curatorService.save(curator);
}
/**
* Delete all curators if list of emails does not exist or curators based on given list.
* Delete all curators for a spedific community.
*
* @param emails
* @param pid
*/
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/curator", method = RequestMethod.DELETE)
public void deleteCurators(@RequestBody(required = false) Optional<List<String>> emails) {
if(emails.isPresent()) {
for(String email: emails.get()) {
Curator curator = curatorDAO.findByEmail(email);
if(curator != null) {
curatorDAO.delete(curator.getId());
}
}
} else {
curatorDAO.deleteAll();
}
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE)
public void deleteCurators(@PathVariable String pid) {
curatorService.deleteCurators(pid);
}
}

View File

@ -2,11 +2,11 @@ package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
import eu.dnetlib.uoaadmintools.entities.Notifications;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email;
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha;
import org.apache.log4j.Logger;

View File

@ -1,16 +1,16 @@
package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
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.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
import java.util.List;
@RestController
@RequestMapping("/explore")

View File

@ -2,10 +2,9 @@ package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
import eu.dnetlib.uoaadmintools.entities.Notifications;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import org.apache.log4j.Logger;

View File

@ -1,21 +1,13 @@
package eu.dnetlib.uoaadmintools.controllers;
//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO;
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
import eu.dnetlib.uoaadmintools.entities.subscriber.Subscriber;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
//import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils;
//import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo;
import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse;
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**

View File

@ -0,0 +1,44 @@
package eu.dnetlib.uoaadmintools.entities;
public class Manager {
private String id;
private String email;
private String name;
private String memberSince;
public Manager() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMemberSince() {
return memberSince;
}
public void setMemberSince(String memberSince) {
this.memberSince = memberSince;
}
}

View File

@ -0,0 +1,18 @@
package eu.dnetlib.uoaadmintools.entities.curator;
import eu.dnetlib.uoaadmintools.entities.Manager;
public class Response {
private Manager[] response;
public Response() {
}
public Manager[] getResponse() {
return response;
}
public void setResponse(Manager[] response) {
this.response = response;
}
}

View File

@ -1,71 +0,0 @@
//package eu.dnetlib.uoaadmintools.handlers;
//
//import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils;
//import org.apache.log4j.Logger;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.List;
//
///**
// * Created by argirok on 23/2/2018.
// */
//public class AuthorizationHandler extends HandlerInterceptorAdapter {
// private final Logger log = Logger.getLogger(this.getClass());
// private AuthorizationUtils helper = new AuthorizationUtils();
// private List<String> allowedPostRequests;
//
// public AuthorizationHandler(String userInfoUrl, String originServer, List<String> allowedPostRequests){
// helper.setOriginServer(originServer);
// helper.setUserInfoUrl(userInfoUrl);
// this.allowedPostRequests = allowedPostRequests;
// }
// @Override
// public boolean preHandle(
// HttpServletRequest request,
// HttpServletResponse response,
// Object handler) throws Exception {
//// log.debug("request method " + request.getRemoteHost());
//// log.debug("properties: " + helper.getOriginServer() + " "+ helper.getUserInfoUrl());
//// log.debug(allowedPostRequests);
//// log.debug(allowedPostRequests.contains(request.getServletPath()));
//// log.debug(request.getServletPath());
// if((request.getMethod().equals("POST") || request.getMethod().equals("DELETE")) &&
// !allowedPostRequests.contains(request.getServletPath())) {
// //TODO check domain & check user info
// if(!this.helper.checkCookies(request) || !helper.isAuthorized(helper.getToken(request))){
//
// response.setHeader("Access-Control-Allow-Credentials","true");
// response.setHeader("Access-Control-Allow-Origin","*");
// response.setHeader("Vary","Origin");
//
// response.setStatus(403);
// response.sendError(403, "Forbidden: You don't have permission to access. Maybe you are not registered.");
// return false;
// }
//
// }
// return true;
// }
//
//
//// @Override
//// public void postHandle(
//// HttpServletRequest request,
//// HttpServletResponse response,
//// Object handler,
//// ModelAndView modelAndView) throws Exception {
//// log.info("I am here - postHandle ");
//// }
////
//// @Override
//// public void afterCompletion(
//// HttpServletRequest request,
//// HttpServletResponse response,
//// Object handler, Exception ex) {
//// log.info("I am here - afterCompletion ");
//// }
//
//}

View File

@ -1,15 +0,0 @@
package eu.dnetlib.uoaadmintools.handlers;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* Created by argirok on 6/3/2018.
*/
@ResponseStatus(HttpStatus.NO_CONTENT)
public class CommunityNotFoundException extends RuntimeException {
public CommunityNotFoundException(String message){
super(message);
}
}

View File

@ -1,17 +0,0 @@
package eu.dnetlib.uoaadmintools.handlers;
import java.util.Date;
public class ErrorDetails {
private Date timestamp;
private String message;
private String details;
public ErrorDetails(Date timestamp, String message, String details) {
super();
this.timestamp = timestamp;
this.message = message;
this.details = details;
}
}

View File

@ -1,54 +0,0 @@
package eu.dnetlib.uoaadmintools.handlers;
import eu.dnetlib.uoaadmintoolslibrary.responses.ExceptionResponse;
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class ExceptionsHandler {
private final Logger log = Logger.getLogger(this.getClass());
// @ExceptionHandler(MissingServletRequestParameterException.class)
// public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
// ExceptionResponse response = new ExceptionResponse();
// response.setErrorCode("Validation Error");
// response.setErrorMessage("Invalid inputs.");
// response.setErrors(ex.getMessage());
// log.debug("invalidInput exception");
//
// return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
// }
// @ExceptionHandler(ContentNotFoundException2.class)
// public ResponseEntity<ExceptionResponse> contentNotFound(Exception ex) {
// ExceptionResponse response = new ExceptionResponse();
// response.setErrorCode("No content found");
// response.setErrorMessage(ex.getMessage());
// response.setErrors(ex.getMessage());
// log.debug("contentNotFound exception" + response.getErrorCode()+ " "+response.getErrorMessage());
// return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
// }
// @ExceptionHandler(NullPointerException.class)
// public ResponseEntity<ExceptionResponse> nullPointerException(Exception ex) {
// ExceptionResponse response = new ExceptionResponse();
// response.setErrorCode("Null pointer Exception");
// response.setErrorMessage("Null pointer Exception");
// response.setErrors(ex.getMessage());
// log.debug("nullPointerException exception");
// return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
// }
// @ExceptionHandler(InvalidReCaptchaException.class)
// public ResponseEntity<ExceptionResponse> invalidReCaptchaException(Exception ex) {
// ExceptionResponse response = new ExceptionResponse();
// response.setErrorCode("Invalid ReCaptcha Exception");
// response.setErrorMessage("Invalid ReCaptcha Exception");
// response.setErrors(ex.getMessage());
// log.debug("invalidReCaptchaException exception");
// return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
// }
}

View File

@ -1,253 +0,0 @@
//package eu.dnetlib.uoaadmintools.handlers.utils;
//
//import org.apache.log4j.Logger;
//
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServletRequest;
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.io.StringReader;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.util.Enumeration;
//
//import com.google.gson.Gson;
//
///**
// * Created by argirok on 27/2/2018.
// */
//public class AuthorizationUtils {
// private final Logger log = Logger.getLogger(this.getClass());
// private String userInfoUrl = null;
//// private String communityAPI ="";
//// List<String> adminRoles = new ArrayList<String>(Arrays.asList("Super Administrator", "Portal Administrator"));
// private String originServer= null;
// public Boolean checkCookies(HttpServletRequest request){
// Boolean valid = true;
// String cookieValue = this.getCookie(request,"AccessToken");
// if(cookieValue == null || cookieValue.isEmpty()){
// log.info("no cookie available ");
// valid = false;
// }else {
// String headerValue = this.getHeadersInfo(request, "x-xsrf-token");
// if(headerValue == null || headerValue.isEmpty()){
// log.info("no header available ");
// valid = false;
// }else{
// if(!cookieValue.equals(headerValue)){
// log.info("no proper header or cookie ");
// valid = false;
// }else if(!hasValidOrigin(this.getHeadersInfo(request, "origin"))){
// log.info("no proper origin ");
// valid = false;
// }
// }
// }
// return valid;
// }
// public String getToken(HttpServletRequest request){
// return this.getHeadersInfo(request, "x-xsrf-token");
// }
// private String getCookie(HttpServletRequest request, String cookieName){
// if(request.getCookies() == null){
// return null;
// }
// for(Cookie c: request.getCookies()){
//// log.debug("cookie "+ c.getName()+ " "+ c.getValue());
// if(c.getName().equals(cookieName)){
// return c.getValue();
// }
//
// }
// return null;
// }
// private String getHeadersInfo(HttpServletRequest request, String name) {
//
// Enumeration headerNames = request.getHeaderNames();
// while (headerNames.hasMoreElements()) {
// String key = (String) headerNames.nextElement();
// String value = request.getHeader(key);
//// log.debug(" key: "+ key+" value: "+ value);
// if(name.equals(key)){
// return value;
// }
// }
// return null;
// }
// public boolean hasValidOrigin(String origin) {
// if (origin != null && origin.indexOf(originServer)!=-1) {
// return true;
// }
// log.debug("Not valid origin. Origin server is \"" + origin + "\", but expected value is \"" + originServer + "\". If the expec cted value is not right, check properties file. ");
// return false;
// }
// public UserInfo getUserInfo(String accessToken){
// String url=userInfoUrl+accessToken;
// URL obj = null;
// String responseStr=null;
//// log.debug("User info url is "+url);
//
// try {
// obj = new URL(url);
// HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// if (con.getResponseCode() != 200) {
// log.debug("User info response code is: " + con.getResponseCode());
// return null;
// }
// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
// StringBuffer response = new StringBuffer();
// String inputLine;
// while ((inputLine = in.readLine()) != null) {
// response.append(inputLine).append("\n");
// }
// in.close();
// responseStr = response.toString();
// }catch(Exception e){
// log.error("An error occured while trying to fetch user info ",e);
// return null;
// }
// return json2UserInfo(responseStr);
// }
// private UserInfo json2UserInfo(String json) {
//
//// log.debug("Try to create userInfo class from json: "+json);
// if (json == null){
// return null;
// }
//
// BufferedReader br = new BufferedReader(new StringReader(json));
// //convert the json string back to object
// Gson gson = new Gson();
// UserInfo userInfo = null;
// try {
// userInfo = gson.fromJson(br, UserInfo.class);
// }catch(Exception e){
// log.debug("Error in parsing json response. Given json is : "+json, e);
// return null;
// }
//
//// log.debug("Original response.........: "+userInfo.toString());
// try {
// if(userInfo != null && userInfo.getEdu_person_entitlements() != null ) {
//
// for (int i = 0; i < userInfo.getEdu_person_entitlements().size(); i++) {
// String role = userInfo.getEdu_person_entitlements().get(i);
//// log.debug("AAI role: "+role);
// role = role.split(":")[role.split(":").length-1];
// role = role.replace("+"," ");
//// log.debug("Adding parsed role : "+role);
// userInfo.getEdu_person_entitlements().set(i,role);
// }
// }
// }catch(Exception e){
// log.debug("Error in parsing Edu_person_entitlements : ",e);
// return null;
// }
//// log.debug("After handling roles : "+userInfo.toString());
//
//
// return userInfo;
// }
// public boolean isAuthorized(String token) {
// UserInfo userInfo = getUserInfo(token);
// if (userInfo != null ) {
// return true;
// } else {
// log.debug(" User has no Valid UserInfo");
// return false;
// }
//
// }
//
// public String getUserInfoUrl() {
// return userInfoUrl;
// }
//
// public String getOriginServer() {
// return originServer;
// }
//
// public void setUserInfoUrl(String userInfoUrl) {
// this.userInfoUrl = userInfoUrl;
// }
//
// public void setOriginServer(String originServer) {
// this.originServer = originServer;
// }
// // private boolean hasRole(List<String> givenRoles, List<String> authorizedRoles) {
//// log.debug("It's registered with role " + givenRoles);
//// for (String gRole : givenRoles) {
//// if (authorizedRoles.indexOf(gRole) != -1) {
//// return true;
//// }
//// }
//// log.debug("Not Authorized. Authorized roles are" + authorizedRoles);
//// return false;
////
//// }
//// private boolean isCommunityManager(String community, String email) {
////
//// CommunityInfo communityInfo = getCommunityInfo(community);
//// if(communityInfo != null && communityInfo.getManagers() != null ) {
////
//// for (int i = 0; i < communityInfo.getManagers().size(); i++) {
//// String manager = communityInfo.getManagers().get(i);
//// log.debug("Community manager: "+manager);
////
//// }
//// }
//// return false;
////
//// }
//// private CommunityInfo getCommunityInfo(String community) {
//// String url = userInfoUrl + community;
//// URL obj = null;
//// String responseStr = null;
//// log.debug("Community info url is " + url);
////
//// try {
//// obj = new URL(url);
//// HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//// log.debug("User info response code is: " + con.getResponseCode());
//// if (con.getResponseCode() != 200) {
//// return null;
//// }
//// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
//// StringBuffer response = new StringBuffer();
//// String inputLine;
//// while ((inputLine = in.readLine()) != null) {
//// response.append(inputLine).append("\n");
//// }
//// in.close();
//// responseStr = response.toString();
//// } catch (Exception e) {
//// log.error("An error occured while trying to fetch user info ", e);
//// return null;
//// }
//// return json2CommunityInfo(community);
//// }
//// private CommunityInfo json2CommunityInfo(String json){
////
//// log.debug("Try to create CommunityInfo class from json: "+json);
//// if (json == null){
//// return null;
//// }
////
//// BufferedReader br = new BufferedReader(new StringReader(json));
//// //convert the json string back to object
//// Gson gson = new Gson();
//// CommunityInfo communityInfo = null;
//// try {
//// communityInfo = gson.fromJson(br, CommunityInfo.class);
//// }catch(Exception e){
//// log.debug("Error in parsing json response. Given json is : "+json, e);
//// return null;
//// }
////
//// log.debug("Original response.........: "+communityInfo.toString());
////
////
////
//// return communityInfo;
//// }
//}

View File

@ -1,81 +0,0 @@
//package eu.dnetlib.uoaadmintools.handlers.utils;
//
//import com.google.gson.Gson;
//import org.apache.log4j.Logger;
//
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.io.StringReader;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by argirok on 27/2/2018.
// */
//public class CommunityInfo {
//
// List<String> managers = new ArrayList<String>();
// private final Logger log = Logger.getLogger(this.getClass());
//
// public List<String> getManagers() {
// return managers;
// }
//
// public void setManagers(List<String> managers) {
// this.managers = managers;
// }
//
// private CommunityInfo getCommunityInfo(String communityAPI, String community) {
// String url = communityAPI + community;
// URL obj = null;
// String responseStr = null;
// log.debug("Community info url is " + url);
//
// try {
// obj = new URL(url);
// HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// log.debug("User info response code is: " + con.getResponseCode());
// if (con.getResponseCode() != 200) {
// return null;
// }
// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
// StringBuffer response = new StringBuffer();
// String inputLine;
// while ((inputLine = in.readLine()) != null) {
// response.append(inputLine).append("\n");
// }
// in.close();
// responseStr = response.toString();
// } catch (Exception e) {
// log.error("An error occured while trying to fetch user info ", e);
// return null;
// }
// return json2CommunityInfo(community);
// }
// private CommunityInfo json2CommunityInfo(String json){
//
// log.debug("Try to create CommunityInfo class from json: "+json);
// if (json == null){
// return null;
// }
//
// BufferedReader br = new BufferedReader(new StringReader(json));
// //convert the json string back to object
// Gson gson = new Gson();
// CommunityInfo communityInfo = null;
// try {
// communityInfo = gson.fromJson(br, CommunityInfo.class);
// }catch(Exception e){
// log.debug("Error in parsing json response. Given json is : "+json, e);
// return null;
// }
//
// log.debug("Original response.........: "+communityInfo.toString());
//
//
//
// return communityInfo;
// }
//}

View File

@ -1,46 +0,0 @@
//package eu.dnetlib.uoaadmintools.handlers.utils;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by argirok on 23/6/2017.
// */
//public class UserInfo {
// String name;
// String email;
// List<String> edu_person_entitlements = new ArrayList<String>();
//
// @Override
// public String toString() {
// return "UserInfo{" +
// "name='" + name + '\'' +
// ", email='" + email + '\'' +
// ", edu_person_entitlements=" + edu_person_entitlements +
// '}';
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public List<String> getEdu_person_entitlements() {
// return edu_person_entitlements;
// }
//
// public void setEdu_person_entitlements(List<String> edu_person_entitlements) {
// this.edu_person_entitlements = edu_person_entitlements;
// }
//}

View File

@ -0,0 +1,57 @@
package eu.dnetlib.uoaadmintools.services;
import eu.dnetlib.uoaadmintools.dao.CuratorDAO;
import eu.dnetlib.uoaadmintools.entities.Manager;
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class CuratorService {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private CuratorDAO curatorDAO;
@Autowired
private ManagerService managerService;
public List<CuratorResponse> getCurators(String pid) {
List<CuratorResponse> curators = new ArrayList<>();
for (Manager manager : managerService.getManagers(pid)) {
log.info(manager.getEmail());
Curator curator = curatorDAO.findByEmail(manager.getEmail());
if (curator != null) {
curators.add(new CuratorResponse(curator));
}
}
return curators;
}
public Curator findById(String id) {
return curatorDAO.findById(id);
}
public Curator save(Curator curator) {
return curatorDAO.save(curator);
}
public void deleteCurators(String pid) {
for (Manager manager : managerService.getManagers(pid)) {
Curator curator = curatorDAO.findByEmail(manager.getEmail());
if (curator != null) {
curatorDAO.delete(curator.getId());
}
}
}
}

View File

@ -0,0 +1,31 @@
package eu.dnetlib.uoaadmintools.services;
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
import eu.dnetlib.uoaadmintools.entities.Manager;
import eu.dnetlib.uoaadmintools.entities.curator.Response;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class ManagerService {
@Autowired
private ManagersApiConfig config;
@Autowired
private RestTemplate restTemplate;
public Manager[] getManagers(String pid) {
ResponseEntity<Response> responseEntity = restTemplate.getForEntity(config.getEmail().replace("{community}", pid), Response.class);
Response response = responseEntity.getBody();
if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) {
return response.getResponse();
} else {
throw new ContentNotFoundException("No managers has been found for community " + pid);
}
}
}

View File

@ -2,16 +2,18 @@
#admintool.security.userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
#admintool.security.originServer = .di.uoa.gr
#admintool.security.postsAllowed = /contact,/contact/
#admintool.mail.host = smtp.gmail.com
#admintool.mail.port = 587
#admintool.mail.auth = true
#admintool.mail.from = openaire.test@gmail.com
#admintool.mail.username = openaire.test@gmail.com
#admintool.mail.password =
#admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
#admintool.mongodb.host=localhost
#admintool.mongodb.port=27017
#admintool.mongodb.database=openaire_admin_beta_20191105
admintool.mail.host = smtp.gmail.com
admintool.mail.port = 587
admintool.mail.auth = true
admintool.mail.from = openaire.test@gmail.com
admintool.mail.username = openaire.test@gmail.com
admintool.mail.password =
admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
admintool.mongodb.host=localhost
admintool.mongodb.port=27017
admintool.mongodb.database=openaire_admin
admintool.managers.api.id = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/id
admintool.managers.api.email = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/email
#beta
#admintool.security.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=