<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Vaadin Spring Security BasicAuth 示例 > 原文: [https://howtodoinjava.com/vaadin/vaadin-spring-security-basicauth-example/](https://howtodoinjava.com/vaadin/vaadin-spring-security-basicauth-example/) 在本教程中,我們將學習在 [spring security](//howtodoinjava.com/spring-security-tutorial/) 模塊提供的[基本認證](//howtodoinjava.com/spring/spring-security/http-basic-authentication-example-using-spring-3/)安全性之后保護 vaadin 應用的安全。 我正在使用 Spring 安全配置更新 [vaadin helloworld 應用](//howtodoinjava.com/vaadin/hello-world-web-application-maven/)源代碼,因此,如果您已經有任何 vaadin 應用,則可以直接查看 Spring 安全性部分。 ```java Table of Contents Development environment Spring Security BasicAuth Configuration Vaadin UI Configuration Maven Dependencies Run the application ``` ## 開發環境 本示例使用以下工具和框架來構建演示 vaadin 應用,該應用在 spring 的基本認證安全性的保護下得到保護。 1. [JDK 1.8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) 2. [Vaadin 7.7.0](https://vaadin.com/download/release/7.7/7.7.0/release-notes.html) 3. [Spring Security 4.1.3.RELEASE](https://mvnrepository.com/artifact/org.springframework.security) 4. [Eclipse Luna](https://eclipse.org/luna/) 5. [Tomcat 7](https://tomcat.apache.org/download-70.cgi) ## Spring Security BasicAuth 配置 要配置 spring basicauth 安全性,您需要在類路徑中添加`applicationContext.xml`文件(如果尚不存在),然后需要配置安全性設置,例如,安全的 URL 模式,哪些角色可以訪問哪些 URL 等。 #### `applicationContext.xml` ```java <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.1.xsd"> <http auto-config="true"> <intercept-url pattern="/vaadinServlet/**" access="hasRole('ROLE_EDITOR')" /> <intercept-url pattern="/vaadinServlet/*.*" access="hasRole('ROLE_EDITOR')" /> <intercept-url pattern="/**" access="hasRole('ROLE_EDITOR')" /> <http-basic /> <csrf disabled="true"/> </http> <authentication-manager> <authentication-provider> <user-service> <user name="howtodoinjava" password="password" authorities="ROLE_EDITOR" /> </user-service> </authentication-provider> </authentication-manager> </beans:beans> ``` 現在,您需要在`web.xml`文件中配置`springSecurityFilterChain`,以便將安全性添加到應用中。 另外,如果您添加了新的`applicationContext.xml`文件,則還需要注冊`ContextLoaderListener`。 #### `web.xml` ```java <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> //Other configuration will be added here </web-app> ``` Spring 基本認證配置已完成。 現在,您可以根據應用的要求修改各個部分。 例如。 您可能要從數據庫中獲取用戶名/密碼詳細信息,然后可以在`applicationContext.xml`文件的`authentication-provider`中使用[`jdbc-user-service`](//howtodoinjava.com/spring/spring-security/jdbc-user-service-based-spring-security-example/) 。 ## Vaadin UI 配置 正如我已經提到的,我正在修改 vaadin helloworld 應用,它具有非常基本的功能。 只需在`web.xml`文件和帶有標簽的主頁屏幕中進行`VaadinServlet`配置,以在認證成功的情況下顯示成功消息。 #### `web.xml` ```java <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> //Spring security configuration as mentioned in above section <context-param> <description>Vaadin production mode</description> <param-name>productionMode</param-name> <param-value>false</param-value> </context-param> <servlet> <servlet-name>vaadinServlet</servlet-name> <servlet-class>com.vaadin.server.VaadinServlet</servlet-class> <init-param> <param-name>UI</param-name> <param-value>com.howtodoinjava.vaadin.demo.AppUI</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>vaadinServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> ``` #### `AppUI.java` ```java package com.howtodoinjava.vaadin.demo; import com.vaadin.annotations.Theme; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Label; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; @Theme("mytheme") public class AppUI extends UI { private static final long serialVersionUID = 1387172685749279538L; @Override protected void init(VaadinRequest vaadinRequest) { final VerticalLayout layout = new VerticalLayout(); Label label = new Label("Welcome to BasicAuth Secured Vaadin Application"); layout.addComponent(label); layout.setMargin(true); layout.setSpacing(true); setContent(layout); } } ``` ## Maven 依賴 應用非常重要的一部分是收集和配置運行時依賴項。 當我們使用 [maven](//howtodoinjava.com/maven/) 時,我已將以下依賴項添加到現有的`pom.xml`文件中。 #### `pom.xml` ```java <!-- Spring Security --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Commons Logging is required with Spring4.x --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> ``` ## 運行應用 現在,該應用已配置完畢,可以進行測試了。 在瀏覽器中點擊應用 URL。 1. #### 點擊網址`http://localhost:8080/VaadinExample/` 您將在瀏覽器彈出窗口中輸入您的用戶名和密碼。 ![Vaadin Spring Security BasicAuth Window](https://img.kancloud.cn/4b/89/4b8976d8b0984ac5f70a092ef9b2b751_357x239.png) Vaadin Spring Security BasicAuth 窗口 2. #### 填寫不正確的憑據并提交 彈出字段將被清除,并再次詢問用戶名/密碼。 3. #### 填寫正確的憑據并提交 應用的主頁將顯示成功消息。 ![Vaadin Spring Security BasicAuth Successful](https://img.kancloud.cn/a7/33/a73318c0df4a000fcb02c0cb491fa512_524x172.png) Vaadin Spring Security BasicAuth 成功 將我的問題放在評論部分。 [源碼下載](//howtodoinjava.com/wp-content/downloads/VaadinSpringSecurityBasicAuthExample.zip) 資源: [Spring 安全參考](https://docs.spring.io/spring-security/site/docs/4.1.3.RELEASE/reference/htmlsingle/) [Vaadin HelloWorld 應用](//howtodoinjava.com/vaadin/hello-world-web-application-maven/) [RFC-2617 BasicAuth](https://tools.ietf.org/html/rfc2617)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看