第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果在 URL 中提供了某些參數(shù),如何只顯示一個頁面?

如果在 URL 中提供了某些參數(shù),如何只顯示一個頁面?

慕哥6287543 2022-12-21 14:36:49
我想在 Spring 中創(chuàng)建一個頁面,其中包含 urlhttp://myapp.com/sign-in?email=myemail@provider.com&pw=passwordpassword是用戶每次要登錄時通過電子郵件收到的一次性密碼。每當用戶訪問此頁面時,我希望發(fā)生兩件事:檢查提供的憑據(jù)是否正確。如果是,則顯示頁面的 HTML 內(nèi)容。我已經(jīng)完成了第一部分:  @Autowired    private var userRepository: UserRepository? = null    @GetMapping    fun signIn(@RequestParam email:String, @RequestParam(name="pw") password:String): RedirectView {        // Is the password correct?        // TODO: Read password hash of the user        val existingUser: Optional<UserInfo>? = userRepository?.findById(email)        if (existingUser == null) {            return redirectToErrorPage("Please register with your e-mail address first")        }        if (!existingUser.isPresent) {            return redirectToErrorPage("Please register with your e-mail address first")        }        val hashInDb = existingUser.get().passwordHash        val hashInParam = PasswordHashCalculator.calculateHash(password)        if (!hashInDb.equals(hashInParam)) {            return redirectToErrorPage("Invalid user name and/or password")        }        // TODO: Display the main page        return null    }我需要如何更改代碼才能顯示主頁(HTML 文件 in src/main/resources/static),但前提是通過身份驗證檢查?更新 1:按照此處return ClassPathResource("main.html")的建議使用沒有幫助。
查看完整描述

3 回答

?
POPMUISE

TA貢獻1765條經(jīng)驗 獲得超5個贊

return ClassPathResource("static/main.html") should answer your question, don't forget to specify `static` folder at the beginning as `ClassPathResource` points to the `resources` folder



查看完整回答
反對 回復 2022-12-21
?
泛舟湖上清波郎朗

TA貢獻1818條經(jīng)驗 獲得超3個贊

你真的不應該以這種方式來保護你的安全。通過 http 以明文形式發(fā)送密碼不是好的做法。

這里有一些使用 spring security 進行基本身份驗證的示例。

https://www.baeldung.com/spring-security-basic-authentication

https://www.baeldung.com/securing-a-restful-web-service-with-spring-security

如果您按照本教程進行操作,那么您可以做的是為初學者分配一個內(nèi)存用戶。然后您可以將您的身份驗證詳細信息進行 Base64Encode 以提供給用戶。然后,對于每個用戶,您可以發(fā)送身份驗證詳細信息,并且當用戶名和密碼通過網(wǎng)絡時,沒有人可以窺探用戶名和密碼,并且您的請求在到達您的控制器之前得到處理。這樣,您就可以將業(yè)務邏輯與身份驗證分離。

這至少是一個開始。希望這可以幫助。


查看完整回答
反對 回復 2022-12-21
?
慕勒3428872

TA貢獻1848條經(jīng)驗 獲得超6個贊

你不應該像這樣處理授權(quán)。您可以做的是啟用 spring-security 并使用 spring security 注釋來處理這種情況。使用以下依賴項并設(shè)置基本的 spring 安全設(shè)置。


@PreAuthorize()然后可以使用諸如此類的注釋在執(zhí)行方法之前驗證用戶權(quán)限。如果您堅持,您甚至可以將此注釋添加到控制器方法以在為每個請求提供服務之前進行驗證。


您可以設(shè)置和LDAP 服務器或 Oauth 甚至使用數(shù)據(jù)庫進行身份驗證(如果您正在處理演示或其他內(nèi)容)。


        <dependency>

            <groupId>org.springframework.security</groupId>

            <artifactId>spring-security-web</artifactId>

            <version>${spring-security.version}</version>

        </dependency>

        <dependency>

            <groupId>org.springframework.security</groupId>

            <artifactId>spring-security-config</artifactId>

            <version>${spring-security.version}</version>

        </dependency>

使用如下配置類來配置安全性:


@Configuration

@EnableWebSecurity

public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired

    DataSource dataSource;


    @Autowired

    public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {


      auth.jdbcAuthentication().dataSource(dataSource)

        .usersByUsernameQuery(

            "select username,password, enabled from users where username=?")

        .authoritiesByUsernameQuery(

            "select username, role from user_roles where username=?");

    }   


    @Override

    protected void configure(HttpSecurity http) throws Exception {


      http.authorizeRequests()

        .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')") //To check admin role permission

        .and()

          .formLogin().loginPage("/login").failureUrl("/login?error") //provide failure url

          .usernameParameter("username").passwordParameter("password")

        .and()

          .logout().logoutSuccessUrl("/login?logout") 

        .and()

          .exceptionHandling().accessDeniedPage("/403")

        .and()

        .csrf();

    }

}

github 中的這個示例項目提供了一個基本設(shè)置,您可以在其中使用 spring security:


https://github.com/mohchi/spring-security-request-mapping


參考使用: https ://www.mkyong.com/spring-security/spring-security-form-login-using-database/


查看完整回答
反對 回復 2022-12-21
  • 3 回答
  • 0 關(guān)注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號