Ich mache gerade ein Projekt über Spring MVC und ich versuche Spring Security zu integrieren. Aber ich habe es versäumt, und ich habe absolut keine Ahnung, was ich vermisse. Bitte sehen Sie sich meinen Code an und geben Sie Ihre Vorschläge an.Warum funktioniert meine Spring Security nicht?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/**"
access="hasRole('ROLE_ADMIN')" />
<security:intercept-url pattern="/suser/**"
access="isAuthenticated()" />
<!-- <security:intercept-url pattern="/resources/**" access="isAuthenticated()"
/> -->
<!-- <security:form-login login-page="/home" default-target-url="/doctor"
authentication-failure-url="/authfailed" username-parameter="email" password-parameter="password"
/> <security:logout logout-success-url="/logoutsuccess" /> <security:csrf/> -->
<!-- <security:csrf disabled="true"/> -->
</security:http>
<security:authentication-manager>
<security:authentication-provider
user-service-ref="userService">
</security:authentication-provider>
</security:authentication-manager>
<security:jdbc-user-service id="userService"
data-source-ref="dataSource"
users-by-username-query="select email , password, true from user where userId=?"
authorities-by-username-query="select userId ,'ROLE_ADMIN' from user where userId=?" />
</beans>
ähnlich mein Controller ist:
@Controller
public class MainController {
@RequestMapping(value = "/signup", method = RequestMethod.GET)
public String getSignupPage() {
return "signup";
}
@RequestMapping(value = "/home", method = RequestMethod.GET)
public ModelAndView getLoginSignupPage() {
return new ModelAndView("module/loginsignup/loginsignup",StringConstants.PAGE_TITLE,StringConstants.WEB_APP_TITLE);
}
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String getIndexPage() {
return "index";
}
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String getAdminPage() {
return "admin";
}
@RequestMapping(value = "/authfailed", method = RequestMethod.GET)
public String getAuthFailPage() {
return "autherror";
}
@RequestMapping(value = "/logoutsuccess", method = RequestMethod.GET)
public String getLogoutSuccessPage() {
return "logoutsuccess";
}
@RequestMapping(value = "/suser/test", method = RequestMethod.GET)
public String getUserPage() {
return "user";
}
}
Auch meine Benutzereinheit:
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private long userId;
@Column
private String firstName;
@Column
private String middleName;
@Column
private String lastName;
@Column
private String email;
@Column
private String password;
@Column
private String userStatus;
@Column
private Date createdDate;
@Column
private Date updatedDate;
@Column
private int createdBy;
@Column
private int updatedBy;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "cityId")
private City city;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "user_link_document",
joinColumns = @JoinColumn(name = "userId"),
inverseJoinColumns = @JoinColumn(name = "documentId"))
private List<Document> documentList;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
private List<Review> reviewList;
Meine Abhängigkeiten in build.gradle Datei:
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("javax.servlet:jstl:1.2")
runtime("mysql:mysql-connector-java")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile ("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-security")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'
}
All meine Konfigurationen für Spring MVC sind korrekt. Abgesehen von Spring Security habe ich keine Probleme. Könnte mir bitte jemand sagen, was los ist? Wenn ich meine Anwendung durchsuche, erhalte ich keine Anmeldeseite, die Spring Security dem Benutzer zur Verfügung stellen sollte.
Nun verhält es sich auch nach dem Auskommentieren nicht anders: /. – Smrita
kommentieren Sie das und überprüfen Sie, ob es '/ home' erreicht oder nicht und umleiten zu' module/loginsignup/loginsignup' .... und wie Sie auf Ihre App zugreifen ?? 'localhost: xxx/APP /' oder 'localhost: xxx/APP/test /' –