Merge branch 'master' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot

This commit is contained in:
annampak 2017-10-13 11:15:47 +03:00
commit df1158a757
20 changed files with 584 additions and 220 deletions

View File

@ -0,0 +1,14 @@
package dao.entities.security;
import java.util.UUID;
import dao.Dao;
import entities.security.UserAuth;
public interface UserAuthDao extends Dao<UserAuth, UUID> {
public String getPasswordHashOfUser(String username);
}

View File

@ -0,0 +1,30 @@
package dao.entities.security;
import java.util.UUID;
import javax.persistence.TypedQuery;
import dao.JpaDao;
import entities.security.UserAuth;
public class UserAuthDaoImpl extends JpaDao<UserAuth, UUID> implements UserAuthDao {
@Override
public UserAuth loadDetails(UserAuth t) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getPasswordHashOfUser(String username) {
String queryString = "SELECT userAuth.password FROM UserAuth userAuth where userAuth.username = :username";
TypedQuery<String> typedQuery = entityManager.createQuery(queryString, String.class);
typedQuery.setParameter("username", username);
return typedQuery.getSingleResult();
}
}

View File

@ -0,0 +1,57 @@
package entities.security;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="\"UserAuth\"")
public class UserAuth {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "username", nullable = false)
private String username;
@Column(name = "password", nullable = false)
private String password; //hash-encoded password
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@ -1,13 +1,19 @@
package entities.security;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -29,106 +35,97 @@ public class UserInfo implements Serializable{
@Column(name = "autoid", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID autoid;
//required
@Column(name = "id")
String id = null;
@Column(name = "email")
String email = null;
//non required
@Column(name = "\"emailIsVerified\"", nullable = true)
Boolean emailIsVerified = null;
@Column(name = "identification", nullable = false)
private String identification = null;
@Column(name = "email", nullable = false)
private String email = null;
@Column(name = "authorization_level", nullable = false)
private Short authorization_level; //0 admin, 1 user
@Column(name = "usertype", nullable = false)
private Short usertype; // 0 internal, 1 external
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "authentication", nullable = true)
private UserAuth authentication;
@Column(name = "verified_email", nullable = true)
private Boolean verified_email = null;
@Column(name = "name", nullable = true)
String name = null;
@Column(name = "\"pictureUrl\"", nullable = true)
String pictureUrl = null;
@Column(name = "locale", nullable = true)
String locale = null;
@Column(name = "\"familyName\"", nullable = true)
String familyName = null;
@Column(name = "\"givenName\"", nullable = true)
String givenName = null;
private String name = null;
@Column(name = "created", nullable = false)
private Date created = null;
@Column(name = "lastloggedin", nullable = true)
private Date lastloggedin = null;
@Type(type="typedefinition.XMLType")
@Column(name = "additionalinfo", columnDefinition = "xml", nullable = true)
private String additionalinfo;
public UserInfo () {}
public UserInfo(String id, String email, Boolean emailIsVerified, String name, String pictureUrl, String locale, String familyName, String givenName, String additionalinfo) {
this.id = id;
this.email = email;
this.emailIsVerified = emailIsVerified;
this.name = name;
this.pictureUrl = pictureUrl;
this.locale = locale;
this.familyName = familyName;
this.givenName = givenName;
this.additionalinfo = additionalinfo;
public String getIdentification() {
return identification;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
public void setIdentification(String identification) {
this.identification = identification;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isEmailIsVerified() {
return emailIsVerified;
public Short getAuthorization_level() {
return authorization_level;
}
public void setEmailIsVerified(boolean emailIsVerified) {
this.emailIsVerified = emailIsVerified;
public void setAuthorization_level(Short authorization_level) {
this.authorization_level = authorization_level;
}
public Short getUsertype() {
return usertype;
}
public void setUsertype(Short usertype) {
this.usertype = usertype;
}
public UserAuth getAuthentication() {
return authentication;
}
public void setAuthentication(UserAuth authentication) {
this.authentication = authentication;
}
public Boolean getVerified_email() {
return verified_email;
}
public void setVerified_email(Boolean verified_email) {
this.verified_email = verified_email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPictureUrl() {
return pictureUrl;
}
public void setPictureUrl(String pictureUrl) {
this.pictureUrl = pictureUrl;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public String getFamilyName() {
return familyName;
}
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
public String getGivenName() {
return givenName;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
}
public Boolean getEmailIsVerified() {
return emailIsVerified;
}
public void setEmailIsVerified(Boolean emailIsVerified) {
this.emailIsVerified = emailIsVerified;
}
public String getAdditionalinfo() {
return additionalinfo;
@ -138,14 +135,6 @@ public class UserInfo implements Serializable{
this.additionalinfo = additionalinfo;
}
@Override
public String toString() {
return "UserInfo [id=" + id + ", email=" + email + ", emailIsVerified=" + emailIsVerified
+ ", name=" + name + ", pictureUrl=" + pictureUrl + ", locale=" + locale + ", familyName=" + familyName
+ ", givenName=" + givenName + ", additionalinfo=" + additionalinfo + "]";
}
}

View File

@ -1,4 +1,4 @@
package rest;
package rest.entities;
import java.io.Console;
import java.util.List;

View File

@ -1,4 +1,4 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;

View File

@ -1,4 +1,4 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;

View File

@ -1,7 +1,10 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -66,7 +69,7 @@ public class DmpProfiles {
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// MANAGE DMPPROFILE(S)
@ -109,31 +112,57 @@ public class DmpProfiles {
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/set" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpProfile) {
String reason = "";
DMPProfile storedDMPProfile = null;
//try first to create
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
try {
storedDMPProfile = dMPProfileDao.create(dmpProfile);
return ResponseEntity.status(HttpStatus.CREATED).body("Created dmpProfile with id: " + storedDMPProfile.getId());
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> dmpprofileStrL = allDmpProfiles.parallelStream().map((dmpProfileObj) -> {
try {
return objectMapper.writeValueAsString(dmpProfileObj);
} catch (JsonProcessingException e) {
return "";
}
catch(Exception e) {
reason += e.getMessage();
//try updating
try {
storedDMPProfile = dMPProfileDao.update(dmpProfile);
return ResponseEntity.status(HttpStatus.CREATED).body("Updated dmpProfile with id: " + storedDMPProfile.getId());
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", dmpprofileStrL)+"]", HttpStatus.OK);
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update dmpProfile! Reason: " + reason);
}
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpprofile) {
DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDMPProfile));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMPProfile dmpprofile) {
DMPProfile dmpp = new DMPProfile();
dmpp.setId(dmpprofile.getId());
try {
dMPProfileDao.delete(dmpp);
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\"");
}
}
}

View File

@ -1,7 +1,10 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -65,9 +68,12 @@ public class Organisations {
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// MANAGE ORGANISATIONS(S)
@RequestMapping(method = RequestMethod.GET, value = { "/organizations" })
@RequestMapping(method = RequestMethod.GET, value = { "/organisations" })
public @ResponseBody ResponseEntity<Object> listOrganisations(){
try {
List<UUID> allIDs = organisationDao.listAllIDs();
@ -79,7 +85,7 @@ public class Organisations {
}
@RequestMapping(method = RequestMethod.GET, value = { "/organizations/{id}" })
@RequestMapping(method = RequestMethod.GET, value = { "/organisations/{id}" })
public @ResponseBody ResponseEntity<Object> getOrganisations(@PathVariable("id") String id) {
try {
Organisation organisation = organisationDao.read(UUID.fromString(id));
@ -91,27 +97,53 @@ public class Organisations {
}
@RequestMapping(method = RequestMethod.POST, value = { "/setOrganisation" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) {
String reason = "";
Organisation storedOrganisation = null;
//try first to create
@RequestMapping(method = RequestMethod.GET, value = { "/organisation/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllOrganisations(){
try {
storedOrganisation = organisationDao.create(organisation);
return ResponseEntity.status(HttpStatus.CREATED).body("Created organisation with id: " + storedOrganisation.getId());
List<Organisation> allOrganisations = organisationDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> organisationStrL = allOrganisations.parallelStream().map((organisationObj) -> {
try {
return objectMapper.writeValueAsString(organisationObj);
} catch (JsonProcessingException e) {
return "";
}
catch(Exception e) {
reason += e.getMessage();
//try updating
try {
storedOrganisation = organisationDao.update(organisation);
return ResponseEntity.status(HttpStatus.CREATED).body("Updated organisation with id: " + storedOrganisation.getId());
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", organisationStrL)+"]", HttpStatus.OK);
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update organisation! Reason: " + reason);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/organisation/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) {
Organisation createdOrganisation = organisationDao.update(organisation);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdOrganisation));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create organisation!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/organisation/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Organisation organisation) {
Organisation org = new Organisation();
org.setId(organisation.getId());
try {
organisationDao.delete(org);
return ResponseEntity.status(HttpStatus.OK).body("DELETED!");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete organisation!\"");
}
}

View File

@ -1,7 +1,10 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -67,6 +70,7 @@ public class Projects {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// MANAGE PROJECT(S)
@ -105,27 +109,53 @@ public class Projects {
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/set" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> setProject(@RequestBody Project project) {
String reason = "";
Project storedProject = null;
//try first to create
@RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllProjects(){
try {
storedProject = projectDao.create(project);
return ResponseEntity.status(HttpStatus.CREATED).body("Created project with id: " + storedProject.getId());
List<Project> allProjects = projectDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> projectStrL = allProjects.parallelStream().map((projectObj) -> {
try {
return objectMapper.writeValueAsString(projectObj);
} catch (JsonProcessingException e) {
return "";
}
catch(Exception e) {
reason += e.getMessage();
//try updating
try {
storedProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body("Updated project with id: " + storedProject.getId());
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", projectStrL)+"]", HttpStatus.OK);
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update project! Reason: " + reason);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setProject(@RequestBody Project project) {
Project createdProject = projectDao.update(project);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdProject));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Project project) {
Project p = new Project();
p.setId(project.getId());
try {
projectDao.delete(p);
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Project!\"");
}
}

View File

@ -1,13 +1,15 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
@ -44,6 +46,7 @@ import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.responses.IDLabelPair;
import helpers.Transformers;
import responses.RestResponse;
@ -66,6 +69,7 @@ public class Registries {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// MANAGE REGISTRY(IES)
@ -93,28 +97,69 @@ public class Registries {
}
@RequestMapping(method = RequestMethod.POST, value = { "/setRegistry" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
String reason = "";
Registry storedRegistry = null;
//try first to create
@RequestMapping(method = RequestMethod.GET, value = { "/registries/listAllLabelIDs" })
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
storedRegistry = registryDao.create(registry);
return ResponseEntity.status(HttpStatus.CREATED).body("Created registry with id: " + storedRegistry.getId());
}
catch(Exception e) {
reason += e.getMessage();
//try updating
try {
storedRegistry = registryDao.update(registry);
return ResponseEntity.status(HttpStatus.CREATED).body("Updated registry with id: " + storedRegistry.getId());
List<IDLabelPair> allIDs = registryDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update registry! Reason: " + reason);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllRegistries(){
try {
List<Registry> allRegistries = registryDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> registryStrL = allRegistries.parallelStream().map((registryObj) -> {
try {
return objectMapper.writeValueAsString(registryObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", registryStrL)+"]", HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/registry/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
Registry createdRegistry = registryDao.update(registry);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdRegistry));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/registry/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Registry registry) {
Registry r = new Registry();
r.setId(registry.getId());
try {
registryDao.delete(r);
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\"");
}
}

View File

@ -1,4 +1,4 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;

View File

@ -1,7 +1,10 @@
package rest;
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -66,6 +69,7 @@ public class Services {
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// MANAGE SERVICE(S)
@ -73,7 +77,7 @@ public class Services {
public @ResponseBody ResponseEntity<Object> listServices(){
try {
List<UUID> allIDs = serviceDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -85,7 +89,7 @@ public class Services {
public @ResponseBody ResponseEntity<Object> getServices(@PathVariable("id") String id) {
try {
Service service = serviceDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(service));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(service));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -93,28 +97,58 @@ public class Services {
}
@RequestMapping(method = RequestMethod.POST, value = { "/setService" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> setService(@RequestBody Service service) {
String reason = "";
Service storedService = null;
//try first to create
@RequestMapping(method = RequestMethod.GET, value = { "/service/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllServices(){
try {
storedService = serviceDao.create(service);
return ResponseEntity.status(HttpStatus.CREATED).body("Created service with id: " + storedService.getId());
List<Service> allServices = serviceDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> serviceStrL = allServices.parallelStream().map((serviceObj) -> {
try {
return objectMapper.writeValueAsString(serviceObj);
} catch (JsonProcessingException e) {
return "";
}
catch(Exception e) {
reason += e.getMessage();
//try updating
try {
storedService = serviceDao.update(service);
return ResponseEntity.status(HttpStatus.CREATED).body("Updated service with id: " + storedService.getId());
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", serviceStrL)+"]", HttpStatus.OK);
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update service! Reason: " + reason);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/service/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setService(@RequestBody Service service) {
Service createdService = serviceDao.update(service);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdService));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/service/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Service service) {
Service s = new Service();
s.setId(service.getId());
try {
serviceDao.delete(s);
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Service entity!\"");
}
}
}

View File

@ -0,0 +1,70 @@
package rest.login;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DataRepositoryDao;
import dao.entities.security.UserAuthDao;
import dao.entities.security.UserInfoDao;
@RestController
@CrossOrigin
public class Login {
@Autowired private UserInfoDao userInfoDao;
@Autowired private UserAuthDao userAuthDao;
private ObjectMapper objectMapper = new ObjectMapper();
@RequestMapping(method = RequestMethod.POST, value = { "/nativeLogin" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<String> nativeLogin(@RequestBody Credentials credentials) {
System.out.println(userAuthDao.getPasswordHashOfUser("admin"));
return ResponseEntity.status(HttpStatus.OK).body("OUR-GENERATED-TOKEN");
}
}
class Credentials implements Serializable{
private static final long serialVersionUID = 3519634756673886633L;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@ -1,4 +1,4 @@
package rest;
package rest.proxy;
import java.io.BufferedReader;
import java.io.IOException;

View File

@ -15,22 +15,29 @@ import org.springframework.web.filter.GenericFilterBean;
public class TokenAuthenticationFilter extends GenericFilterBean {
private static final String HEADER_TOKEN_FIELD = "oauth2-token";
private static final String HEADER_NATIVE_TOKEN_FIELD = "native-token";
private static final String HEADER_GOOGLE_TOKEN_FIELD = "google-token";
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
String accessToken = httpRequest.getHeader(HEADER_TOKEN_FIELD);
if(accessToken==null) accessToken = "";
String nativeToken = httpRequest.getHeader(HEADER_NATIVE_TOKEN_FIELD);
String googleToken = httpRequest.getHeader(HEADER_GOOGLE_TOKEN_FIELD);
//just pass the token into the credentials object of the UsernamePasswordAuthenticationToken class
final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("google-user", accessToken);
UsernamePasswordAuthenticationToken authentication = null;
if(nativeToken != null)
authentication = new UsernamePasswordAuthenticationToken("native-user", nativeToken);
if(googleToken != null)
authentication = new UsernamePasswordAuthenticationToken("google-user", nativeToken);
if(authentication != null) {
SecurityContextHolder.getContext().setAuthentication(authentication);
/*
*/
chain.doFilter(request, response);
}
}
}

View File

@ -1,4 +1,4 @@
package security;
package security.validators;
import java.io.IOException;
import java.security.GeneralSecurityException;
@ -54,13 +54,13 @@ public class GoogleTokenValidator {
if (idToken != null) {
Payload payload = idToken.getPayload();
UserInfo userInfo = new UserInfo(payload.getSubject(), payload.getEmail(),
payload.getEmailVerified(), (String)payload.get("name"), (String)payload.get("picture"),
(String)payload.get("locale"), (String)payload.get("family_name"), (String)payload.get("given_name"), "");
// UserInfo userInfo = new UserInfo(payload.getSubject(), payload.getEmail(),
// payload.getEmailVerified(), (String)payload.get("name"), (String)payload.get("picture"),
// (String)payload.get("locale"), (String)payload.get("family_name"), (String)payload.get("given_name"), "");
// System.out.println(userInfo.toString());
// return userInfo;
return userInfo;
return null;
} else {
throw new NonValidTokenException("Not a valid token");

View File

@ -25,7 +25,7 @@
</bean>
<bean id="proxy" class="rest.Proxy">
<bean id="proxy" class="rest.proxy.Proxy">
<constructor-arg type = "String" value = "${proxy.allowed.host}"/>
</bean>
@ -95,6 +95,7 @@
<bean id="researcherDao" class="dao.entities.ResearcherDaoImpl" />
<bean id="serviceDao" class="dao.entities.ServiceDaoImpl" />
<bean id="userInfoDao" class="dao.entities.security.UserInfoDaoImpl" />
<bean id="userAuthDao" class="dao.entities.security.UserAuthDaoImpl" />
<context:annotation-config />

View File

@ -16,7 +16,7 @@
<mvc:annotation-driven />
<context:component-scan base-package="rest" />
<bean id="proxy" class="rest.Proxy">
<bean id="proxy" class="rest.proxy.Proxy">
<constructor-arg type = "String" value = "${proxy.allowed.host}"/>
</bean>

View File

@ -447,20 +447,46 @@ ALTER TABLE ONLY "DatasetService"
ADD CONSTRAINT "DatasetServiceServiceReference" FOREIGN KEY ("Service") REFERENCES "Service"("ID");
DROP table if exists "UserInfo";
CREATE TABLE "UserInfo" (
"autoid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"id" character varying(500),
"email" character varying(250),
"emailIsVerified" boolean,
"identification" character varying(500) NOT NULL,
"email" character varying(250) NOT NULL,
"authorization_level" smallint NOT NULL,
"usertype" smallint NOT NULL,
"authentication" uuid,
"verified_email" boolean,
"name" character varying(250),
"pictureUrl" character varying(500),
"locale" character varying(50),
"familyName" character varying(250),
"givenName" character varying(250),
"created" timestamp,
"lastloggedin" timestamp,
"additionalinfo" xml,
PRIMARY KEY (id, email)
PRIMARY KEY (identification, email)
);
COMMENT ON COLUMN "UserInfo"."authorization_level" IS 'This stores the authorization level of the user: 0 admin, 1 user, being able to be extended furthermore';
COMMENT ON COLUMN "UserInfo"."usertype" IS 'This stores the type of user: 0 -> internal, 1 external';
DROP table if exists "UserAuth";
CREATE TABLE "UserAuth" (
"id" uuid DEFAULT uuid_generate_v4() NOT NULL UNIQUE,
"username" character varying(200) NOT NULL,
"password" character varying(250) NOT NULL,
PRIMARY KEY (username)
);
CREATE INDEX idx_userauth_username ON "UserAuth"(username);
ALTER TABLE "UserInfo" ADD CONSTRAINT fkey_userinfo_userauth FOREIGN KEY ("authentication") REFERENCES "UserAuth"(id);
COMMENT ON COLUMN "UserAuth"."password" IS 'This field stores a password hash';
ALTER TABLE "UserInfo" OWNER TO dmptool;
ALTER TABLE "UserAuth" OWNER TO dmptool;
REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;