小编Adi*_*l F的帖子

Apache Shiro用于保护REST api

我试图将Shiro整合到我的spring mvc应用程序中.身份验证由LDAP服务器支持,我能够成功地对ldap服务器进行身份验证并获取cookie.

我无法执行的是在后续请求中使用此cookie并获得结果.尝试使用cookie给我一个HTTP 302来再次执行身份验证.例如:GET on(rest/assets/list),标题Cookie: JSESSIONID=abcd重定向为(rest/login)

这是保护api的正确策略吗?api正在被AngularJS应用程序使用,我希望在添加CRUD功能之前启用基于用户组的身份验证.

任何指针都很有用.

源代码如下:

applicationContext.xml文件如下

 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


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

<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>

<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager"/>
</bean>

<bean id="ldapRealm" class="com.directv.nmsupport.security.LDAPRealm">
    <property name="contextFactory" ref="ldapContextFactory" />
    <property name="userDnTemplate" value="uid={0},ou=DirecTV,ou=People,dc=swengdtv,dc=net" />
</bean>

<bean id="ldapContextFactory" class="org.apache.shiro.realm.ldap.JndiLdapContextFactory">
    <property name="url" value="ldap://teon:389"/>
</bean>

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="ldapRealm"/>
    <property name="cacheManager" ref="cacheManager"/>
    <property name="sessionManager" ref="sessionManager" />
</bean>

<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
    <property name="sessionIdCookieEnabled" value="true" />
</bean>

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> …
Run Code Online (Sandbox Code Playgroud)

apache authentication rest spring-mvc shiro

12
推荐指数
1
解决办法
8603
查看次数

使用Spring Cacheable的L1 + L2缓存策略

我正在尝试设置 L1 + L2 缓存策略以与@Cacheable注释一起使用。我的目标是

  1. 配置咖啡因缓存
  2. 配置Redis缓存
  3. 在 Caffeine Cache 中查找项目,如果找到则返回,否则执行步骤 4
  4. 在Redis缓存中查找项目,如果找到则返回并缓存在caffeine中,否则执行第5步
  5. 使用真实服务返回结果。

我知道这不受开箱即用的支持,但我一直在尝试阅读有关如何连接此类解决方案的文档。

我当前的解决方案是将我的实际服务包装在RedisBackedService具有注释的 a 中,而该服务又包装在具有注释的a 中。不用说,这似乎是多余的。redisCacheManagercacheableCaffeineBackedServicecaffeineCacheManagercacheable

任何指示都会有帮助。

spring-data-redis spring-boot spring-cache caffeine

3
推荐指数
1
解决办法
2364
查看次数