Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >弹簧安全UserDetailsService不工作

弹簧安全UserDetailsService不工作
EN

Stack Overflow用户
提问于 2016-08-26 04:57:55
回答 4查看 7.9K关注 0票数 2

好了,伙计们,希望你们能帮我,这是我最后一次尝试。我对这个春天的安全世界很陌生,我不能让它起作用。我尝试了很多东西,学习了很多教程,什么也没做。

问题是,正如您在标题中所看到的,要使自定义用户详细信息服务正常工作。它只是没有登录,它似乎没有调用定制用户详细服务,因为sysouts没有显示在控制台中.

它作为一个魅力与春天安全的记忆功能。下面是我的密码。

弹簧安全控制:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Configuration
@EnableWebSecurity
@ComponentScan(basePackageClasses = CustomUserDetailsService.class)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
UserDetailsService userDetailsService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    //auth.inMemoryAuthentication().withUser("ram").password("ram123").roles("ADMIN");
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordencoder());
}

@Override
public void configure(WebSecurity web) throws Exception {
  web
    .ignoring()
       .antMatchers("/bower_components/**", "/resources/**", "/img/**"); // #3
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.httpBasic().and().csrf().disable()
    .authorizeRequests()
      .antMatchers("/", "/home", "/call").permitAll() // #4
      .antMatchers("/resource", "/video").hasRole("USER") // #6
      .anyRequest().authenticated();
}

@Bean(name="passwordEncoder")
public PasswordEncoder passwordencoder(){
    return new BCryptPasswordEncoder();
}

}

CustomUserDetailsService

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Service("customUserDetailsService")
public class CustomUserDetailsService implements UserDetailsService{

private UserService userService;

@Override
public UserDetails loadUserByUsername(String ssoId)
        throws UsernameNotFoundException {
    User user = userService.findByUsername(ssoId);
    System.out.println("User : "+user);
    if(user==null){
        System.out.println("User not found");
        throw new UsernameNotFoundException("Username not found");
    }
        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), 
             user.isEnabled(), true, true, true, getGrantedAuthorities(user));
}


private List<GrantedAuthority> getGrantedAuthorities(User user){
    List<GrantedAuthority> authorities = new ArrayList<>();

    authorities.add(new SimpleGrantedAuthority(user.getRole()));

    System.out.print("authorities :"+authorities);
    return authorities;
}
}

初始化类

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@SpringBootApplication
@EnableWebSocket
public class One2OneCallApp implements WebSocketConfigurer {

@Bean
public CallHandler callHandler() {
  return new CallHandler();
}

@Bean
public UserRegistry registry() {
  return new UserRegistry();
}

@Bean
public KurentoClient kurentoClient() {
  return KurentoClient.create();
}

@Bean
public UiApplication uiApplication(){
  return new UiApplication();
}

@Bean
public CustomUserDetailsService customUserDetailsService(){
  return new CustomUserDetailsService();
}

@Bean
public SecurityConfig securityConfig(){
  return new SecurityConfig();
}

@Bean
public EncryptPassword encryptPassword(){
  return new EncryptPassword();
}

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry   registry) {
  registry.addHandler(callHandler(), "/call");
}

public static void main(String[] args) throws Exception {
  System.out.println("Iniciando");  
  new SpringApplication(One2OneCallApp.class).run(args);    
}

}

我还测试了与数据库的通信,它运行得非常好。我在寻求任何帮助。抱歉英语不太好。谢谢大家!

编辑:下面回答了我自己的问题。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-09-14 04:44:59

最后,为了我不得不做的演示,我一直呆在内置的记忆花絮中。我认为我的问题与spring启动和应用程序中的初始化有关。

票数 -6
EN

Stack Overflow用户

发布于 2016-08-26 05:12:07

SecurityConfig类中:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Autowired
CustomUserDetailsService customUserDetailsService;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(customUserDetailsService);
}
票数 0
EN

Stack Overflow用户

发布于 2016-08-26 05:44:16

变化

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Autowired
UserDetailsService userDetailsService;

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Autowired
CustomUserDetailsService userDetailsService;

另外,在web/套接字配置中导入安全配置,并将组件扫描移到那里,而不是在安全性上。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@ComponentScan(basePackageClasses = CustomUserDetailsService.class)
@Import(value = { SecurityConfig.class })
public class WebConfig extends WebMvcConfigurerAdapter { /*...*/ }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39166920

复制
相关文章
无法加载 DLL xpstar.dll 或它引用的一个 DLL。原因: 126(找不到指定的模块。)。
需要复制数据库文件,把SQL服务停了,不使用脱机或者分离是觉得比较慢,结果就是再次重启服务后,SQL开始报错:
_一级菜鸟
2020/08/02
2.3K0
[754]ImportError: DLL load failed: 找不到指定的模块
在tensorflow的学习中,想使用tensorflow-gpu版的学习,充分利用计算机。但是跟网上很多博主的方法安装gpu,cuda是安装成功了,但是却一直报以下一个错误。
周小董
2020/02/14
14.7K0
[754]ImportError: DLL load failed: 找不到指定的模块
OSError: [WinError 126] 找不到指定的模块/Could not find 'cudart64_90.dll'.
如果你在使用Python开发时遇到了类似的错误消息,例如OSError: [WinError 126] 找不到指定的模块/Could not find 'cudart64_90.dll',那么你可能是在尝试使用CUDA相关的功能,但缺少了相应的CUDA运行时库文件。
大盘鸡拌面
2023/11/28
9080
Pycharm中出现ImportError:DLL load failed:找不到指定模块的解决方法
最近在师姐机器上跑实验的时候,想利用matplotlib包来绘制损失曲线图,安装过程中碰到了一些小麻烦,感觉之前好像也碰到过类似的问题,网上一搜什么numpy、matplotlib、pillow包版本冲突啊,然后就是各种尝试,直至重装Anaconda,当时特头疼,最后无意中解决了,今天又碰到了类似的问题,这次记录下来防止忘记
全栈程序员站长
2022/09/14
6.8K1
Pycharm中出现ImportError:DLL load failed:找不到指定模块的解决方法
解决module = loader.load_module(fullname) ImportError: DLL load failed: 找不到指定的模块。
在使用Python时,有时可能遇到​​ImportError: DLL load failed: 找不到指定的模块​​错误。这个错误通常是由于无法找到依赖的动态链接库(DLL)文件引起的。本篇文章将介绍一些解决这个问题的方法。
大盘鸡拌面
2023/10/25
1.8K0
[Python] ImportError: DLL load failed … 找不到指定的模块 此类问题解决方法
最近升级 Python 项目,由 Python2.7 升级到 Python3.8.3,项目使用了 PySide2,对于较新的Python3.8.3 , PySide2 可能存在些许不兼容问题,环境配置完成后,出现一连串的 ImportError: DLL load failed 找不到指定模块 对于很多 Python 开发者来说,这类问题最为头疼,不知道如何下手解决。
全栈程序员站长
2022/09/14
11.1K0
[Python] ImportError: DLL load failed … 找不到指定的模块 此类问题解决方法
找不到mfc110.dll,无法执行代码
运行完直接即可进行下载,安装后解决对应的所有问题。 傻瓜式安装,自动安装到C:\Windows\System32下。 comct232.ocx 6.0.98.39 comct332.ocx 6.7
红目香薰
2022/11/30
8710
找不到mfc110.dll,无法执行代码
找不到或无法加载主类 Hello
http://jingyan.baidu.com/album/f96699bb8b38e0894e3c1bef.html?picindex=1
用户9184480
2024/12/13
350
安装tensorflow时候报错ImportError: DLL load failed: 找不到指定的模块。Failed to load the native TensorFlow runtime.
解决方法:降低tensorflow版本,版本太高。在terminal复制粘贴以下命令:
川川菜鸟
2021/10/18
1.4K0
Remote Desktop Services启动失败找不到指定的模块
Windows无法远程连接,排查发现是因为 Remote Desktop Services 无法启动 Remote DEsktop services 错误2,找不到指定的模块 (Windows 2016中为错误126,找不到指定的模块)
大大大黑白格子
2020/06/10
8.7K0
MICROSOFT REPORT VIEWER 2012之无法加载相关的dll
使用VS 2012开发报表, 如果是使用的微软的报表控件的话,默认是使用的MICROSOFT REPORT VIEWER 2012,本地开发基本上没问题,但是一发布服务器,就会发现坑了,微软挖坑从来就不打招呼,坑你没商量。
雪雁-心莱科技
2018/12/27
9090
错误: 找不到或无法加载主类(java)
很多刚学java的同学基本上都遇到过这个问题,刚才我刚了一下idea中入口雷类的包的地址,就出现这个了。原因很简单,在此特做记录,希望能帮助到点开这个文章,遇到错误的你。
手撕代码八百里
2020/07/28
5K0
java提示找不到或无法加载主类
背景 默许jdk的配置大家都没有问题,执行java,javac无报错,但今天在尝试在本地起来kafka的时候,提示java 找不到或无法加载主类,然后日志中提示 Files 找不到或无法加载主类;C:
千往
2018/01/24
1.9K0
java提示找不到或无法加载主类
模块***已加载但找不到入口点DllRegisterServer,请确保***为有效的DLL或OCX文件,然后重试[通俗易懂]
声明一下,本帖子是记录本人解决问题得步骤,并不一定适合所有人,你们能找到这个博文,其他人得估计也试过了不行,没必要回帖喷我,另外360里面有dll修复,网上也大把得修复工具,这个只是手动修复了我自己遇到得问题。
全栈程序员站长
2022/09/14
4.3K0
模块***已加载但找不到入口点DllRegisterServer,请确保***为有效的DLL或OCX文件,然后重试[通俗易懂]
模块已加载,但找不到入口点DLLRegisterServer[通俗易懂]
大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说模块已加载,但找不到入口点DLLRegisterServer[通俗易懂],希望能够帮助大家进步!!!
Java架构师必看
2022/08/01
52K1
模块已加载,但找不到入口点DLLRegisterServer[通俗易懂]
pycharm添加anaconda解释器_anaconda找不到指定模块
PyCharm使用anaconda新建环境是只包含一些基础包,后续如果想要如Scrapy.requests等库的话则需要自己在解释器页面添加了(ctrl+alt+s进入解释器设置页面)
全栈程序员站长
2022/09/27
2.2K0
pycharm添加anaconda解释器_anaconda找不到指定模块
IDEA 出现错误:找不到或无法加载主类
解决方法: idea本身缓存问题 解决:清理缓存重启IDEA file-->invalidate Cache/restart 解决方法二: 在这里设置自己的java文件的目录位置
孙晨c
2019/09/10
6.7K1
IDEA 出现错误:找不到或无法加载主类
idea 错误:找不到或无法加载主类 解决
问题出现的很莫名其妙,, 在项目的PATH 中,将path修改为跟当前项目在一个路径下就可以了
MickyInvQ
2020/09/27
12.6K0
idea 错误:找不到或无法加载主类 解决
php_curl.dll libssh2.dll 始终无法加载的原因 及解决办法
在StackOverflow得到最终原因及解决办法 http://stackoverflow.com/questions/16424117/php-unable-to-load-php-curl-dll-extension libeay32.dll and ssleay32.dll have to be path-accessible for php_curl.dll loading to succeed. Copying them into System32 (or even into the Windo
庞小明
2018/03/09
9480
Java提示错误: 找不到或无法加载主类
检查java在Idea终端中是否可用,如不可用,编辑编译器输出路径:文件→项目结构→模块→路径→输出目录 或 设置→工具→终端→项目设置→环境变量
无刺鱼
2022/03/29
2.1K0

相似问题

使用Gulp w/特定模式重命名文件

16

Gulp w/Browsersync Boot,但不重新加载页面

24

h/w和s/w中断的实现差异

10

因编译错误而中断的凤凰活重加载

12

BrowserSync (w/ gulp)工作非常慢

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文