当前位置: 首页>>代码示例>>Java>>正文


Java SecurityManager类代码示例

本文整理汇总了Java中org.apache.shiro.mgt.SecurityManager的典型用法代码示例。如果您正苦于以下问题:Java SecurityManager类的具体用法?Java SecurityManager怎么用?Java SecurityManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecurityManager类属于org.apache.shiro.mgt包,在下文中一共展示了SecurityManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shiroFilter

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager")SecurityManager manager) {
    ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
    bean.setSecurityManager(manager);
    //配置登录的url和登录成功的url
    bean.setLoginUrl("/login");
    bean.setSuccessUrl("/home");
    //配置访问权限
    LinkedHashMap<String, String> filterChainDefinitionMap=new LinkedHashMap<>();
    filterChainDefinitionMap.put("/login", "anon"); //表示可以匿名访问
    filterChainDefinitionMap.put("/common/**", "anon"); 
    filterChainDefinitionMap.put("/js/**","anon");
    filterChainDefinitionMap.put("/druid/**","anon");
    filterChainDefinitionMap.put("/captcha","anon");
    filterChainDefinitionMap.put("/**", "authc");//表示需要认证才可以访问
    bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return bean;
}
 
开发者ID:ranji1221,项目名称:lemcloud,代码行数:19,代码来源:ShiroConfig.java

示例2: provideSecurityManager

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
@Provides
@Singleton
SecurityManager provideSecurityManager(
        SessionManager sessionManager,
        RememberMeManager rememberMeManager,
        Realms realms,
        Set<AuthenticationListener> authListeners) {


    DefaultSecurityManager manager = new DefaultSecurityManager(realms.getRealms());
    ((AbstractAuthenticator) manager.getAuthenticator()).setAuthenticationListeners(authListeners);
    manager.setSessionManager(sessionManager);
    manager.setRememberMeManager(rememberMeManager);

    return manager;
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:17,代码来源:ShiroModule.java

示例3: setShiroConfiguration

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * Sets shiro configuration to the path of the resource
 * that points to the {@code shiro.ini} file.
 *
 * @param resource the resource
 */
@Autowired
public void setShiroConfiguration(@Value("${shiro.authn.config.file:classpath:shiro.ini}") final Resource resource) {
    try {
        if (resource.exists()) {
            final String location = resource.getURI().toString();
            logger.debug("Loading Shiro configuration from {}", location);

            final Factory<SecurityManager> factory = new IniSecurityManagerFactory(location);
            final SecurityManager securityManager = factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
        } else {
            logger.debug("Shiro configuration is not defined");
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:ShiroAuthenticationHandler.java

示例4: createInstance

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
@Override
protected AbstractShiroFilter createInstance() throws Exception {
	SecurityManager securityManager = getSecurityManager();
	if (securityManager == null){
		throw new BeanInitializationException("SecurityManager property must be set.");
	}

	if (!(securityManager instanceof WebSecurityManager)){
		throw new BeanInitializationException("The security manager does not implement the WebSecurityManager interface.");
	}

	PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
	FilterChainManager chainManager = createFilterChainManager();
	chainResolver.setFilterChainManager(chainManager);
	return new MySpringShiroFilter((WebSecurityManager)securityManager, chainResolver);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:MyShiroFilterFactoryBean.java

示例5: loadShiroConfiguration

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * Sets shiro configuration to the path of the resource
 * that points to the {@code shiro.ini} file.
 *
 * @param resource the resource
 */
public void loadShiroConfiguration(final Resource resource) {
    try {
        final Resource shiroResource = ResourceUtils.prepareClasspathResourceIfNeeded(resource);
        if (shiroResource != null && shiroResource.exists()) {
            final String location = shiroResource.getURI().toString();
            LOGGER.debug("Loading Shiro configuration from [{}]", location);

            final Factory<SecurityManager> factory = new IniSecurityManagerFactory(location);
            final SecurityManager securityManager = factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
        } else {
            LOGGER.debug("Shiro configuration is not defined");
        }
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:ShiroAuthenticationHandler.java

示例6: CentralDogmaSecurityManager

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
public CentralDogmaSecurityManager(File dataDir, Ini securityConfig) {
    try {
        sessionDao = new FileBasedSessionDAO(new File(dataDir, "_sessions").toPath());
    } catch (IOException e) {
        throw new IOError(e);
    }

    sessionManager = new CentralDogmaSessionManager(sessionDao);
    final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig) {
        @Override
        protected SecurityManager createDefaultInstance() {
            DefaultSecurityManager securityManager = new DefaultSecurityManager();
            securityManager.setSessionManager(sessionManager);
            securityManager.setCacheManager(new MemoryConstrainedCacheManager());
            return securityManager;
        }
    };
    delegate = factory.getInstance();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:20,代码来源:CentralDogmaSecurityManager.java

示例7: testHelloWorld

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
@Test
public void testHelloWorld() {
    //1、获取 SecurityManager 工厂,此处使用 Ini 配置文件初始化 SecurityManager
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    //2、得到 SecurityManager 实例 并绑定给 SecurityUtils

    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    //3、得到 Subject 及创建用户名/密码身份验证 Token(即用户身份/凭证)
    Subject subject = SecurityUtils.getSubject();

    UsernamePasswordToken token = new UsernamePasswordToken("test", "234");

    try {
        //4、登录,即身份验证
        subject.login(token);
    } catch (AuthenticationException e) {
        //5、身份验证失败
    }
    Assert.assertEquals(true, subject.isAuthenticated()); //断言用户已经登录
    //6、退出
    subject.logout();
}
 
开发者ID:easymall,项目名称:easymall,代码行数:25,代码来源:LoginTest.java

示例8: testIniRealm

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * testIniRealm
 * @Description: iniRealm的测试
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 上午11:41:43
 */
@Test
@Ignore
public void testIniRealm(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:inirealm-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	UsernamePasswordToken token=new UsernamePasswordToken("james_shu", "1997admin");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用户认证状态:"+subject.isAuthenticated());
	subject.logout();
	System.out.println("用户当前认证状态:"+subject.isAuthenticated());
}
 
开发者ID:fuyunwang,项目名称:ShiroDemo,代码行数:25,代码来源:AuthenticationTest.java

示例9: testCustomRealm

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * testCustomRealm
 * @Description: CustomRealm的测试
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 上午11:41:53
 */
@Test
public void testCustomRealm(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:customrealm-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	
	
	UsernamePasswordToken token=new UsernamePasswordToken("BeautifulSoup", "1997admin");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用户认证状态:"+subject.isAuthenticated());
	subject.logout();
	System.out.println("用户当前认证状态:"+subject.isAuthenticated());
}
 
开发者ID:fuyunwang,项目名称:ShiroDemo,代码行数:26,代码来源:AuthenticationTest.java

示例10: testIniAuthorization

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * testIniAuthorization
 * @Description: 使用inirealm完成授权
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 下午3:05:34
 */
@Test
@Ignore
public void testIniAuthorization(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:permission-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	//首先认证,认证通过之后才能授权
	UsernamePasswordToken token=new UsernamePasswordToken("beautifulsoup", "password");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用户的认证状态:"+subject.isAuthenticated());
	boolean isPermitted=subject.isPermittedAll("user:create:01","user:query");
	subject.checkPermissions("user:create:01","user:query");
	System.out.println(isPermitted);
}
 
开发者ID:fuyunwang,项目名称:ShiroDemo,代码行数:27,代码来源:AuthorizationTest.java

示例11: testCustomRealmAuthorization

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * testCustomRealmAuthorization
 * @Description: 使用自定义realm完成授权
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 下午3:05:46
 */
@Test
public void testCustomRealmAuthorization(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:customrealm-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	//首先认证,认证通过之后才能授权
	UsernamePasswordToken token=new UsernamePasswordToken("BeautifulSoup", "1997admin");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用户的认证状态:"+subject.isAuthenticated());
	boolean isPermitted=subject.isPermittedAll("item:query");
	System.out.println(isPermitted);
}
 
开发者ID:fuyunwang,项目名称:ShiroDemo,代码行数:25,代码来源:AuthorizationTest.java

示例12: shirFilter

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
@Bean("shiroFilter")
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
    shiroFilter.setSecurityManager(securityManager);
    shiroFilter.setLoginUrl("/login.html");
    //shiroFilter.setSuccessUrl("/index.html");
    shiroFilter.setUnauthorizedUrl("/");

    Map<String, String> filterMap = new LinkedHashMap<>();
    filterMap.put("/public/**", "anon");
    filterMap.put("/webjars/**", "anon");
    filterMap.put("/api/**", "anon");

    //swagger配置
    filterMap.put("/swagger**", "anon");
    filterMap.put("/v2/api-docs", "anon");
    filterMap.put("/swagger-resources/configuration/ui", "anon");

    filterMap.put("/login.html", "anon");
    filterMap.put("/sys/login", "anon");
    filterMap.put("/captcha.jpg", "anon");
    filterMap.put("/**", "authc");
    shiroFilter.setFilterChainDefinitionMap(filterMap);

    return shiroFilter;
}
 
开发者ID:guolf,项目名称:pds,代码行数:27,代码来源:ShiroConfig.java

示例13: shiroFilter

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
/**
 * shiroFilter
 * @param manager
 * @return
 */
@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager manager) {
	ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
	bean.setSecurityManager(manager);
	// 配置登录的url
	bean.setLoginUrl("/login");
	//bean.setSuccessUrl("/admin/main");
	// 过滤链
	LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
	filterChainDefinitionMap.put("/login", "anon"); // 表示可以匿名访问
	filterChainDefinitionMap.put("/admin/**", "authc");// 管理员权限需要验证过滤

	bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
	return bean;
}
 
开发者ID:shinyjunjun,项目名称:myblog,代码行数:21,代码来源:ShiroConfig.java

示例14: shiroFilter

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager manager) {
    ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
    bean.setSecurityManager(manager);
    //配置登录的url和登录成功的url
    bean.setLoginUrl("/login");
    //配置访问权限
    LinkedHashMap<String, String> filterChainDefinitionMap=new LinkedHashMap<>();
    filterChainDefinitionMap.put("/login", "anon"); //表示可以匿名访问
    filterChainDefinitionMap.put("/captcha","anon");
    filterChainDefinitionMap.put("/common/**", "anon"); 
    filterChainDefinitionMap.put("/default/**","anon");
    filterChainDefinitionMap.put("/druid/**", "anon");
    filterChainDefinitionMap.put("/**", "authc");//表示需要认证才可以访问
    //filterChainDefinitionMap.put("/**", "anon");
    bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return bean;
}
 
开发者ID:ranji1221,项目名称:lemcloud,代码行数:19,代码来源:ShiroConfig.java

示例15: main

import org.apache.shiro.mgt.SecurityManager; //导入依赖的package包/类
public static void main(String[] args) {
  //此处从ini文件来实现用用户角色权限配置,实际多从数据库表来实现
  Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini.bak");

  //SercurityManager 对象
  SecurityManager instance = factory.getInstance();
  SecurityUtils.setSecurityManager(instance);

  //测试用户
  Subject currentUser = SecurityUtils.getSubject();
  UsernamePasswordToken token = new UsernamePasswordToken("admin", "admin");

  boolean result = false;
  try {
    currentUser.login(token);
    result = true;
    LOG.debug("认证成功");
  } catch (Exception e) {
    result = false;
    LOG.debug("认证失败");
  }

}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:24,代码来源:RealmTest.java


注:本文中的org.apache.shiro.mgt.SecurityManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。