// Path: src/main/java/it/univaq/incipict/profilemanager/business/ProfileManagerException.java
// public class ProfileManagerException extends  RuntimeException {
//    private static final long serialVersionUID = -2747157039796007525L;
// 
//    public ProfileManagerException() {
//       super();
//    }
// 
//    public ProfileManagerException(String message, Throwable cause) {
//       super(message, cause);
//    }
// 
//    public ProfileManagerException(String message) {
//       super(message);
//    }
// 
//    public ProfileManagerException(Throwable cause) {
//       super(cause);
//    }
// }
// 
// Path: src/main/java/it/univaq/incipict/profilemanager/business/SecurityService.java
// public interface SecurityService {
//    
//    User authenticate(String username) throws ProfileManagerException;
// }
// 
// Path: src/main/java/it/univaq/incipict/profilemanager/business/model/User.java
// @Entity
// @Table(name = "User", uniqueConstraints = { @UniqueConstraint(columnNames = "email") })
// public class User implements java.io.Serializable {
//    private static final long serialVersionUID = -5461054434128060682L;
// 
//    @Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
//    @Column(name = "id")
//    private Long id;
// 
//    @Column(name = "firstname", nullable = false, length = 64)
//    private String firstname;
// 
//    @Column(name = "lastname", nullable = false, length = 64)
//    private String lastname;
// 
//    @Column(name = "email", nullable = false, length = 128)
//    private String email;
// 
//    @Column(name = "password", nullable = false, length = 32)
//    private String password;
// 
//    @JsonIgnore
//    @ManyToMany(fetch = FetchType.EAGER)
//    @JoinTable(name = "User_Role", joinColumns = { @JoinColumn(name = "id_user") }, inverseJoinColumns = {
//          @JoinColumn(name = "id_role") })
//    private Set<Role> roles = new HashSet<Role>();
// 
//    @JsonIgnore
//    @ManyToMany(fetch = FetchType.EAGER)
//    @JoinTable(name = "User_Information", joinColumns = { @JoinColumn(name = "id_user") }, inverseJoinColumns = {
//          @JoinColumn(name = "id_information") })
//    private Set<Information> informationSet = new HashSet<Information>();
// 
//    public Long getId() {
//       return id;
//    }
// 
//    public void setId(Long id) {
//       this.id = id;
//    }
// 
//    public String getFirstname() {
//       return firstname;
//    }
// 
//    public void setFirstname(String firstname) {
//       this.firstname = firstname;
//    }
// 
//    public String getLastname() {
//       return lastname;
//    }
// 
//    public void setLastname(String lastname) {
//       this.lastname = lastname;
//    }
// 
//    public String getEmail() {
//       return email;
//    }
// 
//    public void setEmail(String email) {
//       this.email = email;
//    }
// 
//    public String getPassword() {
//       return password;
//    }
// 
//    public void setPassword(String password) {
//       this.password = password;
//    }
// 
//    public Set<Role> getRoles() {
//       return roles;
//    }
// 
//    public void setRoles(Set<Role> roles) {
//       this.roles = roles;
//    }
// 
//    public Set<Information> getInformationSet() {
//       return informationSet;
//    }
// 
//    public void setInformationSet(Set<Information> informationSet) {
//       this.informationSet = informationSet;
//    }
// 
//    @Override
//    public int hashCode() {
//       final int prime = 31;
//       int result = 1;
//       result = prime * result + ((id == null) ? 0 : id.hashCode());
//       return result;
//    }
// 
//    @Override
//    public boolean equals(Object obj) {
//       if (this == obj)
//          return true;
//       if (obj == null)
//          return false;
//       if (getClass() != obj.getClass())
//          return false;
//       User other = (User) obj;
//       if (id == null) {
//          if (other.id != null)
//             return false;
//       } else if (!id.equals(other.id))
//          return false;
//       return true;
//    }
// 
// }


import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import it.univaq.incipict.profilemanager.business.ProfileManagerException;
import it.univaq.incipict.profilemanager.business.SecurityService;
import it.univaq.incipict.profilemanager.business.model.User;
/*
 * Profile Manager - Copyright (C) 2016  Daniele Tellina
 *
 * Profile Manager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * Profile Manager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with Profile Manager.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.univaq.incipict.profilemanager.business.impl;




/**
 * 
 * @author Alexander Perucci (http://www.alexanderperucci.com/)
 *
 */
@Service
public class JPASecurityService implements SecurityService {
   
   @PersistenceContext
   private EntityManager em;

   @Override
   @Transactional
// Path: src/main/java/it/univaq/incipict/profilemanager/business/ProfileManagerException.java
// public class ProfileManagerException extends  RuntimeException {
//    private static final long serialVersionUID = -2747157039796007525L;
// 
//    public ProfileManagerException() {
//       super();
//    }
// 
//    public ProfileManagerException(String message, Throwable cause) {
//       super(message, cause);
//    }
// 
//    public ProfileManagerException(String message) {
//       super(message);
//    }
// 
//    public ProfileManagerException(Throwable cause) {
//       super(cause);
//    }
// }
// 
// Path: src/main/java/it/univaq/incipict/profilemanager/business/SecurityService.java
// public interface SecurityService {
//    
//    User authenticate(String username) throws ProfileManagerException;
// }
// 
// Path: src/main/java/it/univaq/incipict/profilemanager/business/model/User.java
// @Entity
// @Table(name = "User", uniqueConstraints = { @UniqueConstraint(columnNames = "email") })
// public class User implements java.io.Serializable {
//    private static final long serialVersionUID = -5461054434128060682L;
// 
//    @Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
//    @Column(name = "id")
//    private Long id;
// 
//    @Column(name = "firstname", nullable = false, length = 64)
//    private String firstname;
// 
//    @Column(name = "lastname", nullable = false, length = 64)
//    private String lastname;
// 
//    @Column(name = "email", nullable = false, length = 128)
//    private String email;
// 
//    @Column(name = "password", nullable = false, length = 32)
//    private String password;
// 
//    @JsonIgnore
//    @ManyToMany(fetch = FetchType.EAGER)
//    @JoinTable(name = "User_Role", joinColumns = { @JoinColumn(name = "id_user") }, inverseJoinColumns = {
//          @JoinColumn(name = "id_role") })
//    private Set<Role> roles = new HashSet<Role>();
// 
//    @JsonIgnore
//    @ManyToMany(fetch = FetchType.EAGER)
//    @JoinTable(name = "User_Information", joinColumns = { @JoinColumn(name = "id_user") }, inverseJoinColumns = {
//          @JoinColumn(name = "id_information") })
//    private Set<Information> informationSet = new HashSet<Information>();
// 
//    public Long getId() {
//       return id;
//    }
// 
//    public void setId(Long id) {
//       this.id = id;
//    }
// 
//    public String getFirstname() {
//       return firstname;
//    }
// 
//    public void setFirstname(String firstname) {
//       this.firstname = firstname;
//    }
// 
//    public String getLastname() {
//       return lastname;
//    }
// 
//    public void setLastname(String lastname) {
//       this.lastname = lastname;
//    }
// 
//    public String getEmail() {
//       return email;
//    }
// 
//    public void setEmail(String email) {
//       this.email = email;
//    }
// 
//    public String getPassword() {
//       return password;
//    }
// 
//    public void setPassword(String password) {
//       this.password = password;
//    }
// 
//    public Set<Role> getRoles() {
//       return roles;
//    }
// 
//    public void setRoles(Set<Role> roles) {
//       this.roles = roles;
//    }
// 
//    public Set<Information> getInformationSet() {
//       return informationSet;
//    }
// 
//    public void setInformationSet(Set<Information> informationSet) {
//       this.informationSet = informationSet;
//    }
// 
//    @Override
//    public int hashCode() {
//       final int prime = 31;
//       int result = 1;
//       result = prime * result + ((id == null) ? 0 : id.hashCode());
//       return result;
//    }
// 
//    @Override
//    public boolean equals(Object obj) {
//       if (this == obj)
//          return true;
//       if (obj == null)
//          return false;
//       if (getClass() != obj.getClass())
//          return false;
//       User other = (User) obj;
//       if (id == null) {
//          if (other.id != null)
//             return false;
//       } else if (!id.equals(other.id))
//          return false;
//       return true;
//    }
// 
// }


// Path: src/main/java/it/univaq/incipict/profilemanager/business/impl/JPASecurityService.java
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import it.univaq.incipict.profilemanager.business.ProfileManagerException;
import it.univaq.incipict.profilemanager.business.SecurityService;
import it.univaq.incipict.profilemanager.business.model.User;

/*
 * Profile Manager - Copyright (C) 2016  Daniele Tellina
 *
 * Profile Manager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * Profile Manager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with Profile Manager.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.univaq.incipict.profilemanager.business.impl;




/**
 * 
 * @author Alexander Perucci (http://www.alexanderperucci.com/)
 *
 */
@Service
public class JPASecurityService implements SecurityService {
   
   @PersistenceContext
   private EntityManager em;

   @Override
   @Transactional
   public User authenticate(String username) throws ProfileManagerException {