Question

Soory for disgusting you. Actually i am poor in english. I am developing a spring application by using google app engige. 1. If the server is in running mode, for the first if i would try to log into the application. Firstly it should navigate to the login page. 2. If any user wants to access aby page in the application by giving the page name like for example(in my application if i have ABC.jsp page, if the user wnat to access the file by giving 127.0.0.0:8888/ABC.jsp) it should navigate to the some default page which contains some message, and click here to navigate to the home page. Now can you please tell how to do it in my application. can you please tell me the step by step process to achieve this by using Spring MVC ,Objectify ORM and Google app engine.

Was it helpful?

Solution

Still don't quite understand what your problem is.

Add this to your web.xml:

  <welcome-file-list>
    <welcome-file>/login</welcome-file>
  </welcome-file-list>
</web-app>

This ensures that if a user only types http://server:port she is redirected to http://server:port/login.

Now if you want that the user is also redirected to login if she types http://server:port/foobar.html, what you call "random page", which does not exist then you need an HTTP status code mapping.

  <error-page>
    <error-code>404</error-code>
    <location>/login</location>
  </error-page>

If you want that the user must always first authenticate (i.e. go through /login) first before any existing page is displayed you could use Spring Security for that. Example for simple basic-auth:

<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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">

  <!-- HTTP basic authentication in Spring Security -->
  <http>
    <intercept-url pattern="/*" access="ROLE_USER" />
    <http-basic />
  </http>

  <authentication-manager>
    <authentication-provider>
      <user-service>
        <user name="user" password="password" authorities="ROLE_USER" />
      </user-service>
    </authentication-provider>
  </authentication-manager>
</beans:beans>

OTHER TIPS

You can use spring security to do this. Have a look at this link. The http tag should allow this. It will direct a user the login page for users that aren't authenticated. A sample context would be the following.

<beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<beans:property name="loginFormUrl" value="/jsp/login.jsp" />
</beans:bean>


<http auto-config="false" use-expressions="true" entry-point-ref="loginUrlAuthenticationEntryPoint">
    <intercept-url pattern="/protected" access="hasRole('ROLE_protected')" />
    <intercept-url pattern="/jsp/login.jsp*" filters="none"/>
    <logout logout-success-url="/jsp/login.jsp" invalidate-session="true" />
    <session-management invalid-session-url="/jsp/login.jsp?timeout=true" />
</http>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top