Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit 2009f59

Browse files
committed
Updated Some Access Controls section of the tutorial.
1 parent 9844285 commit 2009f59

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

docs/source/tutorial.rst

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ In the next section, we will talk about having access controls the "right" way b
259259
The purpose of this section is to demonstrate the manual labor required in "rolling your own" permissions assertion layer.
260260
Feel free to skip right over to the :ref:`spring-security-meet-stormpath` section.
261261

262-
The code for this section can be found in `tutorials/spring-boot/01-some-access-controls <https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring-boot/01-some-access-controls>`_.
262+
#if( $springboot )
263+
The code for this section can be found in `tutorials/spring-boot/01-some-access-controls`_.
264+
#elseif( $spring )
265+
The code for this section can be found in `tutorials/spring/01-some-access-controls`_.
266+
#end
263267

264268
Let's say there's a restricted page that you only want authenticated users to have access to. We can determine that someone
265269
is logged in simply by obtaining an ``Account`` object. If it's ``null``, the user is not logged in. If it resolves to an
@@ -269,35 +273,51 @@ Let's take a look at the updated ``HelloController.java`` file:
269273

270274
.. code-block:: java
271275
:linenos:
272-
:emphasize-lines: 12
276+
:emphasize-lines: 20
273277
274278
@Controller
275279
public class HelloController {
276280
281+
private AccountResolver accountResolver;
282+
283+
@Autowired
284+
public HelloController(AccountResolver accountResolver) {
285+
Assert.notNull(accountResolver);
286+
this.accountResolver = accountResolver;
287+
}
288+
277289
@RequestMapping("/")
278-
String home(HttpServletRequest req, Model model) {
290+
public String home(HttpServletRequest req, Model model) {
279291
model.addAttribute("status", req.getParameter("status"));
280292
return "home";
281293
}
282294
283295
@RequestMapping("/restricted")
284-
String restricted(HttpServletRequest req) {
285-
if (AccountResolver.INSTANCE.getAccount(req) != null) {
296+
public String restricted(HttpServletRequest req) {
297+
if (accountResolver.getAccount(req) != null) {
286298
return "restricted";
287299
}
288300
289301
return "redirect:/login";
290302
}
291303
}
292304
293-
If we are able to get an account via ``AccountResolver.INSTANCE.getAccount(req)``, then we return the ``restricted``
305+
If we are able to get an account via ``accountResolver.getAccount(req)``, then we return the ``restricted``
294306
template. Otherwise, we redirect to ``/login``.
295307

308+
#if( $springboot )
296309
The code from this section also incorporates some other cool features of
297310
`stormpath-default-spring-boot-starter <https://github.com/stormpath/stormpath-sdk-java/tree/master/extensions/spring/boot/stormpath-default-spring-boot-starter>`_.
298311

299312
It makes use of Thymeleaf templates. Support for Thymeleaf is built in to ``stormpath-default-spring-boot-starter``. In
300313
fact, the default views for login, register and forgot, change and verify are all Thymeleaf templates.
314+
#elseif( $spring )
315+
The code from this section also incorporates some other cool features of
316+
`stormpath-spring-security-webmvc <https://github.com/stormpath/stormpath-sdk-java/tree/master/extensions/spring/stormpath-spring-security-webmvc>`_.
317+
318+
It makes use of JSPs. Support for JSP is built in to ``stormpath-spring-security-webmvc``. In
319+
fact, the default views for login, register and forgot, change and verify are all JSPs.
320+
#end
301321

302322
It also makes use of some settings in ``application.properties``.
303323

@@ -309,10 +329,17 @@ So, in this case, when you logout you will be redirected to the homepage with a
309329

310330
You can see this in action by running this example:
311331

332+
#if( $springboot )
312333
.. code-block:: bash
313334
314335
mvn clean package
315336
mvn spring-boot:run
337+
#elseif( $spring )
338+
.. code-block:: bash
339+
340+
mvn clean package
341+
mvn tomcat7:run
342+
#end
316343

317344
Now, let's take a look at using Spring Security to restrict access.
318345

@@ -796,4 +823,6 @@ for more information on all that the Stormpath Java SDK has to offer.
796823
.. _tutorials/spring-boot: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring-boot
797824
.. _tutorials/spring: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring
798825
.. _tutorials/spring-boot/00-the-basics: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring-boot/00-the-basics
799-
.. _tutorials/spring/00-the-basics: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring/00-the-basics
826+
.. _tutorials/spring/00-the-basics: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring/00-the-basics
827+
.. _tutorials/spring-boot/01-some-access-controls: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring-boot/01-some-access-controls
828+
.. _tutorials/spring/01-some-access-controls: https://github.com/stormpath/stormpath-sdk-java/tree/master/tutorials/spring/01-some-access-controls

0 commit comments

Comments
 (0)