2016-11-29 17 views
-1

Я пытаюсь защитить свой проект Spring Web MVC с помощью Apache Shiro и Stormpath. Я просмотрел некоторые учебные пособия в Интернете и получил пример конфигурации с помощью примера файла siro.ini, а также настройки Сиро через applicationContext.xml Spring. Я пытаюсь получить те же результаты от обоих методов. Вот shiro.ini файл:Попытка защитить Spring Web MVC с помощью Apache Shiro, где управление пользователями осуществляется через Stormpath Api.

[главная]

shiro.loginUrl = админ/login.htm

authc.successUrl = /admin/index.htm

cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager

securityManager.cacheManager = $ cacheManager

stormpathClient = com.stormpath.shiro.client.ClientFactory

stormpathClient.cacheManager = $ cacheManager

stormpathClient.apiKeyFileLocation = $ HOME/.stormpath/apiKey.properties

stormpathRealm = com.stormpath .shiro.realm.ApplicationRealm

stormpathRealm.client = $ stormpathClient

stormpathRealm.applicationRestUrl = https://api.stormpath.com/v1/applications/

stormpathRealm.groupRoleResolver.modeNames = имя

securityManager.realm = $ stormpathRealm

[URLs]

/админ/** = authc

/logout.htm = выезд

и вот боб definations в файле applicationContext.xml:

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> 
    <property name="securityManager" ref="securityManager"/> 
    <property name="loginUrl" value="/admin/login.htm"/> 
    <property name="successUrl" value="/admin/index.htm"/> 
    <!-- override these for application-specific URLs if you like: 
    <property name="unauthorizedUrl" value="/unauthorized.jsp"/> --> 
    <!-- The 'filters' property is not necessary since any declared javax.servlet.Filter bean --> 
    <!-- defined will be automatically acquired and available via its beanName in chain  --> 
    <!-- definitions, but you can perform instance overrides or name aliases here if you like: --> 
    <!-- <property name="filters"> 
     <util:map> 
      <entry key="anAlias" value-ref="someFilter"/> 
     </util:map> 
    </property> --> 
    <property name="filterChainDefinitions"> 
     <value>   
      /admin/** = authc, roles[admin] 
      /logout.htm = logout 
      # some example chain definitions: 
      #/docs/** = authc, perms[document:read] 
      #/** = authc 
      # more URL-to-FilterChain definitions here 
     </value> 
    </property> 
</bean> 

<!-- Define any javax.servlet.Filter beans you want anywhere in this application context. --> 
<!-- They will automatically be acquired by the 'shiroFilter' bean above and made available --> 
<!-- to the 'filterChainDefinitions' property. Or you can manually/explicitly add them  --> 
<!-- to the shiroFilter's 'filters' Map if desired. See its JavaDoc for more details.  --> 
<!--<bean id="someFilter" class="..."/> 
<bean id="anotherFilter" class="..."> ... </bean> 
--> 

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> 
    <!-- Single realm app. If you have multiple realms, use the 'realms' property instead. --> 
    <property name="realm" ref="myRealm"/> 
    <property name="cacheManager" ref="cacheManager"/> 

    <!-- By default the servlet container sessions will be used. Uncomment this line 
    to use shiro's native sessions (see the JavaDoc for more): --> 
    <!-- <property name="sessionMode" value="native"/> --> 
</bean> 
<bean id="stormpathClient" class="com.stormpath.shiro.client.ClientFactory"> 
    <!-- Single realm app. If you have multiple realms, use the 'realms' property instead. --> 
    <property name="cacheManager" ref="cacheManager"/> 
    <property name="apiKeyFileLocation" value="$HOME/.stormpath/apiKey.properties"/> 
    <!-- By default the servlet container sessions will be used. Uncomment this line 
    to use shiro's native sessions (see the JavaDoc for more): --> 
    <!-- <property name="sessionMode" value="native"/> --> 
</bean> 
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/> 

<!-- Define the Shiro Realm implementation you want to use to connect to your back-end --> 
<!-- security datasource: --> 
<bean id="myRealm" class="com.stormpath.shiro.realm.ApplicationRealm"> 
    <property name="applicationRestUrl" value="https://api.stormpath.com/v1/applications/<my app key here removed for privacy>"/> 
    <property name="client" ref="stormpathClient"/> 

</bean> 

<bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" /> 

я получаю сообщение об ошибке сказав:

Невозможно преобразовать значение типа [com.stormpath.shiro.client.ClientFactory] для требуемого типа [com.stormpath .sdk.client.Client] для «клиента» собственности: нет соответствующих редакторов или стратегии преобразования найдено

Это может быть из-за неполной Maven зависимостей:

<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring --> 
<dependency> 
    <groupId>org.apache.shiro</groupId> 
    <artifactId>shiro-spring</artifactId> 
    <version>1.4.0-RC2</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/com.stormpath.shiro/stormpath-shiro-core --> 
<dependency> 
    <groupId>com.stormpath.shiro</groupId> 
    <artifactId>stormpath-shiro-core</artifactId> 
    <version>0.8.0-RC1</version> 
</dependency> 

Может кто-то предложить зависимости, необходимые для достижения этого.

ответ

0

Возможно, вам не хватает элементов factory-bean/factory-method в вашем XML.

На стороне записки, самый простой способ, чтобы начать работу с Apache Shiro и Stormpath, чтобы взглянуть на один из examples В вашем случае вероятно, spring-boot-web один.

Используя автоматическую конфигурацию Spring с помощью shiro-spring-boot-starter, вам нужно только беспокоиться о вашем method annotations.

+0

Не могли бы вы рассмотреть этот вопрос, пожалуйста: https://stackoverflow.com/questions/44584523/apache-shiro-xml-based-configuration-gives-null-pointer-exception-for-dao –

 Смежные вопросы

  • Нет связанных вопросов^_^