springsecurity3.0.5 filterSecurityInterceptor 使用和配置

Spring security用户URL权限FilterSecurityInterceptor使用解析 主要介绍了Spring security用户URL权限FilterSecurityInterceptor使用解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 立即下载
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/jdbc  http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/security    http://www.springframework.org/schema/security/spring-security-3.0.3.xsd
    ">

    <bean id="filterChain"
      class="org.springframework.security.web.FilterChainProxy">
      <security:filter-chain-map path-type="ant">
        <security:filter-chain pattern="/**"
        filters="formValidateCodeFilter,
          mySessionValidateFilter,
          myRempassFilter,
          securityContextPersistenceFilter,
          channelProcessingFilter,
          logoutFilter,
          usernamePasswordAuthenticationFilter,
          rememberMeAuthenticationFilter,
          anonymousAuthenticationFilter,
          exceptionTranslationFilter,
          filterSecurityInterceptor" />
      </security:filter-chain-map>
    </bean>
    
    
    <bean id="mySessionValidateFilter"
      class="com.xxx.framework.security.filter.MySessionValidateFilter">
          <property name="excludePath"  value="${sec.excludePath}"/>
          <property name="filterIndexUrl"  value="${sec.indexUrl}"/>
    </bean>
    
    <bean id="securityContextPersistenceFilter"
      class="org.springframework.security.web.context.SecurityContextPersistenceFilter"/>
      
        <bean id="channelProcessingFilter"
      class="org.springframework.security.web.access.channel.ChannelProcessingFilter">
          <property name="channelDecisionManager"  ref="channelDecisionManagerImpl"/>
          <property name="securityMetadataSource"  ref="myDefaultFilterInvocationSecurityMetadataSource"/>
    </bean>
      
    <bean id="channelDecisionManagerImpl"
      class="org.springframework.security.web.access.channel.ChannelDecisionManagerImpl">
          <property name="channelProcessors">
            <list>
              <ref bean="secureChannelProcessor"/>
              <ref bean="insecureChannelProcessor"/>
            </list>
          </property>
    </bean>  
      
    <bean id="secureChannelProcessor"
      class="org.springframework.security.web.access.channel.SecureChannelProcessor">
        <property name="entryPoint"  ref="channelEntryPoint"/>
    </bean>
    
    <bean id="channelEntryPoint"
      class="org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint">
        <property name="portMapper"  ref="portMapperImpl"/>
    </bean>
    
    <bean id="portMapperImpl"
      class="org.springframework.security.web.PortMapperImpl" scope="prototype">
       <property name="portMappings">
             <map>
                 <entry key="${init.httpPort}"><value>${init.httpsPort}</value></entry>
             </map>
       </property>
    </bean>
    
    <bean id="myDefaultFilterInvocationSecurityMetadataSource"
      class="com.xxx.framework.security.common.MyDefaultFilterInvocationSecurityMetadataSource">
          <constructor-arg type="org.springframework.security.web.util.UrlMatcher" ref="urlMatcher" />
    </bean>
    
    <bean id="insecureChannelProcessor"
      class="org.springframework.security.web.access.channel.InsecureChannelProcessor">
        <property name="entryPoint"  ref="channelEntryPointHttp"/>
    </bean>
    
    <bean id="channelEntryPointHttp"
      class="org.springframework.security.web.access.channel.RetryWithHttpEntryPoint">
          <property name="portMapper"  ref="portMapperImpl"/>
    </bean>    
      
     <bean id="rememberMeAuthenticationFilter"
       class="com.xxx.framework.security.filter.MyRememberMeAuthenticationFilter">
          <property name="rememberMeServices"    ref="rememberMeServices"/>
          <property name="authenticationManager" ref="authenticationManager" />
          <property name="filterProcessesUrl" value="${sec.mainUrl}"/>
          <property name="filterExcludeUrl" value="${sec.excPath}"/>
          <property name="authorizationService" ref="authorizationService"></property>
    </bean>
    
    <bean id="rememberMeServices"
      class="com.xxx.framework.security.common.MyBasedRememberMeServices">
          <property name="key" value="ke4-espa?uFraz5muphuqemayut2cefreqefr-swuqunu6ag"/>
          <property name="tokenValiditySeconds" value="${sec.cookieTime}"/>
          <property name="myUserDetailsService" ref="jdbcUserService"/>
          <property name="parameter" value="rempass"/>
          <property name="cookieName" value="name"/>
    </bean>
      
    <bean id="jdbcRememberMeTokenRepository"
      class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl">
            <property name="dataSource" ref="dataSource"/>
    </bean>
    
    <bean id="rememberMeAuthenticationProvider"
      class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
            <property name="key" value="ke4-espa?uFraz5muphuqemayut2cefreqefr-swuqunu6ag"/>
    </bean>
      
      <bean id="anonymousAuthenticationFilter"
          class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter">
          <property name="userAttribute" value="anonymousUser,anonymous}"/>
          <property name="key" value="BF93JFJ091N00Q7HF"/>
      </bean>
      
      <bean id="filterSecurityInterceptor"
          class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
          <property name="authenticationManager"  ref="authenticationManager"/> <!--ss会判断当前的请求是否已经通过登录的,当没有通过登录的,authenticationManager ss会做登录鉴权认证-->
          <property name="accessDecisionManager"  ref="affirmativeBased"/>
          <property name="securityMetadataSource" ref="filterInvocationDefinitionSource" /><!--securityMetadataSource这个数据源中有个Map结构存放。所有的角色对应的权限这里根据项目需要,我们这是是自定义的,下面的filterInvocationDefinitionSource-->
      </bean>
    
      <bean id="filterInvocationDefinitionSource"
        class="com.xxx.framework.security.common.MyJdbcFilterInvocationDefinitionSourceFactoryBean">
        <constructor-arg type="org.springframework.security.web.util.UrlMatcher" ref="urlMatcher" />
        <constructor-arg type="com.xxx.portal.security.service.AuthorizationService" ref="authorizationService" />
      </bean>
      
      <bean id="urlMatcher"
          class="org.springframework.security.web.util.AntUrlPathMatcher" >
          <constructor-arg type="boolean" value="true" />
      </bean>
      
      <bean class="org.springframework.security.access.vote.AffirmativeBased" id="affirmativeBased">
      <property name="decisionVoters">
        <list>
          <ref bean="roleVoter"/>
        </list>
      </property>
    </bean>
    
    <bean class="com.xxx.framework.security.common.MyRoleVoter" id="roleVoter"></bean><!--自定义Voter代码如下已贴出-->
      
    <bean id="daoAuthenticationProvider" class="com.xxx.framework.security.common.MyDaoAuthenticationProvider">
      <property name="userDetailsService" ref="jdbcUserService"/>
      <property name="passwordEncoder" ref="passwordEncoder"/>
      <property name="saltSource" ref="saltSource"/>
    </bean>
    
    <bean id="anonymousAuthenticationProvider" class="org.springframework.security.authentication.AnonymousAuthenticationProvider">
      <property name="key" value="BF93JFJ091N00Q7HF"/>
    </bean>
    
    <bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager">
      <property name="providers">
        <list>
          <ref local="daoAuthenticationProvider"/>
          <ref local="anonymousAuthenticationProvider"/>
          <ref local="rememberMeAuthenticationProvider"/>
        </list>
      </property>
    </bean>
    
   <bean id="jdbcUserService"
      class="com.xxx.framework.security.common.MyCustomJdbcDaoImpl">
          <property name="dataSource" ref="dataSource"/>
          <property name="enableGroups" value="true"/>
        <property name="enableAuthorities" value="false"/>
        <property name="passwordEncoder" ref="passwordEncoder"/>
        <property name="saltSource" ref="saltSource"/>
        <property name="authorizationService" ref="authorizationService"/>
    </bean>
    
    <bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>
        
    <bean class="org.springframework.security.authentication.dao.ReflectionSaltSource" id="saltSource">
        <property name="userPropertyToUse" value="userId"/>
    </bean>
 
    <bean id="usernamePasswordAuthenticationFilter"
      class="com.xxx.framework.security.filter.MyFormUsernamePasswordAuthenticationFilter">
          <property name="authenticationManager" ref="authenticationManager"/>
          <property name="authenticationSuccessHandler" ref="loginLogAuthenticationSuccessHandler"></property>
         <property name="authenticationFailureHandler" ref="accessAuthenticationFailureHandler"></property>
         <property name="rememberMeServices" ref="rememberMeServices"/>    
    </bean>
    
    <bean id="loginLogAuthenticationSuccessHandler"
        class="com.xxx.framework.security.common.MyFormSimpleUrlAuthenticationSuccessHandler">
        <property name="defaultTargetUrl" value="${sec.mainUrl}"></property>
        <property name="authorizationService" ref="authorizationService"></property>
    </bean>
    
    <bean id="myLoginLogAuthenticationSuccessHandler"
        class="com.xxx.framework.security.common.MySimpleUrlAuthenticationSuccessHandler">
        <property name="defaultTargetUrl" value="${sec.mainUrl}"></property>
    </bean>
    <bean id="accessAuthenticationFailureHandler"
        class="com.xxx.framework.security.common.MyAccessAuthenticationFailureHandler">
        <property name="defaultFailureUrl" value="${sec.indexUrl}"></property>
    </bean>
    
    <bean id="authenticationProcessingFilterEntryPoint"  
         class="org.springframework.security.web.authentication.AuthenticationProcessingFilterEntryPoint">  
    <property name="loginFormUrl" value="${sec.indexUrl}"></property>  
    </bean>
    
    <bean id="formValidateCodeFilter"  
         class="com.xxx.framework.security.filter.MyFormValidateCodeFilter">  
         <property name="filterIndexUrl" value="${sec.indexUrl}"/>
         <property name="filterProcessesUrl" value="${sec.loginUrl}"/>
    </bean>
    
    <bean id="myRempassFilter"  
         class="com.xxx.framework.security.filter.MyRempassFilter">  
         <property name="tokenValiditySeconds" value="${sec.cookieTime}"/>
         <property name="filterProcessesUrl" value="${sec.loginUrl}"/>
    </bean>
    <!--exceptionTranslationFilter用来对AuthenticationException和AccessDeniedException异常的处理。-->
    <bean id="exceptionTranslationFilter"
          class="com.xxx.framework.security.filter.MyExceptionTranslationFilter">
          <property name="authenticationEntryPoint" ref="authenticationEntryPoint"/>
          <property name="accessDeniedHandler"      ref="accessDeniedHandler"/>
    </bean>
    
    <bean id="authenticationEntryPoint"
          class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
          <property name="loginFormUrl" value="${sec.indexUrl}"/>
    </bean>
    <bean id="accessDeniedHandler"
          class="com.xxx.framework.security.common.MyAccessDeniedHandlerImpl">
          <property name="errorPage" value="/accessDenied.action"/>
    </bean>
    
    <bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
          <constructor-arg ref="logoutSuccessHandler"/>
          <constructor-arg>
              <array>
                <ref local="logoutHandler"/>
                <ref local="rememberMeServices"/>
              </array>
          </constructor-arg>
          <property name="filterProcessesUrl" value="/logout.action"/>
    </bean>
    
    <bean id="logoutHandler" class="com.xxx.framework.security.common.MySecurityContextLogoutHandler">
         <property name="authorizationService" ref="authorizationService"></property>
    </bean>
    
    <bean id="logoutSuccessHandler" class="org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler">
           <property name="defaultTargetUrl" value="/exitSystem.action"/>
    </bean>
    

</beans>





package com.xxx.framework.security.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource;
import org.springframework.security.web.access.intercept.RequestKey;
import org.springframework.security.web.util.UrlMatcher;
import com.xxx.portal.security.service.AuthorizationService;
import com.xxx.portal.security.vo.Resource;

public class MyJdbcFilterInvocationDefinitionSourceFactoryBean extends
        DefaultFilterInvocationSecurityMetadataSource
{

    public MyJdbcFilterInvocationDefinitionSourceFactoryBean(
            UrlMatcher urlMatcher, AuthorizationService authorizationService)
    {
        super(urlMatcher, getRequestMap(authorizationService));
        setStripQueryStringFromUrls(true);
    }

    /**
     * url权限封装这里是封装的所有的资源对应的角色。
     */
    private static LinkedHashMap<RequestKey, Collection<ConfigAttribute>> getRequestMap(
            AuthorizationService authorizationService)
    {

        LinkedHashMap<RequestKey, Collection<ConfigAttribute>> resourceMap = new LinkedHashMap<RequestKey, Collection<ConfigAttribute>>();

        for (Resource resource : (List<Resource>) authorizationService
                .queryPathMapping())
        {
            String url = resource.getUrl();
            RequestKey request = new RequestKey("/" + url);
            String role = resource.getRole();

            if (resourceMap.containsKey(request))
            {
                Collection list = resourceMap.get(request);
                list.add(new SecurityConfig(role));
                resourceMap.put(request, list);
            }
            else
            {
                Collection attributes = new ArrayList();
                attributes.add(new SecurityConfig(role));

                resourceMap.put(request, attributes);
            }
        }

        return resourceMap;
    }
}


package com.xxx.framework.security.common;

import java.util.Collection;

import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

public class MyRoleVoter implements AccessDecisionVoter
{

    public boolean supports(ConfigAttribute attribute)
    {

        return true;

    }

    public boolean supports(Class<?> clazz)
    {
        return true;
    }

//下面是投票的关键代码,入参authentication是当前登录用户的角色,attributes是当前用户访问的资源(这里指/xx.aciton)所应该具有的角色。attributes有springsecurity框架获取到。

//下面代码的主要逻辑就是看当前用户的是不是具体访问该资源的角色。如果有则放行,没有则被exceptionTranslationFilter捕获,跳转到访问拒绝提示页面。

    public int vote(Authentication authentication, Object object,
            Collection<ConfigAttribute> attributes)
    {
        int result = ACCESS_ABSTAIN;
        Collection<GrantedAuthority> authorities = extractAuthorities(authentication);

        for (ConfigAttribute attribute : attributes)
        {
            if (this.supports(attribute))
            {

                result = ACCESS_DENIED;

                for (GrantedAuthority authority : authorities)
                {
                    if (attribute.getAttribute()
                            .equals(authority.getAuthority()))
                    {
                        return ACCESS_GRANTED;
                    }
                }
            }
        }
        return result;
    }

    Collection<GrantedAuthority> extractAuthorities(
            Authentication authentication)
    {
        return authentication.getAuthorities();
    }
}



H3C IPsec over GRE VPN 实验 配置 IPsec over GRE VPN 来连通两端内网 阅读详情

相关推荐

从示波器波形看懂死区:手把手教你调ST MCU的PWM,避免三相桥直通炸管

本文详细解析了如何通过示波器波形判断PWM死区时间,并手把手教你调整STM32高级定时器寄存器,避免三相逆变桥直通炸管。文章涵盖死区时间的本质与风险、STM32配置详解、示波器调试技巧及FOC系统中的特殊考量,帮助工程师优化电机驱动性能与安全性。

weixin_30315723的博客 734

史上最简单的Spring Security教程(十六):FilterSecurityInterceptor详解

​FilterSecurityInterceptor作为Spring Security Filter Chain的最后一个Filter,承担着非常重要的作用。如获取当前 request 对应的权限配置,调用访问控制器进行鉴权操作等,都是核心功能。 先简单看一下FilterSecurityInterceptor类的主要功用。 获取当前 request 对应的权限配置,首先是调用基类的beforeInvocation方法。 public void invoke(FilterInv...

银河架构师的博客 9731

拌合楼管理软件开发(十一) 海康威视车牌识别摄像头安装调试,总算是跑通了。

/保存的文件个数这里之所以需要用到委托,直接更新textbox文本中的内容,以及复制picturebox的image会提示不是从齐创建的线程调用。

morsth的博客 4816

【解决】分析SpringSecurity访问请求权限不足AccessDeniedException问题

> 该方法中首先调用了`this.obtainSecurityMetadataSource().getAttributes(object)`方法,通过当前请求路径获取到**访问该请求所需要的权限**(object是上一步调用传过来的参数,封装了我们请求路径的一些信息)。.........

sunao1106的博客 7817

麒麟OS(Kylin OS)操作系统minikube+docker安装使用及遇到的问题

一 ,安装minikube及操作工具kubectl 1,安装kubectl 使用以下命令下载最新版本: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" 要下载指定版本(例如v1.22.0版本) ,请键入: curl -LO https://dl.k8s.io/release/v1.22.0/bin/linux/amd..

qq_23396017的博客 2643

SpringSecurity3.0.5的配置文件及相关类

001 xml version="1.0" encoding="UTF-8"?> 002 beans xmlns="http://www.springframework.org/schema/beans" 003         xmlns:s="http://www.springframework.org/schem

oEveryman的专栏 1112

阅文集团大数据面试题及参考答案

在 Flink 中,watermark 是一种用于处理乱序事件时间的机制。实现接口:通常需要实现 AssignerWithPeriodicWatermarks 或 AssignerWithPunctuatedWatermarks 接口。前者会周期性地生成 watermark,后者则是基于某些特定事件来生成 watermark ,比如接收到某个特定值的消息时。定义位置:可以在数据源处或者在流处理的中间操作中定义 watermark。在数据源定义时,能更精准地根据数据的产生特性设置 watermark;

大模型大数据攻城狮的专栏 1088

MyBatis链接MySQL出现异常,URL报错

Exception 大体类似于下面这种报错 answer 原来是这样写: <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT"/> 改成...

1215ccc 833

猿创征文|SfM(Structure from Motion)学习之路

SfM全称Structure from Motion,译为运动恢复结构,是三维重建pipeline的一部分,又称稀疏重建,在摄影测量领域则称为空三(空中三角测量)。SfM的任务是,给定一系列具有一定重叠度的图像,去同时估计出拍摄每张图像时相机的的位姿(位置t和姿态R)和被拍摄物体或场景的稀疏点云。...............

zeeq的博客 1万+

华为OD机试真题 新系统【小花获胜的奶茶】

华为OD机试真题 新系统【小花获胜的奶茶】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【小花获胜的奶茶】多语言题解。

qq_45776114的博客 385

忽略Java请求参数为空的值,Spring Security - 忽略请求参数规则的Url

I have a web application that uses spring security. It uses elements to describe the access filters for different urls. By default, this does not take request parameters of urls into account. I neede...

weixin_42395171的博客 390

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringSecurity授权流程源码解析

上篇文章分析了SpringSecurity基于用户名和密码的认证过程,这篇分析下授权流程;授权主要处理权限问题,比如说用户没有登录,如果直接请求某一个需要权限的接口,处理的过程是怎样的; 1>.DelegatingFilterProxy 的doFilter方法 这个是认证的过滤入口,最终调用的是FilterChainProxy的doFilter方法 2>.FilterChainP...

xiaoguangtouqiang的博客 2772

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

springsecurity不拦截某个接口_SpringSecurity 默认表单登录页展示流程源码

SpringSecurity 默认表单登录页展示流程源码本篇主要讲解 SpringSecurity提供的默认表单登录页 它是如何展示的的流程,涉及1.FilterSecurityInterceptor,2.ExceptionTranslationFilter ,3.DefaultLoginPageGeneratingFilter 过滤器,并且简单介绍了 AccessDecisionManager ...

weixin_39554290的博客 1775

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

SpringSecurity ,oAuth2.0 从入门到源码精通 之 (四)spring security 的 认证流程、权限验证流程源码解读

(我将我的 Spring Security 专栏地址放在这里,供大家参考,后面会持续更新: SpringSecurity ,oAuth2.0 从入门到源码精通 ,希望可以帮助到正在学习 Spring Security 和 oAuth2.0 的小伙伴)。 经过前面三篇文章的学习,我想大家应该已经很熟悉 Spring Security 在 Spring Boot 中的基本使用了,相信大家肯定也不会满足于此,所以今天我们就一起来讨论一下 Spring Security 的源码,让我们不仅会使用 Spring Se

llk15884975173的博客 747

SpringSecurity学习总结

SpringSecurity

goodbyepig的博客 513

SpringSecurity 默认表单登录页展示流程源码

SpringSecurity 默认表单登录页展示流程源码 本篇主要讲解 SpringSecurity提供的默认表单登录页 它是如何展示的的流程,涉及1.FilterSecurityInterceptor,2.ExceptionTranslationFilter ,3.DefaultLoginPageGeneratingFilter 过滤器,并且简单介绍了 AccessDecisionManager...

qq_34285557的博客 1345

SpringSecurity原理

SpringSecurity源码原理

onePlus5T的博客 1292

SpringSecurity的授权流程源码刨析

一文从源码角度搞清楚SpringSecurity的授权流程。

WayneHu的博客 264

SpringSecurity从入门到精通(超级详细教程,不会你打我)

本文介绍了Spring Security安全框架的基本概念和快速入门方法。主要内容包括: Spring Security与Shiro的对比,指出Spring Security更适合中大型项目 快速搭建SpringBoot工程并集成Spring Security的基本步骤 认证授权流程的核心原理,包括过滤器链结构和认证流程详解 自定义登录校验的解决方案,涉及JWT令牌、Redis存储等关键技术 相关依赖配置和工具类实现,如FastJson序列化处理 文章通过代码示例和流程图

2301_79693537的博客 1025

根据debug信息研究springsecurity的认证逻辑

springsecurity写的不但复杂,并且权限的逻辑和一般国人的习惯不太一样,跟网上找了一堆一堆的文档也没看出个所以然来,这里通过研究debug日志来研究一下springsecurity各组件的调用情况。 环境情况:采用springboot 2.0 + springsecurity 5....

chitiguan0536的博客 1273

默认登录_SpringSecurity 默认表单登录页展示流程源码

SpringSecurity 默认表单登录页展示流程源码本篇主要讲解 SpringSecurity提供的默认表单登录页 它是如何展示的的流程,涉及1.FilterSecurityInterceptor,2.ExceptionTranslationFilter ,3.DefaultLoginPageGeneratingFilter 过滤器,并且简单介绍了 AccessDecisionManager ...

weixin_34790081的博客 967

SpringSecurity简单使用的总结

SpringSecurity的作用:实现对web应用的访问进行认证与授权认证:验证当前访问系统的用户是不是合法的用户,并且确认具体的身份授权:在经过认证以后,判断当前用户是否具有权限进行某个操作。本文对简单使用SpringSecurity做了一些总结......

m0_51972565的博客 377

springsecurity OAuth2.0-第4章: springboot整合 spring security认证与授权

一 spring security DaoAuthenticationProvider和UserDetailsService的职责搞混淆,其实UserDetailsService只负责从特定的地方(通常是数据库)加载用户信息,仅此而已。而DaoAuthenticationProvider的职责更大,它完成完整的认证流程,同时会把UserDetails填充至Authentication。 二 spring boot整合spring security 2.1 工程结构 2.2配置pom文件

健康平安的活着的专栏 856

Spring Security3配置使用

使用Spring Security3的几种方法概述 一种是全部利用配置文件,将用户、权限、资源(url)硬编码在xml文件中,已经实现过。 二种是用户和权限用数据库存储,而资源(url)和权限的对应采用硬编码配置,目前这种方式已经实现。 三种我使用的是第三种 第三种是细分角色和权限,并将用户、角色、权限和资源均采用数据库存储,并且自定义过滤器,代替原有的Filte

顶峰科技的专栏 400

SpringSecurity安全配置—SSH整合

项目中使用了SpringSecurity,发现SpringSecurity实现登录管理很方便,花了一点时间,将SpringSecurity安全配置整理出来,实现SpringSecurity安全配置登陆,供需要的朋友参考,如有整理不到位的地方,请提出意见,谢谢! 使用Springsecurity首先要提的就是jar包了,Springsecurity的jar下载地址:http://static.

u011863709的专栏 799
上一篇: JAVA5多线程---Condition使用---线程通信
下一篇: 使用Spring WS 2.0开发基于SOAP的web service
rabbit0708
博客等级 码龄15年 12粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值