0

I am new to spring security, here i am not able to configure spring security with hibernate.cfg.xml file. So any suggestions are welcomed. Thank you in advance.

My hibernate.cfg.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
      <!-- SQL Dialect -->
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql://localhost:3306/tracking</property>
      <property name="connection.user">root</property>
      <property name="connection.password">Thinkpad@123</property>
      <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
      <property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
      <property name="hibernate.connection.pool_size">5</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.format_sql">true</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <mapping class="com.sample.Entity.Student" />
      <mapping class="com.sample.Entity.Employee" />
      <mapping class="com.sample.Entity.SignUp" />
   </session-factory>
</hibernate-configuration>

Here is my spring-sercurity.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans             https://www.springframework.org/schema/beans/spring-beans-3.0.xsd             http://www.springframework.org/schema/security             https://www.springframework.org/schema/security/spring-security.xsd">
   <http>
      <intercept-url pattern="/**" access="hasRole('USER')" />
      <form-login />
      <logout />
   </http>
   <authentication-manager>
      <authentication-provider>
         <user-service>
            <user name="sagar" password="{noop}12345" authorities="ROLE_USER, ROLE_ADMIN" />
         </user-service>
      </authentication-provider>
   </authentication-manager>
</beans:beans> 
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
Sagar Chidre
  • 5
  • 1
  • 7
  • What exactly do you try to achieve? Store user credentials in the DB? – Mannekenpix Jun 13 '19 at 12:32
  • here in this code securitydatasource will be pointing database properties so how should do in hibernate.cfg.xml file – Sagar Chidre Jun 13 '19 at 12:42
  • in the above code i am manually specifying the username and password but i want connect to database and use the username password and role and than navigate to other page – Sagar Chidre Jun 13 '19 at 12:45
  • 2
    Possible duplicate of [Spring Security 3 database authentication with Hibernate](https://stackoverflow.com/questions/2683308/spring-security-3-database-authentication-with-hibernate) – Mannekenpix Jun 14 '19 at 07:55

0 Answers0