2014-12-16 2 views
0

У меня есть простой весенний проект, который работает локально. URL-адреса перехватываются весной, но когда я загружаю то же самое на сервер приложений Google, система безопасности не работает, и вместо этого выполняется метод assciated.Весенняя безопасность не работает на сервере (google appengine)

public class SpringSecutiryInitializer extends AbstractSecurityWebApplicationInitializer { 
    // Do nothing. This initializes the security chain. 
} 


public class SpringMvcInitializer 
     extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @Override 
    protected Class<?>[] getRootConfigClasses() { 
     return new Class[] { AppConfig.class, SecurityConfig.class }; 
    } 

    @Override 
    protected Class<?>[] getServletConfigClasses() { 
     return null; 
    } 

    @Override 
    protected String[] getServletMappings() { 
     return new String[] { "/" }; 
    } 
} 


@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    Environment env; 
    @Autowired 
    DataSource dataSource; 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) 
     throws Exception { 

    String databaseName = env.getProperty("jdbc.databaseName"); 
    auth.jdbcAuthentication() 
     .dataSource(dataSource) 
     .usersByUsernameQuery(
      "select username,password,enabled from user where username=?") 
     .authoritiesByUsernameQuery(
      "SELECT user.username, role.role FROM (" + databaseName 
       + ".user_role as role JOIN " + databaseName 
       + ".user as user ON" 
       + " role.auth_id = user.auth_id) where user.username=?"); 
    } 
} 

@Configuration 
@EnableWebMvc 
@EnableTransactionManagement 
@ComponentScan({ "com.djw" }) 
public class AppConfig { 
    // configure different beans 
} 

AppEngine-web.xml

<?xml version="1.0" encoding="utf-8"?> 
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> 
    <!-- Fill in the app name and version --> 
    <application>project-name-removed</application> 
    <version>1</version> 
    <threadsafe>true</threadsafe> 

    <!-- Configure serving/caching of GWT files --> 
    <static-files> 
    <include path="**" /> 

    <!-- The following line requires App Engine 1.3.2 SDK --> 
    <include path="**.nocache.*" expiration="0s" /> 

    <include path="**.cache.*" expiration="365d" /> 
    <exclude path="**.gwt.rpc" /> 
    </static-files> 

    <use-google-connector-j>true</use-google-connector-j> 
    <sessions-enabled>true</sessions-enabled> 
    <system-properties> 
    <property name="java.util.logging.config.file" value="WEB-INF/appengine_logging.properties"/> 
    <property name="spring.profiles.active" value="prod"/> 
    </system-properties> 
</appengine-web-app> 

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <display-name>Archetype Created Web Application</display-name> 

    <!-- Declare a Spring MVC DispatcherServlet as usual --> 
    <servlet> 
     <servlet-name>web</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <!-- Configure DispatcherServlet to use AnnotationConfigWebApplicationContext 
      instead of the default XmlWebApplicationContext --> 
     <init-param> 
      <param-name>contextClass</param-name> 
      <param-value> 
       org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      </param-value> 
     </init-param> 
     <!-- Again, config locations must consist of one or more comma- or space-delimited 
      and fully-qualified @Configuration classes --> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>com.djw.config.AppConfig</param-value> 
     </init-param> 
    </servlet> 

    <!-- map all requests for/to the dispatcher servlet --> 
    <servlet-mapping> 
    <servlet-name>web</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

С этим, любой URL я пытаюсь открыть перехватывается весной для имени пользователя и пароля. Но на моем сервере он просто пропускает запросы. почему это произойдет?

ответ

2

Я узнал от here, что Google App Engine поддерживает до сервлета версии 2.5, а AbstractAnnotationConfigDispatcherServletInitializer требует сервлета версии 3.0. Итак, вы должны использовать xml для настройки ваших настроек.

Смежные вопросы