Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. @Entity
  2. @Table(name="Professeurs")
  3. public class Professeur implements Serializable ,Comparable<Professeur>{
  4.  
  5. .....
  6.  
  7. @OneToOne(fetch=FetchType.EAGER)
  8. @JoinColumn(name="idUser",nullable=false)
  9. private User user;
  10.  
  11. ..
  12. }
  13.  
  14. @javax.persistence.Entity
  15. @Table(name="USERS")
  16. public class User implements Serializable {
  17.  
  18. @Id
  19. @GeneratedValue(strategy=GenerationType.IDENTITY)
  20. @Column(name="user_id")
  21. private Long idUser;
  22. private String email;
  23. private String password;
  24.  
  25.  
  26. private boolean actived;
  27.  
  28. @OneToMany(orphanRemoval=true)
  29. @JoinColumn(name="user_id",nullable=false)
  30. private Collection<Role> roles=new ArrayList<Role>();
  31. }
  32.  
  33. <?xml version="1.0" encoding="UTF-8"?>
  34. <beans xmlns="http://www.springframework.org/schema/beans"
  35. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  36. xmlns:context="http://www.springframework.org/schema/context"
  37. xmlns:tx="http://www.springframework.org/schema/tx"
  38. xmlns:s="http://www.springframework.org/schema/security"
  39. xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
  40. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  41. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  42. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
  43.  
  44.  
  45. <bean id="datasource"
  46. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  47. <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
  48. <property name="url" value="jdbc:mysql://localhost:3306/ecoleiqr_base"></property>
  49. <property name="username" value="ecoleiqr"></property>
  50. <property name="password" value="43412012"></property>
  51. </bean>
  52. <bean id="persistenceUnitManager"
  53. class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
  54. <property name="defaultDataSource" ref="datasource"></property>
  55. <property name="persistenceXmlLocations">
  56. <list>
  57. <value>classpath*:META-INF/persistence.xml</value>
  58. </list>
  59. </property>
  60.  
  61. </bean>
  62. <bean id="entityManagerFactory"
  63. class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  64. <property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
  65. <property name="persistenceUnitName" value="UP"></property>
  66. </bean>
  67. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  68. <property name="entityManagerFactory" ref="entityManagerFactory"></property>
  69. </bean>
  70. <tx:annotation-driven transaction-manager="transactionManager" />
  71. <context:annotation-config></context:annotation-config>
  72.  
  73.  
  74. <bean id="dao" class="com.ecole.iqrae.dao.DaoImpl" init-method="calculeAgeAllEleve"/>
  75. <bean id="metier" class="com.ecole.iqrae.metier.MetierImpl">
  76. <property name="dao" ref="dao"></property>
  77. <property name="daoDashboard" ref="dao"></property>
  78. </bean>
  79.  
  80.  
  81. <bean id="eleveValidator" class="com.ecole.iqrae.validator.EleveValidator"/>
  82. <bean id="professeurValidator" class="com.ecole.iqrae.validator.ProfesseurValidator"/>
  83. <bean id="parentValidator" class="com.ecole.iqrae.validator.ParentValidator"/>
  84. <bean id="niveauValidator" class="com.ecole.iqrae.validator.NiveauValidator"/>
  85. <bean id="sectionValidator" class="com.ecole.iqrae.validator.SectionValidator"/>
  86. <bean id="matiereValidator" class="com.ecole.iqrae.validator.MatiereValidator"/>
  87. <bean id="imageValidator" class="com.ecole.iqrae.validator.ImageValidator"/>
  88.  
  89. <!-- Calcul age au demarage de serveur -->
  90. <!-- <bean id="calculAge" class="com.ecole.iqrae.validator.CalculAge" init-method="calculeAgeAllEleve" /> -->
  91.  
  92. <s:http>
  93. <s:intercept-url pattern="/admin/**" access="ROLE_ADMIN"/>
  94. <s:form-login login-page="/login" default-target-url="/admin/dashboard"
  95. authentication-failure-url="/login" />
  96. <s:logout logout-success-url="/login" />
  97. </s:http>
  98. <s:authentication-manager>
  99. <s:authentication-provider>
  100. <!-- <s:password-encoder hash="md5"></s:password-encoder> -->
  101. <s:jdbc-user-service data-source-ref="datasource"
  102. users-by-username-query="select email,password, actived
  103. from users where email=?"
  104. authorities-by-username-query="select u.email, r.roleName from users u, role r
  105. where u.user_id = r.user_id and u.email =? " />
  106.  
  107. </s:authentication-provider>
  108. </s:authentication-manager>
  109.  
  110.  
  111.  
  112. </beans>
  113.  
  114. if(professeur.getIdProfesseur()==null){
  115. Role role=new Role();
  116. role.setRoleName(EcoleIqraeControllerConstants.constants.back.roleProfesseur);
  117.  
  118. User user=new User();
  119. foundDupliquateEmail(professeur.getEmail());
  120. user.setEmail(professeur.getEmail());
  121.  
  122. user.setActived(true);
  123. user.getRoles().add(role);
  124.  
  125.  
  126. em.persist(user);
  127. em.persist(role);
  128. professeur.setUser(user);
  129.  
  130. em.persist(professeur);
  131.  
  132. user.setPassword(professeur.getPrenom()+professeur.getNom()+professeur.getIdProfesseur());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement