会员可以在此提问,尚新途老师有问必答

对大家有帮助的问答会被标记为“推荐”,看完课程过来浏览一下别人提的问题,会帮你学得更全面

截止目前,同学们一共提了128799个问题
JavA小菜2021-05-16 11:43:40

跟上面同学一样的问题,输入密码后报404,代码跟老师一样。

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Spring Security(旧)
误念2021-05-14 11:37:50

commons-collections-3.2.2这个jar上节课什么时候,导入的,没看到呀,也没有使用

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
Cleveland2021-05-12 15:37:10


我照着敲的,访问时候弹出这个

image.png

package com.security.handle;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author  liufupeng
 * @date  2021/5/11
 */
@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {

        httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
        httpServletResponse.setContentType("application/json:charset=utf-8");
        PrintWriter writer = httpServletResponse.getWriter();
        writer.println("{\"code\":\"403\",\"msg\":\"无权限\"}");
        writer.flush();
        writer.close();
    }


}
package com.security.config;

import com.security.handle.MyAccessDeniedHandler;
import com.security.handle.MyAuthenticationFailHandler;
import com.security.handle.MyAuthenticationSuccessHandler;
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.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author liufupeng
 * @date 2021/5/8
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private MyAccessDeniedHandler myAccessDeniedHandler;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        // 表单认证
        http.formLogin()
                .loginProcessingUrl("/login") // 当发现/login时认为是登陆,需要执行UserDetailsServiceImpl
//                .successForwardUrl("/toMain") // 登陆成功 此处为post请求
//                .failureForwardUrl("/fail")
                .usernameParameter("username") //自定义username字段
                .passwordParameter("password")
                .successHandler(new MyAuthenticationSuccessHandler("/toMain"))
                .failureHandler(new MyAuthenticationFailHandler("/fail.html"))
                .loginPage("/login.html");

        //  url 拦截
        http.authorizeRequests()
                .antMatchers("/login.html", "/fail.html").permitAll() // 登陆不需要被认证
//                .antMatchers("/main1.html").hasAuthority("admin")
                .antMatchers("/main1.html").hasIpAddress("127.0.0.1")
                .anyRequest().authenticated();

        http.csrf().disable();

        http.exceptionHandling()
                .accessDeniedHandler(myAccessDeniedHandler);
    }

    @Bean
    public PasswordEncoder getPe() {
        return new BCryptPasswordEncoder();
    }
}


相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Spring Security(旧)
?2021-04-20 18:15:27
相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
JavA小菜2021-04-07 21:37:32
  1. 设置的这个是干嘛用的?。。。。。。。。。。。。。。。。。

image.png

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
just do it2021-04-04 10:48:30

如果想配置认证策略,而且在有多个数据源的情况下,怎么整合?

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
just do it2021-03-30 22:00:36

log.txt

这边连接数据库一直不成功,这个报错信息也看不懂

项目我就不发了就是老师给的样例

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
哦豁2021-03-30 19:39:24

在UserRealm3中写

while(rs.next()){
    SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(authenticationToken.getPrincipal(),rs.getString("pwd"),ByteSource.Util.bytes(rs.getString("salt")),"userRealm3");

    return simpleAuthenticationInfo;
}

运行TestC就会显示登入失败,并且报异常

把ByteSource.Util.bytes(rs.getString("salt")改为ByteSource.Util.bytes("lin")再运行TestC就登入成功


写ByteSource.Util.bytes(rs.getString("salt")出现的异常

log4j:WARN No appenders could be found for logger (org.apache.shiro.io.ResourceUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.sql.SQLException: Column 'salt' not found.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
	at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1162)
	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5728)
	at com.bjsxt.shiro03.UserRealm3.doGetAuthenticationInfo(UserRealm3.java:40)
	at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:568)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
	at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
	at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
	at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
	at com.bjsxt.shiro03.TestC.main(TestC.java:25)
登入失败

Process finished with exit code 0


image.png


数据库

image.png



shiro01.rar


相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
梦见2021-03-25 11:16:54

image.png

老师,查找出菜单里面的内容有多条,再怎么根据ResultSet遍历出来,放入下面的语句啊,不太会了

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
梦见2021-03-24 21:43:27

image.png

老师,这种值怎么直接添加进数据库啊,我怎么添加不进去,varchar不行啊

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
啥也不懂2021-03-16 22:51:55

麻烦老师帮我看看,我这里一直报创建bean对象错误,这是怎么回事?

image.png


image.pngimage.png

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)
微信用户2021-03-15 20:39:49

老师,没有shiro注解的教程吗

相关课程:JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧)

©2014-2023 百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备13018289号-12    营业执照    经营许可证:京B2-20212637