java - Spring security check the user is logged or not when click a button -
i'm creating simple web application online flight reservation system using spring mvc spring security. i've created following table show flight details.
<table class="table table-bordered table-hover table-striped "> <thead> <tr> <th>flight no</th> <th>flight destination</th> <th>flight origin</th> <th>flight date</th> <th>flight time</th> <th>book now</th> </tr> </thead> <tbody> <form:form commandname="reserv" cssclass="form-horizontal"> <c:foreach items="${flightinfos}" var="flightinfo"> <tr> <td>${flightinfo.flightno}</td> <td>${flightinfo.destination}</td> <td>${flightinfo.origin}</td> <td>${flightinfo.flightdate}</td> <td>${flightinfo.flighttime}</td> <td><input type="submit" value="book now" class="btn btn-primary"></td> </tr> </c:foreach> </form:form> </tbody> </table>
in table, want check user logged or not when user click on "book now" button. means can see page need log system book flight. here security.xml file.
<http use-expressions="true"> <intercept-url pattern="/users**" access="hasrole('role_admin')" /> <intercept-url pattern="/users/**" access="hasrole('role_admin')" /> <intercept-url pattern="/account**" access="hasrole('role_user')" /> <intercept-url pattern="/reservation**" access="hasrole('role_user')" /> <form-login login-page="/login.html"/> <csrf disabled="true"/> <logout logout-url="/logout" /> </http>
how can check whether user logged or not, when clicks on "book now" button ? there simple way ?
"how can check whether user logged or not, when clicks on "book now" button ? there simple way ?"
when submit button pressed; form posted url have given (as post) example:
<form action="/myurl" method="post"> first name: <input type="text" name="fname"><br> last name: <input type="text" name="lname"><br> <input type="submit" value="submit"> </form>
just change url restricted in security xml. like:
<intercept-url pattern="/postformurl" access="hasrole('role_user')" />
then when controller mapping of formurl ; there if passed spring security.
Comments
Post a Comment