首页 文章 精选 留言 我的

精选列表

搜索[boot],共8309篇文章
优秀的个人博客,低调大师

spring-boot学习

Controller的使用 注: 通常程序开发后端需要提供的是rest接口,返回一些json格式给前端,尽量不要使用模板的方式,使用模板会在性能上带来很大的损耗. 参数的获取 知识点整理 @Restcontroller和@controller的区别 如果使用@Restcontroller注解,就不能返回jsp,html页面,视图解析器无法解析jsp,html页面 @Controller注解,若返回json等内容到页面,则需要加@Response注解,而且需要页面返回 url映射可以是以集合的形式获取 例:@RequestMapping(value ={"/hello/","/hi"}) 获取一个id值 :@RequestMapping(value ={"/hello/{id}",method=RequestMethod.GET}) @PathVariable("id") 获取操作 导航栏: /hello/12也可以 12/hello @RequestParam("id") 获取操作 导航栏

优秀的个人博客,低调大师

spring boot整合shiro

一、需要的依赖包 <!--shiro的版本--> <properties> <org.apache.shiro.version>1.3.2</org.apache.shiro.version> </properties> <!--shiro--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>${org.apache.shiro.version}</version> /dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> <version>${org.apache.shiro.version}</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>${org.apache.shiro.version}</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-ehcache</artifactId> <version>${org.apache.shiro.version}</version> </dependency> 二、添加ehcache <?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPExml> <ehcacheupdateCheck="false"name="shiroCache"> <!--http://ehcache.org/ehcache.xml--> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="false" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" /> <!--登录记录缓存锁定10分钟--> <cachename="passwordRetryCache" maxEntriesLocalHeap="2000" eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="1800" overflowToDisk="false" statistics="true"> </cache> <cachename="authorizationCache" maxEntriesLocalHeap="2000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="0" overflowToDisk="false" statistics="true"> </cache> <cachename="authenticationCache" maxEntriesLocalHeap="2000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="0" overflowToDisk="false" statistics="true"> </cache> <cachename="shiro-activeSessionCache" maxEntriesLocalHeap="2000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="0" overflowToDisk="false" statistics="true"> </cache> </ehcache> 三、创建一个realm publicclassShiroRealmextendsAuthorizingRealm{ @Autowired privateUserBizbiz; @Override protectedAuthorizationInfodoGetAuthorizationInfo(PrincipalCollectionprincipals){ //获取用户权限 SimpleAuthorizationInfoauthorizationInfo=newSimpleAuthorizationInfo(); authorizationInfo.setRoles(角色集合); authorizationInfo.setStringPermissions(权限集合); returnauthorizationInfo; } @Override protectedAuthenticationInfodoGetAuthenticationInfo(AuthenticationTokentoken)throwsAuthenticationException{ returnnewSimpleAuthenticationInfo(获取到的用户账号, 获取到的用户密码,ByteSource.Util.bytes(user.getUserNo()+Constants.token.salt),getName()); } } 四、添加验证器 publicclassPlatFormCredentialsMatcherextendsHashedCredentialsMatcher{ @Autowired privateUserServiceservice; @Autowired privateEhCacheManagershiroEhcacheManager; @Override publicbooleandoCredentialsMatch(AuthenticationTokentoken,AuthenticationInfoinfo){ Cache<String,AtomicInteger>passwordRetryCache=shiroEhcacheManager.getCache("passwordRetryCache"); Stringuserno=(String)token.getPrincipal(); //retrycount+1 AtomicIntegerretryCount=passwordRetryCache.get(userno); if(retryCount==null){ retryCount=newAtomicInteger(0); passwordRetryCache.put(userno,retryCount); } if(retryCount.incrementAndGet()>5){ //ifretrycount>5throw thrownewExcessiveAttemptsException(); } booleanmatches=super.doCredentialsMatch(token,info); if(matches){ //clearretrycount passwordRetryCache.remove(userno); Result<User>userResult=service.findByUserNo(userno); //根据登录名查询用户 Subjectsubject=SecurityUtils.getSubject(); Sessionsession=subject.getSession(); session.setAttribute("user",userResult.getResultData()); } returnmatches; } } 五、添加shiro配置 @Configuration publicclassShiroConfiguration{ privatestaticMap<String,String>filterChainDefinitionMap=newLinkedHashMap<String,String>(); @Bean(name="ShiroRealm") publicShiroRealmgetShiroRealm(@Qualifier("credentialsMatcher")CredentialsMatchermatcher){ ShiroRealmshiroRealm=newShiroRealm(); shiroRealm.setCredentialsMatcher(matcher); returnshiroRealm; } @Bean(name="shiroEhcacheManager") publicEhCacheManagergetEhCacheManager(){ EhCacheManagerem=newEhCacheManager(); em.setCacheManagerConfigFile("classpath:ehcache/ehcache-shiro.xml"); returnem; } @Bean(name="credentialsMatcher") publicPlatFormCredentialsMatchergetCredentialsMatcher(){ PlatFormCredentialsMatcherplatFormCredentialsMatcher=newPlatFormCredentialsMatcher(); platFormCredentialsMatcher.setHashAlgorithmName("MD5"); platFormCredentialsMatcher.setHashIterations(2); platFormCredentialsMatcher.setStoredCredentialsHexEncoded(true); returnplatFormCredentialsMatcher; } @Bean(name="lifecycleBeanPostProcessor") publicLifecycleBeanPostProcessorgetLifecycleBeanPostProcessor(){ returnnewLifecycleBeanPostProcessor(); } @Bean publicDefaultAdvisorAutoProxyCreatorgetDefaultAdvisorAutoProxyCreator(){ DefaultAdvisorAutoProxyCreatordaap=newDefaultAdvisorAutoProxyCreator(); daap.setProxyTargetClass(true); returndaap; } @Bean(name="securityManager") publicDefaultWebSecurityManagergetDefaultWebSecurityManager(@Qualifier("ShiroRealm")ShiroRealmshiroRealm){ DefaultWebSecurityManagerdwsm=newDefaultWebSecurityManager(); dwsm.setRealm(shiroRealm); dwsm.setCacheManager(getEhCacheManager()); returndwsm; } @Bean publicAuthorizationAttributeSourceAdvisorgetAuthorizationAttributeSourceAdvisor(@Qualifier("securityManager")DefaultWebSecurityManagerdwsm){ AuthorizationAttributeSourceAdvisoraasa=newAuthorizationAttributeSourceAdvisor(); aasa.setSecurityManager(dwsm); returnnewAuthorizationAttributeSourceAdvisor(); } @Bean(name="shiroFilter") publicShiroFilterFactoryBeangetShiroFilterFactoryBean(@Qualifier("securityManager")DefaultWebSecurityManagerdwsm){ ShiroFilterFactoryBeanshiroFilterFactoryBean=newShiroFilterFactoryBean(); shiroFilterFactoryBean .setSecurityManager(dwsm); shiroFilterFactoryBean.setLoginUrl("/login"); shiroFilterFactoryBean.setSuccessUrl("/admin/index"); shiroFilterFactoryBean.setUnauthorizedUrl("/login"); filterChainDefinitionMap.put("/login","authc"); filterChainDefinitionMap.put("/BJUI/**","anon"); filterChainDefinitionMap.put("/platform/**","anon"); filterChainDefinitionMap.put("/admin/course/category/list","perms[user:view]"); filterChainDefinitionMap.put("/admin/course/category/edit","perms[user:update]"); filterChainDefinitionMap.put("/admin/course/category/update","perms[user:update]"); filterChainDefinitionMap.put("/admin/course/category/add","perms[user:add]"); filterChainDefinitionMap.put("/admin/**","anon"); shiroFilterFactoryBean .setFilterChainDefinitionMap(filterChainDefinitionMap); returnshiroFilterFactoryBean; } /** *FilterRegistrationBean *@return */ @Bean publicFilterRegistrationBeanfilterRegistrationBean(){ FilterRegistrationBeanfilterRegistration=newFilterRegistrationBean(); filterRegistration.setFilter(newDelegatingFilterProxy("shiroFilter")); filterRegistration.setEnabled(true); filterRegistration.addUrlPatterns("/*"); filterRegistration.setDispatcherTypes(DispatcherType.REQUEST); returnfilterRegistration; } }

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册