我在带有OAuth2的Spring MVC上有一个REST API.
为了支持表达式处理程序hasRole,hasAuthority我添加了以下配置:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
return new OAuth2MethodSecurityExpressionHandler();
}
}
Run Code Online (Sandbox Code Playgroud)
这@PreAuthorize对控制器工作进行了注释:
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('ROLE_USER')") // This works as expected
public List<Experiment> getExperimentList() {
//...
}
Run Code Online (Sandbox Code Playgroud)
与此同时,我无法为所有控制器进行全局配置:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth, MyAppAuthenticationProvider authenticationProvider) throws Exception {
auth.authenticationProvider(authenticationProvider);
}
@Override
protected void configure(HttpSecurity http) throws …Run Code Online (Sandbox Code Playgroud) java spring-mvc spring-security spring-boot spring-security-oauth2
释放锁时,我收到一个SynchronizationLockException.
当然,我做的第一件事是谷歌搜索问题.我发现了两个主要的错误模式:
问题是这些模式都不适合我的情况.
我有一个非常简单的同步方案:
public class MyClass : IDisposable
{
private readonly object _myLock = new object();
internal void Func1()
{
lock (_myLock)
{
//Some code here
}
}
internal void Func2()
{
lock (_myLock)
{
//Some code here
}
}
public void Dispose()
{
lock (_myLock)
{
//Some code here
} // Here is where I get an exception
}
}
Run Code Online (Sandbox Code Playgroud)
最终我收到SynchronizationLockException了Dispose()释放锁的地方.
我的问题不是"我的代码有什么问题"或"我做错了什么".基本上,我想知道如何(以及在什么情况下)这种情况可能会发生.NET的.NET实现抛出此异常.
谢谢.
我在我的 Web 应用程序中使用了 Ninject DI,其中包含来自 Asp.Net 堆栈(MVC、Web Api 2、SignalR)的一系列技术。
我已经通过以下方法使 DI 适用于所有使用的技术:
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
internal static IKernel CreateKernel()
{
var …Run Code Online (Sandbox Code Playgroud) 我的.NET应用程序可以将同一程序集的多个版本加载到内存中.程序集未签名,但每次编译和装载新的程序集时,它都会自动获得一个新的程序集版本(小部分).我对类型没有任何问题,因为实例化ob对象是受控制的,所以我知道对象是从哪个程序集创建的.
自从VS 2003以来,这一直在运行,但是在最新的VS 2015中,这个场景的调试被打破了.一切正常,只有单个版本的程序集加载到内存中,但每当加载第二个版本时,所有Locals/Watch窗口都变空.并尝试评估QuickWatch中的任何表达式都会产生编译器异常"错误CS1704:已导入具有相同简单名称'MyAssembly'的程序集.请尝试删除其中一个引用(例如'MyAssembly.dll')或将其签名以启用并排侧".
以下是VS2013和VS2015附加调试器的相同应用程序的屏幕截图(加载两个程序集时):
所以这使得VS 2015的调试几乎不可能.
由于最初这是一个compliler错误(据我所知,在VS 2015调试器的封面下使用)互联网搜索不是很有用.这是我能找到的唯一与调试器问题相关的链接: Visual Studio Debugger无法检查变量.与我的情况不同的是,在内存中有两个程序集是一个错误,而在我的情况下,这是一个意图.
所以现在我在思考我的选择.
那么可能有人可以提出更多想法吗?Thnaks.