index.html 81.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
<!DOCTYPE html>



<html lang="en">
<head>

    


    


<title>
        Seed manual - Security    
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta name="robots" content="noindex,nofollow">



<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,700,300,400" rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=Bitter:700" rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="/assets/unify/css/style.css">
<link rel="stylesheet" href="/assets/unify/plugins/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="/css/style.css">



<script type="application/ld+json">
{
  "@context" : "http://schema.org",
  "@type" : "SoftwareApplication",
  "name" : "SeedStack",
  "image" : "http://www.seedstack.org/img/logos/seedstack-logo-round.svg",
  "publisher" : {
    "@type" : "Organization",
    "name" : "Open-Source Software"
  },
  "applicationCategory" : "development stack"
}
</script>



<link rel="search" type="application/opensearchdescription+xml" href="http://beta.seedstack.org/opensearch.xml" title="SeedStack" />



<link rel="apple-touch-icon" sizes="57x57" href="/img/favicons/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/img/favicons/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/img/favicons/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/img/favicons/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/img/favicons/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/img/favicons/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/img/favicons/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/img/favicons/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/img/favicons/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="/img/favicons/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/img/favicons/favicon-194x194.png" sizes="194x194">
<link rel="icon" type="image/png" href="/img/favicons/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/img/favicons/android-chrome-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="/img/favicons/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/img/favicons/manifest.json">
<meta name="apple-mobile-web-app-title" content="SeedStack">
<meta name="application-name" content="SeedStack">
<meta name="msapplication-TileColor" content="#00a300">
<meta name="msapplication-TileImage" content="/img/favicons/mstile-144x144.png">
<meta name="theme-color" content="#ffffff">



<script type="text/javascript">
    window.seedstack = {
        state: {}
    };
</script>


</head>
<body class="homepage">
    
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-5R5FP9"
                  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
        j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
        '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5R5FP9');</script>


    <div id="header">
        <div class="header">
    <div class="container">
        <a class="logo" href="/">SeedStack</a>
        <div class="topbar hidden-xs hidden-sm">
            <ul class="loginbar pull-right">
                <li><i class="fa fa-github"></i> <a target="_blank" href="https://github.com/seedstack">GitHub</a></li>
                <li class="topbar-devider"></li>
                <li><i class="fa fa-keyboard-o"></i> <a style="cursor: pointer;" onclick="seedstack.ui.openHelp();">Shortcuts</a></li>
            </ul>
        </div>
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="fa fa-bars"></span>
        </button>
    </div>
    <div class="collapse navbar-collapse navbar-responsive-collapse" data-role="navigation" style="pointer-events: none;">
        <div class="container">
            <ul class="nav navbar-nav" style="pointer-events: auto;">
                <li>
                    <a href="/getting-started">Getting started</a>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
                        Documentation
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="/docs/seed">Java framework</a></li>
                        <li><a href="/docs/w20">Web framework</a></li>
                        <li><a href="/docs/business">Business framework</a></li>
                        <li><a href="/guides">Guides</a></li>
                    </ul>
                </li>
                <li>
                    <a href="/addons">Add-ons</a>
                </li>
                <li>
                    <a href="/posts">Blog</a>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
                        More
                    </a>
                    <ul class="dropdown-menu">
                        <li><a target="_blank" href="https://github.com/seedstack/samples">Samples <i style="margin-top: 3px" class="pull-right fa fa-github"></i></a></li>
                        <li><a href="/project">Project</a></li>
                        <li><a href="/glossary">Glossary</a></li>
                        <li><a href="/tags">Tags</a></li>
                    </ul>
                </li>
                <li>
                    <i class="search fa fa-search search-btn"></i>
                    <div class="search-open">
                        <form method="GET" action="/search">
                            <div class="input-group animated fadeInDown">
                                <input id="search-field" type="text" class="form-control" placeholder="Search" name="q">
                                <span class="input-group-btn">
                                    <button class="btn-u" type="submit">Go</button>
                                </span>
                            </div>
                        </form>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</div>

<div class="channel-marker beta">
    <div class="container">
        <span><strong>BETA documentation.</strong> <small>You may want go to the <a href="http://seedstack.org">stable documentation</a> instead.</small></span>
    </div>
</div>


        
<div class="title-header small">
    <div class="container">
        <div class="row">
            <div class="col-md-9 col-sm-12">
                <h2>Java framework</h2>
                <p class="hidden-xs">Also known as Seed, the Java framework provides support for a large range of technologies and standards from the Java world.</p>
            </div>
            <div class="col-md-3 hidden-sm hidden-xs">
                <div class="header-image-wrapper">
                    <img class="header-image" src="/img/logos/seed-logo.svg">
                </div>
            </div>
        </div>
    </div>
</div>
<div class="title-subheader">
    <div class="container">
        <ul>
            <li><h3 class=''><i class="fa fa-play-circle"></i> <a href="/docs/seed">Introduction</a></h3></li>
            <li><h3 class='active'><i class="fa fa-book"></i> <a href="/docs/seed/manual">Manual</a></h3></li>
            <li><h3 class=''><i class="fa fa-cogs"></i> <a href="/docs/seed/maven-plugin">Maven plugin</a></h3></li>
            <li><h3><i class="fa fa-info-circle"></i> <a href="/javadoc" target="_blank">Javadoc</a></h3></li>
            <li><h3><i class="fa fa-tag"></i> <a href="https://github.com/seedstack/seed/releases" target="_blank">Releases</a></h3></li>
            <li><h3><i class="fa fa-github"></i> <a href="https://github.com/seedstack/seed" target="_blank">Source</a></h3></li>
        </ul>
    </div>
</div>

    </div>
    <div id="content" class="container">
        <div class="row">
    <div class="col-md-9">
        <div class="content-wrapper">
            <div class="doc-content">
                

<p>Seed provides application security through a powerful security model, which is equally easy to configure and to enforce.
It takes charge of the following tasks:</p>

<ul>
<li>Identification (provides the identity of a subject),</li>
<li>Authentication (verifies the subject identity),</li>
<li>Authorization (defines which roles and permissions a subject can have),</li>
<li>Access-control (enforces access restrictions to entry-points and/or to any arbitrary code).</li>
</ul>

<p>To enable security to your project, you need to add the <code>seed-security-core</code> module. 




    
        
            
        
    

<div class="tab-v2">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab-org-seedstack-seed-seed-security-core-maven" data-toggle="tab" aria-expanded="true">Maven</a></li>
        <li class=""><a href="#tab-org-seedstack-seed-seed-security-core-gradle" data-toggle="tab" aria-expanded="true">Gradle</a></li>
    </ul>
    <span class="tabs-icon fa-2x fa fa-cubes pull-right"></span>
    <div class="clear-both"></div>
    <div class="tab-content">
        <div class="tab-pane in active" id="tab-org-seedstack-seed-seed-security-core-maven">
            <pre style="margin-top: 0;"><code class="xml">&lt;dependency&gt;
    &lt;groupId&gt;org.seedstack.seed&lt;/groupId&gt;
    &lt;artifactId&gt;seed-security-core&lt;/artifactId&gt;<span id="org-seedstack-seed-seed-security-core-version" style="display: none;">
    &lt;version&gt;2.2.0&lt;/version&gt;</span>
&lt;/dependency&gt;</code></pre>
            <small class="pull-right" style="color: #aaa; margin-top: -20px; margin-right: 5px;">
                <span id="org-seedstack-seed-seed-security-core-warn" style="display: none;"><i class="fa fa-warning" style="color: orange;"></i> Specifying versions manually is error-prone, use the <a href="/getting-started/distribution">distribution</a> instead.</span>
                <a style="cursor: pointer;" id="org-seedstack-seed-seed-security-core-show" onclick="$('#org-seedstack-seed-seed-security-core-version, #org-seedstack-seed-seed-security-core-warn').show(); $('#org-seedstack-seed-seed-security-core-show').hide();">Show version</a>
            </small>
        </div>
        <div class="tab-pane in" id="tab-org-seedstack-seed-seed-security-core-gradle">
            <pre style="margin-bottom: 0;"><code class="java">dependencies {
    compile("org.seedstack.seed:seed-security-core:2.2.0")
}</code></pre>
        </div>
    </div>
</div>
</p>

<p>In a Web application, you may want to enable HTTP-based security by adding the <code>seed-web-security</code> module. 




    
        
            
        
    

<div class="tab-v2">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab-org-seedstack-seed-seed-web-security-maven" data-toggle="tab" aria-expanded="true">Maven</a></li>
        <li class=""><a href="#tab-org-seedstack-seed-seed-web-security-gradle" data-toggle="tab" aria-expanded="true">Gradle</a></li>
    </ul>
    <span class="tabs-icon fa-2x fa fa-cubes pull-right"></span>
    <div class="clear-both"></div>
    <div class="tab-content">
        <div class="tab-pane in active" id="tab-org-seedstack-seed-seed-web-security-maven">
            <pre style="margin-top: 0;"><code class="xml">&lt;dependency&gt;
    &lt;groupId&gt;org.seedstack.seed&lt;/groupId&gt;
    &lt;artifactId&gt;seed-web-security&lt;/artifactId&gt;<span id="org-seedstack-seed-seed-web-security-version" style="display: none;">
    &lt;version&gt;2.2.0&lt;/version&gt;</span>
&lt;/dependency&gt;</code></pre>
            <small class="pull-right" style="color: #aaa; margin-top: -20px; margin-right: 5px;">
                <span id="org-seedstack-seed-seed-web-security-warn" style="display: none;"><i class="fa fa-warning" style="color: orange;"></i> Specifying versions manually is error-prone, use the <a href="/getting-started/distribution">distribution</a> instead.</span>
                <a style="cursor: pointer;" id="org-seedstack-seed-seed-web-security-show" onclick="$('#org-seedstack-seed-seed-web-security-version, #org-seedstack-seed-seed-web-security-warn').show(); $('#org-seedstack-seed-seed-web-security-show').hide();">Show version</a>
            </small>
        </div>
        <div class="tab-pane in" id="tab-org-seedstack-seed-seed-web-security-gradle">
            <pre style="margin-bottom: 0;"><code class="java">dependencies {
    compile("org.seedstack.seed:seed-web-security:2.2.0")
}</code></pre>
        </div>
    </div>
</div>
</p>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>The internal security engine is <a href="http://shiro.apache.org/">Apache Shiro</a>. Seed provides additional benefits on top of Shiro
such as:</p>

<ul>
<li>Easy, unified configuration.</li>
<li>Built-in security realms such as LDAP, X509 certificate or configuration-based.</li>
<li>A plugin mechanism to dynamically register additional entry point security.</li>
<li>Security scopes which restrict roles and permissions to specified scopes, like a geographical area.</li>
<li>Data security which can nullify or obfuscate object attributes based on subject authorizations.</li>
</ul>

        </div>
    </div>
</div>

<h1 id="definitions:8c8be46b296d6b9c1a91080fe9b4316b">Definitions</h1>

<h2 id="subject:8c8be46b296d6b9c1a91080fe9b4316b">Subject</h2>

<p>A <em>subject</em> is defined as any entity that request access to an <em>object</em>. For instance, subject are often end-users which
request to access a specific resource through a User-Interface. But subjects can really be anything like a remote computer
or a local program.</p>

<h2 id="principal:8c8be46b296d6b9c1a91080fe9b4316b">Principal</h2>

<p>A <em>principal</em> is a defining characteristic of a subject that can be uniquely identified, like an identifier, a name,
a social-security number, a language, etc&hellip;</p>

<h2 id="user:8c8be46b296d6b9c1a91080fe9b4316b">User</h2>

<p>A <em>user</em> is a specific kind of subject that is defined by principals usually referring to a human operator, like a name
or a user-identifier.</p>

<h2 id="identification:8c8be46b296d6b9c1a91080fe9b4316b">Identification</h2>

<p>Identification is the process of uniquely tracking a subject across its interactions with the system.</p>

<h2 id="authentication:8c8be46b296d6b9c1a91080fe9b4316b">Authentication</h2>

<p>Authentication is the process of verifying the subject identity by validating a proof of identity. This is usually done
by submitting a principal identifying the subject (like a user-identifier) and a proof of identity that the system
understands and trusts, such as a password, a certificate or any other mean.</p>

<h2 id="authorization:8c8be46b296d6b9c1a91080fe9b4316b">Authorization</h2>

<p>Authorization is the process of determining an access policy for a subject. This is done by compiling all granted rights
into an access policy.</p>

<h2 id="access-control:8c8be46b296d6b9c1a91080fe9b4316b">Access control</h2>

<p>Access control is the process of verifying the authorizations of a subject relative to an object. It enforces the policy
that is used to determine <em>who</em> has access to <em>what</em>.</p>

<h1 id="model:8c8be46b296d6b9c1a91080fe9b4316b">Model</h1>

<p>Seed provides a security meta-model that is easy to understand yet powerful enough for the most complex applications. This
meta-model revolves around three main concepts: permissions, roles and subject. It allows to define a fine-grained and
modular security policy.</p>

<h2 id="permissions:8c8be46b296d6b9c1a91080fe9b4316b">Permissions</h2>

<p>Permissions are the most atomic elements of a security policy. They describe concrete actions and represent what can
be done in an application. A well-formed permission statement describes one or more resource(s) and what actions are
possible when a subject interacts with those resources. Consider the following examples of permissions:</p>

<ul>
<li>Open a file,</li>
<li>Print a document,</li>
<li>Access the <code>/products</code> Web resource,</li>
<li>Delete an order.</li>
</ul>

<p>CRUD actions can frequently be found in permissions but any meaningful verb can be used. The fundamental idea is that
a permission should combine a resource description with an action description.</p>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>Permission statements reflect behavior (actions associated with resource types) only. They do <strong>not</strong> reflect who is able to
perform such behavior. Defining who (which subject) can do what (which permission) is done by assigning permission to
subjects.</p>

        </div>
    </div>
</div>

<h3 id="simple-usage:8c8be46b296d6b9c1a91080fe9b4316b">Simple usage</h3>

<p>The simplest expression of a permission is a single term String:</p>

<pre><code>printDocument
deleteDocument
viewDocument
</code></pre>

<p>These permissions represent the ability to <code>print</code>, <code>delete</code> or <code>view</code> a document. This very basic form of permission requires
to be granted one-by-one or with a <code>*</code> wildcard, which will grant all the permissions of the application. This may work
in the simplest applications but it is not recommended. The <em>multi-level</em> permissions should be preferred.</p>

<h3 id="multi-level:8c8be46b296d6b9c1a91080fe9b4316b">Multi-level</h3>

<p>Instead of expressing the permission as a single term, a multi-level permission can be used:</p>

<pre><code>document:print
document:delete
document:view
</code></pre>

<p>The colon (<code>:</code>) is a special character that is used to delimit the different parts of a multi-level permission. There
are no enforced requirements on how a multi-level permission should be organized, but it is recommended to go from the most
general to the most specific, from left to right. Also, there is no limit to the number of parts.</p>

<h3 id="multiple-values:8c8be46b296d6b9c1a91080fe9b4316b">Multiple values</h3>

<p>Each part can contain multiple values, separated by commas (<code>,</code>):</p>

<pre><code>document:print,view
</code></pre>

<p>When assigning this permission to a subject, this grants the ability to <code>print</code> and <code>view</code> documents.</p>

<h3 id="all-values:8c8be46b296d6b9c1a91080fe9b4316b">All values</h3>

<p>To grant all permissions of a specific level, use the <code>*</code> wildcard character:</p>

<pre><code>document:*
*:view
</code></pre>

<p>The first permission, when assigned to a subject, allow to do any action on documents (meaning that any permission check
of the <code>document:XXX</code> pattern will be granted). The second permission grants the view action on all application resources
(meaning that any permission check of the <code>XXX:view</code> pattern will be granted).</p>

<h3 id="instance-level-checks:8c8be46b296d6b9c1a91080fe9b4316b">Instance-level checks</h3>

<p>The identifier of a specific instance can be used at the end of a permission:</p>

<pre><code>document:print:doc273
</code></pre>

<p>This permission allows to print the document identified by the <code>doc273</code> identifier.</p>

<h3 id="missing-parts:8c8be46b296d6b9c1a91080fe9b4316b">Missing parts</h3>

<p>Missing parts in permissions imply that the user has access to all values corresponding to that part:</p>

<pre><code>printer:print
</code></pre>

<p>This permission is equivalent to:</p>

<pre><code>printer:print:*
</code></pre>

<p>Note that you can only leave off parts from the <em>end</em> of the permission.</p>

<h2 id="roles:8c8be46b296d6b9c1a91080fe9b4316b">Roles</h2>

<p>A Role is a named entity that typically represents a set of behaviors or responsibilities. Those behaviors translate to
things you can or can&rsquo;t do with an application. Roles are typically assigned to subject like user accounts, so by
association, subjects can <em>do</em> the things attributed to various roles. There are two kinds of roles that can be used:</p>

<ul>
<li><strong>Implicit roles</strong>: nothing is explicitly expressed in the application to assign permissions to implicit roles. The
allowed behavior is implicitly derived from the role name only. For instance the <code>admin</code> role can do any administration
task and those administration task are protected by a checking if the subject has the <code>admin</code> role. This kind of role,
while superficially simpler, is <strong>strongly discouraged</strong>. Adding, removing or redefining such roles later in the life of
an application will be difficult, costly and may lead to holes in the security model.</li>
<li><strong>Explicit roles</strong>: they are expressed as a named collection of actual permissions. In this form, the allowed behavior
is explicitly defined and the code only contains specific permission checks which directly relates to the code behavior.
Altering the security model later in the life of an application will be easy and won&rsquo;t require to change existing code
with the potential security implications. This kind of role, is <strong>recommended</strong>.</li>
</ul>

<h2 id="subjects:8c8be46b296d6b9c1a91080fe9b4316b">Subjects</h2>

<p>Subjects represent the entity which executes actions on the application. The most common type of subject is the <code>User</code>
type, which represents a human operator interacting with the application. Subjects are allowed to perform certain actions
in your application through their association with roles or direct permissions. Assigning roles and permissions to subjects
is done through a <code>Realm</code> implementation.</p>

<h2 id="realms:8c8be46b296d6b9c1a91080fe9b4316b">Realms</h2>

<p>A realm implementation role is to translate a specific data-model, like an LDAP directory or a set of database tables,
into a security policy expressed with the security meta-model described above. Seed provides several predefined realms:</p>

<ul>
<li>The <code>ConfigurationRealm</code> which computes the security policy from specific properties in the application configuration.</li>
<li>The <code>X509CertificateRealm</code> which computes the security policy from an X509 certificate.</li>
<li>The <code>LdapRealm</code> which computes the security policy from requests to a configured LDAP directory. This realm is available
in the <a href="/addons/ldap">LDAP add-on</a>.</li>
</ul>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>Custom realms can be implemented to compute any data-model into an enforceable security policy.</p>

        </div>
    </div>
</div>

<h1 id="configuration:8c8be46b296d6b9c1a91080fe9b4316b">Configuration</h1>

<p>Beyond defining the security model of the application, the security infrastructure must be configured.</p>

<h2 id="realm-configuration:8c8be46b296d6b9c1a91080fe9b4316b">Realm configuration</h2>

<p>A Realm is a component that can access specific security data such as users, roles, and permissions. The Realm translates
this specific data into a format that is understood by the security engine. There is usually a 1-to-1 relation between
a realm and a datasource, such as an LDAP directory, a set of relational tables or configuration properties.</p>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>Most of the security datasources usually store both authentication and authorization data, so a realm can perform both
the authentication and authorization tasks.</p>

        </div>
    </div>
</div>

<p>To specify the realm(s) to enable, use the following configuration property:</p>

<pre><code class="language-ini">org.seedstack.seed.security.realms = list of realms to use
</code></pre>

<p>The realm name correspond to the simple name of the Java class that implements the realm. For instance to enable the
LDAP realm (which is implemented in the <code><a data-toggle="tooltip" data-html="true" title='org.&amp;#8203;seedstack.&amp;#8203;ldap.&amp;#8203;internal.&amp;#8203;realms.&amp;#8203;LDAPRealm' href='http://seedstack.org/javadoc/org/seedstack/ldap/internal/realms/LDAPRealm.html'>LDAPRealm</a></code> Java class), use
the following configuration:</p>

<pre><code class="language-ini">org.seedstack.seed.security.realms = LdapRealm
</code></pre>

<p>If the property is not specified, the default realm is <code>ConfigurationRealm</code>.</p>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>Note that you can specify multiple realms. In that case the realms are tried in sequence and if at least one realm
successfully authenticates the subject, the overall attempt is considered successful. If none authenticate successfully,
the attempt fails. The data from all the successful realms are merged.</p>

        </div>
    </div>
</div>

<h3 id="configuration-realm:8c8be46b296d6b9c1a91080fe9b4316b">Configuration realm</h3>

<p>This realm relies on the application configuration to authenticate subject and retrieve their roles. It is mainly intended
to be used for testing purposes. To declare subjects (called users in this realm), use the following configuration:</p>

<pre><code class="language-ini">[org.seedstack.seed.security.users]
user1 = password, role1, role2
user2 = password, role3
</code></pre>

<p>This will define two subjects, <code>user1</code> and <code>user2</code> with their respective passwords and roles.</p>

<h3 id="x509-realm:8c8be46b296d6b9c1a91080fe9b4316b">X509 realm</h3>

<p>This realm, which is intended to be used in a Web context, uses the certificates authorized by the Web server when an SSL
connection is in use. It stores the certificates in the user principals as well as the UID declared in the certificate.
It also uses the CN of the issuer of the certificates to define the basic roles of the user.</p>

<h3 id="ldap-realm:8c8be46b296d6b9c1a91080fe9b4316b">LDAP realm</h3>

<p>Check the <a href="/addons/ldap">LDAP add-on documentation</a>.</p>

<h2 id="role-permission-resolver:8c8be46b296d6b9c1a91080fe9b4316b">Role/permission resolver</h2>

<p>There is a role/permission resolver component per Realm. It resolves the Permissions assigned to a Role and provides them
to the Realm. To attach a role/permission resolver to a Realm, use the following configuration:</p>

<pre><code class="language-ini">org.seedstack.seed.security.&lt;RealmName&gt;.role-permission-resolver = ConfigurationRolePermissionResolver
</code></pre>

<p>Where <code>&lt;RealmName&gt;</code> corresponds to the name of the Realm this role/permission resolver is mapped to. The value corresponds
to the simple name of the implementing Java class. When no resolver is specified, the configuration-based role/permission
resolver is used.</p>

<h3 id="configuration-based-role-permission:8c8be46b296d6b9c1a91080fe9b4316b">Configuration-based role/permission</h3>

<p>This role/permission resolver uses the application configuration to do resolution. You can assign permissions to roles
with the following configuration:</p>

<pre><code class="language-ini">[org.seedstack.seed.security.permissions]
role1 = permission1a:permission1b, permission2a:permission2b
role2 = permission3, permission4a:permission4b
role3 = permission5
role4 = permission6
</code></pre>

<p>This configuration assign permissions listed in values to their respective roles as keys. This is the default role/permission
resolver.</p>

<h2 id="role-mapping:8c8be46b296d6b9c1a91080fe9b4316b">Role mapping</h2>

<p><strong>Optionally</strong>, roles provided by realms can be mapped to application-specific roles. To do this, a role mapping component
should be defined in configuration:</p>

<pre><code class="language-ini">org.seedstack.seed.security.&lt;RealmName&gt;.role-mapping = ConfigurationRoleMapping
</code></pre>

<p>Where <code>&lt;RealmName&gt;</code> corresponds to the name of the Realm this role mapping component is mapped to. The value corresponds
to the simple name of the implementing Java class. When no mapping is specified, the configuration-based role mapping
is used.</p>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>When no role mapping is specified, the roles provided by realms are directly used as application roles.</p>

        </div>
    </div>
</div>

<h3 id="configuration-based-role-mapping:8c8be46b296d6b9c1a91080fe9b4316b">Configuration-based role mapping</h3>

<p>This role mapping uses the application configuration to do the mapping:</p>

<pre><code class="language-ini">[org.seedstack.seed.security.roles]
role1 = ORG.APP.ROLE1, ORG.GLOBAL.ADMIN
role2 = ORG.APP.ROLE2
role3 = ORG.APP.{location}.ROLE3
role4 = *
</code></pre>

<p>This configuration defines the following mappings:</p>

<ul>
<li>Application-role <code>role1</code> is attributed to the subject when the realm provides <code>ORG.APP.ROLE1</code> <strong>OR</strong> <code>ORG.GLOBAL.ADMIN</code>.</li>
<li>Application-role <code>role2</code> is attributed to the subject when the realm provides <code>ORG.APP.ROLE2</code>.</li>
<li>Application-role <code>role3</code> is attributed to the subject when the realm provides <code>ORG.APP.FR.ROLE3</code>, where <code>FR</code> is converted
into a security scope. As such a scoped <code>role3</code> is attributed to the subject, which is only valid in <code>FR</code> location.</li>
<li>Application-role <code>role4</code> is attributed to every subject authenticated.</li>
</ul>

<h2 id="example:8c8be46b296d6b9c1a91080fe9b4316b">Example</h2>

<p>The following example is based on the defaults: a <code>ConfigurationRealm</code>, a <code>ConfigurationRolePermissionResolver</code> and a <code>ConfigurationRoleMapping</code>. Their declaration is optional but present here for clarity. You may want to replace each by a more suitable component, especially the <code>ConfigurationRealm</code> which uses the configuration as its users repository.</p>

<pre><code class="language-ini">[org.seedstack.seed.security]
realms = ConfigurationRealm
ConfigurationRealm.role-mapping = ConfigurationRoleMapping
ConfigurationRealm.role-permission-resolver = ConfigurationRolePermissionResolver

[org.seedstack.seed.security.users]
admin = password1, APP.ADMIN
user1 = password2, APP.FR.MANAGER, APP.UK.MANAGER
user2 = password3, APP.BASIC

[org.seedstack.seed.security.roles]
admin = APP.ADMIN
manager = APP.ADMIN, APP.{location}.MANAGER
normal = APP.ADMIN, APP.BASIC
guest = *

[org.seedstack.seed.security.permissions]
admin = users:clear, cache:invalidate
manager = users:delete, users:create
normal = users:list
</code></pre>

<p>Note that:</p>

<ul>
<li>Application-roles (<code>admin</code>, <code>manager</code>, <code>normal</code> and <code>guest</code>) are attributed to a subject if it has <strong>at least one</strong> of the corresponding realm roles (<code>APP.ADMIN</code>, <code>APP.FR.MANAGER</code> , <code>APP.UK.MANAGER</code>, <code>APP.BASIC</code>). For instance, having the <code>APP.ADMIN</code> realm role is enough to have the <code>manager</code> application-role.</li>
<li>Subject <code>user1</code> will only have the <code>users:delete</code> and <code>users:create</code> permissions on <code>FR</code> and <code>UK</code> locations.</li>
<li>Subject <code>admin</code> will have the <code>users:delete</code> and <code>users:create</code> permissions everywhere (no location restriction).</li>
<li>The <code>guest</code> application-role will be attributed to every identified subject.</li>
</ul>

<h1 id="usage:8c8be46b296d6b9c1a91080fe9b4316b">Usage</h1>

<p>Access policy enforcement is achieved by using the Seed security API to protect specific sections of the application code.
Any code can be secured, although restrictions may apply in some cases.</p>

<h2 id="enforcement-strategy:8c8be46b296d6b9c1a91080fe9b4316b">Enforcement strategy</h2>

<p>It is recommended to follow a well-defined strategy in placing security checks in application code. Failing to do so may
lead to unexpected security holes, as <em>one missing or incomplete check may be enough to compromise the entire application</em>.
Any well thought-out strategy will do, but you can consider applying one of the following (or both):</p>

<ul>
<li><strong>Entry-point security</strong>. This strategy consists in only securing the code that allow to interact with the application.
This includes REST resources, servlets and filters, Web-Services, administrative commands, etc&hellip; Any applicative code
can theoretically only be reached through one of these entry points, so this strategy may be enough for most
applications.</li>
<li><strong>In-depth security</strong>. This strategy consists in independently securing each application behavior, regardless of its
depth in the call hierarchy. This includes all the entry points of the previous strategy as well as services, repositories,
finders, etc&hellip; It ensures that no behavior can be executed without the appropriate authorizations, regardless how it is
accessed. This strategy provides higher security, especially in applications with a lot of entry points or when entry
points are often modified, but is costlier to implement. This cost can be mitigated by limiting the checks to critical
application behavior only.</li>
</ul>

<h2 id="annotation-based-checks:8c8be46b296d6b9c1a91080fe9b4316b">Annotation-based checks</h2>

<p>There are two annotations that checks for authorizations before allowing method execution:</p>

<ul>
<li><code>@RequiresRoles</code> which checks that the current subject has one or more role(s) before allowing to execute the method.</li>
<li><code>@RequiresPermissions</code> which checks that the current subject has one or more permission(s) before allowing to execute
the method.</li>
</ul>

<p>When the security check fails, an exception of type <code><a data-toggle="tooltip" data-html="true" title='org.&amp;#8203;seedstack.&amp;#8203;seed.&amp;#8203;security.&amp;#8203;AuthorizationException' href='http://seedstack.org/javadoc/org/seedstack/seed/security/AuthorizationException.html'>AuthorizationException</a></code>
is thrown.</p>

<div class="callout callout-warning">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
            
                <i class="fa fa-exclamation-triangle icon-2x"></i>
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>Note that these annotation-based security checks are implemented with <strong>method interception</strong> and are subject to
<strong><a href="../../../concepts/dependency-injection#method-interception">its limitations</a></strong>.</p>

        </div>
    </div>
</div>

<p>Examples:</p>

<pre><code class="language-java">@RequiresRoles(&quot;administrator&quot;)
public void deleteUser(User user) {
    // This method is executed only if current subject has role 'administrator'
    // When not, an AuthorizationException is thrown
}

@RequiresPermissions(&quot;account:create&quot;)
public void createAccount(Account account) {
    // This method is executed only if current subject has permission 'account:create'
    // When not, an AuthorizationException is thrown
}
</code></pre>

<h2 id="programmatic-checks:8c8be46b296d6b9c1a91080fe9b4316b">Programmatic checks</h2>

<p>If annotation-based security checks cannot be used, or if an programmatic style is preferred, the
<code><a data-toggle="tooltip" data-html="true" title='org.&amp;#8203;seedstack.&amp;#8203;seed.&amp;#8203;security.&amp;#8203;SecuritySupport' href='http://seedstack.org/javadoc/org/seedstack/seed/security/SecuritySupport.html'>SecuritySupport</a></code> facade can be used. It provides various methods to explicitly check for
current subject authorizations. It is more versatile than annotation-based checks and it is required when checking
dynamically generated authorizations. To use it, simply inject it where needed:</p>

<pre><code>@Inject
private SecuritySupport securitySupport;
</code></pre>

<p>To check if the current subject, if any, is authenticated:</p>

<pre><code>if (securitySupport.isAuthenticated()) {
    ...
}
</code></pre>

<p>To check if the current subject, if any, has a specific role:</p>

<pre><code>if (securitySupport.hasRole(&quot;jedi&quot;)) {
    ...
}
</code></pre>

<p>To check if the current subject, if any, has a specific permission:</p>

<pre><code>if (securitySupport.isPermitted(&quot;jediCouncil:attend&quot;)) {
    ...
}
</code></pre>

<div class="callout callout-info">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
                <i class="fa fa-info-circle icon-2x" style="line-height: 30px;"></i>
            
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>There are multiple variations for each of these methods, and many more possibilities. Please refer to the
<a href="/seed/org/seedstack/seed/security/api/SecuritySupport.html">javadoc</a> for more information.</p>

        </div>
    </div>
</div>

<h2 id="other-checks:8c8be46b296d6b9c1a91080fe9b4316b">Other checks</h2>

<p>Seed security can provide additional ways to verify security depending on the technology used to access the application.
For instance, in a Web application, HTTP requests can be filtered to execute security tasks or checks. For more information
about applying HTTP security filtering, refer to <a href="../../web/security">this documentation</a>.</p>

<h2 id="access-subject-principals:8c8be46b296d6b9c1a91080fe9b4316b">Access subject principals</h2>

<p>Note that <code>SecuritySupport</code> provides access to current subject Principals:</p>

<pre><code>// Get current subject id
securitySupport.getSimplePrincipalByName(Principals.IDENTITY).getValue();

// Get current subject first name, if any
securitySupport.getSimplePrincipalByName(Principals.FIRST_NAME).getValue();
</code></pre>

<h1 id="extension:8c8be46b296d6b9c1a91080fe9b4316b">Extension</h1>

<p>As Seed security is based on <a href="http://shiro.apache.org">Apache Shiro</a>, it can be extended by adding existing Shiro components
or by writing your own components. Seed also provides SPI to extend its own security features.</p>

<h2 id="creating-a-realm:8c8be46b296d6b9c1a91080fe9b4316b">Creating a Realm</h2>

<p>You can create a custom Realm by following these steps:</p>

<ol>
<li>Create a class that implements <code><span data-toggle="tooltip" data-html="true" title='org.&amp;#8203;apache.&amp;#8203;shiro.&amp;#8203;realm.&amp;#8203;Realm'>Realm</span></code> or extends an existing Shiro realm.</li>
<li>Use the realm class simple name as the realm name in the application configuration.</li>
</ol>

<h2 id="creating-a-rolepermissionresolver:8c8be46b296d6b9c1a91080fe9b4316b">Creating a RolePermissionResolver</h2>

<p>You can create a custom Role/Permission resolver by following these steps:</p>

<ol>
<li>Create a class that implements <code><span data-toggle="tooltip" data-html="true" title='org.&amp;#8203;apache.&amp;#8203;shiro.&amp;#8203;authz.&amp;#8203;permission.&amp;#8203;RolePermissionResolver'>RolePermissionResolver</span></code>.</li>
<li>Declare you want to use it on a realm in your properties.</li>
</ol>

<h2 id="creating-a-rolemapping:8c8be46b296d6b9c1a91080fe9b4316b">Creating a RoleMapping</h2>

<p>You can create a custom Role mapping by following these steps:</p>

<ol>
<li>Create a class that implements <code><a data-toggle="tooltip" data-html="true" title='org.&amp;#8203;seedstack.&amp;#8203;seed.&amp;#8203;support.&amp;#8203;security.&amp;#8203;core.&amp;#8203;authorization.&amp;#8203;RoleMapping' href='http://seedstack.org/javadoc/org/seedstack/seed/support/security/core/authorization/RoleMapping.html'>RoleMapping</a></code>.</li>
<li>Declare you want to use it on a realm in your properties.</li>
</ol>

<h1 id="testing:8c8be46b296d6b9c1a91080fe9b4316b">Testing</h1>

<p>Testing the security model and its implementation is crucial to ensure effective security. This can be easily done with
Seed through specific integration tests. For a general overview of integration testing, please check
<a href="../testing">this documentation</a>.</p>

<h2 id="configuration-1:8c8be46b296d6b9c1a91080fe9b4316b">Configuration</h2>

<p>You can choose to fully emulate your security infrastructure, for instance by using an LDAP test directory instead of the
real one. The main benefit of this approach is that it tests the security effectiveness as closely as possible to the
real environment. A simpler but still adequate approach is to override the security realm configuration to use a
<code>ConfigurationRealm</code> and define test users in application configuration:</p>

<pre><code class="language-ini">[org.seedstack.seed.security.users]
testUser1 = password, role1, role2
testUser2 = password, role1
testUser3 = password, role3
...
</code></pre>

<p>For more information about the Configuration realm, refer to <a href="#configuration-realm">this section</a>.
For more information on how to override the configuration for testing, refer to <a href="../#override">this documentation</a>.</p>

<h2 id="subject-authentication:8c8be46b296d6b9c1a91080fe9b4316b">Subject authentication</h2>

<p>To authenticate a subject before a test method is executed, use the <code><a data-toggle="tooltip" data-html="true" title='org.&amp;#8203;seedstack.&amp;#8203;seed.&amp;#8203;security.&amp;#8203;WithUser' href='http://seedstack.org/javadoc/org/seedstack/seed/security/WithUser.html'>@WithUser</a></code> annotation:</p>

<pre><code>@RunWith(SeedITRunner.class)
public class MyITWithSecurity {
    @Inject
    private SecuritySupport securitySupport;

    @Inject
    private MySecuredService mySecuredService;


    @Test(expected = AuthorizationException)
    @WithUser(id = &quot;testUser1&quot;, password = &quot;password&quot;)
    public void unprivileged_user_cannot_access_secured_service() {
        mySecuredService.securedMethod();
        fail(&quot;securedMethod() shouldn't have been called&quot;);
    }

    @Test
    @WithUser(id = &quot;testUser3&quot;, password = &quot;password&quot;)
    public void admin_user_is_allowed_to_access_secured_service() {
        mySecuredService.securedMethod();
    }
}
</code></pre>

<h1 id="data-security:8c8be46b296d6b9c1a91080fe9b4316b">Data security</h1>

<p>The goal of the security on data is to protect the data exposed by an application. It has the ability to obfuscate any
attribute of any object that does not pass the security restriction defined on it. For instance, an account number
<code>79927391338710</code> can be transformed into <code>799273******10</code>.</p>

<h2 id="restriction-annotation:8c8be46b296d6b9c1a91080fe9b4316b">@Restriction annotation</h2>

<p>This annotation can be applied on any class attribute. The field value will be obfuscated when data security will be applied:</p>

<pre><code>public class MySecuredPojo {
    @Restriction(value = &quot;${ hasRole('manager') }&quot;, obfuscation = AccountObfuscationHandler.class)
    private String accountNumber;

    ...
}
</code></pre>

<p>The value of the annotation is a security expression (see <a href="#security-expressions">this section</a> for more details). If it
evaluates to false against the current Subject the field will be obfuscated according to the <code>DataObfuscationHandler</code>
specified (see <a href="#dataobfuscationhandler">this section</a> for more details). The default obfuscation handler nullifies the
field.</p>

<h2 id="data-security-service:8c8be46b296d6b9c1a91080fe9b4316b">Data security service</h2>

<p>The security on data can be applied by using the <code>DataSecurityService</code> as follows:</p>

<pre><code>@Inject
private DataSecurityService dataSecurityService;

dataSecurityService.secure(myDto);
</code></pre>

<p>This service will go recursively through the object fields and look for restrictions. Each restriction that evaluates to f
alse against the current Subject will trigger the obfuscation of its associated field.</p>

<h2 id="secured-annotation:8c8be46b296d6b9c1a91080fe9b4316b">@Secured annotation</h2>

<p>You can add a <code>@Secured</code> annotation on any method parameter to automatically apply data security on it. You can also
apply the <code>@Secured</code> annotation directly on the method to apply data security on the return value:</p>

<pre><code>@Secured
public SecuredPojo1 securedMethod(@Secured SecuredPojo2 securedPojo2) {
    ...
}
</code></pre>

<p>Every method annotated with <code>@Secured</code> or with the annotation applied to at least one of its parameters will be intercepted
and the relevant objects will be secured. Note that the
<a href="/docs/seed/concepts/dependency-injection/#method-interception">usual interception limitations</a> apply.</p>

<p><div class="callout callout-warning">
    <div style="display:table; width: 100%">
        <div style="display:table-cell; width: 50px; vertical-align: middle;">
            
            
            
                <i class="fa fa-exclamation-triangle icon-2x"></i>
            
            
        </div>
        <div style="display:table-cell; vertical-align: middle;">
            <p>Please note that the data security interceptor will inspect the whole object graph starting from the secured object, so
you may encounter some performance penalty depending on its size. It shouldn&rsquo;t be a problem for typical use.</p>

        </div>
    </div>
</div></p>

<h2 id="security-expressions:8c8be46b296d6b9c1a91080fe9b4316b">Security expressions</h2>

<p>Security expressions are strings that respect the <a href="https://uel.java.net/">Unified Expression Language (UEL)</a> syntax. The
following methods are available:</p>

<ul>
<li><code>hasRole(String role)</code>. Returns true if the current subject has the specified role, false otherwise.</li>
<li><code>hasOneRole(String... roles)</code>. Returns true if the current subject has at least one of the specified roles, false otherwise.</li>
<li><code>hasAllRoles(String... roles)</code>. Returns true if the current subject has all the specified roles, false otherwise.</li>
<li><code>hasRole(String role, String... scopes)</code>. Returns true if the current subject has the specified role for all the specified scopes, false otherwise.</li>
<li><code>hasPermission(String permission)</code>. Returns true if the current subject has the specified permission, false otherwise.</li>
<li><code>hasOnePermission(String... permissions)</code>. Returns true if the current subject has at least one of the specified permissions, false otherwise.</li>
<li><code>hasAllPermissions(String... permissions)</code>. Returns true if the current subject has all the specified permissions, false otherwise.</li>
<li><code>hasPermission(String permission, String... scopes)</code>. Returns true if the current subject has the specified permission on the specified scopes, false otherwise.</li>
</ul>

<p>Examples:</p>

<pre><code class="language-plain">${ !hasRole('manager') &amp;&amp; hasPermission('salary:view') }
${ hasAllPermissions('salary:view', 'salary:update') }
${ hasPermission('users:manage', 'FR') }
</code></pre>

<p>More resources on EL:</p>

<ul>
<li><a href="http://docs.oracle.com/javaee/6/tutorial/doc/gjddd.html">Oracle tutorial</a></li>
<li><a href="https://uel.java.net/">Unified Expression Language</a></li>
</ul>

<h2 id="dataobfuscationhandler:8c8be46b296d6b9c1a91080fe9b4316b">DataObfuscationHandler</h2>

<p>The goal of a <code>DataObfuscationHandler</code> is to obfuscate data with a specific algorithm.
For instance, it could take a name, eg. &laquo;Doe&raquo; and return an anonymised name &laquo;D.&raquo;. This would be implemented as follows:</p>

<pre><code>/*
 * This {@code DataObfuscationHandler} takes a {@code String}, eg. &quot;Doe&quot; and
 * obfuscate it into &quot;D.&quot;.
 */
public static class NameObfuscationHandler implements DataObfuscationHandler&lt;String&gt; {
    @Override
    public String obfuscate(String data) {
        String result = &quot;&quot;;
        if (data != null &amp;&amp; data.length() &gt; 0) {
            result = data.charAt(0) + &quot;.&quot;;
            result = result.toUpperCase();
        }
        return result;
    }
}
</code></pre>

<h2 id="custom-annotations:8c8be46b296d6b9c1a91080fe9b4316b">Custom annotations</h2>

<p>Custom restriction annotations can be defined and registered with data security by defining a <code>DataSecurityHandler</code>. Start
with defining a custom annotation:</p>

<pre><code>@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD})
public @interface MyRestriction {

    String expression();

    Todo todo() default Todo.Nullify;

    public enum Todo {
        Hide, Round, Nullify
    }

}
</code></pre>

<p>Then, define a <code>DataSecurityHandler</code> which handles the <code>@MyRestriction</code> annotation.</p>

<pre><code>public class MyDataSecurityHandler implements DataSecurityHandler&lt;MyRestriction&gt; {

    @Override
    public Object securityExpression(MyRestriction annotation) {
        return annotation.expression();
    }

    @Override
    public Class&lt;? extends DataObfuscationHandler&lt;?&gt;&gt; securityObfuscationHandler(
                                                                MyRestriction annotation) {    
        if (annotation.todo() .equals( Todo.Round  )) {
            // Uses the rounding obfuscation handler defined below
            return RoundingObfuscationHandler.class;
        }

        if (annotation.todo() .equals( Todo.Hide  )) {
            // Uses the name obfuscation handler defined in the previous section
            return NameObfuscationHandler.class;
        }

        return null;
    }

    public static class RoundingObfuscationHandler 
                        implements DataObfuscationHandler&lt;Integer&gt; {

        @Override
        public Integer obfuscate(Integer data) {
            Integer result = 0;
            if (data != null) {
                result = (int) (Math.ceil(data / 1000) * 1000);
            }
            return result;
        }           
    }
}
</code></pre>

<p>Then, you can apply the annotation on a POJO:</p>

<pre><code>public class MyPojo {       

    private String firstName;

    @MyRestriction(expression=&quot;${1 == 2}&quot; , todo = Todo.Hide)
    private String name;

    @MyRestriction(
        expression=&quot;${ hasRole('manager') }&quot;, 
        todo=Todo.Round
    )
    private Integer salary;

    @MyRestriction(expression=&quot;${false}&quot;)
    private String password;

    public MyPojo(String name, String firstName, String password, Integer salary) {
        this.name = name;
        this.firstName = firstName;
        this.password = password;
        this.salary = salary;
    }

    ...     
}
</code></pre>

            </div>
        </div>
    </div>
    <div class="col-md-3">
        
<div class="side-menu">
    
        
        <div class="list-group">
            <ul class="nav">
                
                
                
                    
                    <li>
                        <a href="/docs/seed/manual/" class="list-group-item ">
                            Basics
                        </a>
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/testing/" class="list-group-item ">
                            Testing
                        </a>
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/security/" class="list-group-item  active ">
                            Security
                        </a>
                        
                        
                            <nav id="TableOfContents">
<ul>
<li><a href="#definitions:8c8be46b296d6b9c1a91080fe9b4316b">Definitions</a>
<ul>
<li><a href="#subject:8c8be46b296d6b9c1a91080fe9b4316b">Subject</a></li>
<li><a href="#principal:8c8be46b296d6b9c1a91080fe9b4316b">Principal</a></li>
<li><a href="#user:8c8be46b296d6b9c1a91080fe9b4316b">User</a></li>
<li><a href="#identification:8c8be46b296d6b9c1a91080fe9b4316b">Identification</a></li>
<li><a href="#authentication:8c8be46b296d6b9c1a91080fe9b4316b">Authentication</a></li>
<li><a href="#authorization:8c8be46b296d6b9c1a91080fe9b4316b">Authorization</a></li>
<li><a href="#access-control:8c8be46b296d6b9c1a91080fe9b4316b">Access control</a></li>
</ul></li>
<li><a href="#model:8c8be46b296d6b9c1a91080fe9b4316b">Model</a>
<ul>
<li><a href="#permissions:8c8be46b296d6b9c1a91080fe9b4316b">Permissions</a>
<ul>
<li><a href="#simple-usage:8c8be46b296d6b9c1a91080fe9b4316b">Simple usage</a></li>
<li><a href="#multi-level:8c8be46b296d6b9c1a91080fe9b4316b">Multi-level</a></li>
<li><a href="#multiple-values:8c8be46b296d6b9c1a91080fe9b4316b">Multiple values</a></li>
<li><a href="#all-values:8c8be46b296d6b9c1a91080fe9b4316b">All values</a></li>
<li><a href="#instance-level-checks:8c8be46b296d6b9c1a91080fe9b4316b">Instance-level checks</a></li>
<li><a href="#missing-parts:8c8be46b296d6b9c1a91080fe9b4316b">Missing parts</a></li>
</ul></li>
<li><a href="#roles:8c8be46b296d6b9c1a91080fe9b4316b">Roles</a></li>
<li><a href="#subjects:8c8be46b296d6b9c1a91080fe9b4316b">Subjects</a></li>
<li><a href="#realms:8c8be46b296d6b9c1a91080fe9b4316b">Realms</a></li>
</ul></li>
<li><a href="#configuration:8c8be46b296d6b9c1a91080fe9b4316b">Configuration</a>
<ul>
<li><a href="#realm-configuration:8c8be46b296d6b9c1a91080fe9b4316b">Realm configuration</a>
<ul>
<li><a href="#configuration-realm:8c8be46b296d6b9c1a91080fe9b4316b">Configuration realm</a></li>
<li><a href="#x509-realm:8c8be46b296d6b9c1a91080fe9b4316b">X509 realm</a></li>
<li><a href="#ldap-realm:8c8be46b296d6b9c1a91080fe9b4316b">LDAP realm</a></li>
</ul></li>
<li><a href="#role-permission-resolver:8c8be46b296d6b9c1a91080fe9b4316b">Role/permission resolver</a>
<ul>
<li><a href="#configuration-based-role-permission:8c8be46b296d6b9c1a91080fe9b4316b">Configuration-based role/permission</a></li>
</ul></li>
<li><a href="#role-mapping:8c8be46b296d6b9c1a91080fe9b4316b">Role mapping</a>
<ul>
<li><a href="#configuration-based-role-mapping:8c8be46b296d6b9c1a91080fe9b4316b">Configuration-based role mapping</a></li>
</ul></li>
<li><a href="#example:8c8be46b296d6b9c1a91080fe9b4316b">Example</a></li>
</ul></li>
<li><a href="#usage:8c8be46b296d6b9c1a91080fe9b4316b">Usage</a>
<ul>
<li><a href="#enforcement-strategy:8c8be46b296d6b9c1a91080fe9b4316b">Enforcement strategy</a></li>
<li><a href="#annotation-based-checks:8c8be46b296d6b9c1a91080fe9b4316b">Annotation-based checks</a></li>
<li><a href="#programmatic-checks:8c8be46b296d6b9c1a91080fe9b4316b">Programmatic checks</a></li>
<li><a href="#other-checks:8c8be46b296d6b9c1a91080fe9b4316b">Other checks</a></li>
<li><a href="#access-subject-principals:8c8be46b296d6b9c1a91080fe9b4316b">Access subject principals</a></li>
</ul></li>
<li><a href="#extension:8c8be46b296d6b9c1a91080fe9b4316b">Extension</a>
<ul>
<li><a href="#creating-a-realm:8c8be46b296d6b9c1a91080fe9b4316b">Creating a Realm</a></li>
<li><a href="#creating-a-rolepermissionresolver:8c8be46b296d6b9c1a91080fe9b4316b">Creating a RolePermissionResolver</a></li>
<li><a href="#creating-a-rolemapping:8c8be46b296d6b9c1a91080fe9b4316b">Creating a RoleMapping</a></li>
</ul></li>
<li><a href="#testing:8c8be46b296d6b9c1a91080fe9b4316b">Testing</a>
<ul>
<li><a href="#configuration-1:8c8be46b296d6b9c1a91080fe9b4316b">Configuration</a></li>
<li><a href="#subject-authentication:8c8be46b296d6b9c1a91080fe9b4316b">Subject authentication</a></li>
</ul></li>
<li><a href="#data-security:8c8be46b296d6b9c1a91080fe9b4316b">Data security</a>
<ul>
<li><a href="#restriction-annotation:8c8be46b296d6b9c1a91080fe9b4316b">@Restriction annotation</a></li>
<li><a href="#data-security-service:8c8be46b296d6b9c1a91080fe9b4316b">Data security service</a></li>
<li><a href="#secured-annotation:8c8be46b296d6b9c1a91080fe9b4316b">@Secured annotation</a></li>
<li><a href="#security-expressions:8c8be46b296d6b9c1a91080fe9b4316b">Security expressions</a></li>
<li><a href="#dataobfuscationhandler:8c8be46b296d6b9c1a91080fe9b4316b">DataObfuscationHandler</a></li>
<li><a href="#custom-annotations:8c8be46b296d6b9c1a91080fe9b4316b">Custom annotations</a></li>
</ul></li>
</ul>
</nav>
                            <script>
                                seedstack.state.previousPage = '\/docs\/seed\/manual\/testing\/';
                            </script>
                            
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/crypto/" class="list-group-item ">
                            Cryptography
                        </a>
                        
                            <script>
                                seedstack.state.nextPage = '\/docs\/seed\/manual\/crypto\/';
                            </script>
                            
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/web/" class="list-group-item ">
                            Web
                        </a>
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/rest/" class="list-group-item ">
                            REST
                        </a>
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/operations/" class="list-group-item ">
                            Operations
                        </a>
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/transactions/" class="list-group-item ">
                            Transactions
                        </a>
                        
                        
                    </li>
                    
                
                    
                    <li>
                        <a href="/docs/seed/manual/more/" class="list-group-item ">
                            More
                        </a>
                        
                        
                    </li>
                    
                
            </ul>
        </div>
        
    
    
    <div class="list-group">
        <ul class="nav">
            <li class="list-group-item"><div style="margin-bottom: 10px;"><i class="fa fa-tag"></i> Tags</div>
                <div class="tags">
                    
                    <a class="label label-default" href="/tags/authentication">Authentication</a>
                    
                    <a class="label label-default" href="/tags/authorization">Authorization</a>
                    
                    <a class="label label-default" href="/tags/permission">Permission</a>
                    
                    <a class="label label-default" href="/tags/access-control">Access-Control</a>
                    
                    <a class="label label-default" href="/tags/identification">Identification</a>
                    
                    <a class="label label-default" href="/tags/role">Role</a>
                    
                    <a class="label label-default" href="/tags/data">Data</a>
                    
                </div>
            </li>
        </ul>
    </div>
    
    <div class="list-group">
        <ul class="nav">
            
                <li><a class="list-group-item" href="https://github.com/seedstack/website/edit/beta/content/docs/seed/manual/security.md" target="_blank"><i class="fa fa-edit"></i> Contribute to this BETA page</a></li>
            
        </ul>
    </div>
</div>

    </div>
</div>

    </div>
    <div id="footer">
        <div class="footer-v3">
    <div class="footer">
        <div class="container">
            <div class="row">
                <div class="col-md-4 md-margin-bottom-40">
                    <div class="headline"><h2>About</h2></div>
                    <p class="margin-bottom-25 md-margin-bottom-40">SeedStack is an Open-Source enterprise-class development stack for building modern and robust applications.</p>
                </div>

                <div class="col-md-4 md-margin-bottom-40">
                    <div class="posts">
                        <div class="headline"><h2>License</h2></div>
                        <p>
                            Code licensed under the <a href="https://www.mozilla.org/MPL/2.0" target="_blank">Mozilla Public License 2.0</a>.
                            <br/>
                            Documentation licensed under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.
                        </p>
                    </div>
                </div>

                <div class="col-md-4 map-img">
                    <div class="headline"><h2>Contact us</h2></div>
                    <address>
                        <p>
                            IRC channel <a href="irc://chat.freenode.net/seedstack">#seedstack on Freenode community</a>
                            <br/>
                            Google group <a href="https://groups.google.com/forum/#!forum/seedstack">seedstack@googlegroups.com</a>
                        </p>
                    </address>

                    <div class="headline"><h2>Stay in touch</h2></div>
                    <div style="margin-bottom: 20px;">
                        <a class="twitter-follow-button"
                           href="https://twitter.com/seedstack"
                           data-show-count="true"
                           data-lang="en">
                            Follow @seedstack
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    </div>
    <div id="hotkeys-modal" class="modal">
    <div class="modal-dialog" style="min-width: 960px !important;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Keyboard shortcuts <a id="show-all-shortcuts" style="cursor: pointer;" onclick="seedstack.ui.showAllShortcuts();">(Show all)</a></h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-4">
                        <table class="keyboard-mappings">
                            <tbody>
                            <tr>
                                <th></th>
                                <th>Global shortcuts</th>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>?</kbd>
                                </td>
                                <td>Show this help dialog</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>/</kbd>
                                </td>
                                <td>Focus the search field</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>alt</kbd> <kbd></kbd>
                                </td>
                                <td>Go to previous menu item</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>alt</kbd> <kbd></kbd>
                                </td>
                                <td>Go to next menu item</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>S</kbd>
                                </td>
                                <td>Go to Seed framework</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>W</kbd>
                                </td>
                                <td>Go to W20 framework</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>B</kbd>
                                </td>
                                <td>Go to Business framework</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>A</kbd>
                                </td>
                                <td>Go to add-ons</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>G</kbd>
                                </td>
                                <td>Go to guides</td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-4 hidden-shortcuts" style="display: none;">
                        <table class="keyboard-mappings">
                            <tbody>
                            <tr>
                                <th></th>
                                <th>Seed framework</th>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>b</kbd>
                                </td>
                                <td>Go to basics</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>t</kbd>
                                </td>
                                <td>Go to testing</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>s</kbd>
                                </td>
                                <td>Go to security</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>c</kbd>
                                </td>
                                <td>Go to cryptography</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>w</kbd>
                                </td>
                                <td>Go to Web</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>r</kbd>
                                </td>
                                <td>Go to REST</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>o</kbd>
                                </td>
                                <td>Go to operations</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>s</kbd> <kbd>T</kbd>
                                </td>
                                <td>Go to transactions</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-md-4 hidden-shortcuts" style="display: none;">
                        <table class="keyboard-mappings">
                            <tbody>
                            <tr>
                                <th></th>
                                <th>Business framework</th>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>b</kbd>
                                </td>
                                <td>Go to basics</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>m</kbd>
                                </td>
                                <td>Go to model</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>l</kbd>
                                </td>
                                <td>Go to lifecycle</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>e</kbd>
                                </td>
                                <td>Go to events</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>p</kbd>
                                </td>
                                <td>Go to policies</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>a</kbd>
                                </td>
                                <td>Go to assemblers</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>f</kbd>
                                </td>
                                <td>Go to finders</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>b</kbd> <kbd>P</kbd>
                                </td>
                                <td>Go to pagination</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4 hidden-shortcuts" style="display: none;">
                        <table class="keyboard-mappings">
                            <tbody>
                            <tr>
                                <th></th>
                                <th>W20 framework</th>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>w</kbd> <kbd>b</kbd>
                                </td>
                                <td>Go to basics</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>w</kbd> <kbd>s</kbd>
                                </td>
                                <td>Go to security</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>w</kbd> <kbd>c</kbd>
                                </td>
                                <td>Go to culture</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>w</kbd> <kbd>h</kbd>
                                </td>
                                <td>Go to hypermedia</td>
                            </tr>
                            <tr>
                                <td class="keys">
                                    <kbd>g</kbd> <kbd>w</kbd> <kbd>u</kbd>
                                </td>
                                <td>Go to UI</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="versions-modal" class="modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 id="versions-title" class="modal-title">Fetching components...</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <table id="versions-table" class="table table-striped table-hover table-bordered">
                            <tr>
                                <th>Component</th>
                                <th>Version</th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/styles/github.min.css">

    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.4.6/mousetrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lunr.js/0.5.9/lunr.min.js"></script>
<script src="/assets/unify/plugins/smoothScroll.js"></script>
<script src="/js/xml2json.js"></script>
<script src="/js/jquery.highlight.js"></script>
<script src="/js/seedstack.js"></script>
<script>
    $(document).ready(function () {
        var $search = $('.search-btn');

        $('.search').click(function () {
            if ($search.hasClass('fa-search')) {
                seedstack.ui.openSearch();
            } else {
                seedstack.ui.closeSearch();
            }
        });

        $('pre code').each(function (i, block) {
            hljs.highlightBlock(block);
        });

        $('.side-menu').affix({
            offset: {
                top: $('#header').height() + 20,
                bottom: $('#footer').height() + 40
            }
        });

        Mousetrap.bind('/', function () {
            seedstack.ui.openSearch();
            return false;
        });

        Mousetrap.bind('alt+up', function () {
            if (seedstack.state.previousPage) {
                window.location = seedstack.state.previousPage;
            }
            return false;
        });

        Mousetrap.bind('alt+down', function () {
            if (seedstack.state.nextPage) {
                window.location = seedstack.state.nextPage;
            }
            return false;
        });

        Mousetrap.bind('?', function () {
            seedstack.ui.openHelp();
            return false;
        });

        Mousetrap.bind('esc', function () {
            seedstack.ui.closeHelp();
            seedstack.ui.closeSearch();
            return false;
        });

        var originalCallback = Mousetrap.stopCallback;
        Mousetrap.stopCallback = function (e, element, combo) {
            if (combo === 'esc') {
                return false;
            }

            return originalCallback(e, element, combo);
        };

        function bindShortcuts(value) {
            $.each(value, function (sequence, item) {
                if (typeof item === 'string') {
                    Mousetrap.bind("g " + sequence, function () {
                        window.location = item;
                        return false;
                    });
                } else if (typeof item === 'object') {
                    Mousetrap.bind("g " + sequence, function () {
                        window.location = item.path;
                        return false;
                    });
                    if (item.shortcuts && location.pathname.indexOf(item.path) === 0) {
                        bindShortcuts(item.shortcuts);
                    }
                }
            });
        }

        function resolveVersions() {
            var $versionsTitle = $('#versions-title');
            if (!seedstack.versions) {
                $.ajax({
                    dataType: 'text',
                    url: '/distribution.pom.xml'
                }).done(function (data) {
                    var pom = new X2JS().xml_str2json(data);

                    if (pom.project && pom.project.properties && pom.project.version) {
                        var $versions = $('#versions-table');
                        var versions = {};

                        $versionsTitle.text("SeedStack " + pom.project.version);

                        $.each(pom.project.properties, function (name, value) {
                            if (/\.version$/.test(name)) {
                                versions[name.substr(0, name.indexOf('.version'))] = value;

                                $versions.append(
                                        '<tr>' +
                                        '<td>' +
                                        name.substr(0, 1).toUpperCase() + name.substr(1, name.indexOf('.version') - 1).replace(/-/g, ' ') +
                                        '</td>' +
                                        '<td>' + value + '</td>' +
                                        '</tr>');
                            }
                        });

                        $('.loginbar').prepend(
                                '<li class="hidden-xs hidden-sm"><i class="fa fa-tag"></i> <a style="cursor: pointer;" onclick="seedstack.ui.openVersions();">Version ' + pom.project.version + '</a></li>' +
                                '<li class="topbar-devider"></li>'
                        );

                        seedstack.versions = versions;
                    }
                }).error(function () {
                    console.error("SeedStack version could not be resolved");
                });
            }
        }

        bindShortcuts(seedstack.ui.shortcuts);

        resolveVersions();

        $('[data-toggle="tooltip"]').tooltip();

        $('#hotkeys-modal, #versions-modal').bind('hidden.bs.modal', function () {
            $("html").css("margin-right", "0px");
        }).bind('show.bs.modal', function () {
            $("html").css("margin-right", "-15px");
        });

        var query = seedstack.strings.parseQueryString(location);
        if (query.h && query.h.length > 0) {
            $('.doc-content').highlight(query.h);
            if (query.scroll) {
                $('html, body').animate({
                    scrollTop: $('span[class=highlight]:first').offset().top - 20
                }, 250);
            }
        }
    });
</script>
<script>window.twttr = (function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {};
    if (d.getElementById(id))return t;
    js = d.createElement(s);
    js.id = id;
    js.src = "https://platform.twitter.com/widgets.js";
    fjs.parentNode.insertBefore(js, fjs);
    t._e = [];
    t.ready = function (f) {
        t._e.push(f);
    };
    return t;
}(document, "script", "twitter-wjs"));</script>

</body>
</html>