V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  src112159  ›  全部回复第 1 页 / 共 1 页
回复总数  18
2020-02-29 01:37:21 +08:00
回复了 lik750 创建的主题 问与答 百度云同步盘突然清空了我电脑上文件夹内所有本地文件!
似乎没人说谷歌硬盘。
2020-02-21 00:38:07 +08:00
回复了 seanxx 创建的主题 MacBook Pro macbookpro 出现爆裂噼里啪啦声音
排除法看看
2019-04-04 10:05:24 +08:00
回复了 cjzlol 创建的主题 生活 耳鸣一个多月了,好烦
是身体太虚引起的,我有过这样的经历,去医院检查也没啥毛病。大部分原因是心理压力和营养不够造成的
2018-12-26 18:46:06 +08:00
回复了 alwayshere 创建的主题 程序员 刚从 win 换到 mac, mac 下有没有类似于 xshell 的工具?
个人感觉比 MAC 版的 SecureCRT 好用
2018-12-26 18:44:18 +08:00
回复了 alwayshere 创建的主题 程序员 刚从 win 换到 mac, mac 下有没有类似于 xshell 的工具?
ZOC7,我现在在用的,推荐试试
2018-12-26 18:42:02 +08:00
回复了 heraldic 创建的主题 Linux deepin Linux 确实好用,暂时整机就用它了
PC 装个黑苹果其实还不错,远景上有很多别人做好的引导
就是因为那个返回的 code 的原因,返回 1001 前段直接 logout 了。。。。
@beny2mor

已经找到问题了,谢谢你的帮助哈,。
@beny2mor
@Service
public class MyAccessDecisionManager implements AccessDecisionManager {


@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null == configAttributes || configAttributes.size() <= 0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("没有操作权限");
}

@Override
public boolean supports(ConfigAttribute attribute) {
return true;
}

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


----------------------------------------------------------------


@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
//返回 json 形式的错误信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
response.getWriter().println("{\"code\":1001, \"msg\":\""+e.getMessage()+"\"}");
response.getWriter().flush();
}
}


----------------------------------------------------------
是有 AccessDecisionManager 的,无权限的资源也返回了这个 json,现在就是会自己跳转到登录
@beny2mor 这样权限控制好像是没有问题的,但就是会跳转到自定义的登录页面
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// 由于使用的是 JWT,我们这里不需要 csrf
.csrf().disable()

.exceptionHandling()
.accessDeniedHandler(myAccessDeniedHandler)
.authenticationEntryPoint(unauthorizedHandler)
.and()

// 基于 token,所以不需要 session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()

.authorizeRequests()

// 允许对于网站静态资源的无授权访问
.antMatchers(
HttpMethod.GET,
"/",
"/*.html",
"/favicon.ico",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/**/*.png",
"/**/*.jpg"
).permitAll()
// 对于获取 token 的 rest api 要允许匿名访问
.antMatchers("/api/auth/**").permitAll()
.antMatchers("/sys_user/**").permitAll()
.antMatchers("/x_mgr/**/*.*").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();

// 添加 JWT filter
httpSecurity
.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
httpSecurity.addFilterBefore(myFilterSecurityInterceptor, FilterSecurityInterceptor.class);
// 禁用缓存
httpSecurity.headers().cacheControl();
}
是跳转到了自定义的登录页。我现在就是在数据库配置了用户-资源权限表,用表里的资源来控制的
也有没有权限的返回值 json。 但就是不知道它为啥还会跳转到登录页
@beny2mor httpSecurity
.csrf().disable()

.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.accessDeniedHandler(myAccessDeniedHandler)

这个是有配置了的。
我在这个 URL 对应的方法上面加注解 @PreAuthorize("hasRole('ROLE_CO')") ,就能实现不跳转。直接返回 json
2018-02-21 12:58:19 +08:00
回复了 rajiha 创建的主题 全球工单系统 网易云音乐部分页面/API 疑似炸了?
网管搞得鬼吧,在路由上过滤了
2018-02-08 17:34:59 +08:00
回复了 liuzl 创建的主题 Python Python 技术公众号 100 天了
大力出奇迹。
我就来
2018-02-07 16:42:49 +08:00
回复了 FourAndHalf 创建的主题 Ubuntu 小米笔记本 Pro 能完美支持 Ubuntu 吗
就算装 Ubuntu 完美驱动,不会觉得软件不够用吗
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4514 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 26ms · UTC 10:06 · PVG 18:06 · LAX 03:06 · JFK 06:06
Developed with CodeLauncher
♥ Do have faith in what you're doing.