Java Web编程入门--spring boot + shiro(续)
2017-05-27 11:01
543 查看
form提交
注:input 属性使用name
后台登录验证代码
<form th:action="@{/login}" method="POST"> <div class="form-group has-feedback"> <input name="username" type="text" class="form-control" placeholder="用户账户" required="" value="test"/><span class="glyphicon glyphicon-envelope form-control-feedback"></span> </div> <div class="form-group has-feedback"> <input name="password" type="password" class="form-control" placeholder="用户密码" required="" value="test"/><span class="glyphicon glyphicon-lock form-control-feedback"></span> </div> <div class="row"> <!-- /.col --> <div class="col-xs-12"> <button class="btn btn-default submit"> <span>登录</span> </button> </div> <!-- /.col --> </div> <div id="tips"></div> </form>
注:input 属性使用name
后台登录验证代码
/** * 认证信息(身份验证) Authentication 是用来验证用户身份 */ @Override protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token) throws AuthenticationException { System.out.println("身份认证-->MyShiroRealm.doGetAuthenticationInfo()"); // 获取用户的输入帐号 String username = (String) token.getPrincipal(); System.out.println("token.getCredentials():"+token.getCredentials()); // 通过username从数据库中查找 User对象,如果找到,没找到. // 实际项目中,这里可以根据实际情况做缓存, // 如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法 SysRightUser sysRightUser = userInfoService.selectByAccount(username); if (sysRightUser == null) { return null; } SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( sysRightUser, // 用户对象 sysRightUser.getPassword(), // 密码 getName() // realm name ); Session session = SecurityUtils.getSubject().getSession(); session.setAttribute("userInfo",sysRightUser); return authenticationInfo; }
相关文章推荐
- Java Web编程入门--spring boot + shiro
- spring boot 入门 使用spring.profiles.active来分区配置-java编程
- 【JavaWeb】Intellij Idea SpringBoot(一)——入门及配置thymeleaf
- 在Java的Struts框架下进行web编程的入门教程
- spring boot 入门hello web 以及错误处理
- Java Web编程入门--junit运行错误ClassNotFoundException
- Struts Spring Hibernate快速入门-Java基础-Java-编程开发
- jeesz分布式企业框架 javaWeb分布式架构 springmvc+mybatis+shiro dubbo zookeeper redis kafka app服务
- Java源码 SpringMVC Mybatis Shiro Bootstrap Rest Webservice
- JAVAWEB开发之Spring详解之——Spring的入门以及IOC容器装配Bean(xml和注解的方式)、Spring整合web开发、整合Junit4测试
- java SSM 框架 微信自定义菜单 快递接口 SpringMVC mybatis redis shiro ehcache websocket
- spring boot web 入门
- Spring Boot入门——web相关配置
- Spring boot 应用有错误提示:Dynamic Web Module 3.1 requires Java 1.7 or newer.
- Java Web编程入门--错误信息“The method getUserById(int) of type UserServiceImpl must override a superclass”
- JAVA_WEB项目之Spring中使用AOP编程运用到Lucene中实现解耦
- Java源码 SpringMVC Mybatis Shiro Bootstrap Rest Webservice
- Java Web开发之集成Spring Boot
- 通过springboot+mybatis+mysql+freemarker创建一个java web项目
- Spring基础:快速入门spring boot(3):创建Restful的Web服务