we will need an apache tomcat server and mysql db server, I'll use tomcat 7 and wamp for db
but before that there is a few things to add to make our test meaningful, we will add an mvc-rest controller that will be protected by our security implementation:
https://gist.github.com/anonymous/8d009f61cb6dea140a27
then modify the mvc-dispatcher-servlet.xml to see this new controller by adding:
<context:component-scan base-package="com.blabadi">which basically tells spring to scan for controller annotation under the base package
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
important points here:
- spring mvc requires to have a context for its servlets that is different than the context of the application, that's why we have a different configuration files : spring-beans and mvc-dispatcher-servlet.xml
- we don't scan controllers in the root context because that will create duplicated instances for them
- the dispatcher servlet is required for both : spring security web and rest services
run the command maven package to our application and deploy the war
if you get this after deployment in tomcat console then you're good to continue :
Now use your favorite rest client to try to access the protected service, here I used postman chrome app :
so our configurations are working, we were able to prevent unauthenticated access to this service, lets try to get authenticated by getting a token:
now we have the token, lets use it:
Awesome! we have fully tested a simple password grant type OAuth2 scenario from end to end!
happy coding..
In the future we will implement another grants and add more scenarios on this project
Excellent .. YOu saved my time.
ReplyDeletehi, i got HTTP Status 404 when try to access /hello
ReplyDeletewhat's wrong?