no message
This commit is contained in:
parent
5cc601b0da
commit
c1f2c615af
|
@ -2,6 +2,7 @@ package eu.eudat.controllers;
|
|||
|
||||
import eu.eudat.models.login.Credentials;
|
||||
import eu.eudat.models.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.login.LoginInfo;
|
||||
import eu.eudat.models.security.Principal;
|
||||
import eu.eudat.security.CustomAuthenticationProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -19,8 +20,8 @@ public class Login {
|
|||
@Autowired
|
||||
private CustomAuthenticationProvider customAuthenticationProvider;
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/googlelogin" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody Credentials credentials) {
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) {
|
||||
try {
|
||||
return new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(HttpStatus.OK);
|
||||
|
||||
|
|
|
@ -97,10 +97,14 @@ public class Projects {
|
|||
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/projects/add" }, consumes = "application/json", produces="application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/projects/createOrUpdate" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseItem<eu.eudat.entities.Project> addProject(@RequestBody eu.eudat.models.project.Project project) {
|
||||
try {
|
||||
Project createdProject = projectDao.createOrUpdate(project.toDataModel());
|
||||
return new ResponseItem<eu.eudat.entities.Project>().payload(createdProject).status(HttpStatus.OK);
|
||||
return new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.OK);
|
||||
}catch (Exception ex){
|
||||
return new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@ public class DatasetDaoImpl implements DatasetDao {
|
|||
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
|
||||
QueryableList<Dataset> query = databaseService.getQueryable(Dataset.class);
|
||||
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
|
||||
if(criteria.getStatus()!=null)query.where((builder, root) -> builder.equal(root.get("status"),criteria.getStatus()));
|
||||
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
|
||||
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart()));
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,25 +14,25 @@ import java.util.UUID;
|
|||
public class Credential {
|
||||
|
||||
@Id
|
||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="userid", nullable=false)
|
||||
@JoinColumn(name="\"UserId\"", nullable=false)
|
||||
private UserInfo userInfo;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
@Column(name = "\"Status\"", nullable = false)
|
||||
private Integer status;
|
||||
|
||||
@Column(name = "provider", nullable = false)
|
||||
@Column(name = "\"Provider\"", nullable = false)
|
||||
private Integer provider;
|
||||
@Column(name = "publicValue", nullable = false)
|
||||
@Column(name = "\"Public\"", nullable = false)
|
||||
private String publicValue;
|
||||
@Column(name = "secret", nullable = false)
|
||||
@Column(name = "\"Secret\"", nullable = false)
|
||||
private String secret;
|
||||
@Column(name = "creationtime", nullable = false)
|
||||
@Column(name = "\"CreationTime\"", nullable = false)
|
||||
private Date creationTime;
|
||||
@Column(name = "lastupdatetime", nullable = false)
|
||||
@Column(name = "\"LastUpdateTime\"", nullable = false)
|
||||
private Date lastUpdateTime;
|
||||
|
||||
public UUID getId() {
|
||||
|
|
|
@ -229,7 +229,14 @@ public class Project implements Serializable,DataEntity<Project> {
|
|||
|
||||
@Override
|
||||
public void update(Project entity) {
|
||||
|
||||
this.description = entity.getDescription();
|
||||
this.label = entity.getLabel();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.created = entity.getCreated();
|
||||
this.definition = entity.getDefinition();
|
||||
this.dmps = entity.getDmps();
|
||||
this.enddate = entity.getEnddate();
|
||||
//this.creationUser = entity.getCreationUser(); //TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,18 +14,18 @@ public class UserToken implements DataEntity<UserToken>{
|
|||
private static final long serialVersionUID = 1225151430484658395L;
|
||||
|
||||
@Id
|
||||
@Column(name = "token", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID token;
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "userid", nullable = false)
|
||||
@JoinColumn(name = "\"UserId\"", nullable = false)
|
||||
private UserInfo user;
|
||||
|
||||
@Column(name = "issuedat", nullable = false)
|
||||
@Column(name = "\"IssuedAt\"", nullable = false)
|
||||
private Date issuedAt = null;
|
||||
|
||||
|
||||
@Column(name = "expiresat", nullable = false)
|
||||
@Column(name = "\"ExpiresAt\"", nullable = false)
|
||||
private Date expiresAt = null;
|
||||
|
||||
public UUID getToken() {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package eu.eudat.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/18/2017.
|
||||
*/
|
||||
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
|
||||
public class UnauthorisedException extends RuntimeException{
|
||||
public UnauthorisedException() {
|
||||
super();
|
||||
}
|
||||
public UnauthorisedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public UnauthorisedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public UnauthorisedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
package eu.eudat.handlers;
|
||||
|
||||
import eu.eudat.exceptions.UnauthorisedException;
|
||||
import eu.eudat.models.security.Principal;
|
||||
import eu.eudat.services.AuthenticationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
@ -15,6 +18,7 @@ import java.util.UUID;
|
|||
*/
|
||||
public final class PrincipalArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
private AuthenticationService authenticationService;
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter methodParameter) {
|
||||
return methodParameter.getParameterType().equals(Principal.class);
|
||||
|
@ -22,12 +26,23 @@ public final class PrincipalArgumentResolver implements HandlerMethodArgumentRes
|
|||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter,ModelAndViewContainer modelAndViewContainer,NativeWebRequest nativeWebRequest,WebDataBinderFactory webDataBinderFactory) throws Exception {
|
||||
Principal principal = new Principal();
|
||||
principal.setName("Giannis");
|
||||
principal.setId(UUID.randomUUID());
|
||||
principal.setExpiresAt(new Date());
|
||||
principal.setToken(UUID.randomUUID());
|
||||
String token = nativeWebRequest.getHeader("AuthToken");
|
||||
if(token == null)throw new UnauthorisedException("Authentication Information Is Missing");
|
||||
UUID authToken;
|
||||
try{
|
||||
authToken = UUID.fromString(token);
|
||||
}catch (IllegalArgumentException ex){
|
||||
throw new UnauthorisedException("Authentication Information Is Missing");
|
||||
}
|
||||
|
||||
Principal principal = this.authenticationService.Touch(authToken);
|
||||
if(principal==null)throw new UnauthorisedException("Authentication Information Missing");
|
||||
return principal;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void PrincipalArgumentResolver(AuthenticationService authenticationService){
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,8 +2,37 @@ package eu.eudat.models.criteria;
|
|||
|
||||
import eu.eudat.entities.Dataset;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
public class DatasetCriteria extends Criteria<Dataset>{
|
||||
private Integer status;
|
||||
private Date periodStart;
|
||||
private Date periodEnd;
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getPeriodStart() {
|
||||
return periodStart;
|
||||
}
|
||||
|
||||
public void setPeriodStart(Date periodStart) {
|
||||
this.periodStart = periodStart;
|
||||
}
|
||||
|
||||
public Date getPeriodEnd() {
|
||||
return periodEnd;
|
||||
}
|
||||
|
||||
public void setPeriodEnd(Date periodEnd) {
|
||||
this.periodEnd = periodEnd;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import eu.eudat.models.datasetprofile.DatasetProfileListingModel;
|
|||
import eu.eudat.models.dmp.DataManagementPlan;
|
||||
import eu.eudat.utilities.builders.DomainModelConverter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -18,6 +19,7 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
private String description;
|
||||
private short status;
|
||||
private String properties;
|
||||
private Date created;
|
||||
private DataManagementPlan dmp;
|
||||
private DatasetProfileListingModel profile;
|
||||
private List<Registry> registries;
|
||||
|
@ -80,7 +82,13 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
this.dataRepositories = dataRepositories;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
|
@ -116,6 +124,7 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
this.registries = new DomainModelConverter<eu.eudat.entities.Registry,Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), Registry.class);
|
||||
this.dataRepositories = new DomainModelConverter<eu.eudat.entities.DataRepository,DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), DataRepository.class);
|
||||
this.services = new DomainModelConverter<eu.eudat.entities.Service,Service>().fromDataModel(entity.getServices().stream().collect(Collectors.toList()), Service.class);
|
||||
this.created = entity.getCreated();
|
||||
}
|
||||
|
||||
public eu.eudat.entities.Dataset toDataModel(){
|
||||
|
@ -128,6 +137,8 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
entity.setStatus(this.status);
|
||||
entity.setDmp(dmp.toDataModel());
|
||||
entity.setDescription(this.description);
|
||||
entity.setCreated(this.created!=null?this.created:new Date());
|
||||
entity.setModified(new Date());
|
||||
entity.setProfile(profile.toDataModel()); ///TODO
|
||||
if(!this.registries.isEmpty()){
|
||||
entity.setRegistries(new HashSet<eu.eudat.entities.Registry>());
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package eu.eudat.models.login;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/18/2017.
|
||||
*/
|
||||
public class LoginInfo {
|
||||
private String ticket;
|
||||
private String service;
|
||||
|
||||
public String getTicket() {
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public void setTicket(String ticket) {
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
}
|
|
@ -9,8 +9,28 @@ import eu.eudat.entities.UserInfo;
|
|||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.dmp.DataManagementPlan;
|
||||
|
||||
|
||||
public class Project implements DataModel<eu.eudat.entities.Project>{
|
||||
|
||||
public enum Status {
|
||||
ACTIVE((short) 0), INACTIVE((short) 1);
|
||||
|
||||
private short value;
|
||||
private Status(short value) { this.value = value; }
|
||||
public short getValue(){return value;}
|
||||
public static Status fromInteger(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return ACTIVE;
|
||||
case 1:
|
||||
return INACTIVE;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported Project Status");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private UUID id;
|
||||
|
||||
private List<DataManagementPlan> dmps;
|
||||
|
@ -25,11 +45,11 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
|
|||
|
||||
private String definition;
|
||||
|
||||
private Date startdate;
|
||||
private Date startDate;
|
||||
|
||||
private Date enddate;
|
||||
private Date endDate;
|
||||
|
||||
private Short status;
|
||||
private Status status;
|
||||
|
||||
private UserInfo creationUser;
|
||||
|
||||
|
@ -96,28 +116,28 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
|
|||
this.definition = definition;
|
||||
}
|
||||
|
||||
public Date getStartdate() {
|
||||
return startdate;
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartdate(Date startdate) {
|
||||
this.startdate = startdate;
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Date getEnddate() {
|
||||
return enddate;
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEnddate(Date enddate) {
|
||||
this.enddate = enddate;
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public Short getStatus() {
|
||||
return status;
|
||||
public short getStatus() {
|
||||
return status.getValue();
|
||||
}
|
||||
|
||||
public void setStatus(Short status) {
|
||||
this.status = status;
|
||||
this.status = Status.fromInteger(status);
|
||||
}
|
||||
|
||||
public UserInfo getCreationUser() {
|
||||
|
@ -160,9 +180,9 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
|
|||
this.reference = entity.getReference();
|
||||
this.uri = entity.getUri();
|
||||
this.definition = entity.getDefinition();
|
||||
this.startdate = entity.getStartdate();
|
||||
this.enddate = entity.getEnddate();
|
||||
this.status = entity.getStatus();
|
||||
this.startDate = entity.getStartdate();
|
||||
this.endDate = entity.getEnddate();
|
||||
this.setStatus(entity.getStatus());
|
||||
this.created = entity.getCreated();
|
||||
this.modified = entity.getModified();
|
||||
this.description = entity.getDescription();
|
||||
|
@ -178,10 +198,10 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
|
|||
entity.setReference(this.reference);
|
||||
entity.setUri(this.uri);
|
||||
entity.setDefinition(this.definition);
|
||||
entity.setStartdate(this.startdate);
|
||||
entity.setStartdate(this.startDate);
|
||||
entity.setCreated(this.created == null? new Date():this.created);
|
||||
entity.setEnddate(this.enddate);
|
||||
entity.setStatus(this.status);
|
||||
entity.setEnddate(this.endDate);
|
||||
entity.setStatus(this.status!=null?this.getStatus():1);
|
||||
entity.setModified(new Date());
|
||||
entity.setDescription(this.description);
|
||||
return entity;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package eu.eudat.security;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.naming.NameAlreadyBoundException;
|
||||
|
||||
import eu.eudat.models.login.Credentials;
|
||||
import eu.eudat.models.login.LoginInfo;
|
||||
import eu.eudat.models.security.Principal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
|
@ -30,14 +32,18 @@ public class CustomAuthenticationProvider {
|
|||
@Autowired private GoogleTokenValidator googleTokenValidator;
|
||||
@Autowired private NativeTokenValidator nativeTokenValidator;
|
||||
|
||||
public Principal authenticate(Credentials credentials) throws AuthenticationException {
|
||||
String token = credentials.getSecret();
|
||||
public Principal authenticate(LoginInfo credentials) throws AuthenticationException {
|
||||
String token = credentials.getTicket();
|
||||
try {
|
||||
Principal principal = googleTokenValidator.validateToken(token);
|
||||
return principal;
|
||||
} catch (NonValidTokenException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Could not validate a user by his token! Reason: " + e.getMessage());
|
||||
throw new AuthenticationServiceException("Token validation failed - Not a valid token");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new AuthenticationServiceException("IO Exeption");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,20 @@
|
|||
package eu.eudat.security.validators;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.Principal;
|
||||
import java.util.*;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.*;
|
||||
import eu.eudat.dao.entities.security.CredentialDao;
|
||||
import eu.eudat.dao.entities.security.UserTokenDao;
|
||||
import eu.eudat.entities.Credential;
|
||||
import eu.eudat.entities.UserToken;
|
||||
import eu.eudat.models.login.LoginInfo;
|
||||
import eu.eudat.services.AuthenticationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
|
@ -24,6 +26,8 @@ import eu.eudat.exceptions.NonValidTokenException;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.sun.org.apache.xalan.internal.xsltc.compiler.Constants.REDIRECT_URI;
|
||||
|
||||
@Component
|
||||
public class GoogleTokenValidator implements TokenValidator {
|
||||
|
||||
|
@ -33,43 +37,38 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
@Autowired private UserInfoDao userInfoDao;
|
||||
@Autowired private CredentialDao credentialDao;
|
||||
@Autowired private AuthenticationService authenticationService;
|
||||
private static final List<String> clientIDs = Arrays.asList(
|
||||
"1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com",
|
||||
"1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com"
|
||||
);
|
||||
@Autowired private UserTokenDao userTokenDao;
|
||||
|
||||
private GoogleIdTokenVerifier verifier = null;
|
||||
private GoogleTokenResponse verifyUser(String authCode) throws IOException {
|
||||
|
||||
|
||||
public GoogleTokenValidator() {
|
||||
verifier = new GoogleIdTokenVerifier.Builder(transport, jacksonFactory)
|
||||
.setAudience(clientIDs)
|
||||
// Or, if multiple clients access the backend:
|
||||
//.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
|
||||
.build();
|
||||
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 String getAccessToken(GoogleTokenResponse response){
|
||||
return response.getAccessToken();
|
||||
}
|
||||
|
||||
private GoogleIdToken getUser(GoogleTokenResponse response) throws IOException {
|
||||
return response.parseIdToken();
|
||||
}
|
||||
@Override
|
||||
public eu.eudat.models.security.Principal validateToken(String token) throws NonValidTokenException {
|
||||
public eu.eudat.models.security.Principal validateToken(String authCode) throws NonValidTokenException, IOException {
|
||||
|
||||
GoogleIdToken idToken = null;
|
||||
try {
|
||||
idToken = verifier.verify(token);
|
||||
}
|
||||
catch(GeneralSecurityException ex) {
|
||||
throw new NonValidTokenException("Token is not valid -> "+ex.getMessage());
|
||||
}
|
||||
catch(IOException ex) {
|
||||
throw new NonValidTokenException("Could not verify token -> "+ex.getMessage());
|
||||
}
|
||||
catch(IllegalArgumentException ex) {
|
||||
throw new NonValidTokenException("Could not verify token");
|
||||
}
|
||||
|
||||
if(idToken == null) {
|
||||
throw new NonValidTokenException("Not a valid token");
|
||||
}
|
||||
GoogleTokenResponse tokenResponse = this.verifyUser(authCode);
|
||||
String token = getAccessToken(tokenResponse);
|
||||
GoogleIdToken idToken = getUser(tokenResponse);
|
||||
|
||||
Payload payload = idToken.getPayload();
|
||||
|
||||
|
@ -78,12 +77,13 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
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
|
||||
userInfo = new UserInfo();
|
||||
userInfo.setName((String)payload.get("name"));
|
||||
|
@ -99,6 +99,7 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
else {
|
||||
userInfo.setLastloggedin(new Date());
|
||||
Set<Credential> credentials = userInfo.getCredentials();
|
||||
if(credentials.contains(credential))credentials.remove(credential);
|
||||
credentials.add(credential);
|
||||
userInfo = userInfoDao.update(userInfo);
|
||||
}
|
||||
|
@ -107,13 +108,20 @@ public class GoogleTokenValidator implements TokenValidator {
|
|||
userToken.setUser(userInfo);
|
||||
userToken.setIssuedAt(new Date());
|
||||
userToken.setToken(UUID.randomUUID());
|
||||
userToken.setExpiresAt(new Date());
|
||||
|
||||
userToken.setExpiresAt(addADay(new Date()));
|
||||
userTokenDao.create(userToken);
|
||||
return authenticationService.Touch(userToken.getToken());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Date addADay(Date date){
|
||||
Date dt = new Date();
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(dt);
|
||||
c.add(Calendar.DATE, 1);
|
||||
dt = c.getTime();
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@ import eu.eudat.entities.UserInfo;
|
|||
import eu.eudat.exceptions.NonValidTokenException;
|
||||
import eu.eudat.models.security.Principal;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface TokenValidator {
|
||||
|
||||
public Principal validateToken(String token) throws NonValidTokenException;
|
||||
public Principal validateToken(String token) throws NonValidTokenException, IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.UUID;
|
|||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
@Service
|
||||
@Service("authenticationService ")
|
||||
public class AuthenticationService {
|
||||
@Autowired
|
||||
UserTokenDao userTokenDao;
|
||||
|
|
|
@ -654,7 +654,6 @@
|
|||
"requires": {
|
||||
"anymatch": "1.3.2",
|
||||
"async-each": "1.0.1",
|
||||
"fsevents": "1.1.3",
|
||||
"glob-parent": "2.0.0",
|
||||
"inherits": "2.0.3",
|
||||
"is-binary-path": "1.0.1",
|
||||
|
@ -1703,7 +1702,6 @@
|
|||
"requires": {
|
||||
"anymatch": "1.3.2",
|
||||
"async-each": "1.0.1",
|
||||
"fsevents": "1.1.3",
|
||||
"glob-parent": "2.0.0",
|
||||
"inherits": "2.0.3",
|
||||
"is-binary-path": "1.0.1",
|
||||
|
@ -3697,910 +3695,6 @@
|
|||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||
"dev": true
|
||||
},
|
||||
"fsevents": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz",
|
||||
"integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"nan": "2.8.0",
|
||||
"node-pre-gyp": "0.6.39"
|
||||
},
|
||||
"dependencies": {
|
||||
"abbrev": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ajv": {
|
||||
"version": "4.11.8",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"co": "4.6.0",
|
||||
"json-stable-stringify": "1.0.1"
|
||||
}
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"are-we-there-yet": {
|
||||
"version": "1.1.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"delegates": "1.0.0",
|
||||
"readable-stream": "2.2.9"
|
||||
}
|
||||
},
|
||||
"asn1": {
|
||||
"version": "0.2.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"assert-plus": {
|
||||
"version": "0.2.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"aws-sign2": {
|
||||
"version": "0.6.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"aws4": {
|
||||
"version": "1.6.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "0.4.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"bcrypt-pbkdf": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"tweetnacl": "0.14.5"
|
||||
}
|
||||
},
|
||||
"block-stream": {
|
||||
"version": "0.0.9",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"inherits": "2.0.3"
|
||||
}
|
||||
},
|
||||
"boom": {
|
||||
"version": "2.10.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"hoek": "2.16.3"
|
||||
}
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.7",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"balanced-match": "0.4.2",
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
},
|
||||
"buffer-shims": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"caseless": {
|
||||
"version": "0.12.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"co": {
|
||||
"version": "4.6.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"delayed-stream": "1.0.0"
|
||||
}
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"cryptiles": {
|
||||
"version": "2.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"boom": "2.10.1"
|
||||
}
|
||||
},
|
||||
"dashdash": {
|
||||
"version": "1.14.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"assert-plus": "1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"assert-plus": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.8",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"deep-extend": {
|
||||
"version": "0.4.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"delegates": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"detect-libc": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ecc-jsbn": {
|
||||
"version": "0.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"jsbn": "0.1.1"
|
||||
}
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"extsprintf": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"forever-agent": {
|
||||
"version": "0.6.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"form-data": {
|
||||
"version": "2.1.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"asynckit": "0.4.0",
|
||||
"combined-stream": "1.0.5",
|
||||
"mime-types": "2.1.15"
|
||||
}
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"fstream": {
|
||||
"version": "1.0.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "4.1.11",
|
||||
"inherits": "2.0.3",
|
||||
"mkdirp": "0.5.1",
|
||||
"rimraf": "2.6.1"
|
||||
}
|
||||
},
|
||||
"fstream-ignore": {
|
||||
"version": "1.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"fstream": "1.0.11",
|
||||
"inherits": "2.0.3",
|
||||
"minimatch": "3.0.4"
|
||||
}
|
||||
},
|
||||
"gauge": {
|
||||
"version": "2.7.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"aproba": "1.1.1",
|
||||
"console-control-strings": "1.1.0",
|
||||
"has-unicode": "2.0.1",
|
||||
"object-assign": "4.1.1",
|
||||
"signal-exit": "3.0.2",
|
||||
"string-width": "1.0.2",
|
||||
"strip-ansi": "3.0.1",
|
||||
"wide-align": "1.1.2"
|
||||
}
|
||||
},
|
||||
"getpass": {
|
||||
"version": "0.1.7",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"assert-plus": "1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"assert-plus": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "1.0.0",
|
||||
"inflight": "1.0.6",
|
||||
"inherits": "2.0.3",
|
||||
"minimatch": "3.0.4",
|
||||
"once": "1.4.0",
|
||||
"path-is-absolute": "1.0.1"
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.1.11",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"har-schema": {
|
||||
"version": "1.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"har-validator": {
|
||||
"version": "4.2.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ajv": "4.11.8",
|
||||
"har-schema": "1.0.5"
|
||||
}
|
||||
},
|
||||
"has-unicode": {
|
||||
"version": "2.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"hawk": {
|
||||
"version": "3.1.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"boom": "2.10.1",
|
||||
"cryptiles": "2.0.5",
|
||||
"hoek": "2.16.3",
|
||||
"sntp": "1.0.9"
|
||||
}
|
||||
},
|
||||
"hoek": {
|
||||
"version": "2.16.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"http-signature": {
|
||||
"version": "1.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"assert-plus": "0.2.0",
|
||||
"jsprim": "1.4.0",
|
||||
"sshpk": "1.13.0"
|
||||
}
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"once": "1.4.0",
|
||||
"wrappy": "1.0.2"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"number-is-nan": "1.0.1"
|
||||
}
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"isstream": {
|
||||
"version": "0.1.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"jodid25519": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"jsbn": "0.1.1"
|
||||
}
|
||||
},
|
||||
"jsbn": {
|
||||
"version": "0.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"json-schema": {
|
||||
"version": "0.2.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"json-stable-stringify": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"jsonify": "0.0.0"
|
||||
}
|
||||
},
|
||||
"json-stringify-safe": {
|
||||
"version": "5.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"jsonify": {
|
||||
"version": "0.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"jsprim": {
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"assert-plus": "1.0.0",
|
||||
"extsprintf": "1.0.2",
|
||||
"json-schema": "0.2.3",
|
||||
"verror": "1.3.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"assert-plus": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.27.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.15",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"mime-db": "1.27.0"
|
||||
}
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"brace-expansion": "1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"node-pre-gyp": {
|
||||
"version": "0.6.39",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"detect-libc": "1.0.2",
|
||||
"hawk": "3.1.3",
|
||||
"mkdirp": "0.5.1",
|
||||
"nopt": "4.0.1",
|
||||
"npmlog": "4.1.0",
|
||||
"rc": "1.2.1",
|
||||
"request": "2.81.0",
|
||||
"rimraf": "2.6.1",
|
||||
"semver": "5.3.0",
|
||||
"tar": "2.2.1",
|
||||
"tar-pack": "3.4.0"
|
||||
}
|
||||
},
|
||||
"nopt": {
|
||||
"version": "4.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"abbrev": "1.1.0",
|
||||
"osenv": "0.1.4"
|
||||
}
|
||||
},
|
||||
"npmlog": {
|
||||
"version": "4.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"are-we-there-yet": "1.1.4",
|
||||
"console-control-strings": "1.1.0",
|
||||
"gauge": "2.7.4",
|
||||
"set-blocking": "2.0.0"
|
||||
}
|
||||
},
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.8.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1.0.2"
|
||||
}
|
||||
},
|
||||
"os-homedir": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"osenv": {
|
||||
"version": "0.1.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"os-homedir": "1.0.2",
|
||||
"os-tmpdir": "1.0.2"
|
||||
}
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"performance-now": {
|
||||
"version": "0.2.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "1.0.7",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"punycode": {
|
||||
"version": "1.4.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"rc": {
|
||||
"version": "1.2.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"deep-extend": "0.4.2",
|
||||
"ini": "1.3.4",
|
||||
"minimist": "1.2.0",
|
||||
"strip-json-comments": "2.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.2.9",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"buffer-shims": "1.0.0",
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
"isarray": "1.0.0",
|
||||
"process-nextick-args": "1.0.7",
|
||||
"string_decoder": "1.0.1",
|
||||
"util-deprecate": "1.0.2"
|
||||
}
|
||||
},
|
||||
"request": {
|
||||
"version": "2.81.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"aws-sign2": "0.6.0",
|
||||
"aws4": "1.6.0",
|
||||
"caseless": "0.12.0",
|
||||
"combined-stream": "1.0.5",
|
||||
"extend": "3.0.1",
|
||||
"forever-agent": "0.6.1",
|
||||
"form-data": "2.1.4",
|
||||
"har-validator": "4.2.1",
|
||||
"hawk": "3.1.3",
|
||||
"http-signature": "1.1.1",
|
||||
"is-typedarray": "1.0.0",
|
||||
"isstream": "0.1.2",
|
||||
"json-stringify-safe": "5.0.1",
|
||||
"mime-types": "2.1.15",
|
||||
"oauth-sign": "0.8.2",
|
||||
"performance-now": "0.2.0",
|
||||
"qs": "6.4.0",
|
||||
"safe-buffer": "5.0.1",
|
||||
"stringstream": "0.0.5",
|
||||
"tough-cookie": "2.3.2",
|
||||
"tunnel-agent": "0.6.0",
|
||||
"uuid": "3.0.1"
|
||||
}
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.6.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "7.1.2"
|
||||
}
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.3.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"set-blocking": {
|
||||
"version": "2.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"sntp": {
|
||||
"version": "1.0.9",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"hoek": "2.16.3"
|
||||
}
|
||||
},
|
||||
"sshpk": {
|
||||
"version": "1.13.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"asn1": "0.2.3",
|
||||
"assert-plus": "1.0.0",
|
||||
"bcrypt-pbkdf": "1.0.1",
|
||||
"dashdash": "1.14.1",
|
||||
"ecc-jsbn": "0.1.1",
|
||||
"getpass": "0.1.7",
|
||||
"jodid25519": "1.0.2",
|
||||
"jsbn": "0.1.1",
|
||||
"tweetnacl": "0.14.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"assert-plus": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"string-width": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"code-point-at": "1.1.0",
|
||||
"is-fullwidth-code-point": "1.0.0",
|
||||
"strip-ansi": "3.0.1"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safe-buffer": "5.0.1"
|
||||
}
|
||||
},
|
||||
"stringstream": {
|
||||
"version": "0.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-regex": "2.1.1"
|
||||
}
|
||||
},
|
||||
"strip-json-comments": {
|
||||
"version": "2.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"tar": {
|
||||
"version": "2.2.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"block-stream": "0.0.9",
|
||||
"fstream": "1.0.11",
|
||||
"inherits": "2.0.3"
|
||||
}
|
||||
},
|
||||
"tar-pack": {
|
||||
"version": "3.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"debug": "2.6.8",
|
||||
"fstream": "1.0.11",
|
||||
"fstream-ignore": "1.0.5",
|
||||
"once": "1.4.0",
|
||||
"readable-stream": "2.2.9",
|
||||
"rimraf": "2.6.1",
|
||||
"tar": "2.2.1",
|
||||
"uid-number": "0.0.6"
|
||||
}
|
||||
},
|
||||
"tough-cookie": {
|
||||
"version": "2.3.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"punycode": "1.4.1"
|
||||
}
|
||||
},
|
||||
"tunnel-agent": {
|
||||
"version": "0.6.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "5.0.1"
|
||||
}
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "0.14.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"uid-number": {
|
||||
"version": "0.0.6",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"uuid": {
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"verror": {
|
||||
"version": "1.3.6",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"extsprintf": "1.0.2"
|
||||
}
|
||||
},
|
||||
"wide-align": {
|
||||
"version": "1.1.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"string-width": "1.0.2"
|
||||
}
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"fstream": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { Component, OnInit, ViewEncapsulation} from '@angular/core';
|
||||
import { ServerService } from './services/server.service';
|
||||
import { JsonObjest } from '../app/entities/JsonObject.class';
|
||||
import { TokenService, TokenProvider } from './services/login/token.service';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute, NavigationExtras } from '@angular/router';
|
||||
import { MainSignInComponent } from './login/main-sign-in/main-sign-in.component';
|
||||
import {BreadcrumbModule,MenuItem} from 'primeng/primeng';
|
||||
|
@ -32,7 +31,7 @@ export class AppComponent implements OnInit {
|
|||
|
||||
|
||||
|
||||
constructor(private tokenService : TokenService, private router: Router, private route: ActivatedRoute, private translate: TranslateService) {
|
||||
constructor( private router: Router, private route: ActivatedRoute, private translate: TranslateService) {
|
||||
// this language will be used as a fallback when a translation isn't found in the current language
|
||||
translate.setDefaultLang('en');
|
||||
// the lang to use, if the lang isn't available, it will use the current loader to get them
|
||||
|
@ -63,7 +62,6 @@ export class AppComponent implements OnInit {
|
|||
}
|
||||
|
||||
logout(){
|
||||
this.tokenService.logout();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import { DynamicFormComponent } from './form/dynamic-form.component';
|
|||
import { DynamicFormFieldComponent } from './form/dynamic-fields/dynamic-form-field.component';
|
||||
import { ServerService } from './services/server.service';
|
||||
import { GlobalVariables } from './services/global-variables.service';
|
||||
import { TokenService, TokenProvider } from './services/login/token.service';
|
||||
import { LocalStorageService } from 'ngx-webstorage';
|
||||
import { DynamicFormGroupComponent } from './form/dynamic-form-group/dynamic-form-group.component';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
@ -56,7 +55,6 @@ import { PDFService } from './services/transformers/pdf.service';
|
|||
import { TabModule } from './tabs/tab.module';
|
||||
import { AngularDraggableModule } from 'angular2-draggable';
|
||||
|
||||
import { NativeLoginService } from './services/login/native-login.service';
|
||||
import { GooggleSignInComponent } from './login/googgle-sign-in/googgle-sign-in.component';
|
||||
import { MainSignInComponent } from './login/main-sign-in/main-sign-in.component';
|
||||
import { NguiAutoCompleteModule } from '@ngui/auto-complete';
|
||||
|
@ -195,8 +193,8 @@ import { FigurecardComponent } from './shared/components/figurecard/figurecard.c
|
|||
useClass: GlobalInterceptor,
|
||||
multi: true,
|
||||
},
|
||||
ServerService, VisibilityRulesService, PaginationService, GlobalVariables, AuthGuard, TokenService,
|
||||
LocalStorageService, RestBase, EestoreService, NativeLoginService, PDFService,
|
||||
ServerService, VisibilityRulesService, PaginationService, GlobalVariables, AuthGuard,
|
||||
LocalStorageService, RestBase, EestoreService, PDFService,
|
||||
AuthService,DashboardService,DatasetService,
|
||||
BaseHttpService
|
||||
],
|
||||
|
|
|
@ -63,9 +63,9 @@ export class AutocompleteRemoteComponent implements OnInit/* , ControlValueAcces
|
|||
this.serverService.getThroughProxy(this.field.data.url, query).subscribe(
|
||||
response => {
|
||||
this.values.length = 0;
|
||||
response.data.forEach(element => {
|
||||
/* response.data.forEach(element => {
|
||||
this.values.push(element.attributes.name);
|
||||
});
|
||||
}); */
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
|
|
|
@ -14,7 +14,6 @@ import 'rxjs/add/operator/switchMap';
|
|||
//import { FieldBase } from '../../app/form/fields/field-base';
|
||||
import { FieldControlService } from '../../app/services/field-control.service';
|
||||
import { ServerService } from '../../app/services/server.service';
|
||||
import { TokenService, TokenProvider } from '../services/login/token.service';
|
||||
import { ModalComponent } from '../modal/modal.component';
|
||||
|
||||
import { Location } from '@angular/common';
|
||||
|
@ -35,7 +34,6 @@ var flatten = require('flat');
|
|||
// import * as scroll from '../../assets/jquery.scrollTo.min.js';
|
||||
|
||||
|
||||
import '../../assets/custom.js';
|
||||
declare function simple_notifier(type: string, title: string, message: string): any;
|
||||
|
||||
|
||||
|
@ -71,7 +69,7 @@ export class DynamicFormComponent implements OnInit {
|
|||
|
||||
private fragment: string;
|
||||
constructor(private serverService: ServerService, private router: Router, private pdfService: PDFService,
|
||||
private _location: Location, private route: ActivatedRoute, private tokenService: TokenService
|
||||
private _location: Location, private route: ActivatedRoute
|
||||
, private visibilityRulesService: VisibilityRulesService
|
||||
) {
|
||||
this.datasetId = route.snapshot.params['id'];
|
||||
|
@ -85,7 +83,7 @@ export class DynamicFormComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
|
||||
this.serverService.getSingleDataset(this.datasetId).subscribe(
|
||||
response => {
|
||||
(response:any) => {
|
||||
this.dataModel = new JsonSerializer<DatasetModel>().fromJSONObject(response, DatasetModel);
|
||||
this.pages = this.getPages(this.dataModel);
|
||||
this.createPagination();
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
import { AuthService } from '../services/auth/auth.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
import { TokenService, TokenProvider } from '../services/login/token.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
constructor(private router: Router, private tokenService: TokenService) { }
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
|
||||
if(this.tokenService.isLoggedIn() == true){
|
||||
constructor(private auth: AuthService, private router: Router) { }
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
let url: string = state.url;
|
||||
if (!this.auth.current()) {
|
||||
this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } });
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<table class="table">
|
||||
<tbody>
|
||||
<tr align="center">
|
||||
<div class="g-signin2" id="googleBtn"></div>
|
||||
<button id="signinButton" (click)="signIn()">Sign in with Google</button>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import { AuthService } from '../../services/auth/auth.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, OnInit, ElementRef, AfterViewInit, VERSION, Injectable } from '@angular/core';
|
||||
import { TokenService, TokenProvider } from '../../services/login/token.service';
|
||||
import {Router} from '@angular/router';
|
||||
import { Router, ActivatedRoute, Params } from "@angular/router";
|
||||
import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component";
|
||||
import { MatPaginator, MatSort, MatSnackBar } from "@angular/material";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
|
||||
declare const gapi: any;
|
||||
|
||||
declare var $ :any;
|
||||
declare var auth2 :any;
|
||||
|
||||
import '../../../assets/custom.js';
|
||||
declare function simple_notifier(type: string, title: string, message:string): any;
|
||||
|
||||
@Component({
|
||||
|
@ -17,10 +20,9 @@ declare function simple_notifier(type: string, title: string, message:string): a
|
|||
export class GooggleSignInComponent implements OnInit, Injectable {
|
||||
|
||||
|
||||
|
||||
constructor(private element: ElementRef, private tokenService : TokenService, private router : Router) {
|
||||
|
||||
}
|
||||
constructor(private element: ElementRef, private router : Router,private authService:AuthService,private route:ActivatedRoute,
|
||||
public snackBar: MatSnackBar,public language: TranslateService
|
||||
) { }
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
|
@ -29,64 +31,54 @@ export class GooggleSignInComponent implements OnInit, Injectable {
|
|||
|
||||
initiateExternalProviders(){
|
||||
|
||||
var clientId = '1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com';
|
||||
var scope = [
|
||||
'profile',
|
||||
'email'
|
||||
].join(' ');
|
||||
|
||||
if(gapi.auth2 == undefined){
|
||||
|
||||
gapi.load('auth2', () => {
|
||||
|
||||
gapi.auth2.init({
|
||||
client_id: clientId,
|
||||
cookiepolicy: 'single_host_origin',
|
||||
scope: scope
|
||||
}).then(()=>this.renderButton());
|
||||
|
||||
});
|
||||
|
||||
}else{
|
||||
gapi.auth2.init({
|
||||
client_id: clientId,
|
||||
cookiepolicy: 'single_host_origin',
|
||||
scope: scope
|
||||
}).then(()=>this.renderButton());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
renderButton() {
|
||||
// if(gapi.auth2 == undefined){
|
||||
|
||||
gapi.signin2.render('googleBtn');
|
||||
var buttonElement = this.element.nativeElement.querySelector('#googleBtn');
|
||||
if(buttonElement)this.attachSignin(buttonElement);
|
||||
// gapi.load('auth2', () => {
|
||||
|
||||
// this.auth2 = gapi.auth2.getAuthInstance({
|
||||
// client_id: clientId,
|
||||
// })
|
||||
// });
|
||||
|
||||
// }else{
|
||||
// this.auth2=gapi.auth2.getAuthInstance({
|
||||
// client_id: clientId,
|
||||
// })}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public attachSignin(element) {
|
||||
|
||||
gapi.auth2.getAuthInstance().attachClickHandler(element, {},
|
||||
(googleUser) => {
|
||||
//simple_notifier("success",null,"Successful login");
|
||||
let profile = googleUser.getBasicProfile();
|
||||
this.tokenService.login(googleUser.getAuthResponse().id_token, TokenProvider.google, profile.getName(), profile.getEmail());
|
||||
},
|
||||
function (error) {
|
||||
//simple_notifier("danger",null,"Failed to login");
|
||||
console.log(JSON.stringify(error, undefined, 2));
|
||||
}
|
||||
);
|
||||
|
||||
public signIn() {
|
||||
auth2.grantOfflineAccess().then((authResult)=>this.signInCallback(authResult))
|
||||
}
|
||||
|
||||
signInCallback(authResult){
|
||||
if (authResult['code']) {
|
||||
this.authService.login({ticket:authResult['code'],service:"google"}).subscribe(
|
||||
res => this.onLogInSuccess(res),
|
||||
error => this.onLogInError(error)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public onLogInSuccess(logoutMessage: any) {
|
||||
this.route.queryParams.subscribe((params: Params) => {
|
||||
let redirectUrl = params['returnUrl'] ? params['returnUrl'] : '/';
|
||||
this.router.navigate([redirectUrl]);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
public onLogInError(errorMessage: string) {
|
||||
console.log(errorMessage);
|
||||
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
|
||||
data: { message: 'GENERAL.SNACK-BAR.UNSUCCESSFUL-LOGIN', language: this.language },
|
||||
duration: 3000,
|
||||
extraClasses: ['snackbar-warning']
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { NativeLoginService } from '../../services/login/native-login.service';
|
||||
import { TokenService, TokenProvider } from '../../services/login/token.service';
|
||||
import {Router} from '@angular/router';
|
||||
import {MenuItem} from 'primeng/primeng';
|
||||
declare const gapi: any;
|
||||
|
||||
import '../../../assets/custom.js';
|
||||
declare function simple_notifier(type: string, title: string, message:string): any;
|
||||
|
||||
@Component({
|
||||
|
@ -22,7 +19,7 @@ export class MainSignInComponent implements OnInit {
|
|||
creds : any = {"username":"","password":""};
|
||||
|
||||
|
||||
constructor( private fb: FormBuilder, private nativeLogin : NativeLoginService, private tokenService : TokenService, private router : Router) {
|
||||
constructor( private fb: FormBuilder, private router : Router) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,27 +36,12 @@ export class MainSignInComponent implements OnInit {
|
|||
|
||||
ngOnInit() {
|
||||
this.createForm();
|
||||
if(this.tokenService.isLoggedIn()){
|
||||
this.router.navigate(['/welcome'], { queryParams: { /*returnUrl: this.state.url*/ }});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
login(){
|
||||
//login using the credentials
|
||||
|
||||
this.nativeLogin.login(this.creds.username, this.creds.password).subscribe(
|
||||
response => {
|
||||
|
||||
simple_notifier("success",null,"Successful login");
|
||||
|
||||
this.tokenService.login(response['token'], TokenProvider.native, this.creds.username, response['email']);
|
||||
this.router.navigate(['/welcome'], { queryParams: { /*returnUrl: this.state.url*/ }});
|
||||
},
|
||||
err => {
|
||||
simple_notifier("danger",null,"Failed to login");
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ export class ModalComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
|
||||
this.serverService.listDmpsLabelID().subscribe(
|
||||
response => {
|
||||
(response:any) => {
|
||||
console.log("response");
|
||||
console.log(response);
|
||||
//let params = new Param();
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse} from '@angular/common/http';
|
||||
import { TokenService, TokenProvider } from './login/token.service';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Injectable()
|
||||
export class GlobalInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(public tokenService: TokenService, private router : Router) {}
|
||||
constructor( private router : Router) {}
|
||||
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
|
||||
|
@ -21,7 +20,6 @@ export class GlobalInterceptor implements HttpInterceptor {
|
|||
if (err instanceof HttpErrorResponse) {
|
||||
if (err.status === 401) {
|
||||
console.log("Received an unauthorized... redirecting to login page");
|
||||
this.tokenService.logout();
|
||||
this.router.navigate(['/login'], { queryParams: { /*returnUrl: this.state.url*/ }});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
import { Injectable, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { TokenService, TokenProvider } from '../login/token.service'
|
||||
import { HttpClient , HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {RestBase} from '../rest-base';
|
||||
|
||||
@Injectable()
|
||||
export class NativeLoginService implements OnInit {
|
||||
|
||||
|
||||
constructor(private restBase: RestBase) {
|
||||
}
|
||||
|
||||
ngOnInit(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
login(username, password){
|
||||
var credentials = {"username": username, "password":password};
|
||||
return this.restBase.login("nativeLogin", credentials);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
import { Injectable, Inject} from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import {LocalStorageService} from 'ngx-webstorage';
|
||||
import {Router} from '@angular/router';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { DOCUMENT } from '@angular/platform-browser';
|
||||
|
||||
|
||||
declare var jQuery : any;
|
||||
|
||||
import '../../../assets/custom.js';
|
||||
declare function sign_out_google(): any;
|
||||
|
||||
@Injectable()
|
||||
export class TokenService {
|
||||
|
||||
constructor (private storage : LocalStorageService, @Inject(DOCUMENT) private document, private router : Router) {
|
||||
//var csrfToken : string = jQuery(document).find('meta[name="csrf-token"]').attr('content');
|
||||
//this.setCSRFToken(csrfToken);
|
||||
}
|
||||
|
||||
/*
|
||||
getCSRFToken() : string{
|
||||
return this.storage.retrieve('csrf-token');
|
||||
}
|
||||
|
||||
setCSRFToken(csrfToken : string){
|
||||
this.storage.store('csrf-token',csrfToken);
|
||||
}
|
||||
*/
|
||||
|
||||
getProvider() : TokenProvider {
|
||||
return this.storage.retrieve('provider');
|
||||
}
|
||||
|
||||
setProvider(provider : TokenProvider){
|
||||
this.storage.store('provider',provider);
|
||||
}
|
||||
|
||||
getToken() : string{
|
||||
return this.storage.retrieve('token');
|
||||
}
|
||||
|
||||
setToken(token : string){
|
||||
this.storage.store('token',token);
|
||||
}
|
||||
|
||||
isLoggedIn(){
|
||||
return this.storage.retrieve('loggedIn');
|
||||
}
|
||||
|
||||
setLoggedIn(boolStatus){
|
||||
this.storage.store('loggedIn',boolStatus);
|
||||
}
|
||||
|
||||
getEmail(){
|
||||
return this.storage.retrieve('email');
|
||||
}
|
||||
|
||||
setEmail(email){
|
||||
this.storage.store('email',email);
|
||||
}
|
||||
|
||||
getUsername(){
|
||||
return this.storage.retrieve('username');
|
||||
}
|
||||
|
||||
setUsername(username){
|
||||
this.storage.store('username',username);
|
||||
}
|
||||
|
||||
|
||||
login(token: string, provider: TokenProvider, username: string, email: string){
|
||||
|
||||
this.setLoggedIn(true);
|
||||
this.setToken(token);
|
||||
this.setProvider(provider);
|
||||
this.setUsername(username);
|
||||
this.setEmail(email);
|
||||
|
||||
window.location.reload();
|
||||
|
||||
}
|
||||
|
||||
|
||||
logout(){
|
||||
//set the log out actions here
|
||||
this.setLoggedIn(false);
|
||||
this.setEmail(null);
|
||||
this.setUsername(null);
|
||||
this.setToken(null);
|
||||
|
||||
if(this.getProvider() == TokenProvider.google){
|
||||
sign_out_google();
|
||||
}
|
||||
|
||||
this.setProvider(null);
|
||||
|
||||
this.router.navigate(['/login'], { queryParams: { /*returnUrl: this.state.url*/ }});
|
||||
|
||||
//window.location.reload();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export enum TokenProvider {
|
||||
native,
|
||||
google
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { HttpClient , HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { TokenService, TokenProvider } from './login/token.service'
|
||||
import 'rxjs/Rx';
|
||||
|
||||
|
||||
|
@ -9,9 +8,9 @@ export class RestBase {
|
|||
|
||||
xml2jsonOBJ: any;
|
||||
|
||||
static get parameters() { return [HttpClient, TokenService] }
|
||||
static get parameters() { return [HttpClient] }
|
||||
|
||||
constructor(public http : HttpClient, public tokenService : TokenService) {
|
||||
constructor(public http : HttpClient) {
|
||||
this.xml2jsonOBJ = new X2JS();
|
||||
}
|
||||
|
||||
|
@ -65,7 +64,7 @@ export class RestBase {
|
|||
}
|
||||
|
||||
private createOptions(parameters : any){
|
||||
var token = this.tokenService.getToken();
|
||||
/* var token = this.tokenService.getToken();
|
||||
var provider: TokenProvider = this.tokenService.getProvider();
|
||||
|
||||
var params = new HttpParams();
|
||||
|
@ -81,8 +80,8 @@ export class RestBase {
|
|||
headers = new HttpHeaders().set('Content-Type', 'application/json').set("google-token", token);
|
||||
if(provider == TokenProvider.native)
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set("native-token", token);
|
||||
let options = { params: params, headers: headers };
|
||||
return options;
|
||||
let options = { params: params, headers: headers }; */
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<h2>{{message}}</h2>
|
|
@ -0,0 +1,49 @@
|
|||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
import { Component, Input } from "@angular/core";
|
||||
import { AuthService } from "../core/services/auth.service";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
var UnauthorizedComponent = (function () {
|
||||
function UnauthorizedComponent(authService, route, router) {
|
||||
this.authService = authService;
|
||||
this.route = route;
|
||||
this.router = router;
|
||||
}
|
||||
UnauthorizedComponent.prototype.ngAfterViewInit = function () {
|
||||
var _this = this;
|
||||
var returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||
var principal = this.authService.current();
|
||||
if (!principal) {
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
|
||||
}
|
||||
else {
|
||||
this.authService.me().subscribe(function (principal) {
|
||||
if (!principal)
|
||||
_this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
|
||||
}, function (err) { return console.error('An error occurred', err); });
|
||||
}
|
||||
};
|
||||
return UnauthorizedComponent;
|
||||
}());
|
||||
__decorate([
|
||||
Input(),
|
||||
__metadata("design:type", String)
|
||||
], UnauthorizedComponent.prototype, "message", void 0);
|
||||
UnauthorizedComponent = __decorate([
|
||||
Component({
|
||||
selector: 'unauthorized-component',
|
||||
templateUrl: './unauthorized.component.html'
|
||||
}),
|
||||
__metadata("design:paramtypes", [AuthService,
|
||||
ActivatedRoute,
|
||||
Router])
|
||||
], UnauthorizedComponent);
|
||||
export { UnauthorizedComponent };
|
||||
//# sourceMappingURL=unauthorized.component.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"unauthorized.component.js","sourceRoot":"","sources":["unauthorized.component.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAMzD,IAAa,qBAAqB;IAG9B,+BACY,WAAwB,EACxB,KAAqB,EACrB,MAAc;QAFd,gBAAW,GAAX,WAAW,CAAa;QACxB,UAAK,GAAL,KAAK,CAAgB;QACrB,WAAM,GAAN,MAAM,CAAQ;IACtB,CAAC;IAEL,+CAAe,GAAf;QAAA,iBAaC;QAZG,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;QACpE,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC3C,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,CAAC;YACF,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,SAAS,CAC3B,UAAA,SAAS;gBACL,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;oBAAC,KAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;YAChG,CAAC,EACD,UAAA,GAAG,IAAI,OAAA,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,EAAvC,CAAuC,CAAC,CAAC;QACxD,CAAC;IACL,CAAC;IACL,4BAAC;AAAD,CAAC,AAvBD,IAuBC;AArBG;IADC,KAAK,EAAE;;sDACe;AAFd,qBAAqB;IAJjC,SAAS,CAAC;QACP,QAAQ,EAAE,wBAAwB;QAClC,WAAW,EAAE,+BAA+B;KAC/C,CAAC;qCAK2B,WAAW;QACjB,cAAc;QACb,MAAM;GANjB,qBAAqB,CAuBjC;SAvBY,qBAAqB"}
|
|
@ -0,0 +1,32 @@
|
|||
import { AuthService } from '../services/auth/auth.service';
|
||||
import { Component, Input } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: 'unauthorized-component',
|
||||
templateUrl: './unauthorized.component.html'
|
||||
})
|
||||
export class UnauthorizedComponent {
|
||||
@Input()
|
||||
public message: string;
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
ngAfterViewInit() {
|
||||
let returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||
let principal = this.authService.current();
|
||||
if (!principal) {
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
|
||||
}
|
||||
else {
|
||||
this.authService.me().subscribe(
|
||||
principal => {
|
||||
if (!principal) this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
|
||||
},
|
||||
err => console.error('An error occurred', err));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { UnauthorizedComponent } from './unauthorized.component';
|
||||
import { UnauthorizedRoutes } from './unauthorized.routes';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
var UnauthorizedModule = (function () {
|
||||
function UnauthorizedModule() {
|
||||
}
|
||||
return UnauthorizedModule;
|
||||
}());
|
||||
UnauthorizedModule = __decorate([
|
||||
NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
HttpClientModule,
|
||||
UnauthorizedRoutes,
|
||||
SharedModule
|
||||
],
|
||||
declarations: [
|
||||
UnauthorizedComponent
|
||||
],
|
||||
exports: [
|
||||
UnauthorizedComponent
|
||||
]
|
||||
})
|
||||
], UnauthorizedModule);
|
||||
export { UnauthorizedModule };
|
||||
//# sourceMappingURL=unauthorized.module.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"unauthorized.module.js","sourceRoot":"","sources":["unauthorized.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAmBtD,IAAa,kBAAkB;IAA/B;IAAkC,CAAC;IAAD,yBAAC;AAAD,CAAC,AAAnC,IAAmC;AAAtB,kBAAkB;IAlB9B,QAAQ,CAAC;QACN,OAAO,EAAE;YACL,YAAY;YACZ,WAAW;YACX,gBAAgB;YAChB,kBAAkB;YAClB,YAAY;SACf;QAED,YAAY,EAAE;YACV,qBAAqB;SACxB;QAED,OAAO,EAAE;YACL,qBAAqB;SACxB;KACJ,CAAC;GAEW,kBAAkB,CAAI;SAAtB,kBAAkB"}
|
|
@ -0,0 +1,27 @@
|
|||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import { UnauthorizedComponent } from './unauthorized.component';
|
||||
import { UnauthorizedRoutes } from './unauthorized.routes';
|
||||
import { SharedModule } from '../shared/shared.module'
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
HttpClientModule,
|
||||
UnauthorizedRoutes,
|
||||
SharedModule
|
||||
],
|
||||
|
||||
declarations: [
|
||||
UnauthorizedComponent
|
||||
],
|
||||
|
||||
exports: [
|
||||
UnauthorizedComponent
|
||||
]
|
||||
})
|
||||
|
||||
export class UnauthorizedModule { }
|
|
@ -0,0 +1,7 @@
|
|||
import { RouterModule } from '@angular/router';
|
||||
import { UnauthorizedComponent } from './unauthorized.component';
|
||||
var routes = [
|
||||
{ path: '', component: UnauthorizedComponent }
|
||||
];
|
||||
export var UnauthorizedRoutes = RouterModule.forChild(routes);
|
||||
//# sourceMappingURL=unauthorized.routes.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"unauthorized.routes.js","sourceRoot":"","sources":["unauthorized.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAU,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,IAAM,MAAM,GAAW;IACnB,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,qBAAqB,EAAE;CACjD,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC"}
|
|
@ -0,0 +1,9 @@
|
|||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { UnauthorizedComponent } from './unauthorized.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', component: UnauthorizedComponent }
|
||||
];
|
||||
|
||||
export const UnauthorizedRoutes = RouterModule.forChild(routes);
|
|
@ -39,7 +39,7 @@ export class DmpDetailedComponent implements OnInit {
|
|||
if(this.dmp.previous != null && this.dmp.previous != ""){
|
||||
this.serverService.getDmpHistory(this.dmp.id).subscribe(
|
||||
response => {
|
||||
this.previousDMPs = response;
|
||||
//this.previousDMPs = response;
|
||||
},
|
||||
error => {
|
||||
console.log("Could not get previous DMPs (history)");
|
||||
|
|
|
@ -30,7 +30,7 @@ export class ProjectDetailedComponent implements OnInit {
|
|||
|
||||
let projectid = params.projectid;
|
||||
this.serverService.getProject(projectid).subscribe(
|
||||
response => {
|
||||
(response:any) => {
|
||||
this.project = response;
|
||||
$('#project-details-modal').modal('show');
|
||||
//get also projects of dmp (there's a problem with the List<> serialization on server - side)
|
||||
|
@ -66,7 +66,7 @@ export class ProjectDetailedComponent implements OnInit {
|
|||
this.users.clear();
|
||||
for(var i=0;i<project.dmps.length;i++){
|
||||
debugger;
|
||||
const user = await this.serverService.getUserByID(project.dmps[i].creator).toPromise();
|
||||
const user:any = await this.serverService.getUserByID(project.dmps[i].creator).toPromise();
|
||||
this.users.set(project.dmps[i].creator, user.name);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ export class ProjectDetailedComponent implements OnInit {
|
|||
project.dmps.forEach(dmp => {
|
||||
if(!this.users.has(dmp.creator)){
|
||||
this.serverService.getUserByID(dmp.creator).subscribe(
|
||||
user => {
|
||||
(user:any) => {
|
||||
this.users.set(dmp.creator, user.name);
|
||||
},
|
||||
error => {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<html itemscope itemtype="http://schema.org/Article">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
|
@ -9,7 +8,6 @@
|
|||
<meta name="csrf-token" content="2c64def7de30197c40276fe1a7ea874ca8871f70be7d7dc3305465a4d5c565e4">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
<meta name="google-signin-client_id" content="524432312250-vhgidft856v8qftsc81kls4c74v87d8o.apps.googleusercontent.com">
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
||||
<!--
|
||||
|
@ -33,8 +31,12 @@
|
|||
<!-- Nice BS notifications -->
|
||||
<script src="assets/bootstrap-notify.min.js"></script>
|
||||
|
||||
<!-- that's google sign in library -->
|
||||
<script src="https://apis.google.com/js/platform.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
|
||||
|
||||
</script>
|
||||
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
|
||||
|
||||
</script>
|
||||
|
||||
<!-- font-awesome css -->
|
||||
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
|
@ -47,13 +49,22 @@
|
|||
|
||||
<!-- my custom global code and css -->
|
||||
<link rel="stylesheet" type="text/css" href="assets/custom.css">
|
||||
<script src="assets/custom.js"></script>
|
||||
|
||||
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
|
||||
<script>
|
||||
var auth2;
|
||||
function start() {
|
||||
gapi.load('auth2', function() {
|
||||
auth2 = gapi.auth2.init({
|
||||
client_id: "524432312250-sc9qsmtmbvlv05r44onl6l93ia3k9deo.apps.googleusercontent.com",
|
||||
scope: "email"
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue