我正在尝试建立一个类似于这个问题的Spring Security Login(问题看起来和我的一样,我确实试过了解决方案,但没有去)
使用MySQL Workbench,我的SQL是
CREATE TABLE IF NOT EXISTS `mtc`.`authorities` (
`username` VARCHAR(45) NOT NULL,
`authority` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`username`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `mtc`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mtc`.`users` (
`username` VARCHAR(45) NOT NULL,
`name` VARCHAR(45) NULL DEFAULT NULL,
`password` VARCHAR(45) NULL DEFAULT NULL,
`gender` VARCHAR(45) NULL DEFAULT NULL,
`member_type` VARCHAR(45) NULL DEFAULT NULL,
`grade` VARCHAR(45) NULL DEFAULT NULL,
`ad_line1` VARCHAR(45) NULL DEFAULT NULL,
`ad_line2` VARCHAR(45) NULL DEFAULT NULL,
`ad_city` VARCHAR(45) NULL DEFAULT NULL,
`ad_county` VARCHAR(45) NULL DEFAULT NULL,
`contact_num` VARCHAR(45) NULL DEFAULT NULL,
`em_con_name` VARCHAR(45) NULL DEFAULT NULL,
`em_con_num` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`username`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
我的所有数据库工作正常,因为我可以通过jdbc连接,我可以显示信息,我可以写入数据库。安全性也在起作用,因为我可以启用和阻止对页面的访问。我也可以使用XML中的硬编码值登录(如果我删除它们,我仍然会遇到同样的问题)
安全context.xml中
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="chris" authorities="admin"
password="chris" />
<security:user name="sorin" authorities="admin"
password="sorin" />
</security:user-service>
</security:authentication-provider>
<security:authentication-provider>
<security:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select username,password, enabled from users where username = ?" />
</security:authentication-provider>
</security:authentication-manager>
<security:http use-expressions="true">
<security:intercept-url pattern="/static/**" access="permitAll" />
<security:intercept-url pattern="/login" access="permitAll" />
<security:intercept-url pattern="/members" access="isAuthenticated()" />
<security:intercept-url pattern="/" access="permitAll" />
<security:intercept-url pattern="/createmembers" access="permitAll" />
<security:intercept-url pattern="/register" access="permitAll" />
<security:intercept-url pattern="/registerSuccess" access="permitAll" />
<security:intercept-url pattern="/**" access="denyAll" />
<security:form-login login-page="/login"
authentication-failure-url="/login?error=true" />
</security:http>
我的登录页面只是在重定向到登录页面时给我一个error = true标记,所以它似乎设置正确。
有什么想法吗? :)