no message
This commit is contained in:
parent
74f11f0f1b
commit
703d0b84c3
|
@ -12,6 +12,7 @@ import eu.eudat.managers.DatasetManager;
|
|||
import eu.eudat.models.dataset.DatasetTableRequest;
|
||||
import eu.eudat.models.helpers.DataTableData;
|
||||
import eu.eudat.models.helpers.responses.*;
|
||||
import eu.eudat.models.listingmodels.DatasetListingModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -41,7 +42,6 @@ import eu.eudat.dao.entities.UserInfoDao;
|
|||
import eu.eudat.models.criteria.DataRepositoryCriteria;
|
||||
import eu.eudat.models.criteria.RegistryCriteria;
|
||||
import eu.eudat.models.criteria.ServiceCriteria;
|
||||
import eu.eudat.responses.RestResponse;
|
||||
|
||||
|
||||
@RestController
|
||||
|
@ -66,14 +66,14 @@ public class Datasets {
|
|||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/datasets/getPaged" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseItem<DataTableData<eu.eudat.models.dataset.Dataset>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest) {
|
||||
public @ResponseBody ResponseItem<DataTableData<DatasetListingModel>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest) {
|
||||
try {
|
||||
DataTableData<eu.eudat.models.dataset.Dataset> dataTable = new DatasetManager().getPaged(datasetDao, datasetTableRequest);
|
||||
return new ResponseItem<DataTableData<eu.eudat.models.dataset.Dataset>>().status(HttpStatus.OK).payload(dataTable);
|
||||
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(datasetDao, datasetTableRequest);
|
||||
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.OK).payload(dataTable);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return new ResponseItem<DataTableData<eu.eudat.models.dataset.Dataset>>().status(HttpStatus.OK).message(ex.getMessage());
|
||||
return new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
|
@ -23,6 +25,8 @@ public class Login {
|
|||
|
||||
@Autowired
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) {
|
||||
try {
|
||||
|
|
|
@ -51,7 +51,6 @@ import eu.eudat.entities.Researcher;
|
|||
import eu.eudat.entities.Service;
|
||||
import eu.eudat.entities.UserInfo;
|
||||
import eu.eudat.helpers.Transformers;
|
||||
import eu.eudat.responses.RestResponse;
|
||||
|
||||
|
||||
@RestController
|
||||
|
|
|
@ -28,9 +28,13 @@ public class DatabaseContext<T extends DataEntity<T>> {
|
|||
public T createOrUpdate(T item, Class<T> type) {
|
||||
if (item.getKeys()[0] != null) {
|
||||
T oldItem = entityManager.find(type, item.getKeys()[0]);
|
||||
oldItem.update(item);
|
||||
entityManager.merge(oldItem);
|
||||
return oldItem;
|
||||
if(oldItem!=null) {
|
||||
oldItem.update(item);
|
||||
entityManager.merge(oldItem);
|
||||
return oldItem;
|
||||
}else {
|
||||
entityManager.persist(item);
|
||||
}
|
||||
} else entityManager.persist(item);
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.dao.entities.security;
|
|||
|
||||
import eu.eudat.dao.Dao;
|
||||
import eu.eudat.entities.Credential;
|
||||
import eu.eudat.entities.Project;
|
||||
import eu.eudat.entities.UserToken;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -9,5 +10,8 @@ import java.util.UUID;
|
|||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
public interface CredentialDao extends Dao<Credential, UUID> {
|
||||
public interface CredentialDao {
|
||||
|
||||
Credential createOrUpdate(Credential item);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package eu.eudat.dao.entities.security;
|
||||
|
||||
import eu.eudat.dao.JpaDao;
|
||||
import eu.eudat.dao.databaselayer.service.DatabaseService;
|
||||
import eu.eudat.entities.Credential;
|
||||
import eu.eudat.entities.Project;
|
||||
import eu.eudat.entities.UserToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -11,9 +14,13 @@ import java.util.UUID;
|
|||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
@Component("credentialDao")
|
||||
public class CredentialDaoImpl extends JpaDao<Credential, UUID> implements CredentialDao {
|
||||
public class CredentialDaoImpl implements CredentialDao {
|
||||
|
||||
@Autowired
|
||||
DatabaseService<Credential> databaseService;
|
||||
|
||||
@Override
|
||||
public Credential loadDetails(Credential credential) {
|
||||
return null;
|
||||
public Credential createOrUpdate(Credential item) {
|
||||
return this.databaseService.createOrUpdate(item,Credential.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name="\"Credential\"")
|
||||
public class Credential {
|
||||
public class Credential implements DataEntity<Credential> {
|
||||
|
||||
@Id
|
||||
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
|
@ -113,4 +113,17 @@ public class Credential {
|
|||
public int hashCode() {
|
||||
return provider.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Credential entity) {
|
||||
this.status = entity.status;
|
||||
this.publicValue = entity.getPublicValue();
|
||||
this.secret = entity.getSecret();
|
||||
this.lastUpdateTime = new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import eu.eudat.dao.entities.ProjectDao;
|
|||
import eu.eudat.models.dataset.Dataset;
|
||||
import eu.eudat.models.dataset.DatasetTableRequest;
|
||||
import eu.eudat.models.helpers.DataTableData;
|
||||
import eu.eudat.models.listingmodels.DatasetListingModel;
|
||||
import eu.eudat.models.project.Project;
|
||||
import eu.eudat.models.project.ProjectTableRequest;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
@ -18,11 +19,11 @@ import java.util.UUID;
|
|||
*/
|
||||
public class DatasetManager {
|
||||
|
||||
public DataTableData<Dataset> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
|
||||
public DataTableData<DatasetListingModel> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
|
||||
QueryableList<eu.eudat.entities.Dataset> items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria());
|
||||
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest);
|
||||
List<Dataset> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, Dataset>().fromDataModel( pagedItems.toList(), eu.eudat.models.dataset.Dataset.class);
|
||||
DataTableData<eu.eudat.models.dataset.Dataset> dataTable = new DataTableData<eu.eudat.models.dataset.Dataset>();
|
||||
List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel( pagedItems.toList(), DatasetListingModel.class);
|
||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
||||
dataTable.setData(datasets);
|
||||
dataTable.setTotalCount(items.count());
|
||||
return dataTable;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package eu.eudat.models.dataset;
|
||||
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.utilities.helpers.LabelGenerator;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DataRepository implements DataModel<eu.eudat.entities.DataRepository>{
|
||||
public class DataRepository implements DataModel<eu.eudat.entities.DataRepository>,LabelGenerator{
|
||||
private String pid;
|
||||
private String name;
|
||||
private String uri;
|
||||
|
@ -49,4 +50,9 @@ public class DataRepository implements DataModel<eu.eudat.entities.DataRepositor
|
|||
entity.setStatus((short)0);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateLabel() {
|
||||
return this.getName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package eu.eudat.models.dataset;
|
||||
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.utilities.helpers.LabelGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Registry implements DataModel<eu.eudat.entities.Registry>{
|
||||
public class Registry implements DataModel<eu.eudat.entities.Registry>,LabelGenerator {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private String abbreviation;
|
||||
|
@ -34,6 +35,11 @@ public class Registry implements DataModel<eu.eudat.entities.Registry>{
|
|||
return abbreviation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateLabel() {
|
||||
return getLabel();
|
||||
}
|
||||
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package eu.eudat.models.dataset;
|
||||
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.utilities.helpers.LabelGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Service implements DataModel<eu.eudat.entities.Service>{
|
||||
public class Service implements DataModel<eu.eudat.entities.Service>,LabelGenerator{
|
||||
private UUID id;
|
||||
private String label;
|
||||
|
||||
|
@ -79,4 +80,9 @@ public class Service implements DataModel<eu.eudat.entities.Service>{
|
|||
eu.eudat.entities.Service entity = new eu.eudat.entities.Service();
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateLabel() {
|
||||
return this.label;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,8 +86,8 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
|
|||
this.label = entity.getLabel();
|
||||
this.project = entity.getProject().getLabel();
|
||||
this.profile = entity.getProfile().getLabel();
|
||||
this.organisations =getLabel(new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class));
|
||||
this.researchers =getLabel(new DomainModelConverter<eu.eudat.entities.Researcher,Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()),Researcher.class));
|
||||
this.organisations =LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class));
|
||||
this.researchers =LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Researcher,Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()),Researcher.class));
|
||||
this.version = ""+entity.getVersion();
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,5 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private <T extends LabelGenerator> String getLabel(List<T> items){
|
||||
return LabelBuilder.generateLabel(items);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
package eu.eudat.models.listingmodels;
|
||||
|
||||
import eu.eudat.entities.*;
|
||||
import eu.eudat.entities.DataRepository;
|
||||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.entities.Organisation;
|
||||
import eu.eudat.entities.Registry;
|
||||
import eu.eudat.entities.Researcher;
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.dataset.*;
|
||||
import eu.eudat.models.dataset.Service;
|
||||
import eu.eudat.models.dmp.*;
|
||||
import eu.eudat.utilities.builders.DomainModelConverter;
|
||||
import eu.eudat.utilities.helpers.LabelBuilder;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/19/2017.
|
||||
*/
|
||||
public class DatasetListingModel implements DataModel<Dataset> {
|
||||
private String id;
|
||||
private String label;
|
||||
private String dmp;
|
||||
private String profile;
|
||||
private String dataRepositories;
|
||||
private String registries;
|
||||
private String services;
|
||||
private String status;
|
||||
private String created;
|
||||
private String description;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
||||
public void setDmp(String dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
public void setProfile(String profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public String getDataRepositories() {
|
||||
return dataRepositories;
|
||||
}
|
||||
|
||||
public void setDataRepositories(String dataRepositories) {
|
||||
this.dataRepositories = dataRepositories;
|
||||
}
|
||||
|
||||
public String getRegistries() {
|
||||
return registries;
|
||||
}
|
||||
|
||||
public void setRegistries(String registries) {
|
||||
this.registries = registries;
|
||||
}
|
||||
|
||||
public String getServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
public void setServices(String services) {
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(String created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromDataModel(Dataset entity) throws InstantiationException, IllegalAccessException {
|
||||
this.id = entity.getId().toString();
|
||||
this.label = entity.getLabel();
|
||||
this.created = entity.getCreated().toString();
|
||||
this.dmp = entity.getDmp()!=null? entity.getDmp().getLabel():"";
|
||||
this.profile = entity.getProfile()!=null? entity.getProfile().getLabel():"";
|
||||
this.description = entity.getDescription();
|
||||
this.status = ""+entity.getStatus();
|
||||
this.registries = LabelBuilder.getLabel(new DomainModelConverter<Registry, eu.eudat.models.dataset.Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), eu.eudat.models.dataset.Registry.class));
|
||||
this.dataRepositories = LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.DataRepository, eu.eudat.models.dataset.DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), eu.eudat.models.dataset.DataRepository.class));
|
||||
this.services = LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Service, eu.eudat.models.dataset.Service>().fromDataModel(entity.getServices().stream().collect(Collectors.toList()), Service.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset toDataModel() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package eu.eudat.responses;
|
||||
|
||||
public class RestResponse {
|
||||
|
||||
private String message;
|
||||
private String objID;
|
||||
|
||||
public RestResponse(String message, String objID) {
|
||||
super();
|
||||
this.message = message;
|
||||
this.objID = objID;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public String getObjID() {
|
||||
return objID;
|
||||
}
|
||||
public void setObjID(String objID) {
|
||||
this.objID = objID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\"message\":\"" + message + "\", \"objID\":\"" + objID + "\"}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.security;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.naming.NameAlreadyBoundException;
|
||||
|
@ -32,7 +33,7 @@ public class CustomAuthenticationProvider {
|
|||
@Autowired private GoogleTokenValidator googleTokenValidator;
|
||||
@Autowired private NativeTokenValidator nativeTokenValidator;
|
||||
|
||||
public Principal authenticate(LoginInfo credentials) throws AuthenticationException {
|
||||
public Principal authenticate(LoginInfo credentials) throws AuthenticationException, GeneralSecurityException {
|
||||
String token = credentials.getTicket();
|
||||
try {
|
||||
Principal principal = googleTokenValidator.validateToken(token);
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.io.IOException;
|
|||
import java.security.GeneralSecurityException;
|
||||
import java.security.Principal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.*;
|
||||
import eu.eudat.dao.entities.security.CredentialDao;
|
||||
|
@ -38,53 +40,39 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
@Autowired private CredentialDao credentialDao;
|
||||
@Autowired private AuthenticationService authenticationService;
|
||||
@Autowired private UserTokenDao userTokenDao;
|
||||
|
||||
private GoogleTokenResponse verifyUser(String authCode) throws IOException {
|
||||
|
||||
GoogleTokenResponse tokenResponse =
|
||||
new GoogleAuthorizationCodeTokenRequest(
|
||||
new NetHttpTransport(),
|
||||
JacksonFactory.getDefaultInstance(),
|
||||
"https://www.googleapis.com/oauth2/v4/token",
|
||||
"524432312250-sc9qsmtmbvlv05r44onl6l93ia3k9deo.apps.googleusercontent.com",
|
||||
"IQjhbYdExPIsjy37mOfB103F",
|
||||
authCode,
|
||||
"postmessage") // Specify the same redirect URI that you use with your web
|
||||
// app. If you don't have a web version of your app, you can
|
||||
// specify an empty string.
|
||||
.execute();
|
||||
return tokenResponse;
|
||||
private GoogleIdTokenVerifier verifier;
|
||||
public GoogleTokenValidator(){
|
||||
verifier = new GoogleIdTokenVerifier.Builder(transport, JacksonFactory.getDefaultInstance())
|
||||
.setAudience(Collections.singletonList("524432312250-sc9qsmtmbvlv05r44onl6l93ia3k9deo.apps.googleusercontent.com"))
|
||||
// Or, if multiple clients access the backend:
|
||||
//.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getAccessToken(GoogleTokenResponse response){
|
||||
return response.getAccessToken();
|
||||
private GoogleIdToken verifyUserAndGetUser(String idTokenString) throws IOException, GeneralSecurityException {
|
||||
|
||||
GoogleIdToken idToken = verifier.verify(idTokenString);
|
||||
|
||||
return idToken;
|
||||
}
|
||||
|
||||
private GoogleIdToken getUser(GoogleTokenResponse response) throws IOException {
|
||||
return response.parseIdToken();
|
||||
}
|
||||
@Override
|
||||
public eu.eudat.models.security.Principal validateToken(String authCode) throws NonValidTokenException, IOException {
|
||||
|
||||
GoogleTokenResponse tokenResponse = this.verifyUser(authCode);
|
||||
String token = getAccessToken(tokenResponse);
|
||||
GoogleIdToken idToken = getUser(tokenResponse);
|
||||
public eu.eudat.models.security.Principal validateToken(String token) throws NonValidTokenException, IOException, GeneralSecurityException {
|
||||
|
||||
GoogleIdToken idToken = this.verifyUserAndGetUser(token);
|
||||
Payload payload = idToken.getPayload();
|
||||
|
||||
UserInfo userInfo = userInfoDao.getByMail(payload.getEmail());
|
||||
|
||||
Credential credential = new Credential();
|
||||
final Credential credential = new Credential();
|
||||
credential.setCreationTime(new Date());
|
||||
credential.setId(UUID.randomUUID());
|
||||
credential.setStatus(1);
|
||||
credential.setLastUpdateTime(new Date());
|
||||
credential.setProvider(1);
|
||||
credential.setSecret(token);
|
||||
credential.setPublicValue(userInfo.getName());
|
||||
credential.setUserInfo(userInfo);
|
||||
credentialDao.create(credential);
|
||||
if(userInfo == null) { //means not existing in db, so create one
|
||||
if(userInfo == null) {
|
||||
credential.setId(UUID.randomUUID());
|
||||
userInfo = new UserInfo();
|
||||
userInfo.setName((String)payload.get("name"));
|
||||
userInfo.setVerified_email(payload.getEmailVerified());
|
||||
|
@ -94,14 +82,24 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
userInfo.setAuthorization_level(new Short("1"));
|
||||
userInfo.setUsertype(new Short("1"));
|
||||
userInfo = userInfoDao.create(userInfo);
|
||||
credential = credentialDao.create(credential);
|
||||
credential.setUserInfo(userInfo);
|
||||
credentialDao.createOrUpdate(credential);
|
||||
}
|
||||
else {
|
||||
userInfo.setLastloggedin(new Date());
|
||||
Set<Credential> credentials = userInfo.getCredentials();
|
||||
if(credentials.contains(credential))credentials.remove(credential);
|
||||
credentials.add(credential);
|
||||
if(credentials.contains(credential)){
|
||||
Credential oldCredential = credentials.stream().filter(item->credential.getProvider().equals(item.getProvider())).findFirst().get();
|
||||
credential.setId(oldCredential.getId());
|
||||
}
|
||||
else{
|
||||
credential.setUserInfo(userInfo);
|
||||
credential.setId(UUID.randomUUID());
|
||||
credentialDao.createOrUpdate(credential);
|
||||
userInfo.getCredentials().add(credential);
|
||||
}
|
||||
userInfo = userInfoDao.update(userInfo);
|
||||
|
||||
}
|
||||
|
||||
UserToken userToken = new UserToken();
|
||||
|
|
|
@ -5,9 +5,10 @@ import eu.eudat.exceptions.NonValidTokenException;
|
|||
import eu.eudat.models.security.Principal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public interface TokenValidator {
|
||||
|
||||
public Principal validateToken(String token) throws NonValidTokenException, IOException;
|
||||
public Principal validateToken(String token) throws NonValidTokenException, IOException, GeneralSecurityException;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,16 +6,22 @@ import java.util.List;
|
|||
* Created by ikalyvas on 12/19/2017.
|
||||
*/
|
||||
public class LabelBuilder {
|
||||
public static <T extends LabelGenerator> String generateLabel(List<T> items){
|
||||
private static <T extends LabelGenerator> String generateLabel(List<T> items){
|
||||
String label="";
|
||||
for(T item : items){
|
||||
if(items.indexOf(item)==3){
|
||||
label+="...";
|
||||
break;
|
||||
}
|
||||
if(items.indexOf(item)>1){
|
||||
label+=", ";
|
||||
}
|
||||
label+=item.generateLabel();
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public static <T extends LabelGenerator> String getLabel(List<T> items){
|
||||
return generateLabel(items);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue