This commit is contained in:
annampak 2018-01-09 16:26:48 +02:00
commit fa10688e98
26 changed files with 328 additions and 231 deletions

View File

@ -172,6 +172,13 @@
<version>2.7.0</version>
</dependency>
<!-- facebook Login -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- Various libs -->
<dependency>

View File

@ -12,6 +12,7 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@ -58,7 +59,7 @@ public class DatasetProfileController extends BaseController{
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/save/{id}" }, consumes="application/json",produces="application/json")
public ResponseEntity<Object> updateDataset(@PathVariable String id,@RequestBody PropertiesModel properties){
try {
@ -73,6 +74,7 @@ public class DatasetProfileController extends BaseController{
return ResponseEntity.status(HttpStatus.OK).body(properties);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}

View File

@ -31,7 +31,6 @@ public class Login {
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) {
try {
return new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());

View File

@ -259,7 +259,11 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Override
public void update(Dataset entity) {
this.setRegistries(entity.getRegistries());
this.setDataRepositories(entity.getDataRepositories());
this.setDescription(entity.getDescription());
this.setLabel(entity.getLabel());
this.setProperties(entity.getProperties());
}
@Override

View File

@ -41,8 +41,8 @@ public class DatasetManager {
eu.eudat.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id));
eu.eudat.models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(datasetEntity.getProfile());
datasetprofile.setStatus(dataset.getStatus());
if(dataset.getProperties()!=null){
JSONObject jobject = new JSONObject(dataset.getProperties());
if(datasetEntity.getProperties()!=null){
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
Map<String,Object> properties = (Map<String, Object>)jobject.toMap();
datasetprofile.fromJsonObject(properties);
}

View File

@ -1,12 +1,13 @@
package eu.eudat.models.login;
import eu.eudat.security.validators.TokenValidatorFactoryImpl;
/**
* Created by ikalyvas on 12/18/2017.
*/
public class LoginInfo {
private String ticket;
private String service;
private TokenValidatorFactoryImpl.LoginProvider provider;
public String getTicket() {
return ticket;
}
@ -15,11 +16,11 @@ public class LoginInfo {
this.ticket = ticket;
}
public String getService() {
return service;
public TokenValidatorFactoryImpl.LoginProvider getProvider() {
return provider;
}
public void setService(String service) {
this.service = service;
public void setProvider(Integer provider) {
this.provider = TokenValidatorFactoryImpl.LoginProvider.fromInteger(provider);
}
}

View File

@ -6,7 +6,7 @@ import java.util.Map;
public class Section implements PropertiesGenerator{
private List<Section> sections;
private List<Group> fieldGroups;
private List<FieldSet> compositeFields;
public List<Section> getSections() {
return sections;
@ -14,16 +14,19 @@ public class Section implements PropertiesGenerator{
public void setSections(List<Section> sections) {
this.sections = sections;
}
public List<Group> getFieldGroups() {
return fieldGroups;
public List<FieldSet> getCompositeFields() {
return compositeFields;
}
public void setFieldGroups(List<Group> fieldGroups) {
this.fieldGroups = fieldGroups;
public void setCompositeFields(List<FieldSet> compositeFields) {
this.compositeFields = compositeFields;
}
@Override
public void toMap(Map<String, Object> fieldValues) {
this.sections.forEach(item->item.toMap(fieldValues));
this.fieldGroups.forEach(item->item.toMap(fieldValues));
this.compositeFields.forEach(item->item.toMap(fieldValues));
}
@Override
public void toMap(Map<String, Object> fieldValues, int index) {

View File

@ -105,14 +105,15 @@ public class Field implements Comparable,PropertiesModelBuilder,ViewStyleDefinit
this.visible = visible;
}
public List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> getValidations() {
return validations;
public List<Integer> getValidations() {
return this.validations.stream().map(item->(int)item.getValue()).collect(Collectors.toList());
}
public void setValidations(List<eu.eudat.models.admin.components.datasetprofile.Field.ValidationType> validations) {
this.validations = validations;
public void setValidations(List<Integer> validations) {
this.validations = eu.eudat.models.admin.components.datasetprofile.Field.ValidationType.fromIntegers(validations);
}
public Field cloneForMultiplicity(String key, Map<String, Object> properties){
Field newField = new Field();
newField.id = key;

View File

@ -2,41 +2,30 @@ package eu.eudat.security;
import java.io.IOException;
import java.security.GeneralSecurityException;
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 eu.eudat.security.validators.TokenValidatorFactory;
import eu.eudat.security.validators.TokenValidatorFactoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.entities.UserInfo;
import eu.eudat.exceptions.NonValidTokenException;
import eu.eudat.security.validators.GoogleTokenValidator;
import eu.eudat.security.validators.NativeTokenValidator;
import eu.eudat.security.validators.TokenValidator;
import eu.eudat.security.validators.google.GoogleTokenValidator;
@Component
public class CustomAuthenticationProvider {
@Autowired private UserInfoDao userInfoDao;
@Autowired private GoogleTokenValidator googleTokenValidator;
@Autowired private NativeTokenValidator nativeTokenValidator;
@Autowired private TokenValidatorFactory tokenValidatorFactory;
public Principal authenticate(LoginInfo credentials) throws AuthenticationException, GeneralSecurityException {
String token = credentials.getTicket();
try {
Principal principal = googleTokenValidator.validateToken(token);
Principal principal = this.tokenValidatorFactory.getProvider(credentials.getProvider()).validateToken(token);
return principal;
} catch (NonValidTokenException e) {
e.printStackTrace();

View File

@ -1,65 +0,0 @@
package eu.eudat.security;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.GenericFilterBean;
public class TokenAuthenticationFilter extends GenericFilterBean {
// public static final String HEADER_TOKEN_FIELD = "Authorization";
public static final String HEADER_NATIVE_TOKEN_FIELD = "native-token";
public static final String HEADER_GOOGLE_TOKEN_FIELD = "google-token";
public static final char HEADERNAME_USERNAME_DELIMITER = 0x1e; //specially crafted delimiter
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
String nativeToken = httpRequest.getHeader(HEADER_NATIVE_TOKEN_FIELD);
String googleToken = httpRequest.getHeader(HEADER_GOOGLE_TOKEN_FIELD);
//just pass the header, the username and the token into the credentials object of the UsernamePasswordAuthenticationToken class
UsernamePasswordAuthenticationToken authentication = null;
if(nativeToken != null)
authentication = new UsernamePasswordAuthenticationToken(HEADER_NATIVE_TOKEN_FIELD, nativeToken);
if(googleToken != null)
authentication = new UsernamePasswordAuthenticationToken(HEADER_GOOGLE_TOKEN_FIELD, googleToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
final HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Origin", "*");
httpResponse.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
httpResponse.setHeader("Access-Control-Max-Age", "7200");
httpResponse.setHeader("Access-Control-Allow-Headers", "content-type, X-CSRF-Token, "+HEADER_NATIVE_TOKEN_FIELD+", "+HEADER_GOOGLE_TOKEN_FIELD);
// httpResponse.addHeader("Access-Control-Expose-Headers", "xsrf-token , " +HEADER_NATIVE_TOKEN_FIELD+", "+HEADER_GOOGLE_TOKEN_FIELD);
if ("OPTIONS".equals(httpRequest.getMethod())) {
httpResponse.setStatus(HttpServletResponse.SC_OK);
}
else {
chain.doFilter(httpRequest, httpResponse);
}
}
}

View File

@ -1,83 +0,0 @@
package eu.eudat.security;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Service;
@Service
public class TokenSessionManager {
private final static long TOTAL_SESSION_MINUTES = 120L;
private final static long IDLE_MINUTES_EXPIRE = 20L;
private static Cache <String, String> cache; //that's thread-safe according to the documentation
private static TokenSessionManager instance = null; //should be one-per-classloader
public static synchronized TokenSessionManager getInstance() {
if (instance == null){
instance = new TokenSessionManager();
initialize();
}
return instance;
}
private static void initialize() {
cache = CacheBuilder.newBuilder()
.expireAfterWrite(TOTAL_SESSION_MINUTES, TimeUnit.MINUTES)
.expireAfterAccess(IDLE_MINUTES_EXPIRE, TimeUnit.MINUTES)
.maximumSize(Long.MAX_VALUE)
.build();
}
public String getUser(String token) {
return cache.getIfPresent(token);
}
public void set(String token, String user) {
cache.put(token, user);
}
public String generateRandomAlphanumeric(int length) {
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[length];
random.nextBytes(bytes);
return encode(bytes);
}
private String encode(byte[] binaryData) {
int n = binaryData.length;
char[] HEXADECIMAL = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
char[] buffer = new char[n * 2];
for (int i = 0; i < n; i++) {
int low = (binaryData[i] & 0x0f);
int high = ((binaryData[i] & 0xf0) >> 4);
buffer[i * 2] = HEXADECIMAL[high];
buffer[(i * 2) + 1] = HEXADECIMAL[low];
}
return new String(buffer);
}
public String hashPassword (String password) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(password.getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++)
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
}
// public static void main(String [] args) throws NoSuchAlgorithmException {
// System.out.println(TokenSessionManager.getInstance().hashPassword("apa$$2gu3$$"));
// }
}

View File

@ -1,29 +0,0 @@
package eu.eudat.security.validators;
import eu.eudat.models.security.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.entities.UserInfo;
import eu.eudat.exceptions.NonValidTokenException;
import eu.eudat.security.TokenSessionManager;
import org.springframework.stereotype.Component;
@Component
public class NativeTokenValidator implements TokenValidator {
@Autowired private TokenSessionManager tokenSessionManager;
@Autowired private UserInfoDao userInfoDao;
@Override
public Principal validateToken(String token) throws NonValidTokenException {
String tokenUser = tokenSessionManager.getUser(token);
if(tokenUser==null || tokenUser.isEmpty())
throw new NonValidTokenException("Login session has expired! Need to eu.eudat.login again!");
return new Principal();
}
}

View File

@ -9,6 +9,6 @@ import java.security.GeneralSecurityException;
public interface TokenValidator {
public Principal validateToken(String token) throws NonValidTokenException, IOException, GeneralSecurityException;
Principal validateToken(String token) throws NonValidTokenException, IOException, GeneralSecurityException;
}

View File

@ -0,0 +1,8 @@
package eu.eudat.security.validators;
/**
* Created by ikalyvas on 1/9/2018.
*/
public interface TokenValidatorFactory {
TokenValidator getProvider(TokenValidatorFactoryImpl.LoginProvider provider);
}

View File

@ -0,0 +1,63 @@
package eu.eudat.security.validators;
import eu.eudat.models.project.Project;
import eu.eudat.security.validators.google.FacebookTokenValidator;
import eu.eudat.security.validators.google.GoogleTokenValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by ikalyvas on 1/9/2018.
*/
@Service("tokenValidatorFactory")
public class TokenValidatorFactoryImpl implements TokenValidatorFactory{
public enum LoginProvider {
GOOGLE((short) 1), FACEBOOK((short) 2), TWITTER((short) 3), LINKEDIN((short) 4);
private short value;
private LoginProvider(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static LoginProvider fromInteger(int value) {
switch (value) {
case 1:
return GOOGLE;
case 2:
return FACEBOOK;
case 3:
return TWITTER;
case 4:
return LINKEDIN;
default:
throw new RuntimeException("Unsupported LoginProvider");
}
}
}
private GoogleTokenValidator googleTokenValidator;
private FacebookTokenValidator facebookTokenValidator;
@Autowired
public TokenValidatorFactoryImpl(GoogleTokenValidator googleTokenValidator, FacebookTokenValidator facebookTokenValidator) {
this.googleTokenValidator = googleTokenValidator;
this.facebookTokenValidator = facebookTokenValidator;
}
public TokenValidator getProvider(LoginProvider provider) {
switch (provider) {
case GOOGLE:
return this.googleTokenValidator;
case FACEBOOK:
return this.facebookTokenValidator;
default:
throw new RuntimeException("Login Provider Not Implemented");
}
}
}

View File

@ -0,0 +1,124 @@
package eu.eudat.security.validators.google;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.dao.entities.security.CredentialDao;
import eu.eudat.dao.entities.security.UserTokenDao;
import eu.eudat.entities.Credential;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.UserToken;
import eu.eudat.exceptions.NonValidTokenException;
import eu.eudat.models.criteria.UserInfoCriteria;
import eu.eudat.models.security.Principal;
import eu.eudat.security.validators.TokenValidator;
import eu.eudat.security.validators.TokenValidatorFactoryImpl;
import eu.eudat.services.ApiContext;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionKey;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.User;
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
import org.springframework.social.facebook.connect.FacebookServiceProvider;
import org.springframework.social.oauth2.AccessGrant;
import org.springframework.social.oauth2.OAuth2Operations;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.*;
/**
* Created by ikalyvas on 1/9/2018.
*/
@Component("facebookTokenValidator")
public class FacebookTokenValidator implements TokenValidator {
private Environment environment;
private ApiContext apiContext;
private FacebookServiceProvider facebookServiceProvider;
@Autowired
public FacebookTokenValidator(Environment environment,ApiContext apiContext) {
this.environment = environment;
this.apiContext= apiContext;
this.facebookServiceProvider = new FacebookServiceProvider(this.environment.getProperty("facebook.login.clientId"), this.environment.getProperty("facebook.login.clientSecret"),this.environment.getProperty("facebook.login.namespace"));
}
@Override
public Principal validateToken(String token) throws NonValidTokenException, IOException, GeneralSecurityException {
User profile = getFacebookUserId(token);
UserInfoCriteria criteria = new UserInfoCriteria();
criteria.setEmail(profile.getEmail());
List<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(criteria).toList();
UserInfo userInfo = null;
if(users.size()>0)userInfo = users.get(0);
final Credential credential = new Credential();
credential.setId(UUID.randomUUID());
credential.setCreationTime(new Date());
credential.setStatus(1);
credential.setLastUpdateTime(new Date());
credential.setProvider((int)TokenValidatorFactoryImpl.LoginProvider.FACEBOOK.getValue());
credential.setSecret(token);
if(userInfo == null) {
userInfo = new UserInfo();
userInfo.setName((String)profile.getName());
userInfo.setVerified_email(profile.isVerified());
userInfo.setEmail(profile.getEmail());
userInfo.setCreated(new Date());
userInfo.setLastloggedin(new Date());
userInfo.setAuthorization_level(new Short("1"));
userInfo.setUsertype(new Short("1"));
userInfo = apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
credential.setPublicValue(userInfo.getName());
credential.setUserInfo(userInfo);
apiContext.getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
}
else {
userInfo.setLastloggedin(new Date());
Set<Credential> credentials = userInfo.getCredentials();
if(credentials.contains(credential)){
Credential oldCredential = credentials.stream().filter(item->credential.getProvider().equals(item.getProvider())).findFirst().get();
credential.setId(oldCredential.getId());
}
else{
credential.setUserInfo(userInfo);
credential.setId(UUID.randomUUID());
credential.setPublicValue(userInfo.getName());
apiContext.getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
userInfo.getCredentials().add(credential);
}
userInfo = apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
}
UserToken userToken = new UserToken();
userToken.setUser(userInfo);
userToken.setIssuedAt(new Date());
userToken.setToken(UUID.randomUUID());
userToken.setExpiresAt(addADay(new Date()));
apiContext.getDatabaseRepository().getUserTokenDao().create(userToken);
return apiContext.getAuthenticationService().Touch(userToken.getToken());
}
private User getFacebookUserId(String accessToken) {
String [] fields = { "id", "email", "first_name", "last_name","name" };
User profile = this.facebookServiceProvider.getApi(accessToken).fetchObject("me",User.class,fields);
return profile;
}
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;
}
}

View File

@ -1,4 +1,4 @@
package eu.eudat.security.validators;
package eu.eudat.security.validators.google;
import java.io.FileReader;
import java.io.IOException;
@ -15,6 +15,8 @@ import eu.eudat.entities.Credential;
import eu.eudat.entities.UserToken;
import eu.eudat.models.criteria.UserInfoCriteria;
import eu.eudat.models.login.LoginInfo;
import eu.eudat.security.validators.TokenValidator;
import eu.eudat.security.validators.TokenValidatorFactoryImpl;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,12 +33,10 @@ import org.springframework.stereotype.Service;
import static com.sun.org.apache.xalan.internal.xsltc.compiler.Constants.REDIRECT_URI;
@Component
@Component("googleTokenValidator")
public class GoogleTokenValidator implements TokenValidator {
private static final JacksonFactory jacksonFactory = new JacksonFactory();
private static final HttpTransport transport = new NetHttpTransport();
@Autowired private UserInfoDao userInfoDao;
@Autowired private CredentialDao credentialDao;
@Autowired private AuthenticationService authenticationService;
@ -73,7 +73,7 @@ public class GoogleTokenValidator implements TokenValidator {
credential.setCreationTime(new Date());
credential.setStatus(1);
credential.setLastUpdateTime(new Date());
credential.setProvider(1);
credential.setProvider((int)TokenValidatorFactoryImpl.LoginProvider.GOOGLE.getValue());
credential.setSecret(token);
if(userInfo == null) {
userInfo = new UserInfo();

View File

@ -12,4 +12,5 @@ public interface ApiContext {
InvitationService getInvitationService();
RemoteFetcher getRemoteFetcher();
MailService getMailService();
AuthenticationService getAuthenticationService();
}

View File

@ -16,6 +16,7 @@ public class ApiContextImpl implements ApiContext{
private RemoteFetcher remoteFetcher;
private InvitationService invitationService;
private MailService mailService;
private AuthenticationService authenticationService;
@Autowired
public void setDatabaseRepository(DatabaseRepository databaseRepository) {
@ -66,4 +67,14 @@ public class ApiContextImpl implements ApiContext{
public void setMailService(MailService mailService) {
this.mailService = mailService;
}
@Override
public AuthenticationService getAuthenticationService() {
return authenticationService;
}
@Autowired
public void setAuthenticationService(AuthenticationService authenticationService) {
this.authenticationService = authenticationService;
}
}

View File

@ -1,6 +1,8 @@
package eu.eudat.services;
import eu.eudat.dao.entities.*;
import eu.eudat.dao.entities.security.CredentialDao;
import eu.eudat.dao.entities.security.UserTokenDao;
/**
* Created by ikalyvas on 1/4/2018.
@ -23,4 +25,6 @@ public interface DatabaseRepository {
InvitationDao getInvitationDao();
DMPProfileDao getDmpProfileDao();
DMPResearcherDao getDmpResearcherDao();
CredentialDao getCredentialDao();
UserTokenDao getUserTokenDao();
}

View File

@ -1,6 +1,8 @@
package eu.eudat.services;
import eu.eudat.dao.entities.*;
import eu.eudat.dao.entities.security.CredentialDao;
import eu.eudat.dao.entities.security.UserTokenDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -25,7 +27,8 @@ public class DatabaseRepositoryImpl implements DatabaseRepository{
private ServiceDao serviceDao;
private UserInfoDao userInfoDao;
private InvitationDao invitationDao;
private CredentialDao credentialDao;
private UserTokenDao userTokenDao;
@Autowired
private void setDataRepositoryDao(DataRepositoryDao dataRepositoryDao) {
this.dataRepositoryDao = dataRepositoryDao;
@ -185,4 +188,24 @@ public class DatabaseRepositoryImpl implements DatabaseRepository{
public void setInvitationDao(InvitationDao invitationDao) {
this.invitationDao = invitationDao;
}
@Override
public CredentialDao getCredentialDao() {
return credentialDao;
}
@Autowired
public void setCredentialDao(CredentialDao credentialDao) {
this.credentialDao = credentialDao;
}
@Override
public UserTokenDao getUserTokenDao() {
return userTokenDao;
}
@Autowired
public void setUserTokenDao(UserTokenDao userTokenDao) {
this.userTokenDao = userTokenDao;
}
}

View File

@ -6,7 +6,8 @@
##########################Persistence##########################################
database.driver-class-name=org.postgresql.Driver
database.url = jdbc:postgresql://develdb1.madgik.di.uoa.gr:5432/dmptool
database.username = dmptool
database.password = dmpt00lu$r
##########################/Persistence##########################################
###################Allowed Proxy Service Host ############################
@ -17,7 +18,8 @@ configuration.externalUrls = file:///C:\\Users\\ikalyvas\\Documents\\Projects\\O
########################/Email#############################
spring.mail.default-encoding=UTF-8
spring.mail.host=smtp.gmail.com
spring.mail.username=kalivasioan@gmail.com
spring.mail.password=A3b*1*92
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.test-connection=false
@ -27,9 +29,10 @@ mail.subject = Invitation to DMP Plan {dmpname}
mail.content = You have been invited to {dmpname} data management plan.Follow the link localhost:4200/invitation/{invitationID} to submit it
mail.from = citesagrdev@gmail.com
########################Persistence/Hibernate Generic#############################
########################FACEBOOK LOGIN Properties#############################
facebook.login.clientId = 110586756143149
facebook.login.clientSecret = 522a847f05c873d0222c85109e24f55a
facebook.login.namespace = eudat
########################Persistence/Hibernate/Batch##############################
#persistence.hibernate.jdbc.batch_size = 30
#persistence.hibernate.order_inserts = true

View File

@ -12,7 +12,7 @@
<button mat-icon-button>
<i class="fa fa-linkedin"></i>
</button>
<button mat-icon-button>
<button mat-icon-button (click)="facebookLogin()">
<i class="fa fa-facebook-square"></i>
</button>
<button mat-icon-button>

View File

@ -1,3 +1,4 @@
import { LoginProviders } from '../models/login/LoginInfo';
import { HttpClient } from '@angular/common/http';
import { Component, OnInit, ElementRef, AfterViewInit, VERSION, Injectable, NgZone } from '@angular/core';
import { Router, ActivatedRoute, Params } from "@angular/router";
@ -7,6 +8,7 @@ import { AuthService } from '../services/auth/auth.service';
import { SnackBarNotificationComponent } from '../shared/components/notificaiton/snack-bar-notification.component';
declare const gapi: any;
declare const FB: any;
@Component({
selector: 'login',
@ -25,6 +27,8 @@ export class LoginComponent implements OnInit {
private zone: NgZone
) { }
ngOnInit() {
gapi.load('auth2', () => {
this.auth2 = gapi.auth2.init({
@ -34,6 +38,14 @@ export class LoginComponent implements OnInit {
});
this.attachGoogleSignin(document.getElementById('googleSignInButton'));
});
FB.init({
appId: '110586756143149',
cookie: false, // enable cookies to allow the server to access
// the session
xfbml: true, // parse social plugins on this page
version: 'v2.8' // use graph api version 2.5
});
}
public attachGoogleSignin(element) {
@ -42,7 +54,7 @@ export class LoginComponent implements OnInit {
var id_token = googleUser.getAuthResponse().id_token;
if (id_token) {
this.authService.login({ ticket: id_token, service: "google" }).subscribe(
this.authService.login({ ticket: id_token, provider: LoginProviders.Google }).subscribe(
res => this.onLogInSuccess(res),
error => this.onLogInError(error)
)
@ -73,4 +85,17 @@ export class LoginComponent implements OnInit {
extraClasses: ['snackbar-warning']
})
}
public facebookLogin() {
FB.login((response: any) => {
if (response.status === 'connected' || 'not_authorized') {
this.authService.login({ ticket: response.authResponse.accessToken, provider: LoginProviders.Facebook }).subscribe(
res => this.onLogInSuccess(res),
error => this.onLogInError(error)
)
}
}, { scope: 'user_friends,email' });
}
}

View File

@ -1,4 +1,9 @@
export enum LoginProviders{
Google = 1,
Facebook = 2
}
export class LoginInfo {
public ticket: string;
public service: string;
public provider: LoginProviders;
}

View File

@ -10,6 +10,7 @@
<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">
<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>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">