Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring security 从不同来源调用Spring Security_Spring Security - Fatal编程技术网

Spring security 从不同来源调用Spring Security

Spring security 从不同来源调用Spring Security,spring-security,Spring Security,我只想对来自HTTP请求的调用运行身份验证/授权 从多个源调用控制器上我希望启用身份验证/授权的方法。在这种情况下,它可以由另一个控制器调用,也可以由直接HTTP请求调用 我可以关闭来自其他控制器的呼叫的身份验证/授权吗 如果你还不够清楚的话,请进一步阅读 假设我在控制器a上有一个方法doIt()。我也有一个控制器B,在其中我注入控制器a。在控制器B上的某个点,我调用“a.doIt()”,但我也可以从对doIt.do的HTTP调用调用doIt()。 如果调用来自HTTP调用,我想测试对身份验证/

我只想对来自HTTP请求的调用运行身份验证/授权

从多个源调用控制器上我希望启用身份验证/授权的方法。在这种情况下,它可以由另一个控制器调用,也可以由直接HTTP请求调用

我可以关闭来自其他控制器的呼叫的身份验证/授权吗

如果你还不够清楚的话,请进一步阅读

假设我在控制器a上有一个方法doIt()。我也有一个控制器B,在其中我注入控制器a。在控制器B上的某个点,我调用“a.doIt()”,但我也可以从对doIt.do的HTTP调用调用doIt()。
如果调用来自HTTP调用,我想测试对身份验证/授权的调用,但如果调用来自控制器B,则不进行测试。

您只需要在URL上配置spring身份验证,而不需要在方法调用上配置。这对您很有用。

您只需要在URL上配置spring身份验证,而不需要在方法调用上配置。这对你很有用。

我看不出有任何方法可以做到这一点,我猜你只需要有第二种方法,比如doitDirectCall(…),实际的其他控制器调用,以及在HTTP请求中调用的doit(…)

我看不出有任何方法可以做到这一点,我猜你只需要有第二个方法,比如实际的其他控制器调用的doitDirectCall(…)和HTTP请求调用的doit(…)

你在B中注入了a的安全代理bean。你不能在没有代理的情况下注入a吗
Bean A代理:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

安全拦截器
secutiryInterceptor:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

...
未代理的Bean A:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

注入Bean“A未代理”的Bean B:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

您正在B中注入A的安全代理bean。您不能在没有代理的情况下注入A吗
Bean A代理:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

安全拦截器
secutiryInterceptor:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

...
未代理的Bean A:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>

注入Bean“A未代理”的Bean B:

<bean id="beanASecured" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetName" value="beanA"/>
  <property name="interceptorNames">
    <value>securityInterceptor</value>
  </property>
</bean>
<bean id="securityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
   ...
</bean>
<bean id="beanA" class="com.A"/>
<bean id="beanB" class="com.B">
   <constructor-arg ref="beanA"/>
</bean>


这对我来说是个问题,因为我们当前的投票人使用方法上的注释来检查该方法所需的授权级别。将其更改为URL(可能使用xml映射)可能需要大量工作。尽管如此,如果我找不到另一个解决方案,这将不得不起作用。谢谢如果使用了方法级授权,那么您将无法逃脱。URL授权将使用相同的设置,只是您需要进行一些配置,因此不需要做太多工作。这对我来说是个问题,因为我们当前的投票者使用方法上的注释来检查该方法所需的授权级别。将其更改为URL(可能使用xml映射)可能需要大量工作。尽管如此,如果我找不到另一个解决方案,这将不得不起作用。谢谢如果使用了方法级授权,那么您将无法逃脱。URL授权将使用相同的设置,只是需要进行一些配置,所以不需要做很多工作。有什么方法可以做到这一点吗?我不这么认为。但实际上,这对我来说是最好的解决方案。这取决于你如何代理这些bean。我编辑了我的帖子以添加一个示例。碰巧我使用@Autowire注释以及“Yes,use de@Qualifier注释”注入了它们。为了确保我正确无误:我必须声明两个单独的bean(在本例中为注释类),一个启用了安全性,另一个禁用了安全性(可能一个从另一个继承),用一个不同的限定符限定每一个,并在自动布线时明确,对吗?有办法做到这一点吗?我不这么认为。但实际上,这对我来说是最好的解决方案。这取决于你如何代理这些bean。我编辑了我的帖子以添加一个示例。碰巧我使用@Autowire注释以及“Yes,use de@Qualifier注释”注入了它们。为了确保我正确无误:我必须声明两个单独的bean(在本例中为注释类),一个启用了安全性,另一个禁用了安全性(可能一个从另一个继承),使用不同的限定符对每个进行限定,并在自动关联时明确,对吗?