Giter Club home page Giter Club logo

shiro-example's Introduction

shiro-example's People

Contributors

orangeyts avatar zhangkaitao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shiro-example's Issues

ehcache exception

<!-- 缓存管理器 使用Ehcache实现 -->
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/>
    </bean>

在Ehcache version2.5之后将会出现以下异常

Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:

  1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
  2. Shutdown the earlier cacheManager before creating new one with same name.

建议修正为以下配置

<!-- 缓存管理器 使用Ehcache实现 -->
    <bean id="cache"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="shared" value="true" />
    </bean>
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"
        init-method="init" destroy-method="destroy">
        <property name="cacheManagerConfigFile" value="classpath:ehcache.xml" />
        <property name="cacheManager" ref="cache" />
    </bean>

XML问题详情页面

关于shiro联合swagger不显示接口提问

image
张老师你好,我在配置了shiro之后,原先的swagger不显实接口信息了,搜寻资料未果,特此向您请教。以下是我的shiro过滤配置

 @Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean shiroFilterFactoryBean() {
        System.out.println("\nShiroConfiguration.shirFilter开始\n");
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager());

        //拦截器
        Map<String, String> filters = new LinkedHashMap<String, String>();
        filters.put("/swagger-ui.html","anon");
        filters.put("/swagger/**","anon");
        filters.put("/webjars/**", "anon");
        filters.put("/swagger-resources/**","anon");
        filters.put("/v2/**","anon");
        filters.put("/doc.html","anon");

        //配置不会被拦截的链接,顺序判断 anon所有url都可以匿名访问
//        filters.put("/**","user");//记住我之后,所有url都可以访问,这显然在实际开发中是不可取的
        filters.put("/static/**", "anon");
        filters.put("/sys/selectAll","roles[超级管-理员]");//如果是roles[超级管理员,管理员]用户要同时满足所有角色
        filters.put("/sys/selectAll","roles[管理员]");
        filters.put("/sys/findByAccount","perms[test3]");
        //配置退出过滤器
        filters.put("/user/logout","logout");
        //过滤链定义,从上向下顺序执行,一般将/**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了
        //authc:所有url都必须认证通过才可以访问;

        //如果不设置会自动寻找Web工程根目录下的/login.jsp页面
        shiroFilterFactoryBean.setLoginUrl("/user/login");

        shiroFilterFactoryBean.setSuccessUrl("/index");

        //未授权页面
        shiroFilterFactoryBean.setUnauthorizedUrl("/error/he");
        filters.put("/**", "authc");
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filters);
        System.out.println("\nShiroConfiguration.shirFilter结束\n");
        return shiroFilterFactoryBean;
    }

期待您的回复。

关于clearCachedAuthorizationInfo

很感谢你写了这么一篇教程,让入门者得益。我遇到这么一个问题,项目用了ehcache,作为管理员打算删除用户A的权限,这时候修改了数据库用户A的之后,需要删除用户A的AuthorizationInfo cache。但是管理员拿不到用户A的principal,我暂时用了这招来删除。
public class ShiroDbRealm extends AuthorizingRealm {
public void clearSomeoneCachedAuthorizationInfo(String username) {
//用户名肯定是唯一的
Cache<Object, AuthorizationInfo> cache = getAuthorizationCache();

    Object k = null;
    if (cache != null) {
        for (Object key : cache.keys()) {
            if (key.toString().equals(username)) {
                k = key;
                break;
            }
        }
        cache.remove(k);
    }
}

}
但是我觉得这种遍历的方法很差劲,其次也没有考虑到对cache加锁。你有更好的建议吗?或者shiro已经内置了更好的api可以处理这种需求。 望告知,谢谢

POM.xml

Non-resolvable parent POM for com.github.zhangkaitao:shiro-example-chapter23-server:[unknown-version]: Could not find artifact com.github.zhangkaitao:shiro-example-chapter23-pom:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]

myRealm or MyRealm??

/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/realm/myRealm.java
or
/shiro-example-chapter3/src/test/java/com/github/zhangkaitao/shiro/chapter3/realm/MyRealm.java
提交到这上面的代码也太不严谨了吧。。。。。。
难道您本地没有这个问题
把代码导入eclispe后,貌似这类的问题不是一个半个

第五章的编码加密的PasswordTest类下的testPasswordServiceWithJdbcRealm测试报IncorrectCredentialsException

请问第五章的编码加密的PasswordTest类下的testPasswordServiceWithJdbcRealm测试为什么无法通过,会报如下错误:
org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - wu, rememberMe=false] did not match the expected credentials.

这一句,
login("classpath:shiro-jdbc-passwordservice.ini", "wu", "123");
是通过下边的ini配置进行加密的吗?

jdbcRealm.credentialsMatcher=$passwordMatcher

passwordService=org.apache.shiro.authc.credential.DefaultPasswordService
passwordMatcher=org.apache.shiro.authc.credential.PasswordMatcher
passwordMatcher.passwordService=$passwordService

其中passwordService是否要重写默认的?

oauth2服务端 .buildJSONMessage()报错

        //检查提交的客户端id是否正确
        if (!oAuthService.checkClientId(oauthRequest.getClientId())) {
            OAuthResponse response =
                    OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST)
                            .setError(OAuthError.TokenResponse.INVALID_CLIENT)
                            .setErrorDescription(Constants.INVALID_CLIENT_DESCRIPTION)
                            .buildJSONMessage();
            return new ResponseEntity(response.getBody(), 
         HttpStatus.valueOf(response.getResponseStatus()));
        }

.buildJSONMessage();方法一直报错

您好,有个关于shiro没有安全退出产生的问题请教下

首先您的跟我学shiro系列让鄙人很受益,减少了不少学习成本,谢谢!
在项目过程中发现一个问题,在ie浏览器下,直接关闭浏览器,再次登陆会显示上一个登陆账号的信息。原因是ie的进程其实是还在的,彻底杀掉进程就不会。我自己尝试了几种解决办法,最终选择了使用一个过滤器在shiro过滤器前,如果发现请求是login且是post提交就先做logout操作。但感觉这始终是没有办法的办法,所以想请教下您,是不是框架本身就提供了类似的功能,或者以你的经验有没有更好更优雅的方法?谢谢!

技术交流

您好!开涛老师!什么时候能加进您的shiro交流群啊!!!急切的想向您学习shiro技术。。跪求把握加进您的交流群啊!qq:997478173

chapter2中可以添加cache

可以把shiro-ehcache添加进去,
反正配置也不多:

cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
securityManager.cacheManager = $cacheManager

deserialize session from String always get an errors

Can you tell me why I always get that error ?
It tells that DelegateSubject is not serializable. I am using shiro v1.4.*

public static Session deserialize(String sessionStr) {
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(sessionStr));
            ObjectInputStream ois = new ObjectInputStream(bis);
            return (Session)ois.readObject();
        } catch (Exception e) {
            throw new RuntimeException("deserialize session error", e);
        }
    }

ehcache.xml configure default cache

参考第十二章的时候,项目运行出现了异常:
org.springframework.beans.MethodInvocationException: Property 'cacheManager' threw exception; nested exception is org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Caches cannot be added by name when default cache config is not specified in the config. Please add a default cache config in the configuration.

不知道是不是版本的问题。ehcache官方文档2.4版的说要在配置文件中加上一个 defaultcache :
http://ehcache.org/documentation/faq#what-does-the-following-error-mean-caches-cannot-be-added-by-name-when-default-cache-config-is-not-specified-in-the-config-please-add-a-default-cache-config-in-the-configuration

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.