当我尝试访问我的应用程序起始页面时出现意外的登录屏幕
Posted
技术标签:
【中文标题】当我尝试访问我的应用程序起始页面时出现意外的登录屏幕【英文标题】:Unexpected login screen appears when I try to visit my application start page 【发布时间】:2019-12-10 09:06:11 【问题描述】:我将我的第一个应用程序部署到了 Google App Engine 标准。经过几次不成功的尝试,它终于开始了。但是当我尝试访问它的起始页面时,我重定向到了登录表单(我不熟悉,所以我想它是由 GCP 提供的)。 我不明白我的申请有什么问题,有没有人有类似的经历?有人对可能发生的事情有什么建议吗?
我将已经工作的 Spring Boot 应用程序迁移到 GCP 云 应用类型:Spring Boot 2 认证类型:基于应用,由Spring提供
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>net.chyslin</groupId>
<artifactId>what-and-where</artifactId>
<version>2.0.2-SNAPSHOT</version>
<name>what-and-where</name>
<description>Information collect and management system</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
<spring-cloud-gcp.version>1.1.2.RELEASE</spring-cloud-gcp.version>
<app-engine-maven-plugin.version>1.3.2</app-engine-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Exclude any jul-to-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.25-incubating</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>$spring-cloud.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M3</version>
</dependency>
</dependencies>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<skipTests>false</skipTests>
<includes>
<include>**/*.class</include>
</includes>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>$app-engine-maven-plugin.version</version>
</plugin>
</plugins>
<finalName>what-where</finalName>
</build>
</project>
application.properties:
spring.cloud.app-id=whatnwhere-south-post-1336
spring.datasource.initialization-mode=always
spring.datasource.hikari.maximum-pool-size=2
connection.host=google
connection.db.name=<database name>
connection.instance-connection-name=<connection name>
spring.datasource.url=jdbc:mysql://$connection.host/$connection.db.name?cloudSqlInstance=$connection.instance-connection-name&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Europe/Kiev
spring.datasource.username=<db user name>
spring.datasource.password=<db passord>
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
view.grid.rows.per.page=10
view.grid.paging.neighbours=3
password.encoder.strength=11
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=<sender-account e-mail>
spring.mail.password=**********
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mvc.locale=uk_UA
spring.mvc.locale-resolver=fixed
lookup.batch.size=10
logging.file=$user.home/what-where/server.log
spring.liquibase.change-log=classpath:/db/liquibase/changelog.xml
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
logging.level.org.hibernate.SQL=WARNING
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=WARNING
security.token.validity.seconds=1209600
security.default.authentication.success.url=/user/profile/welcome
security.supervisor.authentication.success.url=/user/admin/list
security.administrator.authentication.success.url=/user/admin/list
security.operator.authentication.success.url=/vacancy/list
security.viewer.authentication.success.url=/user/profile/welcome
appengine-web.xml:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>what-where</application>
<version>2.0.2</version>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties"/>
</system-properties>
<sessions-enabled>true</sessions-enabled>
<staging>
<enable-jar-classes>true</enable-jar-classes>
</staging>
</appengine-web-app>
app.yaml:
handlers:
- url: /.*
script: this field is required, but ignored
automatic_scaling:
min_num_instances: 1
max_num_instances: 5
resources:
cpu: 2
memory_gb: 2.3
disk_size_gb: 10
volumes:
- name: ramdisk1
volume_type: tmpfs
size_gb: 0.5
应用安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception
System.out.println("*********************************************************");
System.out.println("*********************** Configure *********************");
http
.authorizeRequests()
.antMatchers("/user/profile/**").hasRole(UserRole.VIEWER.name())
.antMatchers("/user/admin/**").hasRole(UserRole.SUPERVISOR.name())
.antMatchers("/vacancy/manage/**").hasAnyRole(UserRole.OPERATOR.name(), UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.antMatchers("/dwelling/manage/**").hasAnyRole(UserRole.OPERATOR.name(), UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.antMatchers("/api/**/save").hasAnyRole(UserRole.OPERATOR.name(), UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.antMatchers("/api/**/delete").hasAnyRole(UserRole.OPERATOR.name(), UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.antMatchers("/master/**/list").hasAnyRole(UserRole.OPERATOR.name(), UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.antMatchers("/master/**/add").hasAnyRole(UserRole.OPERATOR.name(), UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.antMatchers("/history/**").hasAnyRole(UserRole.ADMINISTRATOR.name(), UserRole.SUPERVISOR.name())
.and()
.formLogin()
.loginPage("/user/authentication/login")
.loginProcessingUrl("/j_spring_security_check")
.usernameParameter("login")
.passwordParameter("password")
.failureUrl("/user/authentication/login?error")
.defaultSuccessUrl("/user/profile/welcome", false)
.successHandler(successHandler())
.and()
.logout().logoutUrl("/j_spring_security_logout")
.logoutSuccessUrl("/")
.invalidateHttpSession(true)
.and()
.httpBasic()
.and()
.csrf()
.and()
.rememberMe()
.tokenRepository(persistentTokenRepository())
.tokenValiditySeconds(tokenValiditySeconds)
.and()
.authenticationProvider(authProvider())
.userDetailsService(userDetailsService())
;
我希望我的应用程序的登录页面将被加载,但我被重定向到提到的登录页面(并且无法假设我必须向它提供哪些凭据):https://i.imgur.com/IBKQyah.png
【问题讨论】:
您的着陆页的网址是什么?可能在安全路径下 【参考方案1】:似乎是我在尝试避免另一个问题时自己造成了问题:spring factory 找不到任何存储库接口:我将所有配置内容从应用程序类移动到单独的配置,并且似乎应用程序上下文未在应用程序中初始化引擎。
但是存储库扫描的问题仍然没有解决。
【讨论】:
如果您的问题已解决但您还有其他问题,您应该指定这个新问题,或者编辑您的问题或创建一个新帖子。【参考方案2】:我找到了所有问题的根源:它是 appengine-web.xml 中的以下块:
<staging>
<enable-jar-classes>true</enable-jar-classes>
</staging>
导致 Spring Jpa 无法找到存储库接口。
【讨论】:
嘿,Mykola!如果你的答案对你有用,你能接受与你帖子的主要问题相关的答案吗?这样,它将获得更好的可见性,并将帮助其他有类似问题的用户 =)!以上是关于当我尝试访问我的应用程序起始页面时出现意外的登录屏幕的主要内容,如果未能解决你的问题,请参考以下文章
Glassfish RAR5035:从池中销毁资源时出现意外异常
尝试使用 express-jwt 阻止访问除登录页面以外的 Angular 应用程序时出现问题
在Xamarin中导航时出现白屏问题形成Prism MasterDetails页面