东软医疗java面试题目,SpringSecurity---web,2024阿里Java高级面试题总结

③创建接口mapper,继承mp 的BaseMapper接口

④完善Service实现类

3.3 自定义登录页面与请求放行

package com.ty.config;



import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;

import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

import org.springframework.security.core.userdetails.UserDetailsService;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import org.springframework.security.crypto.password.PasswordEncoder;



@Configuration

public class MySecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired

    UserDetailsService userDetailsService;

    @Autowired

    PasswordEncoder passwordEncoder;



    @Override

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);

    }



    @Override

    protected void configure(HttpSecurity http) throws Exception {

        http.formLogin()

                .loginPage("/login")

                .loginProcessingUrl("/index")

                .defaultSuccessUrl("/hello")

                .failureForwardUrl("/login");

        http.authorizeRequests()

                .antMatchers("/login","/")

                .permitAll()

                .anyRequest()

                .authenticated();

        http.csrf().disable();



    }



    @Bean

    public PasswordEncoder passwordEncoder(){

        return new BCryptPasswordEncoder();

    }

}




<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">



<html xmlns="http://www.w3.org/1999/xhtml"

      xmlns:th="http://www.thymeleaf.org">

    <head>

        <meta charset="UTF-8">

        <title>Login</title>

    </head>

    <body>

        <p id="login">

        <h1>Login</h1>

        <form method="post" th:action="@{/index}">

            <input type="text" required="required" placeholder="用户名" name="username"></input>

            <input type="password" required="required" placeholder="密码" name="password"></input>

            <button class="but" type="submit">登录</button>

        </form>

        </p>

    </body>

</html>



3.4 基于角色和权限进行访问控制
3.4.1 hasAuthority 方法

如果当前的主体具有指定的权限,则返回 true,否则返回 false

3.4.2 hasAnyAuthority 方法

如果当前的主体有任何提供的角色(给定的作为一个逗号分隔的字符串列表)的话,返回

true.

在配置类中


 .antMatchers("/find").hasAuthority("admin")

                .antMatchers("/findAll").hasAnyAuthority("role,admin")



在MyUserDetailServiceImp 中


List<GrantedAuthority> auths = AuthorityUtils.createAuthorityList("admin","role");

        return new User("lisa", passwordEncoder.encode(user.getPassword()),auths);



3.4.3 hasRole 方法

如果用户具备给定角色就允许访问,否则出现 403。

如果当前主体具有指定的角色,则返回 true。


.antMatchers("/test/hello").hasRole("role")





**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**

**深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**

**因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
![img](https://img-blog.csdnimg.cn/img_convert/9f204ffced72a2d1568c4b9ec2e8e721.jpeg)
![img](https://img-blog.csdnimg.cn/img_convert/29138875ed2259dbf9c928780bcee8da.png)
![img](https://img-blog.csdnimg.cn/img_convert/4ca30c8847651a88fc8558023e961d66.png)
![img](https://img-blog.csdnimg.cn/img_convert/d0c033d361f03c817f34c888f07d28e5.png)
![img](https://img-blog.csdnimg.cn/img_convert/a41d61f05ecf72fcb53dcb1c928979b6.png)
![img](https://img-blog.csdnimg.cn/img_convert/7b0dcde397b7d86f29daadd8b85a5295.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!**

**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**

**如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)**
![img](https://img-blog.csdnimg.cn/img_convert/edfbf4a3f2bd19b28358501424b2a997.jpeg)



# 总结

其他的内容都可以按照路线图里面整理出来的知识点逐一去熟悉,学习,消化,不建议你去看书学习,最好是多看一些视频,把不懂地方反复看,学习了一节视频内容第二天一定要去复习,并总结成思维导图,形成树状知识网络结构,方便日后复习。

这里还有一份很不错的《Java基础核心总结笔记》,特意跟大家分享出来

**目录:**

![](https://img-blog.csdnimg.cn/img_convert/c129c56e13289efc4390e13d063869cd.webp?x-oss-process=image/format,png)

**部分内容截图:**

![](https://img-blog.csdnimg.cn/img_convert/7123934d8d982c803c73f4e490d9d5b4.webp?x-oss-process=image/format,png)

![](https://img-blog.csdnimg.cn/img_convert/0aa89a6d234d7598c2ed52ba70f43347.webp?x-oss-process=image/format,png)


[**一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!**](https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0)

**AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算**

起学习成长!**](https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0)

**AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值