GAE + Struts2 + Spring3 + Hibernate4 + LocalHostのMySQLはHTTPセッションを作成し、データストアは常に空です

StackOverflow https://stackoverflow.com//questions/23015761

質問

データストアと休止状態に問題がある場合は、LocalhostでGAE + Struts2 + Spring3 + Hibernate4 + MySQLを統合できましたが、すべてが機能しているようですが、HTTPでセッションを作成しようとすると、セッションはそうではありません作成またはSession.GetLastAccessedDime()は常に1970-01-01(デフォルト値)です。http:localhost:8080 / _ah / adminのデータストアリンクに移動すると、セッションが作成されません。

セキュリティとこのメソッドにESAPIを使用します。

public boolean isSessionTimeout() {
    HttpSession session = ESAPI.httpUtilities().getCurrentRequest().getSession(false);
    if (session == null)
        return true;
    Date deadline = new Date(session.getLastAccessedTime() + IDLE_TIMEOUT_LENGTH);
    Date now = new Date();
    return now.after(deadline);
}
.

常にtrueを返します。

AppEngine-web.xmlでセッションを有効にしていて、この種の設定がTomcatで機能する限り、このような問題がある限り、AppEngineバージョン1.9.2では何らかの問題があります。

私はこのようなMavenでプロジェクトを構築する:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.5.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archiveClasses>true</archiveClasses>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.app.version}</version>
            <configuration>
                <jvmFlags>
                    <jvmFlag>-Dappengine.generated.dir=${project.basedir}/appengine</jvmFlag>
                    <jvmFlag>-Ddatastore.backing_store=${project.basedir}/local_db.bin</jvmFlag>
                </jvmFlags>
            </configuration>
        </plugin>

    </plugins>
</build>
.

私は私のweb.xml、含まれているeSapifilterで最初のフィルタを持っています:

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;

    try {
        ESAPI.httpUtilities().setCurrentHTTP(request, response);
    } catch (Exception e) {
        logger.error(Logger.SECURITY_FAILURE, "Error in ESAPI security filter: " + e.getMessage(), e);
    }

    try {
        // figure out who the current user is
        try {
            ESAPI.authenticator().login();
        } catch (AuthenticationException e) {
            request.setAttribute("message", "Unauthorized");
        }
        // log this request, obfuscating any parameter named password
        ESAPI.httpUtilities().logHTTPRequest(request, logger, Arrays.asList(obfuscate));
        // check access to this URL
        if (!ESAPI.accessController().isAuthorizedForURL(request.getRequestURI())) {
            request.setAttribute("message", "Unauthorized");
        }

        // check for CSRF attacks
        //ESAPI.httpUtilities().verifyCSRFToken(request);
        // forward this request on to the web application
        chain.doFilter(request, response);
        // set up response with content type
        ESAPI.httpUtilities().setContentType(response);
        // set no-cache headers on every response
        // only do this if the entire site should not be cached
        // otherwise you should do this strategically in your controller or actions
        ESAPI.httpUtilities().setNoCacheHeaders(response);
    } catch (Exception e) {
        logger.error(Logger.SECURITY_FAILURE, "Error in ESAPI security filter: " + e.getMessage(), e);
        request.setAttribute("message", e.getMessage());

    } finally {
        // VERY IMPORTANT
        // clear out the ThreadLocal variables in the authenticator
        // some containers could possibly reuse this thread without clearing the User
        try {
            ESAPI.clearCurrent();
        } catch (Exception e) {
            logger.error(Logger.SECURITY_FAILURE, "Error in ESAPI security filter: " + e.getMessage(), e);
        }
    }
}
.

役に立ちましたか?

解決

最後に私は問題を見つけましたかどういうわけか既定のSession.getLastAccessedTime()= 0で作成され、この値をこのような現在時刻に設定します。

    public boolean isSessionTimeout() {
    HttpSession session = ESAPI.httpUtilities().getCurrentRequest().getSession(false);
    if (session == null)
        return true;
    long lastAccessedTime=System.currentTimeMillis();
    if(session.getLastAccessedTime()!=0){
        lastAccessedTime=session.getLastAccessedTime();
    } 
    Date deadline = new Date(lastAccessedTime + IDLE_TIMEOUT_LENGTH);
    Date now = new Date();      
    return now.after(deadline);
}
.

最後にすべてが動作し、私はローカルにセッションを作成することができます、私はプロダクションで試してみませんでした。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top