login button eudat
This commit is contained in:
commit
c2f5c4123b
|
@ -28,6 +28,8 @@ public class CredentialBuilder extends Builder<Credential> {
|
|||
|
||||
private Date lastUpdateTime;
|
||||
|
||||
private String externalId;
|
||||
|
||||
public CredentialBuilder id(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
|
@ -68,6 +70,11 @@ public class CredentialBuilder extends Builder<Credential> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public CredentialBuilder externalId(String externalId) {
|
||||
this.externalId = externalId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Credential build() {
|
||||
Credential credential = new Credential();
|
||||
credential.setStatus(status);
|
||||
|
@ -78,6 +85,7 @@ public class CredentialBuilder extends Builder<Credential> {
|
|||
credential.setPublicValue(publicValue);
|
||||
credential.setUserInfo(userInfo);
|
||||
credential.setId(id);
|
||||
credential.setExternalId(externalId);
|
||||
return credential;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import eu.eudat.models.login.Credentials;
|
|||
import eu.eudat.models.login.LoginInfo;
|
||||
import eu.eudat.models.security.Principal;
|
||||
import eu.eudat.security.CustomAuthenticationProvider;
|
||||
import eu.eudat.security.validators.b2access.B2AccessTokenValidator;
|
||||
import eu.eudat.security.validators.b2access.helpers.B2AccessRequest;
|
||||
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||
import eu.eudat.security.validators.twitter.TwitterTokenValidator;
|
||||
import eu.eudat.services.AuthenticationService;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
|
@ -30,11 +33,14 @@ public class Login {
|
|||
|
||||
private TwitterTokenValidator twitterTokenValidator;
|
||||
|
||||
private B2AccessTokenValidator b2AccessTokenValidator;
|
||||
|
||||
@Autowired
|
||||
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService authenticationService, TwitterTokenValidator twitterTokenValidator) {
|
||||
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService authenticationService, TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator) {
|
||||
this.customAuthenticationProvider = customAuthenticationProvider;
|
||||
this.authenticationService = authenticationService;
|
||||
this.twitterTokenValidator = twitterTokenValidator;
|
||||
this.b2AccessTokenValidator = b2AccessTokenValidator;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -76,6 +82,17 @@ public class Login {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/b2AccessRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<B2AccessResponseToken>> b2AccessRequestToken(@RequestBody B2AccessRequest b2AccessRequest) {
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<B2AccessResponseToken>().payload(this.b2AccessTokenValidator.getAccessToken(b2AccessRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<B2AccessResponseToken>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import eu.eudat.dao.databaselayer.service.DatabaseService;
|
|||
import eu.eudat.entities.DataEntity;
|
||||
|
||||
|
||||
public class DatabaseAccess<T extends DataEntity<T>> {
|
||||
public class DatabaseAccess<T extends DataEntity> {
|
||||
private DatabaseService<T> databaseService;
|
||||
|
||||
public DatabaseService<T> getDatabaseService() {
|
||||
|
|
|
@ -2,13 +2,20 @@ package eu.eudat.dao;
|
|||
|
||||
|
||||
import eu.eudat.entities.DataEntity;
|
||||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
public interface DatabaseAccessLayer<T extends DataEntity<T>, I> {
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface DatabaseAccessLayer<T extends DataEntity, I> {
|
||||
T createOrUpdate(T item);
|
||||
|
||||
CompletableFuture<T> createOrUpdateAsync(T item);
|
||||
|
||||
T find(I id);
|
||||
|
||||
T find(I id, String hint);
|
||||
|
||||
void delete(T item);
|
||||
|
||||
QueryableList<T> asQueryable();
|
||||
|
|
|
@ -13,7 +13,7 @@ import javax.persistence.PersistenceContext;
|
|||
|
||||
|
||||
@Repository("databaseCtx")
|
||||
public class DatabaseContext<T extends DataEntity<T>> {
|
||||
public class DatabaseContext<T extends DataEntity> {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
@ -30,8 +30,8 @@ public class DatabaseContext<T extends DataEntity<T>> {
|
|||
@Transactional
|
||||
public T createOrUpdate(T item, Class<T> type) {
|
||||
EntityManager entityManager = this.entityManager;
|
||||
if (item.getKeys()[0] != null) {
|
||||
T oldItem = entityManager.find(type, item.getKeys()[0]);
|
||||
if (item.getKeys() != null) {
|
||||
T oldItem = entityManager.find(type, item.getKeys());
|
||||
if (oldItem != null) {
|
||||
oldItem.update(item);
|
||||
entityManager.merge(oldItem);
|
||||
|
@ -43,11 +43,6 @@ public class DatabaseContext<T extends DataEntity<T>> {
|
|||
return item;
|
||||
}
|
||||
|
||||
public long count(Class<T> entityClass) {
|
||||
EntityManager entityManager = this.entityManager;
|
||||
return ((Number) entityManager.createQuery("select count(e) from " + entityClass.getSimpleName() + " e").getSingleResult()).longValue();
|
||||
}
|
||||
|
||||
public void delete(T item) {
|
||||
this.entityManager.remove(item);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Set;
|
|||
|
||||
|
||||
@Service("databaseService")
|
||||
public class DatabaseService<T extends DataEntity<T>> {
|
||||
public class DatabaseService<T extends DataEntity> {
|
||||
|
||||
private DatabaseContext<T> databaseCtx;
|
||||
|
||||
|
@ -32,10 +32,6 @@ public class DatabaseService<T extends DataEntity<T>> {
|
|||
return this.databaseCtx.createOrUpdate(item, tClass);
|
||||
}
|
||||
|
||||
public Long count(Class<T> tClass) {
|
||||
return this.databaseCtx.count(tClass);
|
||||
}
|
||||
|
||||
public void delete(T item) {
|
||||
this.databaseCtx.delete(item);
|
||||
}
|
||||
|
|
|
@ -17,5 +17,4 @@ public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
|||
|
||||
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UserInfo principal);
|
||||
|
||||
Long count();
|
||||
}
|
|
@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("dMPDao")
|
||||
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||
|
@ -78,7 +79,12 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Long count() {
|
||||
return this.getDatabaseService().count(DMP.class);
|
||||
public CompletableFuture<DMP> createOrUpdateAsync(DMP item) {
|
||||
return CompletableFuture.supplyAsync(()->this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DMP find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("dataRepositoryDao")
|
||||
public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implements DataRepositoryDao {
|
||||
|
@ -36,6 +37,16 @@ public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implem
|
|||
return getDatabaseService().createOrUpdate(item, DataRepository.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<DataRepository> createOrUpdateAsync(DataRepository item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataRepository find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(DataRepository item) {
|
||||
this.getDatabaseService().delete(item);
|
||||
|
|
|
@ -15,9 +15,4 @@ public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
|
|||
|
||||
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal);
|
||||
|
||||
CompletableFuture<Dataset> createOrUpdateAsync(Dataset item);
|
||||
|
||||
Dataset find(UUID id, String hint);
|
||||
|
||||
Long count();
|
||||
}
|
|
@ -61,11 +61,6 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count() {
|
||||
return this.getDatabaseService().count(Dataset.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Dataset item) {
|
||||
this.getDatabaseService().delete(item);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("datasetProfileDao")
|
||||
public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implements DatasetProfileDao {
|
||||
|
@ -50,4 +51,14 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
|
|||
public QueryableList<DatasetProfile> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(DatasetProfile.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<DatasetProfile> createOrUpdateAsync(DatasetProfile item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatasetProfile find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@Component("externalDatasetDao")
|
||||
|
@ -46,4 +47,14 @@ public class ExternalDatasetDaoImpl extends DatabaseAccess<ExternalDataset> impl
|
|||
public QueryableList<ExternalDataset> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(ExternalDataset.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ExternalDataset> createOrUpdateAsync(ExternalDataset item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalDataset find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@Service("invitationDao")
|
||||
|
@ -43,4 +44,14 @@ public class InvitationDaoImpl extends DatabaseAccess<Invitation> implements Inv
|
|||
public QueryableList<Invitation> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(Invitation.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Invitation> createOrUpdateAsync(Invitation item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Invitation find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("organisationDao")
|
||||
public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements OrganisationDao {
|
||||
|
@ -45,4 +46,14 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
|
|||
public QueryableList<Organisation> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(Organisation.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Organisation> createOrUpdateAsync(Organisation item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Organisation find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,4 @@ public interface ProjectDao extends DatabaseAccessLayer<Project, UUID> {
|
|||
|
||||
QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal);
|
||||
|
||||
Long count();
|
||||
}
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("projectDao")
|
||||
public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao {
|
||||
|
@ -44,11 +45,6 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
|||
return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count() {
|
||||
return this.getDatabaseService().count(Project.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Project item) {
|
||||
this.getDatabaseService().delete(item);
|
||||
|
@ -63,4 +59,14 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
|||
query.where((builder, root) -> builder.equal(root.get("creator"), principal));
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Project> createOrUpdateAsync(Project item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("registryDao")
|
||||
public class RegistryDaoImpl extends DatabaseAccess<Registry> implements RegistryDao {
|
||||
|
@ -45,4 +46,14 @@ public class RegistryDaoImpl extends DatabaseAccess<Registry> implements Registr
|
|||
public QueryableList<Registry> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(Registry.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Registry> createOrUpdateAsync(Registry item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("researcherDao")
|
||||
public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements ResearcherDao {
|
||||
|
@ -45,4 +46,14 @@ public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements Res
|
|||
public QueryableList<Researcher> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(Researcher.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Researcher> createOrUpdateAsync(Researcher item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Researcher find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("serviceDao")
|
||||
public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDao {
|
||||
|
@ -45,4 +46,14 @@ public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDa
|
|||
public QueryableList<Service> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(Service.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Service> createOrUpdateAsync(Service item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Service find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/8/2018.
|
||||
|
@ -39,4 +40,14 @@ public class UserDmpDaoImpl extends DatabaseAccess<UserDMP> implements UserDmpDa
|
|||
public QueryableList<UserDMP> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(UserDMP.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<UserDMP> createOrUpdateAsync(UserDMP item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDMP find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("userInfoDao")
|
||||
public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInfoDao {
|
||||
|
@ -49,4 +50,14 @@ public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInf
|
|||
public QueryableList<UserInfo> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(UserInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<UserInfo> createOrUpdateAsync(UserInfo item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@Component("userRoleDao")
|
||||
|
@ -55,4 +56,14 @@ public class UserRoleDaoImpl extends DatabaseAccess<UserRole> implements UserRol
|
|||
public QueryableList<UserRole> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(UserRole.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<UserRole> createOrUpdateAsync(UserRole item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserRole find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@Component("credentialDao")
|
||||
|
@ -49,4 +50,14 @@ public class CredentialDaoImpl extends DatabaseAccess<Credential> implements Cre
|
|||
public QueryableList<Credential> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(Credential.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Credential> createOrUpdateAsync(Credential item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Credential find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@Component("userTokenDao")
|
||||
|
@ -37,4 +38,14 @@ public class UserTokenDaoImpl extends DatabaseAccess<UserToken> implements UserT
|
|||
public QueryableList<UserToken> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(UserToken.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<UserToken> createOrUpdateAsync(UserToken item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserToken find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,12 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Credential\"")
|
||||
public class Credential implements DataEntity<Credential> {
|
||||
@NamedEntityGraphs({
|
||||
@NamedEntityGraph(
|
||||
name = "credentialUserInfo",
|
||||
attributeNodes = {@NamedAttributeNode("userInfo")})
|
||||
})
|
||||
public class Credential implements DataEntity<Credential,UUID> {
|
||||
|
||||
@Id
|
||||
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
|
@ -31,6 +36,9 @@ public class Credential implements DataEntity<Credential> {
|
|||
@Column(name = "\"LastUpdateTime\"", nullable = false)
|
||||
private Date lastUpdateTime;
|
||||
|
||||
@Column(name = "\"ExternalId\"", nullable = false)
|
||||
private String externalId;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -95,6 +103,14 @@ public class Credential implements DataEntity<Credential> {
|
|||
this.lastUpdateTime = lastUpdateTime;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
|
||||
public void setExternalId(String externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -119,7 +135,7 @@ public class Credential implements DataEntity<Credential> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.*;
|
|||
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
||||
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")})
|
||||
})
|
||||
public class DMP implements Serializable, DataEntity<DMP> {
|
||||
public class DMP implements DataEntity<DMP,UUID> {
|
||||
|
||||
public enum DMPStatus {
|
||||
ACTIVE((short) 0), DELETED((short) 1);
|
||||
|
@ -286,8 +286,8 @@ public class DMP implements Serializable, DataEntity<DMP> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"DMPOrganisation\"")
|
||||
public class DMPOrganisation implements Serializable {
|
||||
public class DMPOrganisation {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.entities;
|
||||
|
||||
public interface DataEntity<T> {
|
||||
public interface DataEntity<T,K> {
|
||||
void update(T entity);
|
||||
|
||||
Object[] getKeys();
|
||||
K getKeys();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"DataRepository\"")
|
||||
public class DataRepository implements Serializable, DataEntity<DataRepository> {
|
||||
public class DataRepository implements Serializable, DataEntity<DataRepository,UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -147,7 +147,7 @@ public class DataRepository implements Serializable, DataEntity<DataRepository>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.*;
|
|||
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
||||
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")})
|
||||
})
|
||||
public class Dataset implements DataEntity<Dataset> {
|
||||
public class Dataset implements DataEntity<Dataset,UUID> {
|
||||
|
||||
public static Set<String> getHints() {
|
||||
return hints;
|
||||
|
@ -313,7 +313,7 @@ public class Dataset implements DataEntity<Dataset> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"DatasetProfile\"")
|
||||
public class DatasetProfile implements Serializable, DataEntity<DatasetProfile> {
|
||||
public class DatasetProfile implements DataEntity<DatasetProfile,UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -132,7 +132,7 @@ public class DatasetProfile implements Serializable, DataEntity<DatasetProfile>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"DatasetProfileRuleset\"")
|
||||
public class DatasetProfileRuleset implements Serializable {
|
||||
public class DatasetProfileRuleset {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"DatasetRegistry\"")
|
||||
public class DatasetRegistry implements Serializable {
|
||||
public class DatasetRegistry {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"DatasetService\"")
|
||||
public class DatasetService implements Serializable {
|
||||
public class DatasetService {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"ExternalDataset\"")
|
||||
public class ExternalDataset implements DataEntity<ExternalDataset> {
|
||||
public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -104,7 +104,7 @@ public class ExternalDataset implements DataEntity<ExternalDataset> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Invitation\"")
|
||||
public class Invitation implements DataEntity<Invitation> {
|
||||
public class Invitation implements DataEntity<Invitation,UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -100,7 +100,7 @@ public class Invitation implements DataEntity<Invitation> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Organisation\"")
|
||||
public class Organisation implements Serializable, DataEntity<Organisation> {
|
||||
public class Organisation implements Serializable, DataEntity<Organisation,UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -151,7 +151,7 @@ public class Organisation implements Serializable, DataEntity<Organisation> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Project\"")
|
||||
public class Project implements DataEntity<Project> {
|
||||
public class Project implements DataEntity<Project,UUID> {
|
||||
|
||||
public enum Status {
|
||||
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
||||
|
@ -248,7 +248,7 @@ public class Project implements DataEntity<Project> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Registry\"")
|
||||
public class Registry implements DataEntity<Registry> {
|
||||
public class Registry implements DataEntity<Registry,UUID> {
|
||||
|
||||
|
||||
@Id
|
||||
|
@ -149,7 +149,7 @@ public class Registry implements DataEntity<Registry> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Researcher\"")
|
||||
public class Researcher implements DataEntity<Researcher> {
|
||||
public class Researcher implements DataEntity<Researcher,UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -150,7 +150,7 @@ public class Researcher implements DataEntity<Researcher> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"Service\"")
|
||||
public class Service implements DataEntity<Service> {
|
||||
public class Service implements DataEntity<Service, UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -150,7 +150,7 @@ public class Service implements DataEntity<Service> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"UserDMP\"")
|
||||
public class UserDMP implements DataEntity<UserDMP> {
|
||||
public class UserDMP implements DataEntity<UserDMP, UUID> {
|
||||
|
||||
public enum UserDMPRoles {
|
||||
OWNER(0), USER(1);
|
||||
|
@ -90,7 +90,7 @@ public class UserDMP implements DataEntity<UserDMP> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.UUID;
|
|||
name = "userInfo",
|
||||
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")})
|
||||
})
|
||||
public class UserInfo implements DataEntity<UserInfo> {
|
||||
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -173,7 +173,7 @@ public class UserInfo implements DataEntity<UserInfo> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"UserRole\"")
|
||||
public class UserRole implements DataEntity<UserRole> {
|
||||
public class UserRole implements DataEntity<UserRole, UUID> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -53,7 +53,7 @@ public class UserRole implements DataEntity<UserRole> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.id == null ? null : this.id};
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
|||
|
||||
@Entity
|
||||
@Table(name = "\"UserToken\"")
|
||||
public class UserToken implements DataEntity<UserToken> {
|
||||
public class UserToken implements DataEntity<UserToken, UUID> {
|
||||
|
||||
@Id
|
||||
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
|
@ -62,7 +62,7 @@ public class UserToken implements DataEntity<UserToken> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] getKeys() {
|
||||
return new UUID[]{this.token == null ? null : this.token};
|
||||
public UUID getKeys() {
|
||||
return this.token;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ public class DashBoardManager {
|
|||
|
||||
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.count());
|
||||
statistics.setTotalDataSetCount(datasetRepository.count());
|
||||
statistics.setTotalProjectCount(projectRepository.count());
|
||||
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.asQueryable().count());
|
||||
statistics.setTotalDataSetCount(datasetRepository.asQueryable().count());
|
||||
statistics.setTotalProjectCount(projectRepository.asQueryable().count());
|
||||
return statistics;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ public class DataManagementPlanManager {
|
|||
|
||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
||||
|
||||
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
|
||||
List<DataManagementPlanListingModel> datamanagementPlans = resultList.stream().map(item -> new DataManagementPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
dataTable.setData(datamanagementPlans);
|
||||
});
|
||||
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
||||
dataTable.setData(resultList);
|
||||
});
|
||||
|
||||
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
||||
dataTable.setTotalCount(count);
|
||||
|
@ -62,7 +62,7 @@ public class DataManagementPlanManager {
|
|||
|
||||
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException {
|
||||
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria());
|
||||
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.toList().stream().map(item -> new DataManagementPlan().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.select(item -> new DataManagementPlan().fromDataModel(item));
|
||||
return datamanagementPlans;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package eu.eudat.managers;
|
|||
|
||||
import eu.eudat.builders.entity.UserInfoBuilder;
|
||||
import eu.eudat.dao.entities.*;
|
||||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.entities.UserInfo;
|
||||
import eu.eudat.models.HintedModelFactory;
|
||||
import eu.eudat.models.criteria.DataRepositoryCriteria;
|
||||
|
@ -24,7 +23,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class DatasetManager {
|
||||
|
@ -36,9 +34,9 @@ public class DatasetManager {
|
|||
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
|
||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
||||
|
||||
CompletableFuture<List<Dataset>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
|
||||
List<DatasetListingModel> datasets = resultList.stream().map(item -> new DatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
dataTable.setData(datasets);
|
||||
CompletableFuture<List<DatasetListingModel>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).
|
||||
selectAsync(item -> new DatasetListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
||||
dataTable.setData(resultList);
|
||||
});
|
||||
|
||||
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
||||
|
|
|
@ -19,20 +19,20 @@ public class DatasetProfileManager {
|
|||
|
||||
public static List<DatasetProfileAutocompleteItem> getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException {
|
||||
QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria());
|
||||
List<DatasetProfileAutocompleteItem> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<DatasetProfileAutocompleteItem> datasetProfiles = items.select(item -> new DatasetProfileAutocompleteItem().fromDataModel(item));
|
||||
return datasetProfiles;
|
||||
}
|
||||
|
||||
public static DataTableData<DatasetProfileListingModel> getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
|
||||
QueryableList<DatasetProfile> items = apiContext.getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
|
||||
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem);
|
||||
List<DatasetProfileListingModel> datasetProfiles = pagedItems.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<DatasetProfileListingModel> datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item));
|
||||
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
|
||||
}
|
||||
|
||||
public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException {
|
||||
QueryableList<DatasetProfile> items = datasetProfileRepository.getAll();
|
||||
List<DatasetProfileListingModel> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item));
|
||||
return datasetProfiles;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class DatasetWizardManager {
|
|||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(principal.getId());
|
||||
QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest, userInfo);
|
||||
List<DataManagentPlanListingModel> dataManagementPlans = items.toList().stream().map(item -> new DataManagentPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<DataManagentPlanListingModel> dataManagementPlans = items.select(item -> new DataManagentPlanListingModel().fromDataModel(item));
|
||||
return dataManagementPlans;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ public class ExternalDatasetManager {
|
|||
public DataTableData<ExternalDatasetListingModel> getPaged(ApiContext apiContext, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception {
|
||||
QueryableList<ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(externalDatasetTableRequest.getCriteria());
|
||||
QueryableList<ExternalDataset> pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest);
|
||||
List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
|
||||
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
|
||||
}
|
||||
|
||||
public List<ExternalDatasetListingModel> getWithExternal(ApiContext apiContext, String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException {
|
||||
ExternalDatasetCriteria criteria = apiContext.getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
||||
QueryableList<eu.eudat.entities.ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
||||
List<ExternalDatasetListingModel> externalDatasets = items.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<ExternalDatasetListingModel> externalDatasets = items.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
|
||||
return externalDatasets;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class InvitationsManager {
|
|||
|
||||
public static List<UserInfoInvitationModel> getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException {
|
||||
QueryableList<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria());
|
||||
List<UserInfoInvitationModel> userModels = users.toList().stream().map(item -> new UserInfoInvitationModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<UserInfoInvitationModel> userModels = users.select(item -> new UserInfoInvitationModel().fromDataModel(item));
|
||||
return userModels;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,18 +6,21 @@ import eu.eudat.models.helpers.common.Ordering;
|
|||
import eu.eudat.models.helpers.requests.TableRequest;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class PaginationManager {
|
||||
|
||||
public static <T extends DataEntity<T>> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||
public static <T extends DataEntity> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||
if (tableRequest.getOrderings() != null) applyOrder(items, tableRequest);
|
||||
if (tableRequest.getLength() != null) items.take(tableRequest.getLength());
|
||||
if (tableRequest.getOffset() != null) items.skip(tableRequest.getOffset());
|
||||
if (tableRequest.getSelection() != null && tableRequest.getSelection().getFields() != null && tableRequest.getSelection().getFields().length > 0)
|
||||
items.withFields(Arrays.asList(tableRequest.getSelection().getFields()));
|
||||
return items;
|
||||
}
|
||||
|
||||
public static <T extends DataEntity<T>> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||
ColumnOrderings columnOrderings = tableRequest.getOrderings();
|
||||
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
|
||||
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
|
||||
|
@ -29,7 +32,7 @@ public class PaginationManager {
|
|||
return;
|
||||
}
|
||||
|
||||
private static <T extends DataEntity<T>> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
|
||||
private static <T extends DataEntity> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
|
||||
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
||||
items.orderBy((builder, root) -> builder.asc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
||||
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
||||
|
@ -40,7 +43,7 @@ public class PaginationManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static <T extends DataEntity<T>> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
|
||||
private static <T extends DataEntity> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
|
||||
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
||||
items.orderBy((builder, root) -> builder.desc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
||||
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
||||
|
|
|
@ -32,9 +32,8 @@ public class ProjectManager {
|
|||
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items, projectTableRequest);
|
||||
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>();
|
||||
|
||||
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).toListAsync().whenComplete((results, throwable) -> {
|
||||
List<eu.eudat.models.project.ProjectListingModel> projects = results.stream().map(item -> new ProjectListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
dataTable.setData(projects);
|
||||
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> new ProjectListingModel().fromDataModel(item)).whenComplete((results, throwable) -> {
|
||||
dataTable.setData(results);
|
||||
});
|
||||
|
||||
CompletableFuture countFuture = pagedItems.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
|
||||
|
@ -58,7 +57,7 @@ public class ProjectManager {
|
|||
|
||||
public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ApiContext apiContext, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
||||
QueryableList<eu.eudat.entities.Project> items = apiContext.getDatabaseRepository().getProjectDao().getWithCriteria(projectCriteria.getCriteria());
|
||||
List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<eu.eudat.models.project.Project> projects = items.select(item -> new Project().fromDataModel(item));
|
||||
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
|
||||
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
||||
|
@ -76,7 +75,7 @@ public class ProjectManager {
|
|||
|
||||
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
||||
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
|
||||
List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<eu.eudat.models.project.Project> projects = items.select(item -> new Project().fromDataModel(item));
|
||||
return projects;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class UserManager {
|
|||
QueryableList<eu.eudat.entities.UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria());
|
||||
QueryableList<eu.eudat.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem);
|
||||
|
||||
List<UserListingModel> modelUsers = pagedUsers.toList().stream().map(item -> new UserListingModel().fromDataModel(item)).collect(Collectors.toList());
|
||||
List<UserListingModel> modelUsers = pagedUsers.select(item -> new UserListingModel().fromDataModel(item));
|
||||
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,20 @@ import eu.eudat.security.validators.TokenValidatorFactoryImpl;
|
|||
|
||||
public class LoginProviderUser {
|
||||
private String name;
|
||||
private String id;
|
||||
private String email;
|
||||
private String secret;
|
||||
private boolean isVerified;
|
||||
private TokenValidatorFactoryImpl.LoginProvider provider;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -13,13 +13,17 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface QueryableList<T extends DataEntity<T>> {
|
||||
public interface QueryableList<T extends DataEntity> {
|
||||
QueryableList<T> where(SinglePredicate<T> predicate);
|
||||
|
||||
<R> List<R> select(SelectPredicate<T, R> predicate);
|
||||
|
||||
<R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate);
|
||||
|
||||
List<T> toList();
|
||||
|
||||
QueryableList<T> withFields(List<String> fields);
|
||||
|
||||
CompletableFuture<List<T>> toListAsync();
|
||||
|
||||
T getSingle();
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QueryableHibernateList<T extends DataEntity<T>> implements QueryableList<T> {
|
||||
public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> {
|
||||
|
||||
private EntityManager manager;
|
||||
private CriteriaQuery<T> query;
|
||||
|
@ -33,7 +33,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
|
||||
|
||||
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
|
||||
private List<Selection> fields = new LinkedList<>();
|
||||
private List<String> fields = new LinkedList<>();
|
||||
private Integer length;
|
||||
private Integer offset;
|
||||
private Set<String> hints;
|
||||
|
@ -59,6 +59,18 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<T> withFields(List<String> fields) {
|
||||
this.fields = fields;
|
||||
return this;
|
||||
}
|
||||
|
||||
private QueryableList<T> selectFields() {
|
||||
List<Selection> rootFields = fields.stream().map(field -> root.get(field)).collect(Collectors.toList());
|
||||
this.query.select(this.manager.getCriteriaBuilder().construct(tClass, rootFields.toArray(new Selection[rootFields.size()])));
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
||||
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
||||
this.query = builder.createQuery(type);
|
||||
|
@ -94,12 +106,11 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public <R> List<R> select(SelectPredicate<T, R> predicate) {
|
||||
List<T> list = this.toList();
|
||||
List<R> newlist = new LinkedList<R>();
|
||||
for (T item : list) {
|
||||
newlist.add(predicate.applySelection(item));
|
||||
}
|
||||
return newlist;
|
||||
return this.toList().stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public <R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate) {
|
||||
return this.toListAsync().thenApplyAsync(items -> items.stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public QueryableList<T> distinct() {
|
||||
|
@ -163,14 +174,14 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public List<T> toList() {
|
||||
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||
if (this.hint != null && this.hints.contains(hint)) {
|
||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList());
|
||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
||||
}
|
||||
return typedQuery.getResultList();
|
||||
|
@ -179,12 +190,13 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
public CompletableFuture<List<T>> toListAsync() {
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (this.hint != null && this.hints.contains(hint)) {
|
||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList());
|
||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
||||
}
|
||||
return typedQuery.getResultList();
|
||||
|
@ -193,6 +205,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
|
||||
public T getSingle() {
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||
|
@ -201,6 +214,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
|
||||
public CompletableFuture<T> getSingleAsync() {
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||
|
@ -209,7 +223,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
|
||||
public T getSingleOrDefault() {
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
|
||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||
|
@ -221,7 +235,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
|
||||
public CompletableFuture<T> getSingleOrDefaultAsync() {
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
|
||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||
|
@ -236,7 +250,6 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
||||
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);
|
||||
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
|
||||
|
||||
criteriaQuery.where(criteriaRoot.get("id").in(ids));
|
||||
if (!this.orderings.isEmpty())
|
||||
criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package eu.eudat.security.customproviders;
|
||||
|
||||
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/22/2018.
|
||||
*/
|
||||
public interface B2AccessCustomProvider {
|
||||
B2AccessUser getUser(String accessToken);
|
||||
|
||||
B2AccessResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret);
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package eu.eudat.security.customproviders;
|
||||
|
||||
import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
|
||||
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/22/2018.
|
||||
*/
|
||||
@Component("b2AccessCustomProvider")
|
||||
public class B2AccessCustomProviderImpl implements B2AccessCustomProvider {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
public B2AccessCustomProviderImpl(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public B2AccessUser getUser(String accessToken) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders headers = this.createBearerAuthHeaders(accessToken);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
Map<String, Object> values = restTemplate.exchange(this.environment.getProperty("b2access.externallogin.user_info_url"), HttpMethod.GET, entity, Map.class).getBody();
|
||||
B2AccessUser b2AccessUser = new B2AccessUser();
|
||||
b2AccessUser.setEmail((String)values.get("email"));
|
||||
b2AccessUser.setId((String)values.get("urn:oid:2.5.4.49"));
|
||||
b2AccessUser.setName((String)values.get("name"));
|
||||
return b2AccessUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public B2AccessResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret) {
|
||||
RestTemplate template = new RestTemplate();
|
||||
HttpHeaders headers = this.createBasicAuthHeaders(clientId, clientSecret);
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||
map.add("code", code);
|
||||
map.add("grant_type", "authorization_code");
|
||||
map.add("redirect_uri", redirectUri);
|
||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
||||
|
||||
|
||||
Map<String, Object> values = template.postForObject(this.environment.getProperty("b2access.externallogin.access_token_url"), request, Map.class);
|
||||
B2AccessResponseToken b2AccessResponseToken = new B2AccessResponseToken();
|
||||
b2AccessResponseToken.setAccessToken((String) values.get("access_token"));
|
||||
return b2AccessResponseToken;
|
||||
}
|
||||
|
||||
private HttpHeaders createBasicAuthHeaders(String username, String password) {
|
||||
return new HttpHeaders() {{
|
||||
String auth = username + ":" + password;
|
||||
byte[] encodedAuth = Base64.encodeBase64(
|
||||
auth.getBytes(Charset.forName("US-ASCII")));
|
||||
String authHeader = "Basic " + new String(encodedAuth);
|
||||
set("Authorization", authHeader);
|
||||
}};
|
||||
}
|
||||
|
||||
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
||||
return new HttpHeaders() {{
|
||||
String authHeader = "Bearer " + new String(accessToken);
|
||||
set("Authorization", authHeader);
|
||||
}};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package eu.eudat.security.customproviders;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/22/2018.
|
||||
*/
|
||||
public class B2AccessUser {
|
||||
private String id;
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.security.validators;
|
||||
|
||||
import eu.eudat.security.validators.b2access.B2AccessTokenValidator;
|
||||
import eu.eudat.security.validators.facebook.FacebookTokenValidator;
|
||||
import eu.eudat.security.validators.google.GoogleTokenValidator;
|
||||
import eu.eudat.security.validators.linkedin.LinkedInTokenValidator;
|
||||
|
@ -11,7 +12,7 @@ import org.springframework.stereotype.Service;
|
|||
@Service("tokenValidatorFactory")
|
||||
public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
||||
public enum LoginProvider {
|
||||
GOOGLE((short) 1), FACEBOOK((short) 2), TWITTER((short) 3), LINKEDIN((short) 4), NATIVELOGIN((short) 5);
|
||||
GOOGLE((short) 1), FACEBOOK((short) 2), TWITTER((short) 3), LINKEDIN((short) 4), NATIVELOGIN((short) 5), B2_ACCESS((short) 6);
|
||||
|
||||
private short value;
|
||||
|
||||
|
@ -35,6 +36,8 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
|||
return LINKEDIN;
|
||||
case 5:
|
||||
return NATIVELOGIN;
|
||||
case 6:
|
||||
return B2_ACCESS;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported LoginProvider");
|
||||
}
|
||||
|
@ -45,13 +48,16 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
|||
private FacebookTokenValidator facebookTokenValidator;
|
||||
private LinkedInTokenValidator linkedInTokenValidator;
|
||||
private TwitterTokenValidator twitterTokenValidator;
|
||||
private B2AccessTokenValidator b2AccessTokenValidator;
|
||||
|
||||
@Autowired
|
||||
public TokenValidatorFactoryImpl(GoogleTokenValidator googleTokenValidator, FacebookTokenValidator facebookTokenValidator, LinkedInTokenValidator linkedInTokenValidator, TwitterTokenValidator twitterTokenValidator) {
|
||||
public TokenValidatorFactoryImpl(GoogleTokenValidator googleTokenValidator, FacebookTokenValidator facebookTokenValidator,
|
||||
LinkedInTokenValidator linkedInTokenValidator, TwitterTokenValidator twitterTokenValidator,B2AccessTokenValidator b2AccessTokenValidator) {
|
||||
this.googleTokenValidator = googleTokenValidator;
|
||||
this.facebookTokenValidator = facebookTokenValidator;
|
||||
this.linkedInTokenValidator = linkedInTokenValidator;
|
||||
this.twitterTokenValidator = twitterTokenValidator;
|
||||
this.b2AccessTokenValidator = b2AccessTokenValidator;
|
||||
}
|
||||
|
||||
public TokenValidator getProvider(LoginProvider provider) {
|
||||
|
@ -64,6 +70,8 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
|||
return this.linkedInTokenValidator;
|
||||
case TWITTER:
|
||||
return this.twitterTokenValidator;
|
||||
case B2_ACCESS:
|
||||
return this.b2AccessTokenValidator;
|
||||
default:
|
||||
throw new RuntimeException("Login Provider Not Implemented");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package eu.eudat.security.validators.b2access;
|
||||
|
||||
import eu.eudat.exceptions.security.NonValidTokenException;
|
||||
import eu.eudat.models.login.LoginInfo;
|
||||
import eu.eudat.models.loginprovider.LoginProviderUser;
|
||||
import eu.eudat.models.security.Principal;
|
||||
import eu.eudat.security.customproviders.B2AccessCustomProvider;
|
||||
import eu.eudat.security.customproviders.B2AccessUser;
|
||||
import eu.eudat.security.validators.TokenValidator;
|
||||
import eu.eudat.security.validators.b2access.helpers.B2AccessRequest;
|
||||
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||
import eu.eudat.services.AuthenticationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/22/2018.
|
||||
*/
|
||||
@Component("b2AccessTokenValidator ")
|
||||
public class B2AccessTokenValidator implements TokenValidator {
|
||||
|
||||
private B2AccessCustomProvider b2AccessCustomProvider;
|
||||
private AuthenticationService authenticationService;
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
public B2AccessTokenValidator(AuthenticationService authenticationService, Environment environment, B2AccessCustomProvider b2AccessCustomProvider) {
|
||||
this.authenticationService = authenticationService;
|
||||
this.environment = environment;
|
||||
this.b2AccessCustomProvider = b2AccessCustomProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException {
|
||||
B2AccessUser b2AccessUser = this.b2AccessCustomProvider.getUser(credentials.getTicket());
|
||||
LoginProviderUser user = new LoginProviderUser();
|
||||
user.setId(b2AccessUser.getId());
|
||||
user.setEmail(b2AccessUser.getEmail());
|
||||
user.setName(b2AccessUser.getName());
|
||||
user.setProvider(credentials.getProvider());
|
||||
user.setSecret(credentials.getTicket());
|
||||
return this.authenticationService.Touch(user);
|
||||
}
|
||||
|
||||
public B2AccessResponseToken getAccessToken(B2AccessRequest b2AccessRequest) {
|
||||
return this.b2AccessCustomProvider.getAccessToken(b2AccessRequest.getCode(), this.environment.getProperty("b2access.externallogin.redirect_uri")
|
||||
, this.environment.getProperty("b2access.externallogin.clientid")
|
||||
, this.environment.getProperty("b2access.externallogin.clientSecret"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.security.validators.b2access.helpers;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/22/2018.
|
||||
*/
|
||||
public class B2AccessRequest {
|
||||
private String code;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.security.validators.b2access.helpers;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/22/2018.
|
||||
*/
|
||||
public class B2AccessResponseToken {
|
||||
private String accessToken;
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ public class FacebookTokenValidator implements TokenValidator {
|
|||
if (profile.getEmail() == null)
|
||||
throw new UnauthorisedException("Cannot login user.Facebook account did not provide email");
|
||||
user.setEmail(profile.getEmail());
|
||||
user.setId(profile.getId());
|
||||
user.setIsVerified(profile.isVerified());
|
||||
user.setName(profile.getName());
|
||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.FACEBOOK);
|
||||
|
|
|
@ -47,11 +47,11 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
|
||||
@Override
|
||||
public eu.eudat.models.security.Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException {
|
||||
|
||||
GoogleIdToken idToken = this.verifyUserAndGetUser(credentials.getTicket());
|
||||
Payload payload = idToken.getPayload();
|
||||
LoginProviderUser user = new LoginProviderUser();
|
||||
user.setSecret(credentials.getTicket());
|
||||
user.setId( payload.getSubject());
|
||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.GOOGLE);
|
||||
user.setName((String) payload.get("name"));
|
||||
user.setEmail(payload.getEmail());
|
||||
|
|
|
@ -47,6 +47,7 @@ public class LinkedInTokenValidator implements TokenValidator {
|
|||
if (linkedInProfile.getEmailAddress() == null)
|
||||
throw new UnauthorisedException("Cannot login user.LinkedIn account did not provide email");
|
||||
user.setEmail(linkedInProfile.getEmailAddress());
|
||||
user.setId(linkedInProfile.getId());
|
||||
user.setIsVerified(true); //TODO
|
||||
user.setName(linkedInProfile.getFirstName() + " " + linkedInProfile.getLastName());
|
||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.LINKEDIN);
|
||||
|
|
|
@ -54,6 +54,7 @@ public class TwitterTokenValidator implements TokenValidator {
|
|||
throw new UnauthorisedException("Cannot login user.Twitter account did not provide email");
|
||||
user.setEmail((String) values.get("email"));
|
||||
user.setIsVerified(true); //TODO
|
||||
user.setId(""+profile.getId());
|
||||
user.setName(profile.getName());
|
||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.TWITTER);
|
||||
user.setSecret(finalOauthToken.getValue());
|
||||
|
|
|
@ -91,12 +91,21 @@ public class AuthenticationService {
|
|||
public Principal Touch(LoginProviderUser profile) {
|
||||
UserInfoCriteria criteria = new UserInfoCriteria();
|
||||
criteria.setEmail(profile.getEmail());
|
||||
|
||||
UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.equal(root.get("email"), profile.getEmail())).getSingleOrDefault();
|
||||
|
||||
if(userInfo == null){
|
||||
Optional<Credential> optionalCredential = Optional.ofNullable(apiContext.getDatabaseRepository().getCredentialDao()
|
||||
.asQueryable().withHint("credentialUserInfo")
|
||||
.where((builder, root) -> builder.and(builder.equal(root.get("provider"), profile.getProvider().getValue()), builder.equal(root.get("externalId"), profile.getId())))
|
||||
.getSingleOrDefault());
|
||||
userInfo = optionalCredential.map(Credential::getUserInfo).orElse(null);
|
||||
}
|
||||
|
||||
final Credential credential = this.apiContext.getBuilderFactory().getBuilder(CredentialBuilder.class)
|
||||
.id(UUID.randomUUID()).creationTime(new Date()).status(1)
|
||||
.lastUpdateTime(new Date()).provider((int) profile.getProvider().getValue())
|
||||
.secret(profile.getSecret())
|
||||
.secret(profile.getSecret()).externalId(profile.getId())
|
||||
.build();
|
||||
|
||||
if (userInfo == null) {
|
||||
|
|
|
@ -49,4 +49,10 @@ spring.profiles.active=devel
|
|||
########################Persistence/Hibernate/Connection pool####################
|
||||
autouser.root.email=root@dmp.com
|
||||
autouser.root.password=root
|
||||
autouser.root.username=root
|
||||
autouser.root.username=root
|
||||
#################################################################################
|
||||
b2access.externallogin.user_info_url = https://unity.eudat-aai.fz-juelich.de:443/oauth2/userinfo
|
||||
b2access.externallogin.access_token_url = https://unity.eudat-aai.fz-juelich.de:443/oauth2/token
|
||||
b2access.externallogin.redirect_uri = http://dmp.eudat.org:4200/api/oauth/authorized/b2access
|
||||
b2access.externallogin.clientid = eudatdmptool
|
||||
b2access.externallogin.clientSecret = A3b*1*92
|
|
@ -6,6 +6,7 @@ import { HomepageComponent } from './homepage/homepage.component';
|
|||
import { AuthGuard } from './guards/auth.guard';
|
||||
import { LoginComponent } from './user-management/login/login.component';
|
||||
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
|
||||
import { B2AccessLoginComponent } from './user-management/login/b2access/b2access-login.component';
|
||||
|
||||
const appRoutes: Routes = [
|
||||
{ path: 'datasets', loadChildren: './datasets/dataset.module#DatasetModule', canActivate: [AuthGuard] },
|
||||
|
@ -17,7 +18,8 @@ const appRoutes: Routes = [
|
|||
{ path: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' },
|
||||
{ path: "users", loadChildren: './users/users.module#UsersModule' },
|
||||
{ path: "datasetsProfiles", loadChildren: './datasets-admin-listing/dataset-admin.module#DatasetAdminModule' },
|
||||
{ path: "welcome", component: WelcomepageComponent }
|
||||
{ path: "welcome", component: WelcomepageComponent },
|
||||
{ path: "api/oauth/authorized/b2access", component: B2AccessLoginComponent }
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
|
|
@ -33,6 +33,7 @@ import { DatasetProfileModule } from './dataset-profile-form/dataset-profile.mod
|
|||
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
|
||||
import { HelpContentService } from './services/help-content/help-content.service';
|
||||
import { HelpContentComponent } from './help-content/help-content.component';
|
||||
import { B2AccessLoginComponent } from './user-management/login/b2access/b2access-login.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -40,7 +41,8 @@ import { HelpContentComponent } from './help-content/help-content.component';
|
|||
PageNotFoundComponent,
|
||||
HomepageComponent,
|
||||
WelcomepageComponent,
|
||||
HelpContentComponent
|
||||
HelpContentComponent,
|
||||
B2AccessLoginComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
@ -53,7 +55,8 @@ import { HelpContentComponent } from './help-content/help-content.component';
|
|||
LoginOptions.googleOauth,
|
||||
LoginOptions.nativeLogin,
|
||||
LoginOptions.linkedInOauth,
|
||||
LoginOptions.twitterOauth
|
||||
LoginOptions.twitterOauth,
|
||||
LoginOptions.b2Access
|
||||
],
|
||||
facebookConfiguration: { clientId: "110586756143149" },
|
||||
googleConfiguration: { clientId: '524432312250-sc9qsmtmbvlv05r44onl6l93ia3k9deo.apps.googleusercontent.com' },
|
||||
|
@ -64,7 +67,14 @@ import { HelpContentComponent } from './help-content/help-content.component';
|
|||
accessTokenUri: "https://www.linkedin.com/oauth/v2/accessToken",
|
||||
clientSecret: "2OCO9e3wKylW05Tt"
|
||||
},
|
||||
twitterConfiguration: { clientId: "HiR4hQH9HNubKC5iKQy0l4mAZ", oauthUrl: "https://api.twitter.com/oauth/authenticate" }
|
||||
twitterConfiguration: { clientId: "HiR4hQH9HNubKC5iKQy0l4mAZ", oauthUrl: "https://api.twitter.com/oauth/authenticate" },
|
||||
b2accessConfiguration: {
|
||||
clientId: "eudatdmptool",
|
||||
clientSecret: "A3b*1*92",
|
||||
oauthUrl: "https://unity.eudat-aai.fz-juelich.de/oauth2-as/oauth2-authz",
|
||||
redirectUri: "http://dmp.eudat.org:4200/api/oauth/authorized/b2access",
|
||||
accessTokenUri: "https://unity.eudat-aai.fz-juelich.de:443/oauth2/token"
|
||||
}
|
||||
}),
|
||||
HttpModule,
|
||||
HttpClientModule,
|
||||
|
|
|
@ -2,8 +2,10 @@ export enum LoginProviders {
|
|||
Google = 1,
|
||||
Facebook = 2,
|
||||
Twitter = 3,
|
||||
LinkedIn = 4
|
||||
}
|
||||
LinkedIn = 4,
|
||||
NativeLogin = 5,
|
||||
B2Accesss = 6
|
||||
}
|
||||
|
||||
export class LoginInfo {
|
||||
public ticket: string;
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
<mat-toolbar color="primary">
|
||||
<a class="app-title" routerLink="/">{{'NAV-BAR.TITLE' | translate}}</a>
|
||||
<div *ngIf="isAuthenticated()">
|
||||
<button mat-button class="navbar-button" routerLink="/projects">{{'NAV-BAR.PROJECTS' | translate}}</button>
|
||||
<button mat-button class="navbar-button" routerLink="/dmps">{{'NAV-BAR.DMPS' | translate}}</button>
|
||||
<button mat-button class="navbar-button" routerLink="/datasets">{{'NAV-BAR.DATASETS' | translate}}</button>
|
||||
<button *ngIf="isAdmin()" mat-button class="navbar-button" routerLink="/users">{{'NAV-BAR.USERS' | translate}}</button>
|
||||
<button *ngIf="isAdmin()" mat-button class="navbar-button" routerLink="/datasetsProfiles">{{'NAV-BAR.DATASETS(ADMIN)' | translate}}</button>
|
||||
</div>
|
||||
<span class="navbar-spacer"></span>
|
||||
<div *ngIf="isAuthenticated();else loginoption">
|
||||
<span class="user-label">{{this.getPrincipalName()}}</span>
|
||||
<button mat-icon-button class="navbar-icon" (click)="logout()">
|
||||
<mat-icon class="navbar-icon">exit_to_app</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
<ng-template #loginoption>
|
||||
<a class="app-title" routerLink="/">{{'NAV-BAR.TITLE' | translate}}</a>
|
||||
<div *ngIf="isAuthenticated()">
|
||||
<button mat-button class="navbar-button" routerLink="/projects">{{'NAV-BAR.PROJECTS' | translate}}</button>
|
||||
<button mat-button class="navbar-button" routerLink="/dmps">{{'NAV-BAR.DMPS' | translate}}</button>
|
||||
<button mat-button class="navbar-button" routerLink="/datasets">{{'NAV-BAR.DATASETS' | translate}}</button>
|
||||
<button *ngIf="isAdmin()" mat-button class="navbar-button" routerLink="/users">{{'NAV-BAR.USERS' | translate}}</button>
|
||||
<button *ngIf="isAdmin()" mat-button class="navbar-button" routerLink="/datasetsProfiles">{{'NAV-BAR.DATASETS(ADMIN)' | translate}}</button>
|
||||
</div>
|
||||
<span class="navbar-spacer"></span>
|
||||
<div *ngIf="isAuthenticated();else loginoption">
|
||||
<span class="user-label">{{this.getPrincipalName()}}</span>
|
||||
<button mat-icon-button class="navbar-icon" (click)="logout()">
|
||||
<mat-icon class="navbar-icon">exit_to_app</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
<ng-template #loginoption>
|
||||
<button mat-button [routerLink]=" ['/login'] ">
|
||||
<span class="login-label">Log in</span>
|
||||
<button mat-icon-button class="navbar-icon" [routerLink]=" ['/login'] ">
|
||||
<mat-icon class="navbar-icon">input</mat-icon>
|
||||
</button>
|
||||
</ng-template>
|
||||
</mat-toolbar>
|
||||
</button>
|
||||
</ng-template>
|
||||
</mat-toolbar>
|
|
@ -0,0 +1,26 @@
|
|||
import { LoginService } from '../../utilties/login-service';
|
||||
import { Component, OnInit } from '@angular/core'
|
||||
import { Router, ActivatedRoute, Params } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'b2access-login',
|
||||
templateUrl: './b2access-login.component.html',
|
||||
})
|
||||
export class B2AccessLoginComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private loginService: LoginService
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParams.subscribe((data: any) => {
|
||||
if (!data["code"]) this.loginService.b2AccessGetAuthCode()
|
||||
else this.loginService.b2AccessLogin(data["code"])
|
||||
})
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
<i class="fa fa-twitter"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn btn_red"><span class="iconmedium"></span><a href="#"></a><span></span></div>
|
||||
<button *ngIf="hasB2AccessOauth()" class="mat-icon-button" (click)="b2AccessLogin()" ><span class="iconmedium"></span><span></span></button>
|
||||
</div>
|
||||
<div *ngIf="hasNativeLogin()">
|
||||
<!-- <p class="tip">Or Be Classical</p> -->
|
||||
|
@ -38,7 +38,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button mat-button (click)="nativeLogin()">LET'S GO</button>
|
||||
<button mat-button (click)="nativeLogin()">LOGIN</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -45,6 +45,11 @@ export class LoginComponent implements OnInit {
|
|||
public nativeLogin() {
|
||||
this.loginService.nativeLogin(this.credential);
|
||||
}
|
||||
|
||||
public b2AccessLogin() {
|
||||
return this.loginService.b2AccessInitialiseLogin();
|
||||
}
|
||||
|
||||
public hasFacebookOauth(): boolean {
|
||||
return this.loginService.hasProvider(LoginOptions.facebookOauth);
|
||||
}
|
||||
|
@ -65,4 +70,8 @@ export class LoginComponent implements OnInit {
|
|||
return this.loginService.hasProvider(LoginOptions.nativeLogin);
|
||||
}
|
||||
|
||||
public hasB2AccessOauth(): boolean {
|
||||
return this.loginService.hasProvider(LoginOptions.b2Access);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,5 +4,6 @@ export enum LoginOptions{
|
|||
twitterOauth = 3,
|
||||
googleOauth = 4,
|
||||
nativeLogin = 5,
|
||||
all = 6
|
||||
b2Access = 6,
|
||||
all = 7,
|
||||
}
|
|
@ -17,4 +17,11 @@ export class LinkedInConfiguration extends LoginProviderConfiguration {
|
|||
public redirectUri: string
|
||||
public accessTokenUri: string
|
||||
public clientSecret: string
|
||||
}
|
||||
|
||||
export class B2AccessConfiguration extends LoginProviderConfiguration {
|
||||
public oauthUrl: string
|
||||
public redirectUri: string
|
||||
public accessTokenUri: string
|
||||
public clientSecret: string
|
||||
}
|
|
@ -3,6 +3,7 @@ import {
|
|||
GoogleLoginConfiguration,
|
||||
LinkedInConfiguration,
|
||||
TwitterLoginConfiguration,
|
||||
B2AccessConfiguration,
|
||||
} from './LoginProviderConfiguration';
|
||||
import { LoginOptions } from './LoginOptions';
|
||||
export class LoginServiceConfiguration {
|
||||
|
@ -11,4 +12,5 @@ export class LoginServiceConfiguration {
|
|||
public googleConfiguration?: GoogleLoginConfiguration;
|
||||
public twitterConfiguration?: TwitterLoginConfiguration;
|
||||
public linkedInConfiguration?: LinkedInConfiguration;
|
||||
public b2accessConfiguration?: B2AccessConfiguration;
|
||||
}
|
|
@ -56,6 +56,7 @@ export class LoginService {
|
|||
case LoginOptions.googleOauth: return this.hasAllRequiredFieldsConfigured(this.config.googleConfiguration)
|
||||
case LoginOptions.linkedInOauth: return this.hasAllRequiredFieldsConfigured(this.config.linkedInConfiguration);
|
||||
case LoginOptions.twitterOauth: return this.hasAllRequiredFieldsConfigured(this.config.twitterConfiguration);
|
||||
case LoginOptions.b2Access: return this.hasAllRequiredFieldsConfigured(this.config.b2accessConfiguration);
|
||||
case LoginOptions.nativeLogin: return true;
|
||||
default: throw new Error("Unsupported Provider Type")
|
||||
}
|
||||
|
@ -169,6 +170,31 @@ export class LoginService {
|
|||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* B2ACCESS LOG IN
|
||||
*/
|
||||
|
||||
public b2AccessInitialiseLogin() {
|
||||
this.router.navigate(["/api/oauth/authorized/b2access"])
|
||||
}
|
||||
|
||||
public b2AccessGetAuthCode() {
|
||||
window.location.href = this.config.b2accessConfiguration.oauthUrl + "?response_type=code&client_id=" + this.config.b2accessConfiguration.clientId + "&redirect_uri=" + this.config.b2accessConfiguration.redirectUri + "&state=987654321&scope=USER_PROFILE"
|
||||
}
|
||||
|
||||
public b2AccessLogin(code: String) {
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.set('Content-Type', 'application/json');
|
||||
headers = headers.set('Accept', 'application/json');
|
||||
this.httpClient.post(HostConfiguration.Server + "auth/b2AccessRequestToken", { code: code }, { headers: headers })
|
||||
.subscribe((data: any) => {
|
||||
this.authService.login({ ticket: data.payload.accessToken, provider: LoginProviders.B2Accesss, data: null }).subscribe(
|
||||
res => this.onLogInSuccess(res),
|
||||
error => this.onLogInError(error)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* NATIVE LOGIN
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
|
||||
export const environment = {
|
||||
production: false,
|
||||
Server: 'http://192.168.32.64:8080/api/',
|
||||
Server: 'http://devel-21.local.cite.gr:8080/api/',
|
||||
App: 'localhost:4200/'
|
||||
};
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<script src="https://apis.google.com/js/platform.js"></script>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
|
@ -12,14 +14,14 @@
|
|||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
<script src="//connect.facebook.net/en_US/all.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
||||
<script src="https://apis.google.com/js/platform.js" async defer></script>
|
||||
<script type="text/javascript" src="//platform.linkedin.com/in.js">
|
||||
api_key: 86bl8vfk77clh9
|
||||
</script>
|
||||
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
|
||||
crossorigin="anonymous">
|
||||
|
||||
</head>
|
||||
|
||||
|
|
Loading…
Reference in New Issue