우리가 개발할 때, 우리는 때때로 전통적인 스프링 시로를 스프링 부츠 프로젝트로 전환하거나 직접 통합해야합니다. XML 구성과 스프링 Bean 코드 구성의 관계 인 이름에 대한 지식을 알아 내야합니다. Spring Boot는 XML 구성 파일이 없기 때문에 매우 중요합니다 (절대적으로 Spring Boot는 XML 구성을 참조 할 수 있습니다).
의존성 소개 :
<pectionency> <artifactid> ehcache-core </artifactid> <groupId> net.sf.ehcache </groupid> <버전> 2.5.0 </version> </dependency> <prectionency> <groupId> org.apache.shiro </groupid> <artifactid> shiro-ehcache </version> 1.2.2.2.2.2.2.2.2.2.2.2.2.2.2.22. <groupid> org.slf4j </groupid> <artifactid> slf4j-api </artifactid> <bersion> 1.7.25 </version> </fectionency> <prectionency> <groupid> org.apache.shiro </groupid> <artifactid> shiro-core </arevactid> 1.3 </version> </version> </version> </version> </version> <groupid> org.apache.shiro </groupid> <artifactid> Shiro-web </artifactid> <bersion> 1.2.3 </version> </fectionency> <groupidency> <groupid> org.apache.shiro </groupid> <artifactid> shiro-spring </areverifactid> 1.3 </version> </rependency> </refence> <groupid> org.apache.shiro </groupid> <artifactid> Shiro-spring </artifactid> <bersion> 1.2.3 </version> </fectionency>
오류가 발생하면 SLF4J를 찾을 수 없습니다.
<pectionency> <groupid> org.slf4j </groupid> <artifactid> slf4j-log4j12 </artifactid> <bersion> 1.7.25 </version> </fectionency>
기존 XML 구성은 다음과 같습니다.
<? xml 버전 = "1.0"alcoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://ww.w.w3.org/2001/xmlschema-instance" xmlns : context = "http://www.springframework.org/schema/context"xmlns : aop = "http://www.springframework.org/schema/aop"xmlns : tx = "http://www.spramwork.org/schema/schema/schema/schema. xsi : schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/sprring.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <context : component-scan base-package ="com.len "/> <!-<beal id ="myRealm ">"myRealm "> ref = "Credentialsmatcher"/> </bean> <bean id = "repmissionFilter"/<!-현재 사용자 정의 인터 셉션 검증을 제거하고 개인 별 로그인 서비스를 처리합니다.> <!-<bean id = "CustomAdVicFilter"> <속성 이름 = "avelickeyAttribute"value = "shirologInfailure"</bean>-> <Bean id = "verfityCode"> 이름 = "실패 KirologinFailure"/> <속성 이름 = "jcaptchaparam"value = "code"/> <속성 이름 = "verfiticode"value = "true"/> </bean> <!-shiro 필터-> <bean id = "shirofilter"> value = "/login"/> <property name = "UnauthorizedUrl"value = "/gologin"/> <property name = "filters"> <map> <enterd key = "per"value-ref = "permissionFilter"/> <Entry Key = "valcode"value-ref = "verfityCodeFilter"/>>-<Entry Key = "main" value-Ref = "CustomAdVicFilter" />-> < /map> < /property> <속성 이름 = "FilterChainDefinitions"> <value> <! <value>- /** = Anonany URL은 익명으로 액세스 할 수 있습니다-> /login = vercode, anon /getCode = anon /logout /logout /plugin /** = anon <! 액세스->/user/** = per <!-/login = main->/** = authc </valuec </valec> </property> </bean> <!-보안 관리자-> <bean id = "securitymanager"> <property name = "realm"ref = "myRealm"/<property name = "cachemanager"ref = "cachemanager"! />-> </bean> <!-자격 증명 매칭 자-> <bean id = "CredentialSmatcher"> <creptuctor-arg index = "0"ref = "cachemanager"/> <constructor-arg index = "1"value = "5"/> <속성 이름 = "hashalgorithmname"value = "md5"> <속성 이름 = "Hashiteration" "hashiteration". <!-cache-> <bean id = "cachemanager"> <property name = "cachemanagerconfigfile"value = "classpath : ehcache/ehcache.xml"/> </bean> <!-열기 주석-> <bean> <property name = "securitymanager"ref = "SecurityManager"/>> <bean id = "LIFECYCYSEDPRESOR" /> < /beans>
Bean으로 변환 새 클래스 생성 Shiroconfig
@ConfigurationPublic Class ShiroConfig {@bean public retrylimitcredentialsmatcher getRetrylimitcredentialsmatcher () {retrylimitcredentialsmatcher rm = 새로운 retrylimitcredentialsmatcher (getCachemanager (), "); rm.sethashalgorithmname ( "md5"); rm.sethisterations (4); RM 리턴; } @bean public loginrealm getLoginRealm () {loginRealm Realm = new loginRealm (); Realm.SetCredentialSmatcher (getRetryLimitCredentialSmatcher ()); 리턴 영역; } @bean public ehcachemanager getCacheManager () {ehcachemanager ehcachemanager = new ehcacheManager (); ehcachemanager.setCachemanagerConfigfile ( "classpath : ehcache/ehcache.xml"); ehcachemanager를 반환합니다. } @bean public lifecyclebeanpostprocessor getLifeCycleBeanPostProcessor () {return new LifeCycleBeanPostProcessor (); } @Bean (이름 = "SecurityManager") public defaultWebSecurityManager getDefaultWebSecurityManager () {DefaultWebSecurityManager dwm = new DefaultWebsecurityManager (); dwm.setRealm (getLoginRealm ()); dwm.setCacheManager (getCacheManager ()); 반환 dwm; } @Bean public arbismissionFilter getPermissionFilter () {repmissionFilter pf = new AprismentFilter (); 반환 pf; } @bean public verfityCodeFilter getVerfityCodeFilter () {verfityCodeFilter vf = new VerfityCodeFilter (); vf.setfailurekeyAttribute ( "ShirologinFailure"); vf.setjcaptchaparam ( "코드"); vf.setverfiticode (true); 반환 vf; } @Bean (name = "shirofilter") public shirofilterfactorybean getshirofilterfactorybean () {shirofilterfactorybean sfb = new shirofilterfactorybean (); sfb.setsecurityManager (getDefaultWebsecurityManager ()); sfb.setLoginUrl ( "/login"); sfb.setunauthorizedurl ( "/gologin"); Map <String, 필터> 필터 = New Hashmap <> (); filters.put ( "per", getPermissionFilter ()); filters.put ( "vercode", getVerfityCodeFilter ()); sfb.setfilters (필터); Map <String, String> filtermap = New LinkedHashMap <> (); filtermap.put ( "/login", "vercode, anon"); //filtermap.put("/login","Anon "); filtermap.put ( "/getCode", "Anon"); filtermap.put ( "/로그 아웃", "로그 아웃"); filtermap.put ( "/plugin/**", "anon"); filtermap.put ( "/user/**", "per"); filtermap.put ( "/**", "authc"); sfb.setfilterchainDefinitionMap (filtermap); 반환 SFB; } @Bean public defaultAdvisorAutoProxyCreator AdvisorAutoProxyCreator () {defaultAdvisorAutoProxyCreator AdvisorAutoProxyCreator = 새로운 DefaultAdvisorAutoProxyCreator (); AdvisorAutoProxyCreator.SetProxyTargetCrats (True); 반환 AdvisorAutoProxyCreator; } @bean public authorizationAttributesOURCEADvisor getAuthorizationAttributesOUrceAdvisor () {authorizationAttributesourceAdvisor as = new AuthorizationAttributeSourceadvisor (); as.setsecurityManager (getDefaultWebsecurityManager ()); 다시 반환; } @bean public filterregistrationbean delegatingfilterproxy () {filterregistrationBean filterregistrationBean = new FilterRegistrationBean (); DELEGATETFILTERPROXY PROXY = NEW DELEGATINGFILTERPROXY (); proxy.setTargetFilterLifeCycle (true); proxy.settargetBeanName ( "shirofilter"); FilterRegistrationBean.SetFilter (프록시); 반환 필터 등록 비안; }카테고리 중 일부는 사용자 정의 인터셉터 및 영역입니다. 현재 Spring은 Shiro를 주입 할 수 있습니다. 즉, Spring Boot는 Shiro를 통합합니다.
다른 구성으로 인해 실패한 경우 Shiro와 통합되는 오픈 소스 프로젝트 Lenos 빠른 개발 스프링 부팅 버전을 참조하여 학습에 사용할 수 있습니다.
주소 : https://gitee.com/bweird/lenosp
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.