黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 實現簡單的Shiro登錄認證問題

實現簡單的Shiro登錄認證問題

更新時間:2021-11-16 10:20:49 來源:動力節點 瀏覽1080次

實現Shiro簡單登錄認證后出現問題。您不使用 ajax 請求登錄。當你點擊login訪問一個controller方法,securityuils.getsubject.login(token)訪問提交時,找不到地址。是否需要加密碼呢?

//This is the controller
@RequestMapping("/checkLogin.do")
    private void login(HttpServletRequest request) throws UserException{
        String account = request.getParameter("account");
        String password = request.getParameter("password");
        UsernamePasswordToken token = new UsernamePasswordToken(account,password);
        Subject currentUser = SecurityUtils.getSubject();
        try{
            if(!currentUser.isAuthenticated()){
                currentUser.login(token);
            }
        }catch(UnknownAccountException uae){
            //User name / password error
            Throw new useraccountexception ("wrong user name or password! "";
        }catch(IncorrectCredentialsException ice){
            //User name / password error
            Throw new usercredentialsexception ("wrong user name or password! "";
        }catch(ExcessiveAttemptsException eae){
            //Abnormal login times, account locked
            Throw new userattemptsexception ("login more than 5 times, account locked! "";
        }catch(AuthenticationException ae){
            //Other exceptions
            Throw new userexception ("login failed! "";
        }
    }
    
}
//This is realm
@Override
    protected AuthenticationInfo doGetAuthenticationInfo(
            AuthenticationToken token) throws AuthenticationException {
        //Token based on user name and password
        //This token is from currentuser.login (token) of registcontroller
        UsernamePasswordToken uptoken = (UsernamePasswordToken)token;
        //Call service to query user through user account
        UserAuthDTO userAuth = userService.getUserAuthByAccount((String)uptoken.getPrincipal());
        if(userAuth == null){
            return null;
        }
        String identity = userAuth.getAccount();
        String password = userAuth.getPassword();
        String salt = userAuth.getSalt();
        if(userAuth.getIsLocked() != null && userAuth.getIsLocked() == 1){
            Throw new authenticationexception ("the account is locked! "";
        }
        AuthenticationInfo authInfo = new SimpleAuthenticationInfo(userAuth
                , password, ByteSource.Util.bytes(identity+salt), this.getName()); 
        System. Out. Println ("realm login authentication is over! "";
        return authInfo;
    }
}
//This is Shiro configuration
 <! -- configuration filter will be referenced by the filter configured in web.xml -- >
        <! -- Shiro's web filter -- >
        <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
            <! -- inject security component -- >
            <property name="securityManager" ref="securityManager" />
            <! -- set login address -- >
            <property name="loginUrl" value="/user/login.do"/>
            <property name="successUrl" value="/index.jsp"/>
<!--            <property name="unauthorizedUrl" value="/unauthorized.jsp"/> -->
            <! -- because every bean of type javax.servlet.filter that has been defined can pass the bean name in the definition of the chain
            So the filters property is not required. But you can replace the filters with the filters property as needed
            Instance or alias filter -- >
            <!-- <property name="filters">
                <map>
                    <entry key="anAlias" value-ref="someFilter"/>
                </map>
            </property>-->
            <! -- processor execution chain -- >
            <property name="filterChainDefinitions">
                <value>
                    <! -- define permission interception -- >
                    <! -- set anonymous access to static resources -- >
                    <! -- set anonymous access to login registration page -- >
                    /regist.jsp = anon
                    /login.jsp = anon
                </value>
            </property>
        </bean>
        <!-- securityManager -->
        <! -- Security Manager -- >
        <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
            <property name="realm" ref="userAuthenticatorRealm"/>
        </bean>        
        <! -- ensure bean execution of lifecycle function within Shiro -- >
<!--        <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>-->
        
        <! -- configure the realm for specific authentication and authorization -- >
        <! -- inherit the user-defined realm of authorizing realm used to complete user login authentication -- >
        <bean id="userAuthenticatorRealm" class="com.maikesiwei.mksw.user.shiro.realm.UserAuthenticatorRealm">
            <! -- inject credentialsmatcher for certificate matching -- >
            <property name="credentialsMatcher" ref="credentialsMatcher"/>
        </bean>
        <! -- credential matcher -- >
        <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
            <! -- encryption hash algorithm -- >
            <property name="hashAlgorithmName" value="SHA-256"/>
            <! -- iterations -- >
            <property name="hashIterations" value="5"/>
        </bean>

最后點擊登錄。

HTTP Status 404 – /web-templet/user/user/checkLogin

type 狀態報告

信息 /web-templet/user/user/checkLogin

描述 請求的資源不可用。

Apache Tomcat/8.0.44

如果在登錄頁面直接點擊登錄,會報賬號密碼錯誤。如果直接填寫賬號,點擊登錄域,會發現用戶返回到認證信息,頁面如下:

如果大家想了解更多相關知識,可以關注一下動力節點的Shiro視頻教程,里面的內容詳細,由淺到深,適合沒有基礎的小伙伴學習,希望對大家能夠有所幫助。

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 久久亚洲最大成人网4438 | 国产清纯91天堂在线观看 | 国产欧美日韩不卡一区二区三区 | 欧美三级又粗又硬 | 成人免费观看国产高清 | 久久在现| 精品午夜寂寞影院在线观看 | 中文字幕aⅴ在线视频 | 久久久高清日本道免费观看 | 91亚洲精品第一综合不卡播放 | 日本高清一区 | 成年网站免费入口在线观看 | 九九伦理影院手机观看 | 欧美在线观看你懂的 | 激情一区二区三区成人 | 欧美整片sss | 欧美一区二区三区精品影视 | 成年人在线视频网站 | 亚洲欧美日韩高清中文在线 | 又色又爽又黄的视频女女高清 | 一级寡妇乱色毛片全场免费 | 亚洲一区二区三区高清 不卡 | 国内外精品免费视频 | 亚洲福利 | 亚洲女视频 | 最近中文字幕在线看免费视频 | 亚洲最大的视频网站 | 亚洲欧美视频 | 无遮挡h肉动漫在线观看日本 | 黄色a级片免费 | 日韩久久中文字幕 | 日韩中文字幕视频在线 | 欧美激情一区二区三区视频 | 欧美精品免费在线观看 | 日韩不卡毛片 | 美国videos 18高清hd | 国产成人精品免费大全 | 激情影院a | 欧美ay亚洲ay日韩ay | 大象焦伊人久久综合网色视 | 狠狠操天天 |