day88_shiro_2

Shiro登录机制验证,自定义FormAuthenticationFilter 自定义登录form拦截器:org.apache.shiro.web.filter.authc.FormAuthenticationFilter 问题描述 使用shiro进行系统身份验证-权限控制,登录界面进行登录操作何时触发 boolean org.apache.shiro.web.filter.authc.AuthenticatingFilter.execute 阅读详情

shiro第二天 shiro授权 shiro和企业项目整合开发

8 复习

什么是权限管理?
权限管理是系统的安全范畴,要求必须是合法的用户才可以访问系统(用户认证),且必须具有该 资源的访问权限才可以访问该 资源(授权)。
认证:对用户合法身份的校验,要求必须是合法的用户才可以访问系统。
授权:访问控制,必须具有该 资源的访问权限才可以访问该 资源。

权限模型:

标准权限数据模型包括 :
用户、
角色、
权限(包括资源和权限)、
用户角色关系、
角色权限关系。

权限分配:
通过UI界面方便给用户分配权限,对上边权限模型进行增、删、改、查操作。

权限控制:

基于角色的权限控制:根据角色判断是否有操作权限,因为角色的变化 性较高,如果角色修改需要修改控制代码,系统可扩展性不强。
基于资源的权限控制:根据资源权限判断是否有操作权限,因为资源较为固定,如果角色修改或角色中权限修改不需要修改控制代码,使用此方法系统可维护性很强。建议使用。

权限管理的解决方案:

粗颗粒权限:
比如对系统的url、
菜单、
jsp页面、
页面上按钮、
类方法进行权限管理,
即对资源类型进行权限管理。

对于细颗粒权限管理:

细颗粒权限管理是系统的业务逻辑,业务逻辑代码不方便抽取统一代码,建议在系统业务层进行处理。

基于url的权限管理(掌握):

企业开发常用的方法,使用web应用中filter来实现,用户请求url,通过filter拦截,判断用户身份是否合法(用户认证),判断请求的地址是否是用户权限范围内的url(授权)。

shiro:

shiro是一个权限管理框架,是apache下的开源项目。相比spring security框架更简单灵活,spring security对spring依赖较强。shiro可以实现web系统、c/s、分布式等系统 权限管理。

shiro认证流程:(掌握)

1、subject(主体)请求认证,调用subject.login(token)

2、SecurityManager (安全管理器)执行认证

3、SecurityManager通过ModularRealmAuthenticator进行认证。

4、ModularRealmAuthenticator将token传给realm,realm根据token中用户信息从数据库查询用户信息(包括身份和凭证)

5、realm如果查询不到用户给ModularRealmAuthenticator返回null,ModularRealmAuthenticator抛出异常(用户不存在)

6、realm如果查询到用户给ModularRealmAuthenticator返回AuthenticationInfo(认证信息)

7、ModularRealmAuthenticator拿着AuthenticationInfo(认证信息)去进行凭证(密码 )比对。如果一致则认证通过,如果不致抛出异常(凭证错误)。

subject:主体

Authenticator:认证器( shiro提供)

realm(一般需要自定义):相当于数据源,认证器需要realm从数据源查询用户身份信息及权限信息。

9 课程安排

1、shiro授权

通过测试代码讲解基于角色权限控制,基于资源的权限控制(掌握)

2、shiro与spring进行整合

项目框架springmvc+mybatis+shiro

3、在整合工程下学习:

认证
授权
sessionManager
缓存管理
....

10 shiro授权

10.1 授权流程

这里写图片描述

10.2 三种授权方法

Shiro 支持三种方式的授权:
编程式:通过写if/else 授权代码块完成:

Subject subject = SecurityUtils.getSubject();
if(subject.hasRole(“admin”)) {
//有权限
} else {
//无权限
}

注解式:通过在执行的Java方法上放置相应的注解完成:

@RequiresRoles("admin")
public void hello() {
//有权限
}

JSP/GSP 标签:在JSP/GSP 页面通过相应的标签完成:

<shiro:hasRole name="admin">
<!— 有权限—>
</shiro:hasRole>

10.3 shiro-permission.ini

shiro-permission.ini里边的内容相当于在数据库。

#用户
[users]
#用户zhang的密码是123,此用户具有role1和role2两个角色
zhang=123,role1,role2
wang=123,role2

#权限
[roles]
#角色role1对资源user拥有create、update权限
role1=user:create,user:update
#角色role2对资源user拥有create、delete权限
role2=user:create,user:delete
#角色role3对资源user拥有create权限
role3=user:create

权限标识符号规则:资源:操作:实例(中间使用半角:分隔)
user:create:01 表示对用户资源的01实例进行create操作。
user:create:表示对用户资源进行create操作,相当于user:create:*,对所有用户资源实例进行create操作。

user:*:01 表示对用户资源实例01进行所有操作。

10.4 程序编写

这里写图片描述

11 自定义realm进行授权

11.1 需求

上边的程序通过shiro-permission.ini对权限信息进行静态配置,实际开发中从数据库中获取权限数据。就需要自定义realm,由realm从数据库查询权限数据。
realm根据用户身份查询权限数据,将权限数据返回给authorizer(授权器)。

11.2 自定义realm

在原来自定义的realm中,修改doGetAuthorizationInfo方法。

这里写图片描述

11.3 shiro-realm.ini

在shiro-realm.ini中配置自定义的realm,将realm设置到securityManager中。

[main]
#自定义 realm
customRealm=cn.itcast.shiro.realm.CustomRealm
#将realm设置到securityManager,相当 于spring中注入
securityManager.realms=$customRealm

11.4 测试程序

// 自定义realm进行资源授权测试
    @Test
    public void testAuthorizationCustomRealm() {

        // 创建SecurityManager工厂
        Factory<SecurityManager> factory = new IniSecurityManagerFactory(
                "classpath:shiro-realm.ini");

        // 创建SecurityManager
        SecurityManager securityManager = factory.getInstance();

        // 将SecurityManager设置到系统运行环境,和spring后将SecurityManager配置spring容器中,一般单例管理
        SecurityUtils.setSecurityManager(securityManager);

        // 创建subject
        Subject subject = SecurityUtils.getSubject();

        // 创建token令牌
        UsernamePasswordToken token = new UsernamePasswordToken("zhangsan",
                "111111");

        // 执行认证
        try {
            subject.login(token);
        } catch (AuthenticationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println("认证状态:" + subject.isAuthenticated());
        // 认证通过后执行授权

        // 基于资源的授权,调用isPermitted方法会调用CustomRealm从数据库查询正确权限数据
        // isPermitted传入权限标识符,判断user:create:1是否在CustomRealm查询到权限数据之内
        boolean isPermitted = subject.isPermitted("user:create:1");
        System.out.println("单个权限判断" + isPermitted);

        boolean isPermittedAll = subject.isPermittedAll("user:create:1",
                "user:create");
        System.out.println("多个权限判断" + isPermittedAll);

        // 使用check方法进行授权,如果授权不通过会抛出异常
        subject.checkPermission("items:add:1");

    }

11.5 授权流程

1、对subject进行授权,调用方法isPermitted("permission串")
2、SecurityManager执行授权,通过ModularRealmAuthorizer执行授权

3、ModularRealmAuthorizer执行realm(自定义的CustomRealm)从数据库查询权限数据,调用realm的授权方法:doGetAuthorizationInfo

4、realm从数据库查询权限数据,返回ModularRealmAuthorizer
5、ModularRealmAuthorizer调用PermissionResolver进行权限串比对

6、如果比对后,isPermitted中"permission串"在realm查询到权限数据中,说明用户访问permission串有权限,否则 没有权限,抛出异常。

12 shiro与项目整合

12.1 需求

将原来基于url的工程改成使用shiro实现。

12.2 创建新工程

创建web工程 :permission_shiro1110

12.3 去除原工程 的认证和授权的拦截

删除springmvc.xml中:

<mvc:interceptors>

12.4 jar包

包括 :
shiro-web的jar、
shiro-spring的jar
shiro-code的jar

这里写图片描述

12.5 web.xml中配置shiro的filter

在web系统中,shiro也通过filter进行拦截。filter拦截后将操作权交给spring中配置的filterChain(过虑链儿)
shiro提供很多filter。

在web.xml中配置filter

这里写图片描述

12.6 applicationContext-shiro.xml

在applicationContext-shiro.xml 中配置web.xml中fitler对应spring容器中的bean。

这里写图片描述

12.7 静态资源

对静态资源设置逆名访问:
修改applicationContext-shiro.xml:

这里写图片描述

12.8 登陆

12.8.1 原理

使用FormAuthenticationFilter过虑器实现 ,原理如下:

将用户没有认证时,请求loginurl进行认证,用户身份和用户密码提交数据到loginurl

FormAuthenticationFilter拦截住取出request中的username和password(两个参数名称是可以配置的)

FormAuthenticationFilter调用realm传入一个token(username和password)
realm认证时根据username查询用户信息(在Activeuser中存储,包括 userid、usercode、username、menus)。

如果查询不到,realm返回null,FormAuthenticationFilter向request域中填充一个参数(记录了异常信息)

12.8.2 登陆页面

由于FormAuthenticationFilter的用户身份和密码的input的默认值(username和password),修改页面的账号和密码 的input的名称为username和password

12.8.3 登陆代码实现

这里写图片描述

12.8.4 认证拦截过虑器

在applicationContext-shiro.xml中配置:

这里写图片描述

12.9 退出

12.9.1 使用LogoutFilter

不用我们去实现退出,只要去访问一个退出的url(该 url是可以不存在),由LogoutFilter拦截住,清除session。

在applicationContext-shiro.xml配置LogoutFilter:

这里写图片描述

可以删除原来的logout的controller方法代码。

这里写图片描述

12.10 认证信息在页面显示

1、认证后用户菜单在首页显示
2、认证后用户的信息在页头显示

12.10.1 修改realm设置完整认证信息

realm从数据库查询用户信息,将用户菜单、usercode、username等设置在SimpleAuthenticationInfo中。

先使用静态代码实现:

这里写图片描述

12.10.2 修改first.action将认证信息在页面显示

这里写图片描述

12.11 授权过虑器测试

12.11.1 使用PermissionsAuthorizationFilter

在applicationContext-shiro.xml中配置url所对应的权限。

测试流程:
1、在applicationContext-shiro.xml中配置filter规则

<!--商品查询需要商品查询权限  -->
    /items/queryItems.action = perms[item:query]

2、用户在认证通过后,请求/items/queryItems.action
3、被PermissionsAuthorizationFilter拦截,发现需要“item:query”权限
4、PermissionsAuthorizationFilter调用realm中的doGetAuthorizationInfo获取数据库中正确的权限
5、PermissionsAuthorizationFilter对item:query 和从realm中获取权限进行对比,如果“item:query”在realm返回的权限列表中,授权通过。

12.11.2创建refuse.jsp
如果授权失败,跳转到refuse.jsp,需要在spring容器中配置:

这里写图片描述

12.11.3 问题总结

1、在applicationContext-shiro.xml中配置过虑器链接,需要将全部的url和权限对应起来进行配置,比较发麻不方便使用。

2、每次授权都需要调用realm查询数据库,对于系统性能有很大影响,可以通过shiro缓存来解决。

12.12 shiro的过虑器

过滤器简称 对应的java类

这里写图片描述

anon:例子/admins/**=anon 没有参数,表示可以匿名使用。
authc:例如/admins/user/**=authc表示需要认证(登录)才能使用,FormAuthenticationFilter是表单认证,没有参数 
perms:例子/admins/user/**=perms[user:add:*],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,例如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。
user:例如/admins/user/**=user没有参数表示必须存在用户, 身份认证通过或通过记住我认证通过的可以访问,当登入操作时不做检查

12.13 认证

12.13.1 需求

修改realm的doGetAuthenticationInfo,从数据库查询用户信息,realm返回的用户信息中包括 (md5加密后的串和salt),实现让shiro进行散列串的校验。

12.13.2 修改doGetAuthenticationInfo从数据库查询用户信息

1、将SysService注入到realm中。

这里写图片描述

//realm的认证方法,从数据库查询用户信息
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(
            AuthenticationToken token) throws AuthenticationException {

        // token是用户输入的用户名和密码 
        // 第一步从token中取出用户名
        String userCode = (String) token.getPrincipal();

        // 第二步:根据用户输入的userCode从数据库查询
        SysUser sysUser = null;
        try {
            sysUser = sysService.findSysUserByUserCode(userCode);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        // 如果查询不到返回null
        if(sysUser==null){//
            return null;
        }
        // 从数据库查询到密码
        String password = sysUser.getPassword();

        //盐
        String salt = sysUser.getSalt();

        // 如果查询到返回认证信息AuthenticationInfo

        //activeUser就是用户身份信息
        ActiveUser activeUser = new ActiveUser();

        activeUser.setUserid(sysUser.getId());
        activeUser.setUsercode(sysUser.getUsercode());
        activeUser.setUsername(sysUser.getUsername());
        //..

        //根据用户id取出菜单
        List<SysPermission> menus  = null;
        try {
            //通过service取出菜单 
            menus = sysService.findMenuListByUserId(sysUser.getId());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //将用户菜单 设置到activeUser
        activeUser.setMenus(menus);


        //将activeUser设置simpleAuthenticationInfo
        SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
                activeUser, password,ByteSource.Util.bytes(salt), this.getName());

        return simpleAuthenticationInfo;
    }

12.13.3 设置凭证匹配器

数据库中存储到的md5的散列值,在realm中需要设置数据库中的散列值它使用散列算法 及散列次数,让shiro进行散列对比时和原始数据库中的散列值使用的算法 一致。

这里写图片描述

12.14 授权

12.14.1 需求

修改realm的doGetAuthorizationInfo,从数据库查询权限信息。
使用注解式授权方法。
使用jsp标签授权方法。

12.14.2修改doGetAuthorizationInfo从数据库查询权限

// 用于授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(
            PrincipalCollection principals) {

        //从 principals获取主身份信息
        //将getPrimaryPrincipal方法返回值转为真实身份类型(在上边的doGetAuthenticationInfo认证通过填充到SimpleAuthenticationInfo中身份类型),
        ActiveUser activeUser =  (ActiveUser) principals.getPrimaryPrincipal();

        //根据身份信息获取权限信息
        //从数据库获取到权限数据
        List<SysPermission> permissionList = null;
        try {
            permissionList = sysService.findPermissionListByUserId(activeUser.getUserid());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //单独定一个集合对象 
        List<String> permissions = new ArrayList<String>();
        if(permissionList!=null){
            for(SysPermission sysPermission:permissionList){
                //将数据库中的权限标签 符放入集合
                permissions.add(sysPermission.getPercode());
            }
        }


        //查到权限数据,返回授权信息(要包括 上边的permissions)
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
        //将上边查询到授权信息填充到simpleAuthorizationInfo对象中
        simpleAuthorizationInfo.addStringPermissions(permissions);

        return simpleAuthorizationInfo;
    }

12.14.3 开启controller类aop支持

对系统中类的方法给用户授权,建议在controller层进行方法授权。

在springmvc.xml中配置:

这里写图片描述

12.14.4 在controller方法中添加注解

这里写图片描述

这里写图片描述

这里写图片描述

12.14.5 jsp标签 授权

Jsp页面

<%@taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>

称   标签条件(均是显示标签内容)

这里写图片描述

修改itemsList.jsp页面:

这里写图片描述

12.14.6 授权测试

当调用controller的一个方法,由于该 方法加了@RequiresPermissions("item:query") ,shiro调用realm获取数据库中的权限信息,看”item:query”是否在权限数据中存在,如果不存在就拒绝访问,如果存在就授权通过。

当展示一个jsp页面时,页面中如果遇到<shiro:hasPermission name="item:update">,shiro调用realm获取数据库中的权限信息,看item:update是否在权限数据中存在,如果不存在就拒绝访问,如果存在就授权通过。

问题:只要遇到注解或jsp标签的授权,都会调用realm方法查询数据库,需要使用缓存解决此问题。

12.15 shiro缓存

针对上边授权频繁查询数据库,需要使用shiro缓存。

12.15.1 缓存流程

shiro中提供了对认证信息和授权信息的缓存。shiro默认是关闭认证信息缓存的,对于授权信息的缓存shiro默认开启的。主要研究授权信息缓存,因为授权的数据量大。

用户认证通过。
该 用户第一次授权:调用realm查询数据库
该 用户第二次授权:不调用realm查询数据库,直接从缓存中取出授权信息(权限标识符)。

12.15.2 使用ehcache

12.15.2.1 添加Ehcache的jar包

这里写图片描述

12.15.2.2 配置cacheManager

这里写图片描述

这里写图片描述

12.15.2.3 shiro-ehcache.xml

这里写图片描述

12.15.2.4 缓存清空

如果用户正常退出,缓存自动清空。

如果用户非正常退出,缓存自动清空。

如果修改了用户的权限,而用户不退出系统,修改的权限无法立即生效。
需要手动进行编程实现:
在权限修改后调用realm的clearCache方法清除缓存。
下边的代码正常开发时要放在service中调用。
在service中,权限修改后调用realm的方法。
在realm中定义clearCached方法:

//清除缓存
    public void clearCached() {
        PrincipalCollection principals = SecurityUtils.getSubject().getPrincipals();
        super.clearCache(principals);
    }

测试清除缓存controller方法:

这里写图片描述

12.16 sessionManager

和shiro整合后,使用shiro的session管理,shiro提供sessionDao操作 会话数据。

配置sessionManager

这里写图片描述

这里写图片描述

12.17 验证码

12.17.1 思路

shiro使用FormAuthenticationFilter进行表单认证,验证校验的功能应该加在FormAuthenticationFilter中,在认证之前进行验证码校验。

需要写FormAuthenticationFilter的子类,继承FormAuthenticationFilter,改写它的认证方法,在认证之前进行验证码校验。

12.17.2 自定义FormAuthenticationFilter

这里写图片描述

12.17.3 配置自定义FormAuthenticationFilter

这里写图片描述

这里写图片描述

12.17.4 在login.action对验证错误 进行解析

这里写图片描述

12.17.5 在登陆页面添加验证码

这里写图片描述

12.17.6 在filter配置匿名访问验证码jsp

这里写图片描述

12.18 记住我

用户登陆选择“自动登陆”本次登陆成功会向cookie写身份信息,下次登陆从cookie中取出身份信息实现自动登陆。

12.18.1 用户身份实现java.io.Serializable接口

向cookie记录身份信息需要用户身份信息对象实现序列化接口,如下:

这里写图片描述

这里写图片描述

这里写图片描述

12.18.2 配置rememeberMeManager

这里写图片描述

这里写图片描述

12.18.3 登陆页面

这里写图片描述

12.18.4 配置rememberMe的input名称

这里写图片描述

12.18.5 测试

自动登陆后,需要查看 cookei是否有rememberMe

这里写图片描述

12.18.6 使用UserFilter

如果设置记住我,下次访问某些url时可以不用登陆。将记住我即可访问的地址配置让UserFilter拦截。

这里写图片描述

登录不会走自定义的FormAuthenticationFilter及其onLoginSuccess原因 NULL 博文链接:https://yuhuiblog695685688425687986842568269.iteye.com/blog/2405464 立即下载

相关推荐

从零搭建PIC MCU开发环境:MPLAB IDE与HI-TECH编译器安装破解全攻略

本文详细介绍了从零搭建PIC MCU开发环境的完整流程,包括MPLAB IDE 8.85的安装配置、HI-TECH C编译器的安装与破解,以及PICkit3编程器的使用技巧。通过清晰的步骤说明和常见问题解决方案,帮助开发者快速搭建稳定的PIC单片机开发环境,适用于PIC16/18系列MCU开发。

weixin_29188997的博客 303

shiro 自定义FormAuthenticationFilter,记住我

验证码 思路 shiro使用FormAuthenticationFilter进行表单认证,验证校验的功能应该加在FormAuthenticationFilter中,在认证之前进行验证码校验。 需要写FormAuthenticationFilter的子类,继承FormAuthenticationFilter,改写它的认证方法,在认证之前进行验证码校验。 自定义FormAuth

爱笑的博客 3万+

个人信息保护合规审计人员(中级)能力测试试卷

本文是关于个人信息保护合规考试的试题解析,内容涵盖《个人信息保护法》相关规定。试卷包含单选题、多选题、判断题、简答题和案例分析题五种题型,总分100分,考试时间120分钟。试题重点考察个人信息处理的基本原则、敏感个人信息处理要求、合规审计流程、个人信息保护影响评估等内容。通过案例分析题详细解析了人脸识别登录、数据共享、跨境传输等场景下的合规要求。参考答案均严格依据《个人信息保护法》等法律法规,为个人信息处理活动提供了明确的合规指引。

qq_41525079的博客 940

【备忘】JavaEE系统架构师学习路线图

转载自:http://www.javaxxz.com/thread-286706-1-1.html 第1阶段(Java程序员) - Java语言基础     - 101 JavaSE:【101】JAVASE视频教程        -01-常见Dos命令、Java历史、Java跨平台、配置Path环境变量、第一个HelloWorld例子        -02-配置JAVA_HOME、临时或c

kkwerw88的博客 3906

STM32F407 CubeMX UART DMA高效解析BNO085九轴数据

本文详细介绍了如何在STM32F407平台上使用CubeMX配置UART和DMA高效解析BNO085九轴传感器数据。通过DMA循环接收机制实现低CPU占用的实时数据采集,并分享数据解析技巧、错误处理及实战调试经验,为嵌入式开发者提供完整解决方案。

o4p5q6r7s的博客 256

IAR9.20.4安装与注册全攻略:附资源及典型问题解决方案

本文提供IAR9.20.4的详细安装与注册指南,涵盖环境准备、安装步骤、权限设置及注册机使用技巧。针对典型问题如评估版残留、权限不足和杀毒软件拦截等,给出了具体解决方案,帮助用户顺利完成IAR开发环境的搭建与激活。

a2b3c4d5e的博客 308

自定义FormAuthentia

1.shiro使用FormAuthenticationFilter进行验证码进行表单验证,验证码的功能应该加在FormAuthenticationFilter中,在认证之前进行验证码校验。 需要编写FormAuthenticationFilter的子类,继承FormAuthenticationFilter,改写它的认证方法,在认证之前进行验证码校验 2.自定义FormAuthenticatio

abou15871390117的博客 433

Google账号找回通用方法(尤其是知道账号密码仍无法登录和找回的)

Google账号找回通用方法【尤其是知道账号密码仍无法登录和找回的】普通找回注意:适用于常用谷歌账户的设备和网络情况下无法使用手机或辅助邮箱验证码进行密码找回特殊找回方法注意;适用于1.新的设备以及网络环境(包括由于非正常原因导致设备系统以及应用信息变更)2.没有开启辅助验证(手机/邮箱)3.知道账号密码但无法登录或找回。通过申诉进行找回 普通找回 注意:适用于 常用谷歌账户的设备和网络情况下 无法使用手机或辅助邮箱验证码进行密码找回 通过恢复页面进行恢复 https://accounts.google

极客代码-极致生活 23万+

Day374.shiro授权&Shiro+jsp整合Springboot -Shiro

Shiro授权 一、授权 授权,即访问控制,控制谁能访问哪些资源。主体进行身份认证后需要分配权限方可访问系统的资源,对于某些资源没有权限是无法访问的。 二、关键对象 授权可简单理解为who对what(which)进行How操作: Who,即主体(Subject),主体需要访问系统中的资源。 What,即资源(Resource),如系统菜单、页面、按钮、类方法、系统商品信息等。资源包括资源类型和资源实例,比如商品信息为资源类型,类型为t01的商品为资源实例,编号为001的商品信息也属于资源实例。 How,权限

阿昌爱Java 853

11.11华为OD机试真题 新系统 - 管线同类区段归并 (Java/Py/C/C++/Js/Go)

11.11华为OD机试真题 新系统 - 管线同类区段归并 (Java/Py/C/C++/Js/Go)

算法大师! 385

如何给K8S配置一个具有永久有效的kubeconfig

在 Amazon EKS 环境中,Kubernetes 的认证机制与 AWS IAM 深度集成,通过aws-iam-authenticator动态生成临时凭证。这种设计虽然增强了安全性,但给需要持久化凭证的工具链(如 CI/CD 系统中的 KubeVela)带来了挑战。具体表现为:临时凭证失效​​:默认 Token 有效期为 15 分钟至 1 小时;​​IAM 角色限制​​:直接使用aws eks get-token生成的凭证无法持久化

小杨同学的博客 671

厚积薄发打卡Day88: 利用Swagger2搭建REST-API前后端调试

官网链接:https://swagger.io/solutions/api-design/ 使用指南:使用Swagger2自动生成API接口文档 背景: 对于前后端分离的项目,前后端的工程师协同开发,在这种开发模式下,维持一份及时更新且完整的 Rest API 文档将会极大的提高我们的工作效率。 传统意义上的文档都是后端开发人员手动编写的,相信大家也都知道这种方式很难保证文档的及时性,这种文档久而久之也就会失去其参考意义,反而还会加大我们的沟通成本。而Swagger 给我们提供了一个全新的维护 API .

COOLGWAYNE_TECH_BLOG 230

34、实数域上高效负循环卷积算法解析

本文介绍了一种高效的实数域负循环卷积算法,通过引入离散傅里叶负循环变换(DFNT)避免传统方法的冗余,显著提升计算效率。文章详细分析了算法原理、误差传播机制,并推导出误差与方差界,提出无误差和基于3σ规则的参数设置方案。结合Cooley-Tukey与Gentleman-Sande FFT路径优化,实验验证了算法在不同精度和多项式长度下的性能优势与结果正确性,为密码学与信号处理等领域提供了高精度、高性能的卷积计算解决方案。

salt的博客 121

Java学习笔记-Day88 Spring Security安全框架

Java学习笔记-Day88 Spring Security一、Spring Security的简介二、Spring Security和Shiro比较三、Spring Security的使用   一、Spring Security的简介   Spring Security正是Spring 家族中的成员,Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,D

qq_42141141的博客 515

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

网络安全渗透实战 记一次攻防演练渗透测试实战,黑客技术零基础入门到实战教程!

这次攻防演练的其中一个目标,通过密码复用爆破成功的某台机器里,刚好存在着域管进程,提权到system权限后注入到域管进程,通过Dcsync成功获取域管密码的hash值,其中一个被禁用的账户刚好可以通过cmd5解出,解出明文密码并激活账户,成功登录两台域控机器,除此以外还可以尝试域漏洞、NTLM中继等。当我们拿到集权设备后,一般里面会有靶标系统或核心系统,这些分数是很高的,这次演练某目标就是通过云管平台登录官网机器,抓取浏览器密码成功获取后台密码,成功拿下官网控制权。

qq_41314882的博客 1292

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

攻防演练某市级HVV攻防演练总结,从零基础到精通,理论与实践结合的最佳路径!

正如今年的xx题目,学习应从本手开始,把基础打好,才能在实战中打出妙手操作,如果眼高手低,往往会落到俗手的下场这次攻防演练每个队伍分配不同的目标,有些队伍拿的点可以直接 nday 打,有些队伍外网打点十分困难比如我们,但分数是是统一算的,可以说不是那么的公平不过也算是提供了些许经验,简单做一下总结,都是比较基础的东西,如有写的不正确的地方欢迎各位师傅指正。

2401_85688943的博客 910

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

记一次攻防演练渗透测试实战,黑客技术零基础入门到实战教程!

这次攻防演练的其中一个目标,通过密码复用爆破成功的某台机器里,刚好存在着域管进程,提权到system权限后注入到域管进程,通过Dcsync成功获取域管密码的hash值,其中一个被禁用的账户刚好可以通过cmd5解出,解出明文密码并激活账户,成功登录两台域控机器,除此以外还可以尝试域漏洞、NTLM中继等。当我们拿到集权设备后,一般里面会有靶标系统或核心系统,这些分数是很高的,这次演练某目标就是通过云管平台登录官网机器,抓取浏览器密码成功获取后台密码,成功拿下官网控制权。

白帽阿叁的博客 966

攻防演练某市级HVV攻防演练总结

正如今年的xx题目,学习应从本手开始,把基础打好,才能在实战中打出妙手操作,如果眼高手低,往往会落到俗手的下场这次攻防演练每个队伍分配不同的目标,有些队伍拿的点可以直接 nday 打,有些队伍外网打点十分困难比如我们,但分数是是统一算的,可以说不是那么的公平不过也算是提供了些许经验,简单做一下总结,都是比较基础的东西,如有写的不正确的地方欢迎各位师傅指正。

shandongjiushen的博客 921
上一篇: day87_shiro_1
下一篇: 网上图书商城视频教程day01
csdn_AF
博客等级 码龄10年 161粉丝 122原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址