diff --git a/DISCLAIMER b/DISCLAIMER deleted file mode 100644 index 54053adb..00000000 --- a/DISCLAIMER +++ /dev/null @@ -1,10 +0,0 @@ -Apache Amber is an effort undergoing incubation at the Apache Software -Foundation (ASF), sponsored by the Shindig PMC. - -Incubation is required of all newly accepted projects until a further review -indicates that the infrastructure, communications, and decision making process -have stabilized in a manner consistent with other successful ASF projects. - -While incubation status is not necessarily a reflection of the completeness -or stability of the code, it does indicate that the project has yet to be -fully endorsed by the ASF. diff --git a/KEYS b/KEYS deleted file mode 100644 index 6b989676..00000000 --- a/KEYS +++ /dev/null @@ -1,321 +0,0 @@ -This file contains the PGP and GPG keys of Apache Amber -developers. Please don't use them for email unless you have -to. Their main purpose is code signing. - -Users: pgp < KEYS - gpg --import KEYS - -Amber Developers: - pgp -kxa and append it to this file. - (pgpk -ll && pgpk -xa ) >> this file. - (gpg --list-sigs \ - && gpg --armor --export ) >> this file. - -************************************ PLEASE NOTE ********************************************************** - - Edit this file in SVN at - https://svn.apache.org/repos/asf/incubator/amber/trunk/KEYS - - N.B. use a command such as the following to check it out without downloading every Amber module: - svn co --depth=files https://svn.apache.org/repos/asf/incubator/amber/trunk/ - -************************************************************************************************************ -pub 4096R/62590808 2010-04-14 - Key fingerprint = 0D7E 15FB 2B3A D181 21B9 74C8 0B66 2050 6259 0808 -uid Pid * (Stuart Williams) -uid Stuart Williams (Identity) -uid Pidster -sub 4096R/4762F81E 2010-04-14 -sub 4096R/A93AFAFD 2010-04-14 - - ------BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1.4.5 (Darwin) - -mQINBEvFfXkBEAClvXQ4bG3ib0nQQfEpmlZaZyAGi+4njhhDAP/n5Zbi2wLcAnlR -WF3FyrSOnFns9V1gNA6zdLPhUs1KwH5vBDlU2ZkOF3b6pGhAdTr0HPefEBwz6StK -Jlch9t+xJjV/llA2/n5UUkCLw3gqyJQMvbFSfzLT9YGF1ehsngvK/vRGIqZ+TIoC -+lGasSJ8B692unnvDF+MSdNu7X2ioQJP/1SPLg+/fHGZQr3zdjf6BOJSHTd7yg6E -/jCYe2F8TxdcoMdYuSNIf3B+whMHltq9HdHipZj5/JCo9tKyQuzk1I9kdgsFehIe -fd4mnrwlv87CM0q6m4FgzivG6/gIJiddgfUHAqmRvDh5CtXHLzXEDGJEA8xkQ+Jc -AAbgOYfGyYh+1D59U5R5qoUkVeb2tM6SUpHOYK9E8H5Pml4kHyXFctdq8kD5y+dN -A46/ru3bQEYNcBlyGEpOPs8okmoBxYlUCMdH38YDLbBEverDh1tJZ6TrNWEr9if8 -vtljEZc/Mebh9n6btImmrHszAs6M5qHNvuHaWfTuuXwPEhsdcFF0jLMREUMFRicc -CSibwKxnHua1u9JlufYaJUeJifnI/ugpIS8Lbaaj3BDT9DIWVbIJKr5yAdFv3nVV -IOiyhxQh85y6yOoXsTR80ADu5fvaXbiEOhD5hsvcRlP/q9m2Vxpul8O0ewARAQAB -tClQaWQgKiAoU3R1YXJ0IFdpbGxpYW1zKSA8cGlkQHBpZHN0ZXIuY29tPokCOAQT -AQoAIgIbAwULCQgHAwUVCgkICwMWAgMCHgECF4AFAkvNfeICGQEACgkQC2YgUGJZ -CAj6JA//b1YL1D8WvPyeYlln6oKxDsJuKYZpJKwL8MI/SvXQZ974FPvCqBsPU0wl -G84hfDvoaBc4affWNxlAkubPmhCtYBqI6BN0AIS1pigxnpAPMToch5bb7TqHFVjS -AIQu6EnfWKi7uoZIlUvA6FOwXeJMKG5lPl1WvEhVi/UP29zXvimikSM2DRIqj0Vc -J865GWzmA8oopvfP3wmpmNeHXcswbnrQ6f/8AFokg9Vxv5lasA70wsiFK7CEO+24 -Fm4VXl9TAUY40g8BWgca4hkRTpsjXHp115CdFOc9IHJygQBzizlzJHt4NYMOF1/N -dp8p6lfdo0Iynttzx0C8Yn7feAsbN5jxBxvYC3haknqCKb1VWwesTwZTPvWoNCH8 -okC6LCP6lMzYQhwNiVLNfviR6V41An/ACFK4luxRQDFP1AXc8xTs90WtXgk3UkY4 -CGLLatH386dkeFrTNVPmxGTVlTEtLYRQIOqgcmL05FJ9nPaDVD6gQv8SIfp4UdL5 -HM6Mv4off60w3kPvIoHiT8YeoVET+OH7xKpVB6CeoMvwcLAN2Of8+dUhwAvEyk9g -RW+CXuLFG9Tly3cuAjz0CdFkHEv+gg87kmzb7ArJ71wh5PRc4s7GMrWE7zBvc10u -qUT3W3mWThJS27IG0eo2NmfjSk7tZ/wmVJ/96qHURTJSMeJbuAu0OFN0dWFydCBX -aWxsaWFtcyAoSWRlbnRpdHkpIDxzdHVhcnQud2lsbGlhbXNAcGlkc3Rlci5jb20+ -iQI1BBMBCgAfBQJLxX15AhsDBQsJCAcDBRUKCQgLAxYCAwIeAQIXgAAKCRALZiBQ -YlkICM+AD/9LdUKcABy5cWxQohXDu40mZCLodP5A3boZF+L2O9jpK/lUSnFewKEJ -znavs2RLCwpzRcJDNqRc6vEzOyrbQvAs6vMNygAGETB9uxaEKesknj0ZxCsqqxV0 -VujHYdRlVg4qwsKftrXv4K5nCLkBRv3YZQ0JzcX/wRlfz81SlINoM/IuT5+QzCGK -SjxrM1xrhxZgwHIitNCR5BHl+CsqjpjDPLJj1mFqPTLniKKUZCB7uN2e38FYazKG -UIeQXq/e989zTimvQ24AYUjoGnTuqg1liPd3pKq0ryAvdYZTUpj98CZZ6jCCkDis -AOSJerwXZzB/o9ADX2mFJukdD3MXLRJcAdV1CrEg4DGau8w6JYROgUc+C4RONmih -sXKyhI7Nj97t822Rj1NAO7z3ptnAwSJGx6WSxFGvWht14vuQLf9bH6FzBlhIxUKh -DWIqq29K22ck6Fqb5dHbRyE5253tWt0y48dx5W1kP6LOW9zhLN3NBw59SN4O8H6c -2jP8j8qExeswpbECiq+gdnqMGkRjDKQwxf93OhmCbCTYXtZtgJttLVCg7gXXlNbT -MrEfbWkZFd21RvGu3LTnWfZLtmKvg4Qe89UTAla/phpJKgYF/WAFbC9E2jmh8kQo -+ETHw+EFWYy4RjjIthmGegGQ45KbxZA36woKHjsmnB0eZdA1RUXf+dHMkcyPARAA -AQEAAAAAAAAAAAAAAAD/2P/gABBKRklGAAECAABkAGQAAP/sABFEdWNreQABAAQA -AAA8AAD/7gAOQWRvYmUAZMAAAAAB/9sAhAAGBAQEBQQGBQUGCQYFBgkLCAYGCAsM -CgoLCgoMEAwMDAwMDBAMDg8QDw4MExMUFBMTHBsbGxwfHx8fHx8fHx8fAQcHBw0M -DRgQEBgaFREVGh8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8f -Hx8fHx8fHx8fHx//wAARCABkAGQDAREAAhEBAxEB/8QAmgAAAQUBAQEAAAAAAAAA -AAAAAAECBQYHBAgDAQEAAgMBAQAAAAAAAAAAAAAABAUCAwYBBxAAAgEDAgUDAgQE -BQUAAAAAAQIDAAQFERIhYRMUBjFBUSIHcYEyQpGhsXLwUmIjFcGCsjMkEQACAQMD -AgMFBwUAAAAAAAAAAQIRAwQhMRJBBVFhInGBkcEy8KHREyMUBrFCUmJy/9oADAMB -AAIRAxEAPwDytQBQBQBQBQBQBQBQBQBQBQH3nsL+CGOee2ligmGsMroyo4+VYjQ/ -lWKmm6J7HiknsfCsj0KAKAKAKA6cdjMlkrlbXH2st3cNxEUKM7afOig8KxlNRVW6 -I8bS3Lvj/sb57dKrTw29gDpwuZl3AH5WPqEfnUGfdLMetfYR55dtdT5eWfZ/yTx+ -xW9jdMnAOFx2quWi5lSNSv8AqrzG7nbuy4/S/PqY2cyE3TYq2F8czebkmjxdo1y1 -uoecgqqoCdBuZyqjU+g1qbcvRh9ToSJTUdy14X7PeRXLbsppj0HExfTJLp8kA7UB -9tTryqFe7lCP06ke7lxjtqWyy+znjyoOq007a8dzkf8AiEqvn3WfShFlnSJS38A8 -N8cQ5i7jSzgg+rup5XkII9owdo3H2AVm+K1PNvXvRHVs1vJuXPStSGtvuphctm7f -Dx4qRrO7lW3iup5d7lnOxd8RDLsOuhGvpUiXbpwg58tVrp+JteHKMXKuqMq7OP8A -57stP9ruujt/09Tbp/Crrn6K+RY8vTXyLB4He+AWPXuvJYri4vUb/wCOFI1kgC6f -qYFl1bX014VGy4X5aW2kuviaciNx6QaSLxZfcz7f3Ti0mt5bZH0US3METQryZUL7 -R+C1WywL8dU6+9kR412Oq1LOfEPF7qNZ4sVY30DruSaCGIRsD77ogv8AWory7kXR -uSftfzNf7hrRtoi737YeJ5mIwx2keDMMqu17AznqKARJCEldh7g7vQHhUi3nXI66 -y8vnsboX5rVeov3ivjfjfjWMNrhIBGZNO4uCweWUj/PJ/wBBwHxUDIyZ3HWRHu5D -lvuSDTon1tpoPUk8KirciKWuw0TzbS0Fq8gHDgAuuvxvKa1moeNEbFB+CIa7wlrH -c3F3YY8W15dSRtflV27+mjhHIBKk6ycSPzrersmuLdUtjbG5L6GceVymDwdjvzN7 -DZBQWEQ06j/2xL9TE/hSFq5dlSKr9vEx4znKkVUynyT725q4ke38fjXHWS8EndVk -uXH+Yltyp+AH51dWO0wiqz9T+4n2sCK+rVlAyeZy+Ul6uSvJruT1Bmdn0/AE6D8q -srdqMFSKSJsIRjsqHPb3E1tcRXEDmOeF1kikHqrqdVI/Ais2k1RnrVdBOvN1+vvP -W3dTqe+7XXXX51pTSgoMr09CgOrH5bKY6ZZrC7ltZFO4NE7JxHzoeNYTtxkqSVTG -UFLdVPW/2Vkj8ww9tNcXiYi9u4t+xEDC4mjd0cruI9k3befD0qkt4MJXZW3J+nYr -7dlc5QrtsS2UwUtni8Zl72S2WXILoYl1gnVtG1DISeovD19j7VozMN27fJOq8DLu -WJ+U2q8kmdOD8Lyd/Y3OZhVI7eBZmSecmR2aEHVYoh6Dcu0tqPzpidvlchybpH72 -YYWI501omTKeFYq38ct87mcvPGlzDFKkMEaK2+ZAwjUP1C548vmpb7ZZhDlOTob7 -+Bbtylyk/S9zMvLfL7Hx/AS5QM0vQmj0i4K8kbuVChiNpO3j9PDh8VW2cfnc4x0T -rSvzIVu3V0j1PL+Yyl1lspdZG6cvPdSNIxY66bjqFGvso4Cupt21CKitkW8IqKoj -jrMyCgCgCgDQ/FAFAJQGo/aj7g21giYLKMqRbj2Nw/BPrOrQyH9oLfUjftb14Gqj -uOG5PnDfr+KK/Lxm/VHc2pmxk+s1wI2MY2OLjQlNfZg/of8AAqglO43q2yrc5t6t -sl8N5lf4GCS1xd3vSQa9nos6Ekfq+rgnD1OvEVMxs67aVOnmSrGVOCIjyLyeWRTk -PKLwR2Fsn1KWBXaBwiREVERT6aKNW9K8neuX5Jbvotkvt4sxdyd2eup5y+4vn975 -blS41hxVuSLG09AB6b2A/cR/D0q/w8RWY/7PdlrZsqC82VKphvCgCgCgCgJI2fKg -ENpyoBptOVAIbPlQGoeBfdRMfDDj/JImuIrcBLXIhQ8saegR9eLAexHGqfM7Y5Pl -b08V0K/Iw6usPgaJifMsLnp7m2wUxKWsPcXD9Jo0Qa6cAwXc7VU3cOdujmt/Mhyx -5R1kjztmsnls1ePdZC5kuHYkoHYlVHsFX9I4fArqrVmNtUiqFzC2oqiRHdoa2GYh -tWoBO1agE7dqATt3oA6D0Baez5UAhs+VAN7TlQCGz5UB14XCLkcxZWLaqlzMkbsv -qEJ+oj/t1rVfucIOXgjC5PjFvwPQ2A8VwGChljxFkIY7oK0zMzOzhR9OrMT81yd7 -JndfqdaFVK5KW5nv3N+2WBx+HlzeHia3kjlU3NvuLRFJTt1RT+naxHAHSrbt+fOU -1CepLsX23RmVG05Vdk0Q2fKgG9nyoBOz5UA3tOVAJ2lAWzs+VAIbPlQDez5UAGyI -AJUgN+kkcDp66UBKeKWhXOwuB9SRzMv93SZV/mwqF3B/pP2r+pHyfoN6idIrdRt/ -9aBFHwFGgrlGqldUoXlmSkuPHvKbaVtRHNaRQofYSrGx0/PU1Z4Vv9S2/Gv3VN2O -vVF+0yc2fKulLMQ2fKgG9nyoBDZ8qAb2nKgE7Tj6UBbOz5UAhs+VAEePklkSKNS8 -kjBEQepZjoAPxNYykopt6JA9H+M+BYV/EbXAZrGRsY4I5JoX0Z0nkB6jLIvENqP2 -mvjPc+93llyyLFx0cmk1s4rbR/Mso21xo0Zl434bZ2n3JzVpEGNhhyFgDncxaVt0 -YY++0Jr/AArvLncpXsK1cl9dyNXT4FNmpJ8UX2/tI1jOnxVdauciBJGc+QYcta+T -sy8JILO7i/uhZlf+SVb4l6k7a8G18TOxLWPk2Z6bPlXTFmJ2fKgGmz5UAhs+VANN -nyoA7PlQFrNnyoBOz5UB3+K2OV/5MXdlZ3lzd2JSaPtoYp0U6kAsjcT7aaVzneMl -Qtu3fkoW7lV4V95KtRi9Vujf/Fchkbq0t5sqjQ5Ca3DSxSJ0n0SRwpaPU7SVOulf -J+52LcJNWXytqWj33S6kyLM0yeYxuN+4ObgnbY16++aMqwdRHGCJHI1HTKfu9uGt -d122254Vvrxj89vaUvcLTUudfcSN55BjJIty3cJUjgeommh/OpFuy49CrkyJt+lm -5cvDZuslr2faNcg6r133kqP7BoT+Nb2/y+Le/KvuM1FxSZnltib24VzHbOzROYpl -A4q6+oI9a6n95a/yWpawXNVjqj5tZMrFWXRlOhB9iKkJ11QGGz5V6BDZ8qAabTlQ -CdnyoCyNsHtQHyeSIUBcft5594x48JocjavHPM3HJRjqapw0RkH1KFPxrXCfyzsm -bmTUrb5W4rSHn1fvLjCtWZQ0nGNzqpafCW3xoW+7+7ngS3sTRX0ku9GBEVvMxLnT -b9O3UnTX0FcjZ/jmaoNShTXq0SbmI4R5OVtL/uH4meea3mVz2bubrEW04sJ40UNd -J2xP0qJAAzK+19o11U12vaLFuxjKN1/qKu2vsOXzpWXc5KVX5FXzWLMmZnsjaRyX -eSeSa1OisQh9Sx9V6X9NNKvMTLtxx9f7NPf0+Jqs30rfsLZYeRZHENdw3GFmmspJ -Wliu7QK8p1UDWVN3H9OmvDQfNVH7eFyMWppS6p7e5kePFxWupUchPaZa/lu3ZreU -6L04ZHRlAJI36bdW4+pFX+NgwjBJvl5lhjL8uNE6nQiRbQAddBpqTqfzNT0qKhsH -9up+K9AdoPigE7PlQCdpyoDpePUUBzS2hb3oDhmxjtrxoDhGMyVtcd1Y3MlrdKjR -pNGeKq/BtAdRqa13bMbi4yVUYTgpKjJseYeYL1EdLaZXjYCRlIYPoqof3ahdGY/J -NVcuzW9KNkd4i8Srtjsq14b03EneFt/chiHDcj8cvSrNWIcOFFx8CR+XGnGmhcbb -zrJW9lBbyY0z35LCW5VtseqAFG/B/q3D2PzVJPs8nN0fpIX7N102IfKXOazGQF3d -mOJYnk6EcSAExSbdElb9xUrw0qzw8NWFo9Xv4EqzZUD6w20w9TU03HbHG49aA6UB -oB1AFAFAJwoBDtoBjdL3oBh6NAN/2OVAA6FAOHSoB46dAPG2gHUAUAUB/9mJAjUE -EwEKAB8FAkvFgVQCGwMFCwkIBwMFFQoJCAsDFgIDAh4BAheAAAoJEAtmIFBiWQgI -FNsP/2//2YK8VlBnwxuoiVnaa3064H8J8rGm8ugXLrcVXp+0iWIFzQCEnYUITHXm -Bw5B6ezdJvRL/M7ibMHAPtVxivkSrpARkGdaX65r8WxgVyquMUkqpywZFtmFwPzo -xXnxXDb3G5QIrHlh9QCwLtFYBOAx1XZTK4AJSutwEOyFBSPxenGj2jB2J9hYW02l -CSklcsjHMGFI2awM0XeusuyYdESmYDyh9Zr4SkU0GsDVUhhjWW6i3DI8OzIfR0km -ef31dAXP6pt+yis+C5j2/S7cDMdWtGXvBfPK4SjxQXqkY1iwnIwz1ZmQXRMloS2P -H1IDzWYVYGBmNG7kn6GgXAOtu+7KcmjTalJYFI9/W4HK1wcwsBNTQVQmORW3QB4b -aruQfzzFnqWKCOGoLPOH4Z0yyL0Z07SEHG9qjtymiBBw8AX/N2NVnKQPNb6FBM+I -SNJBrnyx0sBT4/zJevc3QGUnp8eeRFGTtdlrm++740NK2YYehUO4L86TsWKgoRdn -X/Hj0LNHAdCC0KIZhxiFIGyfmuceXoV4yH5nAw93DatqpvN+wd/FtbBqGHA8c7pr -zuttqsFmox/yAiR+CK01ojnvY6c0rp2XjfS7A3DUjNtcbuE3D69ZdX2M29ZJlXwv -5jieMWVDHdcII3vl0F9ko4L8+8QtCdFG0E2b2YJpEOoMiGQatChQaWRzdGVyIChC -dXNpbmVzcykgPHBpZEBuZXV0cmFsZ3JleS5uZXQ+iQI1BBMBCgAfBQJLxYltAhsD -BQsJCAcDBRUKCQgLAxYCAwIeAQIXgAAKCRALZiBQYlkICKYED/0dNygZPZd+Mfrz -WzuBQmvviegHSGfQSru+fHlYLL+P5JWynQUFH+7gjmWDdiJiLmwCSGO/ihJ9rlin -6B3WOE6wifcSn6mr4uSqPbsJH1FaUZWuE/wZ6T8x1rNz2oHRQ85YZWwH+19dApoJ -dqx8w7yp74+y0CM4gmbVlfW1D0d+1lbyfXd5l1S4iCWppwlOBjjAv9Pqa3GDUlFh -Aw6qTt+vGfKQPaJTF1u7A8+hmzBa7jcHjzygyiV0D4oRQfYDORXxQPM/y1/MZ5DZ -caglmijo5hlHZdJiOh2LLe89f8MARB/di7v1IqwmZlpKHSMflEno41xSdjHi85FD -LV647CLEY5IE+FAAsXtEXkLutHzGXTlj4vC+WDeTt10lTm+i+AJIx8ROP0JwwGT7 -QI9Rv/q8W6U5dpfBoYD2jZxDmxCJ/fvMqfgEBeBdoqYjbJdDsNYTB7WA3dyflGAo -ShFrSBtpv8ytYq+EVyds9Zvi+xYdPIZo9RSKyhoSNc/u/TmQcQLSVttMQprO6X5Z -k48Kr/MkkOeLvuTzL9I1nMOOfe5I7TwCfD8T3gjyO94hs3nyGHPhQNsHevyU+JCN -VO5dF6q/d38RqvjTCVAjQdk3/Xexg+TifArr3mL/q/9CSXxtgql3L2JI7tgHGeRP -eZUF7dCCpdGJhvdWRFkYrMiO4dbCfYkCNQQTAQoAHwUCS8WAVAIbAwULCQgHAwUV -CgkICwMWAgMCHgECF4AACgkQC2YgUGJZCAg8lg//TKtHKQgQ+YZPPt1XD/5g9yx7 -L7k3A1jMETToqlGaTawYZNV0nQRHGwzWLunC26+rhOu5UKjBjKYXiGKt/kZJnJcm -1rriLLl9nn/PAF1/SfoxPhkHNA8awomZrLKXfMR0c20Fa8/k+bSkQaWSIyO7+Iua -pTCQrmTfiCrEYmZKuEBseZDI52IvN5Krv8dKsJ5lt9Lzps/jjAmmeRNqhmUpJRSY -MJdRft63jzJ01XRvtnQKLK3tSga3ZboJZmGFTBz8gbxoIKpT34LSmtDT1H4+l1h/ -H9M+so6WMy6Pb/mp78KjpQoqCdEXu3WOPm34p2o6nIu3/NVhNsn0FDypeuO6TxWR -zcVWSwZZHf2ucjOnt9AUAuixk/t10yYtpyk6WfeytFRokJyMxqSczh2Q3ruoke+b -F46kS5P+ip60KuFuHU86uGwMb4dPCAysEg7zM0qLTdjlaDwEASuL6uucplyIfFhi -725qrDR89obIzQGY7/bFgbvqpaXBV1yVZNIGXOjtmy1Fx/U3eaZ/bIhHah+YmXNK -s9XQPyVzMFXyCypHl9+SetYneWjJAnYm5mHJzWMOMOgeXCwKYsogCRoxif3ehJwb -pBaqLorz/wQ9qXZasi+G/pTock1O0QobiYPOYTT+cljnX7+3NcKm1sUbHL8qt2EG -EacT9mGwcZ3Ol4CXZVK0HFBpZHN0ZXIgPHBpZHN0ZXJAYXBhY2hlLm9yZz6JAjUE -EwEKAB8FAkwTS60CGwMFCwkIBwMFFQoJCAsDFgIDAh4BAheAAAoJEAtmIFBiWQgI -cD8QAIAuzd10zuGOCxi1rmWTTecYZb9Cc1RzWna12PI2FniFYqncQPlkkP+lhnZg -Z36Fpsv1ZJuzP/brmitiiR5ewdAVefhdHqZps7Y+cQp60RT1mAZ3mUR3kC/TeSr2 -kfG/BnFjGD/59BRP3QvOsYNbcB16HeIAqGpt0XrL+dhSyIFeD2IOpAlTmRHKP7WK -qEUcdIfiYWtQv0Xk47HL3819EjnKPm1Ee1RpOG5DxV/X3fX07XnNAeqgwFbUK1eQ -GqUZmvasZeLPOZDFQIEK5VCOHm//z0T5JfudPJwRINRNesDvhK5GvF0xQVIMV1cQ -jL90hgxaoUeti9WmFyjhgpQHM3jK0tdhcRBm96/HlIt0dbb2ZqGEIRc69V6Tsnux -eZFtToE7fuZHsEZMON4O7sRyXwEw2SeEQrPAetwsSYazGt4vmbjQlYkQJpdffwAj -j94xE7PqWUtWmvX1a7td7mRCuHvCUYqTRoKd9XVEm7du9S2l/SBptiM+uVzV7Dm6 -gYUB1QORStDAg18g5SzFV74Tc0STvfTYskdK0ZrlXICaJ4la5aTtoXlSbMMA4eay -XkDdh2cS12r42yeZQhS1QPOtdOyIx7VS2JPfJd9T+7OImzmbMnIPMr9u8Of/PD9l -5MfuNnuXa6awIWTKkmXOTjw4OIxBHgSSOgI3qfwlws2w0PAduQINBEvFfXkBEAC9 -GUNu8RZ/zY4BX8snhKcxZrv8FirsDPzcASJn3RUSadGyJJw+0sf0pUg80Zj5nK3X -4c/vqMeu3Du8X88CSLCW6BcKJu/jsFv3qh9htzSiC+wIv+pdHyPLG+Wfqr75rxVO -iQvGajPAIE2/jITbI4NYhq3SjzDjzn+YZeR5QsA2Uj7c8Kqnc9o6ZgZaNgkvN4vx -fleRS8ubzW1HsfPaDIJzvg+u4E5lKWdqNv1D+rUmshrrSgpVZD7m+SlMbAiC0Xrl -2cpYB+oFeEPTM6v8+KORTNnJGVGFBTKGs6lzyrS8Pq411e4bSaoG9VHjaRahrmtw -27kg58Hg9FZRtilQblLFWFxx/Rg/tAnzUBcll/xiKHpcshDAr1VKn8TcoFMjrzOP -mfwxC6LOIdjLcY0XNSjUM6vNcnJrmsTKOgZGkD+JZk5pSsxnMWNU7VgKWO/Wmjvy -5qUa7FZkh/A7FPus8eLf/711NstUB6+6k/0eoZaVvtZ5MVKhBrkYscLNGOtaV7hw -m+0cjQGLK/x0ntj6NciF9pMiGpC+AP0XVIv4rdjA4MC2ZMOf2UttfkzXWIab70Mr -vxJw9m3VknWOBXTzKDLzTtD4Y0AIGVyzqz86dHlrLXK5Zwort/tFOjpSp9SZUV09 -nSyT+re36V2VaOzEtZjpf4a1DinuIiQfugVgb0QnjwARAQABiQIfBBgBCgAJBQJL -xX15AhsMAAoJEAtmIFBiWQgIruQP/3YRvBzgcEQAXBrdh3Zfd7QRYJCk9xSNGGzz -MVkIKH2n3nhRNRwplsARfnDKMu7ujh+Nk3a1zUX8GK2+xhxt0XJ7jBrZoMtEPiSm -jLkSSu2GYBbhVsNE3XYnxm19ZpvsNO72qU4mEjTKElY7jI0oaWntLCJguW0wua4S -c43Nqg6cg1Ttv891l5d1eTk64S/PA9qmQyRG9lI5dtRqNLDlyMPzdWelP3lGzqLP -c83HYHKCzjJ4Updfv2bU+eCW/qyyQkicCKyrka0KIyh3GXbHCqmGFuHJTknlF6ML -dcEAInBNbjakeWTJinjcivPwPN5NwgSOyte+uI0UB5tWUvwoyqr4e8CJE80M0ZtT -YN8rKJJx+/g6EvFUf+qxunanjEV6ZP2LfylVfLJsObnQN0Jv0ae47/F9b2SeWh/C -aKtCxi0vzg+s+MKdBTXqUAIPBzQMyL//oq9VpQwqFFMD7fNBjBt2qKRYCmk/UFaq -btG7T6y6zcj/gobPr9QcJYM7FOaY6L0QTA/H/qmf+xwt4klDsa4DwdVXXVCY0dYs -JZ9crRJi61EojtCiC7Z4uMPrszl8+KXoI+u/kObNjQz6YQsKz3Hq4cZB4+n13x1p -YZXKxNuwWF2JUQkGvcCg+wAkUKypIrcjc1OtnvugNcNVlwStx1wAekBg5u+Qsmya -B/huA4TpuQINBEvFiB0BEACz8LRTLr0najj4u5xDZwJ5kWa45ClbiTHCSdePANZQ -qi7x8qOXdhZen23R8iBKMjLnEix/HlgrA3OacsG/Xy/CqPxkupOTxklDfThKMH6a -ifjDr23N3i4ODTyYolh2a8lAKH0WgV1z85RqjD6qu0nh9Xr3mb4GDFOOqs1ppNf6 -AzOLTMKFbOMLJ9SVHEgUNRvig4kUid6jAoNrmDLNn/KbtwWlHWtAz4nUCGZfGmMP -VKnmg9mwEwfHm4r0/BN2sXK12zbyrqJTsiDP4h0MIs81wlWBgHdxwXhBgBJK8vhy -4sD2CXApjL2fbf5gjn3ApOdTKrpyTZpJwRKlSeLkSy/BYKBzbSHmFz3HHTdn0u1a -T/9gJYO4MGLhO/Kpm1Ht0aRHaoberswSiCpQQ77EPysJgiauyErRL0ynkDHfEbkB -JGbgMjJZn8WYxYxAkVU3vYneEcHhmMZ4At0gcLxN1/wJykMUiEw/uZmUYpdcVC36 -c/fM/6jCo6Y5QO6Ho5ENrwEVTSX8GTdUtsKFrDNh4blTcMmTKO9ijq8pNhZ/GpsZ -PVXpfx9QYH6dJx9Q9W0MLVx90WRdw+TpDqdSkPOyQndlwsm0+ywPvDhAQ3Gjx5/X -St4WbfT1jYKd5+PQh5/1NyDc5YYQdRkfftwk3PTDFqAgnTnG4SjFrCS4ImbCKiUv -SwARAQABiQQ+BBgBCgAJBQJLxYgdAhsCAikJEAtmIFBiWQgIwV0gBBkBCgAGBQJL -xYgdAAoJEGoM2OGpOvr9zPYP/3T/rytnOvMw9Pa4B5rvaQDRgWfCIR4apaEC2nZN -jnkocl1tkP1b3wkH2X9DmAlpwqttj7NoDJl/uqv4s/SUnB1RyPPBSTmaHmSaKVpl -SoD6DMh6I9WAbXYQ5lW0DAAE+a45/oiRr1FsE57xevT4p8Ss/QMlVFv6HSaOyqNI -gES3/jSlxLBJji30+ZaMYUJCO+yUrdi+i6oXdpKKodRcfKSMqAcNmadaYzzzfq48 -ZCcRRxjY4hzUh9mn6RIqwmBFOarQkRG8jeyyCd2PBPm4yaPPop2/jKduGfQv99q4 -B+jdZEfm0ZQCGR1f5j+jDnG2lzPTUXZuUpSuSqz6yj2p/QBVaLDYW07HMARrLCii -777gZOLMVf3hFMEyRH9uRc5qYalrGCM7L7koVUzavY+igjo3mM5XFJ8LEvjmMOEl -RdtjxsyNe47+Eofs0cT6xhM1nKB0FIAm0m7djGC5LlsWFEQeyvB6Fu7zsFAdQxep -TyYX9jSE7an0gQofZq0RqfO0t8+T33NCkJox9YXD8wpkaGIi54EHK2a+dPF7GntH -34w571YzUwJAjLia2fELneojGPtUm9u3aCiPP6GskeGrBS3ZGiOJI4ebCrEYqe+f -qzIlUpQRHsJh7B+BfvrkiXscwwceunYSJowU1Rjbruqe7fEkRoqMRhbF+F4ebnB2 -ZlU+CyYP/R1IwLOjX5MjylDtjVTVULqjUEeuvcRSR+movlF7fOgl5kp+WS7zLZ/R -OKWXVJJFNgMTcTGDiy7tYE8c2+0wznZwJe/SQVgRfrob+Wo921vKX+odrESL7J/u -GxJO8Ev6fFFXj2EnZFH55POK0LBy1AE5Fz1Tkx+y/ASj+rq3+ELz51HaqMgYb00K -L5x9hL/4H/tDMrkzFx2TDEhLDyKbzt0i0+8oDUGRt+CBB5BhTsx0MbwQ162A4ZiR -36E/jX/B5whZodD+xWf9r6ryHtudPSvm3/cveeU89EuuKV1FoLQPQ0myshmLnSIV -mLLCS1pVpommlNwFkORDRxdziMLuasSBGyKs//xepDSwTky6RihvkKxvKq1WQ/6Y -KpoS4cjsCUBeuSbWZi4WqGvonRfDmI7Zehbw8W3BzMIQJjwbRqiqVdCd1FIrD+FN -FKNjCo2M1HXTHsjLsYRh20atEZFAw8YPBH7nYeefDcPcJihagnqFEPDUVxz+b50v -dCurH91Y/1LO03LVW4Yrt81hIS5q8AtoBAOyOVJ63HlWjDTy5ockVpB4sxIGd8+o -rp4+Ul9Ryr2Um/AiuVbkGG+6m1qXomMlAlDQ85XiQ9Xjs9ialxSjM7ZSot7Sf+3p -UQnxiQionc1HZl0Yc+hKIqAvpPlgb8aDV3aJdCb6dFPeBGLz6ygX -=bniM ------END PGP PUBLIC KEY BLOCK----- - -pub 1024D/19FEA27D 2010-03-24 -uid Simone Tripodi (simonetripodi) -sig 3 19FEA27D 2010-03-24 Simone Tripodi (simonetripodi) -sub 4096g/C002CC79 2010-03-24 -sig 19FEA27D 2010-03-24 Simone Tripodi (simonetripodi) - ------BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1.4.9 (Darwin) - -mQGiBEuqRGMRBACBis5psYJVe33ZtVEl8KbmdPWvZ02PZOgn4XxIDl4Gc/ShtuKr -0LYk7jOFeh00hwJWGROllsa18VxEfEZpDCLlOOX9Df0BONcq6ObUyZi1ila0oLpz -PdZ7bvhysgJReSKvOxlbV+wT6VkvcBwAZRi4gbu/LIeterad1aquPJA82wCg2AIi -wjgbSfKXmT5p191BnnyDcsED/jWivZhW6bz6IgMcJjJ1i3UUsQh8xYHr9j+lM9ML -4OwM7o2znonsrx8orypGK8/3sx4SPtaUSWsh7DOLmmb2xJQgnY4H4+75Hw4Pu5Uq -3hzHbmNKKrsF1xO5sfTRsN7KqS/JwNcb/iJC2YBvcClBHxLhZuOhe4k1o0LSQ3C1 -A1+SA/943uYa1/XVTnSe7b8egDejtjpqJ7rPveansJfzQt0+3ZTJFSaYZlY69W2i -WafKKPvQkkQGYfWxOSk1s4lzBDvFBqQKpFY2E/JVFgymrEy0F7iSpG//A85/QWJg -5rHxD2E5ftEyQ20wTX51B0tVQ8VWiwuT0F/t349OAbcxIYXQFrQ5U2ltb25lIFRy -aXBvZGkgKHNpbW9uZXRyaXBvZGkpIDxzaW1vbmV0cmlwb2RpQGFwYWNoZS5vcmc+ -iGAEExECACAFAkuqRGMCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDK9exZ -Gf6ifQjuAJ4wEmGExNReb2ppL3iMWitxdf8aAwCaA65zG5hiWqkl/dlYN2TYy08R -Q9y5BA0ES6pEYxAQAJ/yi70fJ2hQNMuvzFGgAA0t/XnQmabPnGY9X2VA6Wvrvh79 -jvtZKFzz9CNAANc1wjrWyLSXl/BzGL3Qnz2C4ECqdb5jTsU4JdN8rNqU8ABwQpQg -65hEyczEbfZu77Phau7JgXJ59AgesrTEZ97QJsOn/AD9in6rdvGWkmjL/3KuDEKv -WSeZ63TkjAVYb+s2iJ7tUUXma4Yy6vy0P4K05PEQU4A0XxkfXqWKYdm1kAOzmfH+ -7FSWirKdgfdaisHOra2Nyh8L7hlGe8NmgsIhWvA18i5kAxDTgurr90FiFX0/rWae -yw03ltDQkIJDABlL4pabxR46W/XCD5ET7jpiYkxIxYgCjpvSNh8utfvb+/gbpMd+ -dU6u1wNhGVKZVtU0OVzV7cp79gD4cW276Qw3z00uyGj+QEGgQGXaj/9E6ofDnlOw -mZqGPnDqotGq62ry0dHNpMx2tmBAmuUts9lB34/7tsYx0LvbSc/j34rZQWoorUX5 -8ewVwJd7CFHEkTL3dsJYrshW0yhq84nmhtpJM99zPPXdw5tc5o3a8EHIM/u1zmWU -DNgZQahdvfLXX5VSlbiT5gOx8e8KafBvIF5GhdFTl/3zspHXB7jPlhF6HDrFa49b -xZAtQDVhfG2ewr6oOv0g6I/uFVUDlTr6Aeaju/HSxbZCewJGM2WwQAwWAdbHAAMF -D/9p5TRPn5gfY4ZP9eYbYf1XqmzN8ExOsWAKIr0DooNXIsZqUkSGEKYTU9a8F4cc -Ehzi4fFmI9mm6FWTOM+nOIW3pghy9kiKbNTbJim+p1sphriEoDhrM2bsjNtEpvmB -1W+6KtnjgiVj5DFy9R/fGdZyY9GHcpt29Hf+fxesLrrqxe5EDqV8Lrs1IYVPDqqJ -fqzTM87HH7CLohs79gvKARNWyKJXdZnI3bvdpBI4oED8pyKpS57iqew6lVvRbxli -EtqYotcKnU8s8JNWj8y1jaoaoBP2jVro3EnZ/CCz7JtRz8Iyqg8U8MneMpxFxqpP -LnRbytX6/sHbL4859GujSUb5zhXM3GfWaIcfBStCXBICoPyQcJC9xEiDxHOKNuDd -0rB2K9Si1JKs9D7mwUURw7c0OH0U7WKHRIjdEQ9wruvIsG1DKf272ABlR1vc3wBQ -u+karL6ZVwDFpTOhI0rxupwXeFbrFNXw65zrvs9je7BnPS5P/jh+UK2fuX/2cpBn -uZD3ZRUDxOla07lsU69yUAVs+LUpk6GJ85oz4usDk/QVrd4tqbKOCLbIP+c8AaTH -bnx1XBeZosJmn+cjAXUZ0gredlbRqwR5HrAUMsSUswfHVEw/a5dm4xWDlOxpSkH1 -niquivoyoZQAFOlEA9Sm/q9ckHspvApUvGXiBTNt+rVUOYhJBBgRAgAJBQJLqkRj -AhsMAAoJEMr17FkZ/qJ9vzwAn0vGmShhBzWDSkLjTQ+qW8VXLee2AKCCqsqCN9eL -dcC0KEtNPufKywDTzA== -=vtxx ------END PGP PUBLIC KEY BLOCK----- - -pub 2048R/B58B0910 2011-07-16 -uid Lukasz Moren -sig 3 B58B0910 2011-07-16 Lukasz Moren - ------BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v2.0.17 (MingW32) - -mQENBE4hlPUBCAChCiZcLoXKT3FaIJh3tGqvPP3UzmRxwOO6yJ9ekt0qxKwaciAo -/Ht8w7EC13GpiARZCox95gziobV0Ykp7Imzf0Eq0ElZO8PoR5xogKUoSspe/Xg4F -yAZshIevWGjIB+3Z2yYJNMa+x8b0VOb6iRhYyfaNGpTK7iu2xtL8x4VTU0zs83mj -HdHcrORwEdr6Cnk/5oUz522soslgAWsAc3Jjfa0gZyiL1oJ2xBZJ3vTixxBU5GRj -/Su522pqQrzXd+bYCXut8dZrUb44ldJuASi3fGMKTeJMrFzxqWXvgsOnDrMVa4av -W1SZiJe1F55UV2zXZ5xlpQMM5/paQxEkKii1ABEBAAG0JUx1a2FzeiBNb3JlbiA8 -bHVrYXN6Lm1vcmVuQGdtYWlsLmNvbT6JATcEEwEKACEFAk4hlPUCGw8FCwkIBwMF -FQoJCAsFFgIDAQACHgECF4AACgkQeKA0MrWLCRByIQf/T4EBzxcfd2EgpdXcEd6/ -y/jl6TzMJ3UTaDAB9OFfc2q6CYQ2j9cQz49ycp5OwI5zo0O0+CVGfadtiW993t3D -r5uq36m1RjfM8RQDnul7MpT/Ujaxht1CdDzzet0VeQ/6NfyZps/LMZxV2bstkSuN -9BwgRwZJlRDT5nYYwpBwBuRLTR1yvcxDvVI5KBvjXVq5SxJVBIDKCxMC1fDJbmI7 -wqbn0GDvU0+VJkBFcMLkltF8TVMk/VFuZ5wtKmep9EP3JPsffIVsV/TVPa+VUvAR -akJqtvS0RBsqAT0pJ8gOYj6OvPwWkPtEvh4IfO5ajwWV+MasebWJKS+oUq50p2Q7 -GQ== -=EfW1 ------END PGP PUBLIC KEY BLOCK----- diff --git a/NOTICE b/NOTICE index 3f59805c..b1073e6b 100644 --- a/NOTICE +++ b/NOTICE @@ -1,2 +1,5 @@ +Apache Oltu +Copyright 2010-2017 The Apache Software Foundation + This product includes software developed by The Apache Software Foundation (http://www.apache.org/). diff --git a/commons/deploySite.sh b/commons/deploySite.sh new file mode 100755 index 00000000..7328d417 --- /dev/null +++ b/commons/deploySite.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +mvn clean site site:stage -P site +mvn scm-publish:publish-scm -Dusername=$1 -Dpassword=$2 -P site diff --git a/commons/encodedtoken/pom.xml b/commons/encodedtoken/pom.xml new file mode 100644 index 00000000..85e75692 --- /dev/null +++ b/commons/encodedtoken/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + + org.apache.oltu.commons + org.apache.oltu.commons.parent + 3-SNAPSHOT + + + org.apache.oltu.commons.encodedtoken + 1.0.2-SNAPSHOT + bundle + + Apache Oltu - Commons - Encoded Token + Apache Oltu Encoded Token shared utility + + + + org.apache.commons.codec.binary;version="[1.4,2)" + + + + + commons-codec + commons-codec + 1.9 + + + + diff --git a/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenDecoder.java b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenDecoder.java new file mode 100644 index 00000000..20bf2162 --- /dev/null +++ b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenDecoder.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.encodedtoken; + +import java.nio.charset.Charset; + +import org.apache.commons.codec.binary.Base64; + +public abstract class TokenDecoder { + + /** + * The {@code UTF-8} charset reference. + */ + private static final Charset UTF_8 = Charset.forName("UTF-8"); + + /** + * Empty Line separator for rfc 2045 section 6.8 + * {@see org.apache.commons.codec.binary.Base64} + */ + private static final byte[] LINE_SEPARATOR = {}; + + public static final String base64Decode(String base64encoded) { + return new String(new Base64(-1, LINE_SEPARATOR, true).decode(base64encoded), UTF_8); + } + + public static final byte[] base64DecodeToByte(String base64encoded) { + return new Base64(-1, LINE_SEPARATOR, true).decode(base64encoded); + } + + public static final String base64Encode(String input) { + return new String(new Base64(-1, LINE_SEPARATOR, true).encode(input.getBytes(UTF_8)), UTF_8); + } + + public static final String base64Encode(byte [] input) { + return new String(new Base64(-1, LINE_SEPARATOR, true).encode(input)); + } +} diff --git a/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenReader.java b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenReader.java new file mode 100644 index 00000000..7962934d --- /dev/null +++ b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenReader.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.encodedtoken; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public abstract class TokenReader extends TokenDecoder { + + /** + * The Base64 JSON string default separator. + */ + private final Pattern base64urlTokenPattern = Pattern.compile("([a-zA-Z0-9-​_=]+)\\.([a-zA-Z0-9-_​=]+)\\.([a-zA-Z0-9-_=]+)"); + + /** + * Read the base64url token string + * @param base64String + * @return + */ + public T read(String base64String) { + if (base64String == null || base64String.isEmpty()) { + throw new IllegalArgumentException("Impossible to obtain a Token from a null or empty string"); + } + + // TODO improve multi-line tokens + StringBuilder buffer = new StringBuilder(); + BufferedReader reader = new BufferedReader(new StringReader(base64String)); + String line = null; + try { + while ((line = reader.readLine()) != null) { + buffer.append(line.trim()); + } + } catch (IOException e) { + // it cannot happen + } finally { + try { + reader.close(); + } catch (IOException e) { + // swallow it + } + } + + Matcher matcher = base64urlTokenPattern.matcher(buffer.toString()); + if (!matcher.matches()) { + throw new IllegalArgumentException(base64String + + "is not a valid Token, it does not match with the pattern: " + + base64urlTokenPattern.pattern()); + } + + // HEADER + String header = matcher.group(1); + String decodedHeader = base64Decode(header); + + // BODY + String body = matcher.group(2); + String decodedBody = base64Decode(body); + + // SIGNATURE + // Keep signature encoded in base64url + String signature = matcher.group(3); + + return build(base64String, decodedHeader, decodedBody, signature); + } + + /** + * Build the token reader + * + * @param rawString + * @param decodedHeader + * @param decodedBody + * @param encodedSignature + * @return + */ + protected abstract T build(String rawString, String decodedHeader, String decodedBody, String encodedSignature); +} diff --git a/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenWriter.java b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenWriter.java new file mode 100644 index 00000000..a3c0e42b --- /dev/null +++ b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/TokenWriter.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.encodedtoken; + +public abstract class TokenWriter extends TokenDecoder { + + public final String write(T token) { + if (token == null) { + throw new IllegalArgumentException("Impossible to build a Token from a null JWS representation."); + } + + String header = writeHeader(token); + String encodedHeader = base64Encode(header); + + String body = writeBody(token); + String encodedBody = base64Encode(body); + + String signature = writeSignature(token); + + return new StringBuilder() + .append(encodedHeader) + .append('.') + .append(encodedBody) + .append('.') + .append(signature) + .toString(); + } + + protected abstract String writeHeader(T token); + + protected abstract String writeBody(T token); + + protected abstract String writeSignature(T token); + +} diff --git a/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/package-info.java b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/package-info.java new file mode 100644 index 00000000..69de1bee --- /dev/null +++ b/commons/encodedtoken/src/main/java/org/apache/oltu/commons/encodedtoken/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Common reusable Encoded Token utilities. + */ +package org.apache.oltu.commons.encodedtoken; diff --git a/commons/encodedtoken/src/test/java/org/apache/oltu/commons/encodedtoken/TokenReaderTest.java b/commons/encodedtoken/src/test/java/org/apache/oltu/commons/encodedtoken/TokenReaderTest.java new file mode 100644 index 00000000..f7887e38 --- /dev/null +++ b/commons/encodedtoken/src/test/java/org/apache/oltu/commons/encodedtoken/TokenReaderTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.encodedtoken; + +import org.junit.Assert; +import org.junit.Test; + +public class TokenReaderTest { + + private TokenReader tokenReader; + + @Test + public void test_read() { + tokenReader = new TokenReader() { + protected String build(String rawString, String decodedHeader, + String decodedBody, String encodedSignature) { + + return ""; + } + }; + + String accessToken = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"; + Assert.assertNotNull(tokenReader.read(accessToken)); + } + + @Test + public void test_read2() { + tokenReader = new TokenReader() { + protected String build(String rawString, String decodedHeader, + String decodedBody, String encodedSignature) { + return null; + } + }; + String accessToken = "BadToken"; + try { + tokenReader.read(accessToken); + Assert.fail("failed test"); + }catch (IllegalArgumentException e) { + //expected + } + + } +} diff --git a/commons/json/pom.xml b/commons/json/pom.xml new file mode 100644 index 00000000..e57f6b7a --- /dev/null +++ b/commons/json/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.apache.oltu.commons + org.apache.oltu.commons.parent + 3-SNAPSHOT + + + org.apache.oltu.commons.json + 1.0.2-SNAPSHOT + bundle + + Apache Oltu - Commons - JSON + Apache Oltu JSON shared utility + + + + org.apache.geronimo.specs + geronimo-json_1.1_spec + 1.0 + + + + diff --git a/spec-api/src/main/java/org/apache/amber/HTTPMethod.java b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableBuilder.java similarity index 52% rename from spec-api/src/main/java/org/apache/amber/HTTPMethod.java rename to commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableBuilder.java index 3b8949fc..313ee286 100644 --- a/spec-api/src/main/java/org/apache/amber/HTTPMethod.java +++ b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableBuilder.java @@ -14,56 +14,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber; +package org.apache.oltu.commons.json; -/** - * Enumeration of available HTTP methods. - * - * Enumerates methods are defined in - * HTTP/1.1: Method Definitions. - * - * @version $Id$ - */ -public enum HTTPMethod { - - /** - * The {@code HEAD} HTTP method. - */ - HEAD, - - /** - * The {@code POST} HTTP method. - */ - POST, +import java.util.LinkedHashMap; +import java.util.Map; - /** - * The {@code PUT} HTTP method. - */ - PUT, +public abstract class CustomizableBuilder { /** - * The {@code GET} HTTP method. + * The registry that keeps the custom fields. */ - GET, + private final Map customFields = new LinkedHashMap(); - /** - * The {@code DELETE} HTTP method. - */ - DELETE, + protected final Map getCustomFields() { + return customFields; + } /** - * The {@code OPTIONS} HTTP method. + * TODO + * + * @param key + * @param value + * @return */ - OPTIONS, + public final CustomizableBuilder setCustomField(String key, Object value) { + if (key == null) { + throw new IllegalArgumentException("Null key not allowed."); + } + if (value != null) { + customFields.put(key, value); + } + return this; + } - /** - * The {@code TRACE} HTTP method. - */ - TRACE, - - /** - * The {@code CONNECT} HTTP method. - */ - CONNECT; + public abstract E build(); } diff --git a/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntity.java b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntity.java new file mode 100644 index 00000000..e3fc13b9 --- /dev/null +++ b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntity.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.json; + +import java.util.Formatter; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +/** + * TODO + */ +public abstract class CustomizableEntity { + + /** + * The registry that keeps the custom fields. + */ + private final Map customFields; + + /** + * TODO + * + * @param customFields + */ + public CustomizableEntity(Map customFields) { + if (customFields == null) { + throw new IllegalArgumentException("Null custom field registry not allowed."); + } + this.customFields = customFields; + } + + /** + * Return the specified custom field value, + * {@code null} if the custom field is not present. + * + * @param name the custom field name, it cannot be null. + * @return the specified custom field value, + * {@code null} if the custom field is not present. + */ + public final T getCustomField(String name, Class type) { + if (name == null) { + throw new IllegalArgumentException("Null custom field name not present in the registry."); + } + + Object value = customFields.get(name); + + if (value != null) { + return type.cast(value); + } + + return null; + } + + /** + * Returns the custom fields stored in the entity. + * + * @return the custom fields stored in the entity. + */ + public final Set> getCustomFields() { + return customFields.entrySet(); + } + + @Override + public String toString() { + if (customFields.isEmpty()) { + return ""; + } + + Formatter formatter = new Formatter(); + + formatter.format( ", " ); + + int counter = 0; + for (Entry customField : customFields.entrySet()) { + Object value = customField.getValue(); + + if (value != null) { + if (counter++ > 0) { + formatter.format(", "); + } + + String pattern; + if (customField.getValue() instanceof Number) { + pattern = "\"%s\": %s"; + } else { + pattern = "\"%s\": \"%s\""; + } + + formatter.format(pattern, customField.getKey(), value); + } + } + + try { + return formatter.toString(); + } finally { + formatter.close(); + } + } + +} diff --git a/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntityReader.java b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntityReader.java new file mode 100644 index 00000000..757a650c --- /dev/null +++ b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntityReader.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.json; + +import static java.lang.String.format; + +import java.io.StringReader; +import java.util.Map.Entry; + +import javax.json.*; + +/** + * TODO + */ +public abstract class CustomizableEntityReader> { + + private final B builder; + + public CustomizableEntityReader(B builder) { + this.builder = builder; + } + + protected final B getBuilder() { + return builder; + } + + /** + * + * @param jsonString + */ + public void read(String jsonString) { + if (jsonString == null) { + throw new IllegalArgumentException("Null string does not represent a valid JSON object"); + } + + StringReader reader = new StringReader(jsonString); + JsonReader jsonReader = Json.createReader(reader); + JsonStructure structure = jsonReader.read(); + + if (structure == null || structure instanceof JsonArray) { + throw new IllegalArgumentException(format("String '%s' is not a valid JSON object representation", + jsonString)); + } + + JsonObject object = (JsonObject) structure; + for (Entry entry : object.entrySet()) { + String key = entry.getKey(); + JsonValue jsonValue = entry.getValue(); + + // guard from null values + if (jsonValue != null) { + Object value = toJavaObject(jsonValue); + + // if the concrete implementation is not able to handle the property, set the custom field + if (!handleProperty(key, value)) { + builder.setCustomField(key, value); + } + } + } + + jsonReader.close(); + } + + private static Object toJavaObject(JsonValue jsonValue) { + Object value = null; + + switch (jsonValue.getValueType()) { + case ARRAY: + JsonArray array = (JsonArray) jsonValue; + Object[] values = new Object[array.size()]; + for (int i = 0; i < array.size(); i++) { + JsonValue current = array.get(i); + values[i] = toJavaObject(current); + } + value = values; + break; + + case FALSE: + value = false; + break; + + case NULL: + value = null; + break; + + case NUMBER: + JsonNumber jsonNumber = (JsonNumber) jsonValue; + value = jsonNumber.numberValue(); + break; + + case OBJECT: + // not supported in this version + break; + + case STRING: + JsonString jsonString = (JsonString) jsonValue; + value = jsonString.getString(); + break; + + case TRUE: + value = true; + break; + + default: + break; + } + + return value; + } + + protected abstract boolean handleProperty(String key, T value); + +} diff --git a/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntityWriter.java b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntityWriter.java new file mode 100644 index 00000000..42e8ce47 --- /dev/null +++ b/commons/json/src/main/java/org/apache/oltu/commons/json/CustomizableEntityWriter.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.commons.json; + +import java.io.StringWriter; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Map.Entry; + +import javax.json.Json; +import javax.json.stream.JsonGenerator; + +public abstract class CustomizableEntityWriter { + + private final StringWriter stringWriter = new StringWriter(); + + private final JsonGenerator generator = Json.createGenerator(stringWriter); + + public final String write(CE customizableEntity) { + generator.writeStartObject(); + + handleProperties(customizableEntity); + + for (Entry customFields : customizableEntity.getCustomFields()) { + set(customFields.getKey(), customFields.getValue()); + } + + generator.writeEnd().close(); + + return stringWriter.toString(); + } + + protected abstract void handleProperties(CE customizableEntity); + + protected final void set(String key, T value) { + if (key != null && value != null) { + if (value instanceof Boolean) { + generator.write(key, (Boolean) value); + } else if (value instanceof Double) { + generator.write(key, (Double) value); + } else if (value instanceof Integer) { + generator.write(key, (Integer) value); + } else if (value instanceof BigDecimal) { + generator.write(key, (BigDecimal) value); + } else if (value instanceof BigInteger) { + generator.write(key, (BigInteger) value); + } else if (value instanceof Long) { + generator.write(key, (Long) value); + } else if (value instanceof String) { + String string = (String) value; + if (!string.isEmpty()) { + generator.write(key, string); + } + } + } + } + + protected final void set(String key, T[] value) { + if (value == null) { + return; + } + + generator.writeStartArray(key); + + for (T item : value) { + if (item != null) { + if (item instanceof Boolean) { + generator.write((Boolean) item); + } else if (item instanceof Double) { + generator.write((Double) item); + } else if (item instanceof Integer) { + generator.write((Integer) item); + } else if (item instanceof BigDecimal) { + generator.write((BigDecimal) item); + } else if (item instanceof BigInteger) { + generator.write((BigInteger) item); + } else if (item instanceof Long) { + generator.write((Long) item); + } else if (item instanceof String) { + generator.write((String) item); + } + } + } + + generator.writeEnd(); + } + +} diff --git a/commons/json/src/main/java/org/apache/oltu/commons/json/package-info.java b/commons/json/src/main/java/org/apache/oltu/commons/json/package-info.java new file mode 100644 index 00000000..b774b1c0 --- /dev/null +++ b/commons/json/src/main/java/org/apache/oltu/commons/json/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Common reusable JSON utilities. + */ +package org.apache.oltu.commons.json; diff --git a/commons/pom.xml b/commons/pom.xml new file mode 100644 index 00000000..4c4437d7 --- /dev/null +++ b/commons/pom.xml @@ -0,0 +1,89 @@ + + + + 4.0.0 + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + ../parent + + + org.apache.oltu.commons + org.apache.oltu.commons.parent + 3-SNAPSHOT + pom + + Apache Oltu - Commons + Shared utilities across multiple Apache Oltu modules + + + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/commons + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/commons + https://svn.apache.org/repos/asf/oltu/trunk/commons + + + + + apache.website + ${siteUrlDeployment} + + + + + ${user.home}/oltu-sites/oltu-commons-site/ + file://${siteFilePath} + ${user.home}/oltu-sites/oltu-commons + + + + encodedtoken + json + + + + + site + + + + org.apache.maven.plugins + maven-site-plugin + + ${project.reporting.outputDirectory}/apidocs + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${scmPubCheckoutDirectory} + scm:svn:https://svn.apache.org/repos/asf/oltu/site/apidocs/commons + Oltu Commons apidocs deployment + ${project.build.directory}/staging + true + + + + + + + + diff --git a/demos/client-demo/pom.xml b/demos/client-demo/pom.xml new file mode 100644 index 00000000..9b0d0f31 --- /dev/null +++ b/demos/client-demo/pom.xml @@ -0,0 +1,236 @@ + + + + 4.0.0 + + + org.apache.oltu.demos + org.apache.oltu.demos.parent + 1-SNAPSHOT + + + org.apache.oltu.demos.client + war + + Apache Oltu - Demos - Client + + + 1.0.3-SNAPSHOT + 1.0.4-SNAPSHOT + 0.0.1-SNAPSHOT + 3.2.18.RELEASE + 2.5 + 1.7.25 + + + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + + + + + org.apache.oltu.oauth2.common + org.apache.oltu.oauth2 + ${oltu.oauth2.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${oltu.oauth2.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.jwt + ${oltu.oauth2.jwt.version} + + + + + org.apache.oltu.openidconnect + org.apache.oltu.openidconnect.common + ${oltu.oidc.version} + + + + org.apache.oltu.openidconnect + org.apache.oltu.openidconnect.client + ${oltu.oidc.version} + + + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.dynamicreg.client + ${oltu.oauth2.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.dynamicreg.common + ${oltu.oauth2.version} + + + + org.apache.johnzon + johnzon-core + 1.1.4 + + + + + + org.springframework + spring-context + ${org.springframework.version} + + + + commons-logging + commons-logging + + + + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + + + + org.tuckey + urlrewritefilter + 3.1.0 + runtime + + + + javax.servlet + servlet-api + ${servlet-api.version} + provided + + + + + standard + taglibs + 1.1.2 + jar + runtime + + + + javax.servlet + jstl + 1.2 + runtime + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + ${basedir}/src/main/resources/ + + + ${project.build.directory}/war-legals/ + /META-INF + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + prepare-package + prepare-package + + single + + + false + war-legals + false + + ${basedir}/src/main/assembly/prepare-war-legals.xml + + + + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.24 + + + / + + + + 8080 + 60000 + + + 10 + + + + + + diff --git a/demos/client-demo/src/main/assembly/LICENSE-with-deps b/demos/client-demo/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..90b9f8cc --- /dev/null +++ b/demos/client-demo/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,286 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J components (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above + +For the Apache Commons-Logging component (http://commons.apache.org/logging/) +This is licensed under the The Apache Software License, Version 2.0, see above + +For the Spring Framework components (http://www.springsource.org/) +These are licensed under the The Apache Software License, Version 2.0, see above + +For the Standard Taglib component (http://tomcat.apache.org/taglibs/standard/) +This is licensed under the The Apache Software License, Version 2.0, see above + +For the Url Rewrite Filter component (http://www.tuckey.org/urlrewrite/) +This is licensed under the BSD License +Copyright (c) 2005-2012, Paul Tuckey +All rights reserved. +==================================================================== +Licensed under the BSD License. Text as follows. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + - Neither the name tuckey.org nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +==================================================================== + +Please note that some code used in UrlRewriteFilter is under other +permissive licenses. + +==================================================================== + +For the AOP Alliance component (http://aopalliance.sourceforge.net/) +This is licensed under the Public Domain license diff --git a/demos/client-demo/src/main/assembly/NOTICE-with-deps b/demos/client-demo/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/demos/client-demo/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/demos/client-demo/src/main/assembly/bin.xml b/demos/client-demo/src/main/assembly/bin.xml new file mode 100644 index 00000000..c56181cb --- /dev/null +++ b/demos/client-demo/src/main/assembly/bin.xml @@ -0,0 +1,54 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + ${project.groupId}:${project.artifactId} + + + + + diff --git a/demos/client-demo/src/main/assembly/prepare-war-legals.xml b/demos/client-demo/src/main/assembly/prepare-war-legals.xml new file mode 100644 index 00000000..455ec369 --- /dev/null +++ b/demos/client-demo/src/main/assembly/prepare-war-legals.xml @@ -0,0 +1,42 @@ + + + + + prepare-war-legals + + dir + + false + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java similarity index 56% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java index 38a2cf49..c6066068 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/Utils.java @@ -19,48 +19,90 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.demo; +package org.apache.oltu.oauth2.client.demo; +import org.apache.oltu.oauth2.client.demo.exception.ApplicationException; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.demo.model.OAuthRegParams; +import org.apache.oltu.oauth2.common.OAuthProviderType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletContext; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.client.demo.exception.ApplicationException; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; -import org.apache.amber.oauth2.client.demo.model.OAuthRegParams; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ +@Component public final class Utils { - private Utils() { + + public Utils() { + } + + private String redirectUri; + + @Autowired + private void setServletContext(ServletContext ctx) { + String contextPath = ctx.getContextPath(); + redirectUri = "http://localhost:8080" + contextPath + "/redirect"; } - public static final String REDIRECT_URI = "http://localhost:8080/redirect"; public static final String DISCOVERY_URI = "http://localhost:8080"; public static final String REG_TYPE_PULL = "pull"; public static final String REG_TYPE_PUSH = "push"; - public static final String FACEBOOK = "facebook"; - public static final String FACEBOOK_AUTHZ = "https://graph.facebook.com/oauth/authorize"; - public static final String FACEBOOK_TOKEN = "https://graph.facebook.com/oauth/access_token"; - - public static final String GOWALLA = "gowalla"; - public static final String GOWALLA_AUTHZ = "https://gowalla.com/api/oauth/authorize"; - public static final String GOWALLA_TOKEN = "https://gowalla.com/api/oauth/access_token"; - - public static final String GITHUB = "github"; - public static final String GITHUB_AUTHZ = "https://github.com/login/oauth/authorize"; - public static final String GITHUB_TOKEN = "https://github.com/login/oauth/access_token"; + public static final String REQUEST_TYPE_QUERY = "queryParameter"; + public static final String REQUEST_TYPE_HEADER = "headerField"; + public static final String REQUEST_TYPE_BODY = "bodyParameter"; + + public static final String GENERIC = "generic"; + + public static final String FACEBOOK = OAuthProviderType.FACEBOOK.getProviderName(); + public static final String FACEBOOK_AUTHZ = OAuthProviderType.FACEBOOK.getAuthzEndpoint(); + public static final String FACEBOOK_TOKEN = OAuthProviderType.FACEBOOK.getTokenEndpoint(); + public static final String FACEBOOK_SCOPE = "public_profile"; + public static final String FACEBOOK_RESOURCE_URL = "https://graph.facebook.com/me"; + + public static final String GOOGLE = OAuthProviderType.GOOGLE.getProviderName(); + public static final String GOOGLE_AUTHZ = OAuthProviderType.GOOGLE.getAuthzEndpoint(); + public static final String GOOGLE_TOKEN = OAuthProviderType.GOOGLE.getTokenEndpoint(); + public static final String GOOGLE_SCOPE = "openid profile"; + public static final String GOOGLE_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; + + public static final String LINKEDIN = OAuthProviderType.LINKEDIN.getProviderName(); + public static final String LINKEDIN_AUTHZ = OAuthProviderType.LINKEDIN.getAuthzEndpoint(); + public static final String LINKEDIN_TOKEN = OAuthProviderType.LINKEDIN.getTokenEndpoint(); + public static final String LINKEDIN_SCOPE = "r_basicprofile"; + public static final String LINKEDIN_RESOURCE_URL = "https://www.linkedin.com/v1/people/~"; + + public static final String GITHUB = OAuthProviderType.GITHUB.getProviderName(); + public static final String GITHUB_AUTHZ = OAuthProviderType.GITHUB.getAuthzEndpoint(); + public static final String GITHUB_TOKEN = OAuthProviderType.GITHUB.getTokenEndpoint(); + public static final String GITHUB_SCOPE = ""; + public static final String GITHUB_RESOURCE_URL = "https://api.github.com/user"; + + public static final String MICROSOFT = OAuthProviderType.MICROSOFT.getProviderName(); + public static final String MICROSOFT_AUTHZ = OAuthProviderType.MICROSOFT.getAuthzEndpoint(); + public static final String MICROSOFT_TOKEN = OAuthProviderType.MICROSOFT.getTokenEndpoint(); + public static final String MICROSOFT_SCOPE = ""; + public static final String MICROSOFT_RESOURCE_URL = ""; + + public static final String INSTAGRAM = OAuthProviderType.INSTAGRAM.getProviderName(); + public static final String INSTAGRAM_AUTHZ = OAuthProviderType.INSTAGRAM.getAuthzEndpoint(); + public static final String INSTAGRAM_TOKEN = OAuthProviderType.INSTAGRAM.getTokenEndpoint(); + public static final String INSTAGRAM_SCOPE = ""; + public static final String INSTAGRAM_RESOURCE_URL = ""; public static final String SMART_GALLERY = "smart_gallery"; public static final String SMART_GALLERY_AUTHZ = "http://localhost:8090/oauth/authorize"; public static final String SMART_GALLERY_TOKEN = "http://localhost:8090/oauth/token"; public static final String SMART_GALLERY_REGISTER = "http://localhost:8090/oauthreg/register"; - public static void validateRegistrationParams(OAuthRegParams oauthParams) throws ApplicationException { + public String getRedirectUri() { + return redirectUri; + } + + public void validateRegistrationParams(OAuthRegParams oauthParams) throws ApplicationException { String regType = oauthParams.getRegistrationType(); @@ -93,9 +135,7 @@ public static void validateRegistrationParams(OAuthRegParams oauthParams) throws } - public static void validateAuthorizationParams(OAuthParams oauthParams) throws ApplicationException { - - + public void validateAuthorizationParams(OAuthParams oauthParams) throws ApplicationException { String authzEndpoint = oauthParams.getAuthzEndpoint(); String tokenEndpoint = oauthParams.getTokenEndpoint(); String clientId = oauthParams.getClientId(); @@ -120,7 +160,7 @@ public static void validateAuthorizationParams(OAuthParams oauthParams) throws A sb.append("Client Secret "); } - if (!REDIRECT_URI.equals(redirectUri)) { + if (!getRedirectUri().equals(redirectUri)) { sb.append("Redirect URI"); } @@ -132,7 +172,7 @@ public static void validateAuthorizationParams(OAuthParams oauthParams) throws A } - public static void validateTokenParams(OAuthParams oauthParams) throws ApplicationException { + public void validateTokenParams(OAuthParams oauthParams) throws ApplicationException { String authzEndpoint = oauthParams.getAuthzEndpoint(); String tokenEndpoint = oauthParams.getTokenEndpoint(); @@ -163,7 +203,7 @@ public static void validateTokenParams(OAuthParams oauthParams) throws Applicati sb.append("Client Secret "); } - if (!REDIRECT_URI.equals(redirectUri)) { + if (!getRedirectUri().equals(redirectUri)) { sb.append("Redirect URI"); } diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java similarity index 78% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java index c7d19a6e..0267bf3b 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java @@ -18,52 +18,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.apache.amber.oauth2.client.demo.controller; - - -import java.io.IOException; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.amber.oauth2.client.demo.exception.ApplicationException; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.types.ResponseType; +package org.apache.oltu.oauth2.client.demo.controller; + +import org.apache.oltu.oauth2.client.demo.Utils; +import org.apache.oltu.oauth2.client.demo.exception.ApplicationException; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.ResponseType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.RedirectView; -import org.apache.amber.oauth2.client.demo.Utils; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * Handles requests for the application welcome page. - * - * @author Maciej Machulak - * @author Lukasz Moren */ @Controller -@RequestMapping("/") public class AuthzController { - private Logger logger = LoggerFactory.getLogger(AuthzController.class); + @Autowired + private Utils utils; + @RequestMapping("/authorize") public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, HttpServletRequest req, HttpServletResponse res) throws OAuthSystemException, IOException { - try { + logger.debug("start processing /authorize request"); - Utils.validateAuthorizationParams(oauthParams); + try { + utils.validateAuthorizationParams(oauthParams); res.addCookie(new Cookie("clientId", oauthParams.getClientId())); res.addCookie(new Cookie("clientSecret", oauthParams.getClientSecret())); @@ -71,6 +68,7 @@ public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthPa res.addCookie(new Cookie("tokenEndpoint", oauthParams.getTokenEndpoint())); res.addCookie(new Cookie("redirectUri", oauthParams.getRedirectUri())); res.addCookie(new Cookie("scope", oauthParams.getScope())); + res.addCookie(new Cookie("state", oauthParams.getState())); res.addCookie(new Cookie("app", oauthParams.getApplication())); OAuthClientRequest request = OAuthClientRequest @@ -79,15 +77,15 @@ public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthPa .setRedirectURI(oauthParams.getRedirectUri()) .setResponseType(ResponseType.CODE.toString()) .setScope(oauthParams.getScope()) + .setState(oauthParams.getState()) .buildQueryMessage(); return new ModelAndView(new RedirectView(request.getLocationUri())); - } catch (ApplicationException e) { + logger.error("failed to validate OAuth authorization request parameters", e); oauthParams.setErrorMessage(e.getMessage()); return new ModelAndView("get_authz"); } } - } diff --git a/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java new file mode 100644 index 00000000..145af6fd --- /dev/null +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java @@ -0,0 +1,162 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.client.demo.controller; + +import org.apache.oltu.oauth2.client.demo.Utils; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.demo.model.OAuthRegParams; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.jwt.JWT; +import org.apache.oltu.oauth2.jwt.io.JWTClaimsSetWriter; +import org.apache.oltu.oauth2.jwt.io.JWTHeaderWriter; +import org.apache.oltu.oauth2.jwt.io.JWTReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.io.IOException; + +/** + */ +@Controller +public class MainController { + + private Logger logger = LoggerFactory.getLogger(MainController.class); + + private final JWTReader jwtReader = new JWTReader(); + + @Autowired + private Utils utils; + + @RequestMapping("/index") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams) + throws OAuthSystemException, IOException { + return new ModelAndView("index"); + } + + @RequestMapping("/main/{app}") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + @ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams, + @PathVariable("app") String app) + throws OAuthSystemException, IOException { + + if (Utils.SMART_GALLERY.equalsIgnoreCase(app)) { + addRegParamsForSmartGallery(oauthRegParams); + return new ModelAndView("register"); + } + + boolean selected = false; + if (Utils.GENERIC.equalsIgnoreCase(app)) { + selected = true; + } else if (Utils.GITHUB.equalsIgnoreCase(app)) { + selected = true; + addGithubParams(oauthParams); + } else if (Utils.FACEBOOK.equalsIgnoreCase(app)) { + selected = true; + addFacebookParams(oauthParams); + } else if (Utils.GOOGLE.equalsIgnoreCase(app)) { + selected = true; + addGoogleParams(oauthParams); + } else if (Utils.LINKEDIN.equalsIgnoreCase(app)) { + selected = true; + addLinkedInParams(oauthParams); + } else if (Utils.MICROSOFT.equalsIgnoreCase(app)) { + selected = true; + addMicrosfotParams(oauthParams); + } else if (Utils.INSTAGRAM.equalsIgnoreCase(app)) { + selected = true; + addInstagramParams(oauthParams); + } + + if (selected) { + oauthParams.setApplication(app); + oauthParams.setRedirectUri(utils.getRedirectUri()); + return new ModelAndView("get_authz"); + } + + return new ModelAndView("index"); + } + + private void addRegParamsForSmartGallery(OAuthRegParams oauthRegParams) { + oauthRegParams.setAuthzEndpoint(Utils.SMART_GALLERY_AUTHZ); + oauthRegParams.setTokenEndpoint(Utils.SMART_GALLERY_TOKEN); + oauthRegParams.setRegistrationEndpoint(Utils.SMART_GALLERY_REGISTER); + oauthRegParams.setApplication(Utils.SMART_GALLERY); + oauthRegParams.setRedirectUri(utils.getRedirectUri()); + } + + private void addLinkedInParams(OAuthParams oauthParams) { + oauthParams.setAuthzEndpoint(Utils.LINKEDIN_AUTHZ); + oauthParams.setTokenEndpoint(Utils.LINKEDIN_TOKEN); + oauthParams.setScope(Utils.LINKEDIN_SCOPE); + } + + private void addGoogleParams(OAuthParams oauthParams) { + oauthParams.setAuthzEndpoint(Utils.GOOGLE_AUTHZ); + oauthParams.setTokenEndpoint(Utils.GOOGLE_TOKEN); + oauthParams.setScope(Utils.GOOGLE_SCOPE); + } + + private void addFacebookParams(OAuthParams oauthParams) { + oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ); + oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN); + oauthParams.setScope(Utils.FACEBOOK_SCOPE); + } + + private void addGithubParams(OAuthParams oauthParams) { + oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ); + oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN); + oauthParams.setScope(Utils.GITHUB_SCOPE); + } + + private void addMicrosfotParams(OAuthParams oauthParams) { + oauthParams.setAuthzEndpoint(Utils.MICROSOFT_AUTHZ); + oauthParams.setTokenEndpoint(Utils.MICROSOFT_TOKEN); + oauthParams.setScope(Utils.MICROSOFT_SCOPE); + } + + private void addInstagramParams(OAuthParams oauthParams) { + oauthParams.setAuthzEndpoint(Utils.INSTAGRAM_AUTHZ); + oauthParams.setTokenEndpoint(Utils.INSTAGRAM_AUTHZ); + oauthParams.setScope(Utils.INSTAGRAM_SCOPE); + } + + @RequestMapping("/decode") + public ModelAndView decode(@ModelAttribute("oauthParams") OAuthParams oauthParams) { + try { + JWT jwt = jwtReader.read(oauthParams.getJwt()); + + oauthParams.setHeader(new JWTHeaderWriter().write(jwt.getHeader())); + oauthParams.setClaimsSet(new JWTClaimsSetWriter().write(jwt.getClaimsSet())); + } catch (Exception e) { + logger.error("Error while decoding the token", e); + oauthParams.setErrorMessage("Error while decoding the token: " + e); + } + + return new ModelAndView("index"); + } + +} diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java similarity index 76% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java index df841b90..122431d2 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java @@ -19,47 +19,36 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.demo.controller; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.amber.oauth2.client.demo.Utils; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; -import org.apache.amber.oauth2.client.response.OAuthAuthzResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +package org.apache.oltu.oauth2.client.demo.controller; + +import org.apache.oltu.oauth2.client.demo.Utils; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @Controller -@RequestMapping("/redirect") public class RedirectController { + private Logger logger = LoggerFactory.getLogger(RedirectController.class); - @RequestMapping(method = RequestMethod.GET) + @RequestMapping(value = "/redirect", method = RequestMethod.GET) public ModelAndView handleRedirect(@ModelAttribute("oauthParams") OAuthParams oauthParams, HttpServletRequest request, HttpServletResponse response) { + logger.debug("creating OAuth authorization response wrapper (/redirect)"); try { - - // Create the response wrapper - OAuthAuthzResponse oar = null; - oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request); - - - // Get Authorization Code - String code = oar.getCode(); - // Get OAuth Info String clientId = Utils.findCookieValue(request, "clientId"); String clientSecret = Utils.findCookieValue(request, "clientSecret"); @@ -67,29 +56,39 @@ public ModelAndView handleRedirect(@ModelAttribute("oauthParams") OAuthParams oa String tokenEndpoint = Utils.findCookieValue(request, "tokenEndpoint"); String redirectUri = Utils.findCookieValue(request, "redirectUri"); String scope = Utils.findCookieValue(request, "scope"); + String state = Utils.findCookieValue(request, "state"); - String app = Utils.findCookieValue(request, "app"); - response.addCookie(new Cookie("app", app)); - - oauthParams.setAuthzCode(code); oauthParams.setClientId(clientId); oauthParams.setClientSecret(clientSecret); oauthParams.setAuthzEndpoint(authzEndpoint); oauthParams.setTokenEndpoint(tokenEndpoint); oauthParams.setRedirectUri(redirectUri); oauthParams.setScope(Utils.isIssued(scope)); - oauthParams.setApplication(app); + oauthParams.setState(Utils.isIssued(state)); + + // Create the response wrapper + OAuthAuthzResponse oar = null; + oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request); + + // Get Authorization Code + String code = oar.getCode(); + oauthParams.setAuthzCode(code); + String app = Utils.findCookieValue(request, "app"); + response.addCookie(new Cookie("app", app)); + + oauthParams.setApplication(app); } catch (OAuthProblemException e) { + logger.error("failed to create OAuth authorization response wrapper", e); StringBuffer sb = new StringBuffer(); - sb.append("
"); - sb.append("Error code: ").append(e.getError()).append("
"); - sb.append("Error description: ").append(e.getDescription()).append("
"); - sb.append("Error uri: ").append(e.getUri()).append("
"); - sb.append("State: ").append(e.getState()).append("
"); + sb.append("
"); + sb.append("Error code: ").append(e.getError()).append("
"); + sb.append("Error description: ").append(e.getDescription()).append("
"); + sb.append("Error uri: ").append(e.getUri()).append("
"); + sb.append("State: ").append(e.getState()).append("
"); oauthParams.setErrorMessage(sb.toString()); - return new ModelAndView("main"); + return new ModelAndView("get_authz"); } return new ModelAndView("request_token"); diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java similarity index 51% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java index 311cbe7e..cd04cdaf 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java @@ -19,65 +19,50 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.demo.controller; - -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; - -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.demo.Utils; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; -import org.apache.amber.oauth2.client.demo.model.OAuthRegParams; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.ext.dynamicreg.client.OAuthRegistrationClient; -import org.apache.amber.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; -import org.apache.amber.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; +package org.apache.oltu.oauth2.client.demo.controller; + +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.demo.Utils; +import org.apache.oltu.oauth2.client.demo.exception.ApplicationException; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.demo.model.OAuthRegParams; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.ext.dynamicreg.client.OAuthRegistrationClient; +import org.apache.oltu.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest; +import org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; -import org.apache.amber.oauth2.client.demo.exception.ApplicationException; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ @Controller -@RequestMapping("/") public class RegistrationController { + private Logger logger = LoggerFactory.getLogger(RegistrationController.class); + + @Autowired + private Utils utils; + @RequestMapping(value = "/register") public ModelAndView authorize(@ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams, @ModelAttribute("oauthParams") OAuthParams oauthParams, HttpServletRequest req) throws OAuthSystemException, IOException { + logger.debug("start processing /register request"); try { + utils.validateRegistrationParams(oauthRegParams); - Utils.validateRegistrationParams(oauthRegParams); - - OAuthClientRequest request = null; - if (Utils.REG_TYPE_PULL.equals(oauthRegParams.getRegistrationType())) { - request = OAuthClientRegistrationRequest - .location(oauthRegParams.getRegistrationEndpoint(), OAuthRegistration.Type.PULL) - .setUrl(oauthRegParams.getUrl()) - .buildBodyMessage(); - } else { - request = OAuthClientRegistrationRequest - .location(oauthRegParams.getRegistrationEndpoint(), OAuthRegistration.Type.PUSH) - .setName(oauthRegParams.getName()) - .setUrl(oauthRegParams.getUrl()) - .setDescription(oauthRegParams.getDescription()) - .setRedirectURL(oauthRegParams.getRedirectUri()) - .setIcon(oauthRegParams.getIcon()) - .buildBodyMessage(); - } - + OAuthClientRequest request = getoAuthClientRequest(oauthRegParams); OAuthRegistrationClient client = new OAuthRegistrationClient(new URLConnectionClient()); OAuthClientRegistrationResponse response = client.clientInfo(request); @@ -91,14 +76,35 @@ public ModelAndView authorize(@ModelAttribute("oauthRegParams") OAuthRegParams o return new ModelAndView("get_authz"); - } catch (ApplicationException e) { + logger.error("failed to validate OAuth authorization request parameters", e); oauthRegParams.setErrorMessage(e.getMessage()); return new ModelAndView("register"); } catch (OAuthProblemException e) { + logger.error("failed to acquire OAuth client registration info", e); oauthRegParams.setErrorMessage(e.getMessage()); return new ModelAndView("register"); } } + private OAuthClientRequest getoAuthClientRequest(OAuthRegParams oauthRegParams) throws OAuthSystemException { + OAuthClientRequest request; + if (Utils.REG_TYPE_PULL.equals(oauthRegParams.getRegistrationType())) { + request = OAuthClientRegistrationRequest + .location(oauthRegParams.getRegistrationEndpoint(), OAuthRegistration.Type.PULL) + .setUrl(oauthRegParams.getUrl()) + .buildBodyMessage(); + } else { + request = OAuthClientRegistrationRequest + .location(oauthRegParams.getRegistrationEndpoint(), OAuthRegistration.Type.PUSH) + .setName(oauthRegParams.getName()) + .setUrl(oauthRegParams.getUrl()) + .setDescription(oauthRegParams.getDescription()) + .setRedirectURL(oauthRegParams.getRedirectUri()) + .setIcon(oauthRegParams.getIcon()) + .buildBodyMessage(); + } + return request; + } + } diff --git a/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java new file mode 100644 index 00000000..510d4b6a --- /dev/null +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java @@ -0,0 +1,92 @@ +/** + * Copyright 2010 Newcastle University + *

+ * http://research.ncl.ac.uk/smart/ + *

+ * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.client.demo.controller; + +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.demo.Utils; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthResourceResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; + +@Controller +public class ResourceController { + + private Logger logger = LoggerFactory.getLogger(ResourceController.class); + + @RequestMapping("/get_resource") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest req) { + + logger.debug("start processing /get_resource request"); + + try { + OAuthClientRequest request = getoAuthClientRequest(oauthParams); + + OAuthClient client = new OAuthClient(new URLConnectionClient()); + OAuthResourceResponse resourceResponse = client.resource(request, oauthParams.getRequestMethod(), OAuthResourceResponse.class); + + if (resourceResponse.getResponseCode() == 200) { + oauthParams.setResource(resourceResponse.getBody()); + } else { + oauthParams.setErrorMessage( + "Could not access resource: " + resourceResponse.getResponseCode() + " " + resourceResponse.getBody()); + } + } catch (OAuthSystemException e) { + logger.error("Failed to process get_resource request", e); + oauthParams.setErrorMessage(e.getMessage()); + } catch (OAuthProblemException e) { + logger.error("Invalid get_resource request", e); + oauthParams.setErrorMessage(e.getMessage()); + } + + return new ModelAndView("resource"); + } + + private OAuthClientRequest getoAuthClientRequest(OAuthParams oauthParams) throws OAuthSystemException { + OAuthClientRequest request = null; + + OAuthBearerClientRequest oAuthBearerClientRequest = + new OAuthBearerClientRequest(oauthParams.getResourceUrl()) + .setAccessToken(oauthParams.getAccessToken()); + String requestType = oauthParams.getRequestType(); + if (Utils.REQUEST_TYPE_QUERY.equals(requestType)) { + request = oAuthBearerClientRequest.buildQueryMessage(); + } else if (Utils.REQUEST_TYPE_HEADER.equals(requestType)) { + request = oAuthBearerClientRequest.buildHeaderMessage(); + } else if (Utils.REQUEST_TYPE_BODY.equals(requestType)) { + request = oAuthBearerClientRequest.buildBodyMessage(); + } + return request; + } +} diff --git a/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java new file mode 100644 index 00000000..2efdd7b7 --- /dev/null +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java @@ -0,0 +1,131 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.client.demo.controller; + +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.demo.Utils; +import org.apache.oltu.oauth2.client.demo.exception.ApplicationException; +import org.apache.oltu.oauth2.client.demo.model.OAuthParams; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.GitHubTokenResponse; +import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.jwt.JWT; +import org.apache.oltu.oauth2.jwt.io.JWTClaimsSetWriter; +import org.apache.oltu.oauth2.jwt.io.JWTHeaderWriter; +import org.apache.oltu.openidconnect.client.response.OpenIdConnectResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.net.URI; + +@Controller +public class TokenController { + private Logger logger = LoggerFactory.getLogger(TokenController.class); + + @Autowired + private Utils utils; + + @RequestMapping("/get_token") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest req) throws OAuthSystemException, IOException { + logger.debug("authorizing"); + + try { + utils.validateTokenParams(oauthParams); + + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(oauthParams.getTokenEndpoint()) + .setClientId(oauthParams.getClientId()) + .setClientSecret(oauthParams.getClientSecret()) + .setRedirectURI(oauthParams.getRedirectUri()) + .setCode(oauthParams.getAuthzCode()) + .setGrantType(GrantType.AUTHORIZATION_CODE) + .buildBodyMessage(); + + OAuthClient client = new OAuthClient(new URLConnectionClient()); + String app = Utils.findCookieValue(req, "app"); + + Class cl = OAuthJSONAccessTokenResponse.class; + + if (Utils.FACEBOOK.equalsIgnoreCase(app)) { + oauthParams.setResourceUrl(Utils.FACEBOOK_RESOURCE_URL); + } else if (Utils.GITHUB.equalsIgnoreCase(app)) { + cl = GitHubTokenResponse.class; + oauthParams.setResourceUrl(Utils.GITHUB_RESOURCE_URL); + } else if (Utils.GOOGLE.equalsIgnoreCase(app)) { + cl = OpenIdConnectResponse.class; + oauthParams.setResourceUrl(Utils.GOOGLE_RESOURCE_URL); + } else if (Utils.LINKEDIN.equalsIgnoreCase(app)) { + oauthParams.setResourceUrl(Utils.LINKEDIN_RESOURCE_URL); + } + + OAuthAccessTokenResponse oauthResponse = client.accessToken(request, cl); + + oauthParams.setAccessToken(oauthResponse.getAccessToken()); + oauthParams.setExpiresIn(oauthResponse.getExpiresIn()); + oauthParams.setRefreshToken(Utils.isIssued(oauthResponse.getRefreshToken())); + + if (Utils.GOOGLE.equalsIgnoreCase(app)) { + OpenIdConnectResponse openIdConnectResponse = ((OpenIdConnectResponse) oauthResponse); + JWT idToken = openIdConnectResponse.getIdToken(); + if (idToken != null) { + oauthParams.setIdToken(idToken.getRawString()); + + oauthParams.setHeader(new JWTHeaderWriter().write(idToken.getHeader())); + oauthParams.setClaimsSet(new JWTClaimsSetWriter().write(idToken.getClaimsSet())); + + URI uri = URI.create(oauthParams.getTokenEndpoint()); + oauthParams.setIdTokenValid(openIdConnectResponse.checkId(uri.getHost(), oauthParams.getClientId())); + } + } + + return new ModelAndView("get_resource"); + + } catch (ApplicationException e) { + logger.error("failed to validate OAuth token request parameters", e); + oauthParams.setErrorMessage(e.getMessage()); + return new ModelAndView("request_token"); + } catch (OAuthProblemException e) { + logger.error("failed to acquire OAuth access token", e); + StringBuffer sb = new StringBuffer(); + sb.append("
"); + sb.append("Error code: ").append(e.getError()).append("
"); + sb.append("Error description: ").append(e.getDescription()).append("
"); + sb.append("Error uri: ").append(e.getUri()).append("
"); + sb.append("State: ").append(e.getState()).append("
"); + oauthParams.setErrorMessage(sb.toString()); + return new ModelAndView("get_authz"); + } + } +} diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/exception/ApplicationException.java similarity index 88% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/exception/ApplicationException.java index 11ac9f99..b030b47a 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/exception/ApplicationException.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.demo.exception; +package org.apache.oltu.oauth2.client.demo.exception; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class ApplicationException extends Exception { diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/model/OAuthParams.java similarity index 69% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/model/OAuthParams.java index 37f85cc0..e30e85e6 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/model/OAuthParams.java @@ -19,13 +19,13 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.demo.model; +package org.apache.oltu.oauth2.client.demo.model; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthParams { @@ -36,14 +36,22 @@ public class OAuthParams { private String tokenEndpoint; private String authzCode; private String accessToken; - private String expiresIn; + private Long expiresIn; private String refreshToken; private String scope; + private String state; private String resourceUrl; private String resource; private String application; - - private String errorMessage; + private String requestType; + private String requestMethod; + private String idToken; + private String header; + private String claimsSet; + private String jwt; + private boolean idTokenValid; + + private String errorMessage; public String getClientId() { return clientId; @@ -109,11 +117,15 @@ public void setAccessToken(String accessToken) { this.accessToken = accessToken; } - public String getExpiresIn() { + public Long getExpiresIn() { return expiresIn; } public void setExpiresIn(String expiresIn) { + this.expiresIn = Long.parseLong(expiresIn); + } + + public void setExpiresIn(Long expiresIn) { this.expiresIn = expiresIn; } @@ -148,6 +160,14 @@ public String getScope() { public void setScope(String scope) { this.scope = scope; } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } public String getApplication() { return application; @@ -156,4 +176,60 @@ public String getApplication() { public void setApplication(String application) { this.application = application; } + + public String getRequestType() { + return requestType; + } + + public void setRequestType(String requestType) { + this.requestType = requestType; + } + + public String getRequestMethod() { + return requestMethod; + } + + public void setRequestMethod(String requestMethod) { + this.requestMethod = requestMethod; + } + + public String getIdToken() { + return idToken; + } + + public void setIdToken(String idToken) { + this.idToken = idToken; + } + + public String getHeader() { + return header; + } + + public void setHeader(String header) { + this.header = header; + } + + public String getClaimsSet() { + return claimsSet; + } + + public void setClaimsSet(String claimsSet) { + this.claimsSet = claimsSet; + } + + public String getJwt() { + return jwt; + } + + public void setJwt(String jwt) { + this.jwt = jwt; + } + + public boolean isIdTokenValid() { + return idTokenValid; + } + + public void setIdTokenValid(boolean idTokenValid) { + this.idTokenValid = idTokenValid; + } } diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/model/OAuthRegParams.java similarity index 91% rename from oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java rename to demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/model/OAuthRegParams.java index c617f53a..0517e0d8 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java +++ b/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/model/OAuthRegParams.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.demo.model; +package org.apache.oltu.oauth2.client.demo.model; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthRegParams extends OAuthParams { diff --git a/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml b/demos/client-demo/src/main/resources/META-INF/jdoconfig.xml similarity index 100% rename from oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml rename to demos/client-demo/src/main/resources/META-INF/jdoconfig.xml diff --git a/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml b/demos/client-demo/src/main/resources/META-INF/persistence.xml similarity index 100% rename from oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml rename to demos/client-demo/src/main/resources/META-INF/persistence.xml diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties b/demos/client-demo/src/main/resources/log4j.properties similarity index 92% rename from oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties rename to demos/client-demo/src/main/resources/log4j.properties index b9fcb6e8..f697a334 100644 --- a/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties +++ b/demos/client-demo/src/main/resources/log4j.properties @@ -1,29 +1,31 @@ -# -# Copyright 2010 Newcastle University -# -# http://research.ncl.ac.uk/smart/ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -log4j.rootCategory=INFO, CONSOLE - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n - -log4j.logger.org.apache.amber.oauth2=DEBUG \ No newline at end of file +# +# Copyright 2010 Newcastle University +# +# http://research.ncl.ac.uk/smart/ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +log4j.rootCategory=INFO, CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n + +#log4j.logger.org.hibernate.search=TRACE + +log4j.logger.org.apache.oltu.oauth2.client.demo=DEBUG diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml b/demos/client-demo/src/main/webapp/WEB-INF/spring/app-config.xml similarity index 79% rename from oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml rename to demos/client-demo/src/main/webapp/WEB-INF/spring/app-config.xml index 0dbdc76c..a27c04b2 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml +++ b/demos/client-demo/src/main/webapp/WEB-INF/spring/app-config.xml @@ -26,10 +26,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml b/demos/client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml similarity index 79% rename from oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml rename to demos/client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml index 650f7374..c2017a26 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml +++ b/demos/client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml @@ -26,12 +26,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> + + + + diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml b/demos/client-demo/src/main/webapp/WEB-INF/urlrewrite.xml similarity index 100% rename from oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml rename to demos/client-demo/src/main/webapp/WEB-INF/urlrewrite.xml diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/components/_header.jsp similarity index 59% rename from oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp rename to demos/client-demo/src/main/webapp/WEB-INF/views/components/_header.jsp index e8186b44..04d165ad 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/components/_header.jsp @@ -20,28 +20,11 @@ limitations under the License. --%> - -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ page session="false" %> -<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> - - - - OAuth V2.0 Client Application - - - -

Sample OAuth V2.0 Client Application

- -

Web Server Flow

- -

Choose Application

- -Smart Gallery -Facebook -Github -Gowalla - - - +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +
+
+ Apache Oltu - Sample OAuth V2.0 Client Application" /> +

Apache Oltu

+

Sample OAuth V2.0 Client Application

+
+
\ No newline at end of file diff --git a/demos/client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp new file mode 100644 index 00000000..0f45af09 --- /dev/null +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp @@ -0,0 +1,87 @@ +<%-- + + Copyright 2010 Newcastle University + + http://research.ncl.ac.uk/smart/ + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.oltu.oauth2.client.demo.model.OAuthParams"--%> + + + + + " rel="stylesheet" media="screen"> + Apache Oltu - OAuth V2.0 Client Application + + + + + +
+ + + +
Error: ${oauthParams.errorMessage}
+
+ + + +
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + + +
+ +
+ + + diff --git a/demos/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp new file mode 100644 index 00000000..cc833cf3 --- /dev/null +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp @@ -0,0 +1,164 @@ +<%-- + + Copyright 2010 Newcastle University + + http://research.ncl.ac.uk/smart/ + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.oltu.oauth2.client.demo.model.OAuthParams"--%> + + + + + " rel="stylesheet" media="screen"> + Apache Oltu - OAuth V2.0 Client Application + + + + + +
+ + + +
${oauthParams.errorMessage}
+
+ + + +
+ +
+ +
+
+
+ +
+ + + + + +
+
+
+ +
+ + + + +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + + +
+
+ +
+ + +
+
+

OpenId Connect

+
+
ID Token is NOT valid
+
+
+ + +
+
+

OpenId Connect

+
+
ID Token is valid
+
+
+ + +
+
+

Header

+
+
+
+
+ + +
+
+

Claims Set

+
+
+
+
+
+ +
+ + + diff --git a/demos/client-demo/src/main/webapp/WEB-INF/views/index.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/index.jsp new file mode 100644 index 00000000..2c66df52 --- /dev/null +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/index.jsp @@ -0,0 +1,93 @@ +<%-- + + Copyright 2010 Newcastle University + + http://research.ncl.ac.uk/smart/ + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.oltu.oauth2.client.demo.model.OAuthParams"--%> + + + + + " rel="stylesheet" media="screen"> + Apache Oltu - OAuth V2.0 Client Application + + + + + +
+ + + + +

JWT decoder

+ + +
${oauthParams.errorMessage}
+
+ + + + + +
 
+ +
+ + +
 
 
+ +
+
+

Header

+
+
${oauthParams.header}
+
+
+ + +
+
+

Claims Set

+
+
${oauthParams.claimsSet}
+
+
+ +
+ + diff --git a/demos/client-demo/src/main/webapp/WEB-INF/views/register.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/register.jsp new file mode 100644 index 00000000..14d12d90 --- /dev/null +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/register.jsp @@ -0,0 +1,93 @@ +<%-- + + Copyright 2010 Newcastle University + + http://research.ncl.ac.uk/smart/ + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthRegParams" type="org.apache.oltu.oauth2.client.demo.model.OAuthRegParams"--%> + + + + + " rel="stylesheet" media="screen"> + Apache Oltu - OAuth V2.0 Client Application + + + + + +
+ + + +
${oauthRegParams.errorMessage}
+
+ + + +
+ +
+ + + + +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + + + + +
+ +
+ + diff --git a/demos/client-demo/src/main/webapp/WEB-INF/views/request_token.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/request_token.jsp new file mode 100644 index 00000000..4f381443 --- /dev/null +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/request_token.jsp @@ -0,0 +1,86 @@ +<%-- + + Copyright 2010 Newcastle University + + http://research.ncl.ac.uk/smart/ + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.oltu.oauth2.client.demo.model.OAuthParams"--%> + + + + + " rel="stylesheet" media="screen"> + Apache Oltu - OAuth V2.0 Client Application + + + + + +
+ + + +
${oauthParams.errorMessage}
+
+ + + +
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + + +
+ +
+ + diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/resource.jsp b/demos/client-demo/src/main/webapp/WEB-INF/views/resource.jsp similarity index 55% rename from oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/resource.jsp rename to demos/client-demo/src/main/webapp/WEB-INF/views/resource.jsp index 82d29f86..95792032 100644 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/resource.jsp +++ b/demos/client-demo/src/main/webapp/WEB-INF/views/resource.jsp @@ -24,25 +24,32 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ page session="false" %> -<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> +<%--@elvariable id="oauthParams" type="org.apache.oltu.oauth2.client.demo.model.OAuthParams"--%> - - OAuth V2.0 Client Application - - - -

Sample OAuth V2.0 Client Application

- -

Web Server Flow

- -

Your Resource:

- - -

${oauthParams.errorMessage}

-
- - - - + + + " rel="stylesheet" media="screen"> + Apache Oltu - OAuth V2.0 Client Application + + + + + +
+ + + +
${oauthParams.errorMessage}
+
+ +
+ +
+ ">Restart flow +
+ diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/web.xml b/demos/client-demo/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/web.xml rename to demos/client-demo/src/main/webapp/WEB-INF/web.xml diff --git a/demos/client-demo/src/main/webapp/css/bootstrap.min.css b/demos/client-demo/src/main/webapp/css/bootstrap.min.css new file mode 100644 index 00000000..a553c4f5 --- /dev/null +++ b/demos/client-demo/src/main/webapp/css/bootstrap.min.css @@ -0,0 +1,9 @@ +/*! + * Bootstrap v3.0.0 + * + * Copyright 2013 Twitter, Inc + * Licensed under the Apache License v2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Designed and built with all the love in the world by @mdo and @fat. + *//*! normalize.css v2.1.0 | MIT License | git.io/normalize */article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,video{display:inline-block}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{margin:.67em 0;font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}hr{height:0;-moz-box-sizing:content-box;box-sizing:content-box}mark{color:#000;background:#ff0}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em}pre{white-space:pre-wrap}q{quotes:"\201C" "\201D" "\2018" "\2019"}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:0}fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid #c0c0c0}legend{padding:0;border:0}button,input,select,textarea{margin:0;font-family:inherit;font-size:100%}button,input{line-height:normal}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button}button[disabled],html input[disabled]{cursor:default}input[type="checkbox"],input[type="radio"]{padding:0;box-sizing:border-box}input[type="search"]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0}@media print{*{color:#000!important;text-shadow:none!important;background:transparent!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}@page{margin:2cm .5cm}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}.navbar{display:none}.table td,.table th{background-color:#fff!important}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table{border-collapse:collapse!important}.table-bordered th,.table-bordered td{border:1px solid #ddd!important}}*,*:before,*:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}html{font-size:62.5%;-webkit-tap-highlight-color:rgba(0,0,0,0)}body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.428571429;color:#333;background-color:#fff}input,button,select,textarea{font-family:inherit;font-size:inherit;line-height:inherit}button,input,select[multiple],textarea{background-image:none}a{color:#428bca;text-decoration:none}a:hover,a:focus{color:#2a6496;text-decoration:underline}a:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}img{vertical-align:middle}.img-responsive{display:block;height:auto;max-width:100%}.img-rounded{border-radius:6px}.img-thumbnail{display:inline-block;height:auto;max-width:100%;padding:4px;line-height:1.428571429;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.img-circle{border-radius:50%}hr{margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);border:0}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:16.099999999999998px;font-weight:200;line-height:1.4}@media(min-width:768px){.lead{font-size:21px}}small{font-size:85%}cite{font-style:normal}.text-muted{color:#999}.text-primary{color:#428bca}.text-warning{color:#c09853}.text-danger{color:#b94a48}.text-success{color:#468847}.text-info{color:#3a87ad}.text-left{text-align:left}.text-right{text-align:right}.text-center{text-align:center}h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:500;line-height:1.1}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small,.h1 small,.h2 small,.h3 small,.h4 small,.h5 small,.h6 small{font-weight:normal;line-height:1;color:#999}h1,h2,h3{margin-top:20px;margin-bottom:10px}h4,h5,h6{margin-top:10px;margin-bottom:10px}h1,.h1{font-size:36px}h2,.h2{font-size:30px}h3,.h3{font-size:24px}h4,.h4{font-size:18px}h5,.h5{font-size:14px}h6,.h6{font-size:12px}h1 small,.h1 small{font-size:24px}h2 small,.h2 small{font-size:18px}h3 small,.h3 small,h4 small,.h4 small{font-size:14px}.page-header{padding-bottom:9px;margin:40px 0 20px;border-bottom:1px solid #eee}ul,ol{margin-top:0;margin-bottom:10px}ul ul,ol ul,ul ol,ol ol{margin-bottom:0}.list-unstyled{padding-left:0;list-style:none}.list-inline{padding-left:0;list-style:none}.list-inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt,dd{line-height:1.428571429}dt{font-weight:bold}dd{margin-left:0}@media(min-width:768px){.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}.dl-horizontal dd:before,.dl-horizontal dd:after{display:table;content:" "}.dl-horizontal dd:after{clear:both}.dl-horizontal dd:before,.dl-horizontal dd:after{display:table;content:" "}.dl-horizontal dd:after{clear:both}}abbr[title],abbr[data-original-title]{cursor:help;border-bottom:1px dotted #999}abbr.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:10px 20px;margin:0 0 20px;border-left:5px solid #eee}blockquote p{font-size:17.5px;font-weight:300;line-height:1.25}blockquote p:last-child{margin-bottom:0}blockquote small{display:block;line-height:1.428571429;color:#999}blockquote small:before{content:'\2014 \00A0'}blockquote.pull-right{padding-right:15px;padding-left:0;border-right:5px solid #eee;border-left:0}blockquote.pull-right p,blockquote.pull-right small{text-align:right}blockquote.pull-right small:before{content:''}blockquote.pull-right small:after{content:'\00A0 \2014'}q:before,q:after,blockquote:before,blockquote:after{content:""}address{display:block;margin-bottom:20px;font-style:normal;line-height:1.428571429}code,pre{font-family:Monaco,Menlo,Consolas,"Courier New",monospace}code{padding:2px 4px;font-size:90%;color:#c7254e;white-space:nowrap;background-color:#f9f2f4;border-radius:4px}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:1.428571429;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;border-radius:4px}pre.prettyprint{margin-bottom:20px}pre code{padding:0;font-size:inherit;color:inherit;white-space:pre-wrap;background-color:transparent;border:0}.pre-scrollable{max-height:340px;overflow-y:scroll}.container{padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}.container:before,.container:after{display:table;content:" "}.container:after{clear:both}.container:before,.container:after{display:table;content:" "}.container:after{clear:both}.row{margin-right:-15px;margin-left:-15px}.row:before,.row:after{display:table;content:" "}.row:after{clear:both}.row:before,.row:after{display:table;content:" "}.row:after{clear:both}.col-xs-1,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9,.col-xs-10,.col-xs-11,.col-xs-12,.col-sm-1,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-sm-10,.col-sm-11,.col-sm-12,.col-md-1,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-md-10,.col-md-11,.col-md-12,.col-lg-1,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-lg-10,.col-lg-11,.col-lg-12{position:relative;min-height:1px;padding-right:15px;padding-left:15px}.col-xs-1,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9,.col-xs-10,.col-xs-11{float:left}.col-xs-1{width:8.333333333333332%}.col-xs-2{width:16.666666666666664%}.col-xs-3{width:25%}.col-xs-4{width:33.33333333333333%}.col-xs-5{width:41.66666666666667%}.col-xs-6{width:50%}.col-xs-7{width:58.333333333333336%}.col-xs-8{width:66.66666666666666%}.col-xs-9{width:75%}.col-xs-10{width:83.33333333333334%}.col-xs-11{width:91.66666666666666%}.col-xs-12{width:100%}@media(min-width:768px){.container{max-width:750px}.col-sm-1,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-sm-10,.col-sm-11{float:left}.col-sm-1{width:8.333333333333332%}.col-sm-2{width:16.666666666666664%}.col-sm-3{width:25%}.col-sm-4{width:33.33333333333333%}.col-sm-5{width:41.66666666666667%}.col-sm-6{width:50%}.col-sm-7{width:58.333333333333336%}.col-sm-8{width:66.66666666666666%}.col-sm-9{width:75%}.col-sm-10{width:83.33333333333334%}.col-sm-11{width:91.66666666666666%}.col-sm-12{width:100%}.col-sm-push-1{left:8.333333333333332%}.col-sm-push-2{left:16.666666666666664%}.col-sm-push-3{left:25%}.col-sm-push-4{left:33.33333333333333%}.col-sm-push-5{left:41.66666666666667%}.col-sm-push-6{left:50%}.col-sm-push-7{left:58.333333333333336%}.col-sm-push-8{left:66.66666666666666%}.col-sm-push-9{left:75%}.col-sm-push-10{left:83.33333333333334%}.col-sm-push-11{left:91.66666666666666%}.col-sm-pull-1{right:8.333333333333332%}.col-sm-pull-2{right:16.666666666666664%}.col-sm-pull-3{right:25%}.col-sm-pull-4{right:33.33333333333333%}.col-sm-pull-5{right:41.66666666666667%}.col-sm-pull-6{right:50%}.col-sm-pull-7{right:58.333333333333336%}.col-sm-pull-8{right:66.66666666666666%}.col-sm-pull-9{right:75%}.col-sm-pull-10{right:83.33333333333334%}.col-sm-pull-11{right:91.66666666666666%}.col-sm-offset-1{margin-left:8.333333333333332%}.col-sm-offset-2{margin-left:16.666666666666664%}.col-sm-offset-3{margin-left:25%}.col-sm-offset-4{margin-left:33.33333333333333%}.col-sm-offset-5{margin-left:41.66666666666667%}.col-sm-offset-6{margin-left:50%}.col-sm-offset-7{margin-left:58.333333333333336%}.col-sm-offset-8{margin-left:66.66666666666666%}.col-sm-offset-9{margin-left:75%}.col-sm-offset-10{margin-left:83.33333333333334%}.col-sm-offset-11{margin-left:91.66666666666666%}}@media(min-width:992px){.container{max-width:970px}.col-md-1,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-md-10,.col-md-11{float:left}.col-md-1{width:8.333333333333332%}.col-md-2{width:16.666666666666664%}.col-md-3{width:25%}.col-md-4{width:33.33333333333333%}.col-md-5{width:41.66666666666667%}.col-md-6{width:50%}.col-md-7{width:58.333333333333336%}.col-md-8{width:66.66666666666666%}.col-md-9{width:75%}.col-md-10{width:83.33333333333334%}.col-md-11{width:91.66666666666666%}.col-md-12{width:100%}.col-md-push-0{left:auto}.col-md-push-1{left:8.333333333333332%}.col-md-push-2{left:16.666666666666664%}.col-md-push-3{left:25%}.col-md-push-4{left:33.33333333333333%}.col-md-push-5{left:41.66666666666667%}.col-md-push-6{left:50%}.col-md-push-7{left:58.333333333333336%}.col-md-push-8{left:66.66666666666666%}.col-md-push-9{left:75%}.col-md-push-10{left:83.33333333333334%}.col-md-push-11{left:91.66666666666666%}.col-md-pull-0{right:auto}.col-md-pull-1{right:8.333333333333332%}.col-md-pull-2{right:16.666666666666664%}.col-md-pull-3{right:25%}.col-md-pull-4{right:33.33333333333333%}.col-md-pull-5{right:41.66666666666667%}.col-md-pull-6{right:50%}.col-md-pull-7{right:58.333333333333336%}.col-md-pull-8{right:66.66666666666666%}.col-md-pull-9{right:75%}.col-md-pull-10{right:83.33333333333334%}.col-md-pull-11{right:91.66666666666666%}.col-md-offset-0{margin-left:0}.col-md-offset-1{margin-left:8.333333333333332%}.col-md-offset-2{margin-left:16.666666666666664%}.col-md-offset-3{margin-left:25%}.col-md-offset-4{margin-left:33.33333333333333%}.col-md-offset-5{margin-left:41.66666666666667%}.col-md-offset-6{margin-left:50%}.col-md-offset-7{margin-left:58.333333333333336%}.col-md-offset-8{margin-left:66.66666666666666%}.col-md-offset-9{margin-left:75%}.col-md-offset-10{margin-left:83.33333333333334%}.col-md-offset-11{margin-left:91.66666666666666%}}@media(min-width:1200px){.container{max-width:1170px}.col-lg-1,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-lg-10,.col-lg-11{float:left}.col-lg-1{width:8.333333333333332%}.col-lg-2{width:16.666666666666664%}.col-lg-3{width:25%}.col-lg-4{width:33.33333333333333%}.col-lg-5{width:41.66666666666667%}.col-lg-6{width:50%}.col-lg-7{width:58.333333333333336%}.col-lg-8{width:66.66666666666666%}.col-lg-9{width:75%}.col-lg-10{width:83.33333333333334%}.col-lg-11{width:91.66666666666666%}.col-lg-12{width:100%}.col-lg-push-0{left:auto}.col-lg-push-1{left:8.333333333333332%}.col-lg-push-2{left:16.666666666666664%}.col-lg-push-3{left:25%}.col-lg-push-4{left:33.33333333333333%}.col-lg-push-5{left:41.66666666666667%}.col-lg-push-6{left:50%}.col-lg-push-7{left:58.333333333333336%}.col-lg-push-8{left:66.66666666666666%}.col-lg-push-9{left:75%}.col-lg-push-10{left:83.33333333333334%}.col-lg-push-11{left:91.66666666666666%}.col-lg-pull-0{right:auto}.col-lg-pull-1{right:8.333333333333332%}.col-lg-pull-2{right:16.666666666666664%}.col-lg-pull-3{right:25%}.col-lg-pull-4{right:33.33333333333333%}.col-lg-pull-5{right:41.66666666666667%}.col-lg-pull-6{right:50%}.col-lg-pull-7{right:58.333333333333336%}.col-lg-pull-8{right:66.66666666666666%}.col-lg-pull-9{right:75%}.col-lg-pull-10{right:83.33333333333334%}.col-lg-pull-11{right:91.66666666666666%}.col-lg-offset-0{margin-left:0}.col-lg-offset-1{margin-left:8.333333333333332%}.col-lg-offset-2{margin-left:16.666666666666664%}.col-lg-offset-3{margin-left:25%}.col-lg-offset-4{margin-left:33.33333333333333%}.col-lg-offset-5{margin-left:41.66666666666667%}.col-lg-offset-6{margin-left:50%}.col-lg-offset-7{margin-left:58.333333333333336%}.col-lg-offset-8{margin-left:66.66666666666666%}.col-lg-offset-9{margin-left:75%}.col-lg-offset-10{margin-left:83.33333333333334%}.col-lg-offset-11{margin-left:91.66666666666666%}}table{max-width:100%;background-color:transparent}th{text-align:left}.table{width:100%;margin-bottom:20px}.table thead>tr>th,.table tbody>tr>th,.table tfoot>tr>th,.table thead>tr>td,.table tbody>tr>td,.table tfoot>tr>td{padding:8px;line-height:1.428571429;vertical-align:top;border-top:1px solid #ddd}.table thead>tr>th{vertical-align:bottom;border-bottom:2px solid #ddd}.table caption+thead tr:first-child th,.table colgroup+thead tr:first-child th,.table thead:first-child tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child td{border-top:0}.table tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed thead>tr>th,.table-condensed tbody>tr>th,.table-condensed tfoot>tr>th,.table-condensed thead>tr>td,.table-condensed tbody>tr>td,.table-condensed tfoot>tr>td{padding:5px}.table-bordered{border:1px solid #ddd}.table-bordered>thead>tr>th,.table-bordered>tbody>tr>th,.table-bordered>tfoot>tr>th,.table-bordered>thead>tr>td,.table-bordered>tbody>tr>td,.table-bordered>tfoot>tr>td{border:1px solid #ddd}.table-bordered>thead>tr>th,.table-bordered>thead>tr>td{border-bottom-width:2px}.table-striped>tbody>tr:nth-child(odd)>td,.table-striped>tbody>tr:nth-child(odd)>th{background-color:#f9f9f9}.table-hover>tbody>tr:hover>td,.table-hover>tbody>tr:hover>th{background-color:#f5f5f5}table col[class*="col-"]{display:table-column;float:none}table td[class*="col-"],table th[class*="col-"]{display:table-cell;float:none}.table>thead>tr>td.active,.table>tbody>tr>td.active,.table>tfoot>tr>td.active,.table>thead>tr>th.active,.table>tbody>tr>th.active,.table>tfoot>tr>th.active,.table>thead>tr.active>td,.table>tbody>tr.active>td,.table>tfoot>tr.active>td,.table>thead>tr.active>th,.table>tbody>tr.active>th,.table>tfoot>tr.active>th{background-color:#f5f5f5}.table>thead>tr>td.success,.table>tbody>tr>td.success,.table>tfoot>tr>td.success,.table>thead>tr>th.success,.table>tbody>tr>th.success,.table>tfoot>tr>th.success,.table>thead>tr.success>td,.table>tbody>tr.success>td,.table>tfoot>tr.success>td,.table>thead>tr.success>th,.table>tbody>tr.success>th,.table>tfoot>tr.success>th{background-color:#dff0d8;border-color:#d6e9c6}.table-hover>tbody>tr>td.success:hover,.table-hover>tbody>tr>th.success:hover,.table-hover>tbody>tr.success:hover>td{background-color:#d0e9c6;border-color:#c9e2b3}.table>thead>tr>td.danger,.table>tbody>tr>td.danger,.table>tfoot>tr>td.danger,.table>thead>tr>th.danger,.table>tbody>tr>th.danger,.table>tfoot>tr>th.danger,.table>thead>tr.danger>td,.table>tbody>tr.danger>td,.table>tfoot>tr.danger>td,.table>thead>tr.danger>th,.table>tbody>tr.danger>th,.table>tfoot>tr.danger>th{background-color:#f2dede;border-color:#eed3d7}.table-hover>tbody>tr>td.danger:hover,.table-hover>tbody>tr>th.danger:hover,.table-hover>tbody>tr.danger:hover>td{background-color:#ebcccc;border-color:#e6c1c7}.table>thead>tr>td.warning,.table>tbody>tr>td.warning,.table>tfoot>tr>td.warning,.table>thead>tr>th.warning,.table>tbody>tr>th.warning,.table>tfoot>tr>th.warning,.table>thead>tr.warning>td,.table>tbody>tr.warning>td,.table>tfoot>tr.warning>td,.table>thead>tr.warning>th,.table>tbody>tr.warning>th,.table>tfoot>tr.warning>th{background-color:#fcf8e3;border-color:#fbeed5}.table-hover>tbody>tr>td.warning:hover,.table-hover>tbody>tr>th.warning:hover,.table-hover>tbody>tr.warning:hover>td{background-color:#faf2cc;border-color:#f8e5be}@media(max-width:768px){.table-responsive{width:100%;margin-bottom:15px;overflow-x:scroll;overflow-y:hidden;border:1px solid #ddd}.table-responsive>.table{margin-bottom:0;background-color:#fff}.table-responsive>.table>thead>tr>th,.table-responsive>.table>tbody>tr>th,.table-responsive>.table>tfoot>tr>th,.table-responsive>.table>thead>tr>td,.table-responsive>.table>tbody>tr>td,.table-responsive>.table>tfoot>tr>td{white-space:nowrap}.table-responsive>.table-bordered{border:0}.table-responsive>.table-bordered>thead>tr>th:first-child,.table-responsive>.table-bordered>tbody>tr>th:first-child,.table-responsive>.table-bordered>tfoot>tr>th:first-child,.table-responsive>.table-bordered>thead>tr>td:first-child,.table-responsive>.table-bordered>tbody>tr>td:first-child,.table-responsive>.table-bordered>tfoot>tr>td:first-child{border-left:0}.table-responsive>.table-bordered>thead>tr>th:last-child,.table-responsive>.table-bordered>tbody>tr>th:last-child,.table-responsive>.table-bordered>tfoot>tr>th:last-child,.table-responsive>.table-bordered>thead>tr>td:last-child,.table-responsive>.table-bordered>tbody>tr>td:last-child,.table-responsive>.table-bordered>tfoot>tr>td:last-child{border-right:0}.table-responsive>.table-bordered>thead>tr:last-child>th,.table-responsive>.table-bordered>tbody>tr:last-child>th,.table-responsive>.table-bordered>tfoot>tr:last-child>th,.table-responsive>.table-bordered>thead>tr:last-child>td,.table-responsive>.table-bordered>tbody>tr:last-child>td,.table-responsive>.table-bordered>tfoot>tr:last-child>td{border-bottom:0}}fieldset{padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:inherit;color:#333;border:0;border-bottom:1px solid #e5e5e5}label{display:inline-block;margin-bottom:5px;font-weight:bold}input[type="search"]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;line-height:normal}input[type="file"]{display:block}select[multiple],select[size]{height:auto}select optgroup{font-family:inherit;font-size:inherit;font-style:inherit}input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}input[type="number"]::-webkit-outer-spin-button,input[type="number"]::-webkit-inner-spin-button{height:auto}.form-control:-moz-placeholder{color:#999}.form-control::-moz-placeholder{color:#999}.form-control:-ms-input-placeholder{color:#999}.form-control::-webkit-input-placeholder{color:#999}.form-control{display:block;width:100%;height:34px;padding:6px 12px;font-size:14px;line-height:1.428571429;color:#555;vertical-align:middle;background-color:#fff;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.form-control:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.form-control[disabled],.form-control[readonly],fieldset[disabled] .form-control{cursor:not-allowed;background-color:#eee}textarea.form-control{height:auto}.form-group{margin-bottom:15px}.radio,.checkbox{display:block;min-height:20px;padding-left:20px;margin-top:10px;margin-bottom:10px;vertical-align:middle}.radio label,.checkbox label{display:inline;margin-bottom:0;font-weight:normal;cursor:pointer}.radio input[type="radio"],.radio-inline input[type="radio"],.checkbox input[type="checkbox"],.checkbox-inline input[type="checkbox"]{float:left;margin-left:-20px}.radio+.radio,.checkbox+.checkbox{margin-top:-5px}.radio-inline,.checkbox-inline{display:inline-block;padding-left:20px;margin-bottom:0;font-weight:normal;vertical-align:middle;cursor:pointer}.radio-inline+.radio-inline,.checkbox-inline+.checkbox-inline{margin-top:0;margin-left:10px}input[type="radio"][disabled],input[type="checkbox"][disabled],.radio[disabled],.radio-inline[disabled],.checkbox[disabled],.checkbox-inline[disabled],fieldset[disabled] input[type="radio"],fieldset[disabled] input[type="checkbox"],fieldset[disabled] .radio,fieldset[disabled] .radio-inline,fieldset[disabled] .checkbox,fieldset[disabled] .checkbox-inline{cursor:not-allowed}.input-sm{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.input-sm{height:30px;line-height:30px}textarea.input-sm{height:auto}.input-lg{height:45px;padding:10px 16px;font-size:18px;line-height:1.33;border-radius:6px}select.input-lg{height:45px;line-height:45px}textarea.input-lg{height:auto}.has-warning .help-block,.has-warning .control-label{color:#c09853}.has-warning .form-control{border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.has-warning .form-control:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.has-warning .input-group-addon{color:#c09853;background-color:#fcf8e3;border-color:#c09853}.has-error .help-block,.has-error .control-label{color:#b94a48}.has-error .form-control{border-color:#b94a48;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.has-error .form-control:focus{border-color:#953b39;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392}.has-error .input-group-addon{color:#b94a48;background-color:#f2dede;border-color:#b94a48}.has-success .help-block,.has-success .control-label{color:#468847}.has-success .form-control{border-color:#468847;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.has-success .form-control:focus{border-color:#356635;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b}.has-success .input-group-addon{color:#468847;background-color:#dff0d8;border-color:#468847}.form-control-static{padding-top:7px;margin-bottom:0}.help-block{display:block;margin-top:5px;margin-bottom:10px;color:#737373}@media(min-width:768px){.form-inline .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.form-inline .form-control{display:inline-block}.form-inline .radio,.form-inline .checkbox{display:inline-block;padding-left:0;margin-top:0;margin-bottom:0}.form-inline .radio input[type="radio"],.form-inline .checkbox input[type="checkbox"]{float:none;margin-left:0}}.form-horizontal .control-label,.form-horizontal .radio,.form-horizontal .checkbox,.form-horizontal .radio-inline,.form-horizontal .checkbox-inline{padding-top:7px;margin-top:0;margin-bottom:0}.form-horizontal .form-group{margin-right:-15px;margin-left:-15px}.form-horizontal .form-group:before,.form-horizontal .form-group:after{display:table;content:" "}.form-horizontal .form-group:after{clear:both}.form-horizontal .form-group:before,.form-horizontal .form-group:after{display:table;content:" "}.form-horizontal .form-group:after{clear:both}@media(min-width:768px){.form-horizontal .control-label{text-align:right}}.btn{display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:normal;line-height:1.428571429;text-align:center;white-space:nowrap;vertical-align:middle;cursor:pointer;border:1px solid transparent;border-radius:4px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.btn:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn:hover,.btn:focus{color:#333;text-decoration:none}.btn:active,.btn.active{background-image:none;outline:0;-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}.btn.disabled,.btn[disabled],fieldset[disabled] .btn{pointer-events:none;cursor:not-allowed;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none}.btn-default{color:#333;background-color:#fff;border-color:#ccc}.btn-default:hover,.btn-default:focus,.btn-default:active,.btn-default.active,.open .dropdown-toggle.btn-default{color:#333;background-color:#ebebeb;border-color:#adadad}.btn-default:active,.btn-default.active,.open .dropdown-toggle.btn-default{background-image:none}.btn-default.disabled,.btn-default[disabled],fieldset[disabled] .btn-default,.btn-default.disabled:hover,.btn-default[disabled]:hover,fieldset[disabled] .btn-default:hover,.btn-default.disabled:focus,.btn-default[disabled]:focus,fieldset[disabled] .btn-default:focus,.btn-default.disabled:active,.btn-default[disabled]:active,fieldset[disabled] .btn-default:active,.btn-default.disabled.active,.btn-default[disabled].active,fieldset[disabled] .btn-default.active{background-color:#fff;border-color:#ccc}.btn-primary{color:#fff;background-color:#428bca;border-color:#357ebd}.btn-primary:hover,.btn-primary:focus,.btn-primary:active,.btn-primary.active,.open .dropdown-toggle.btn-primary{color:#fff;background-color:#3276b1;border-color:#285e8e}.btn-primary:active,.btn-primary.active,.open .dropdown-toggle.btn-primary{background-image:none}.btn-primary.disabled,.btn-primary[disabled],fieldset[disabled] .btn-primary,.btn-primary.disabled:hover,.btn-primary[disabled]:hover,fieldset[disabled] .btn-primary:hover,.btn-primary.disabled:focus,.btn-primary[disabled]:focus,fieldset[disabled] .btn-primary:focus,.btn-primary.disabled:active,.btn-primary[disabled]:active,fieldset[disabled] .btn-primary:active,.btn-primary.disabled.active,.btn-primary[disabled].active,fieldset[disabled] .btn-primary.active{background-color:#428bca;border-color:#357ebd}.btn-warning{color:#fff;background-color:#f0ad4e;border-color:#eea236}.btn-warning:hover,.btn-warning:focus,.btn-warning:active,.btn-warning.active,.open .dropdown-toggle.btn-warning{color:#fff;background-color:#ed9c28;border-color:#d58512}.btn-warning:active,.btn-warning.active,.open .dropdown-toggle.btn-warning{background-image:none}.btn-warning.disabled,.btn-warning[disabled],fieldset[disabled] .btn-warning,.btn-warning.disabled:hover,.btn-warning[disabled]:hover,fieldset[disabled] .btn-warning:hover,.btn-warning.disabled:focus,.btn-warning[disabled]:focus,fieldset[disabled] .btn-warning:focus,.btn-warning.disabled:active,.btn-warning[disabled]:active,fieldset[disabled] .btn-warning:active,.btn-warning.disabled.active,.btn-warning[disabled].active,fieldset[disabled] .btn-warning.active{background-color:#f0ad4e;border-color:#eea236}.btn-danger{color:#fff;background-color:#d9534f;border-color:#d43f3a}.btn-danger:hover,.btn-danger:focus,.btn-danger:active,.btn-danger.active,.open .dropdown-toggle.btn-danger{color:#fff;background-color:#d2322d;border-color:#ac2925}.btn-danger:active,.btn-danger.active,.open .dropdown-toggle.btn-danger{background-image:none}.btn-danger.disabled,.btn-danger[disabled],fieldset[disabled] .btn-danger,.btn-danger.disabled:hover,.btn-danger[disabled]:hover,fieldset[disabled] .btn-danger:hover,.btn-danger.disabled:focus,.btn-danger[disabled]:focus,fieldset[disabled] .btn-danger:focus,.btn-danger.disabled:active,.btn-danger[disabled]:active,fieldset[disabled] .btn-danger:active,.btn-danger.disabled.active,.btn-danger[disabled].active,fieldset[disabled] .btn-danger.active{background-color:#d9534f;border-color:#d43f3a}.btn-success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.btn-success:hover,.btn-success:focus,.btn-success:active,.btn-success.active,.open .dropdown-toggle.btn-success{color:#fff;background-color:#47a447;border-color:#398439}.btn-success:active,.btn-success.active,.open .dropdown-toggle.btn-success{background-image:none}.btn-success.disabled,.btn-success[disabled],fieldset[disabled] .btn-success,.btn-success.disabled:hover,.btn-success[disabled]:hover,fieldset[disabled] .btn-success:hover,.btn-success.disabled:focus,.btn-success[disabled]:focus,fieldset[disabled] .btn-success:focus,.btn-success.disabled:active,.btn-success[disabled]:active,fieldset[disabled] .btn-success:active,.btn-success.disabled.active,.btn-success[disabled].active,fieldset[disabled] .btn-success.active{background-color:#5cb85c;border-color:#4cae4c}.btn-info{color:#fff;background-color:#5bc0de;border-color:#46b8da}.btn-info:hover,.btn-info:focus,.btn-info:active,.btn-info.active,.open .dropdown-toggle.btn-info{color:#fff;background-color:#39b3d7;border-color:#269abc}.btn-info:active,.btn-info.active,.open .dropdown-toggle.btn-info{background-image:none}.btn-info.disabled,.btn-info[disabled],fieldset[disabled] .btn-info,.btn-info.disabled:hover,.btn-info[disabled]:hover,fieldset[disabled] .btn-info:hover,.btn-info.disabled:focus,.btn-info[disabled]:focus,fieldset[disabled] .btn-info:focus,.btn-info.disabled:active,.btn-info[disabled]:active,fieldset[disabled] .btn-info:active,.btn-info.disabled.active,.btn-info[disabled].active,fieldset[disabled] .btn-info.active{background-color:#5bc0de;border-color:#46b8da}.btn-link{font-weight:normal;color:#428bca;cursor:pointer;border-radius:0}.btn-link,.btn-link:active,.btn-link[disabled],fieldset[disabled] .btn-link{background-color:transparent;-webkit-box-shadow:none;box-shadow:none}.btn-link,.btn-link:hover,.btn-link:focus,.btn-link:active{border-color:transparent}.btn-link:hover,.btn-link:focus{color:#2a6496;text-decoration:underline;background-color:transparent}.btn-link[disabled]:hover,fieldset[disabled] .btn-link:hover,.btn-link[disabled]:focus,fieldset[disabled] .btn-link:focus{color:#999;text-decoration:none}.btn-lg{padding:10px 16px;font-size:18px;line-height:1.33;border-radius:6px}.btn-sm,.btn-xs{padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.btn-xs{padding:1px 5px}.btn-block{display:block;width:100%;padding-right:0;padding-left:0}.btn-block+.btn-block{margin-top:5px}input[type="submit"].btn-block,input[type="reset"].btn-block,input[type="button"].btn-block{width:100%}.fade{opacity:0;-webkit-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{display:none}.collapse.in{display:block}.collapsing{position:relative;height:0;overflow:hidden;-webkit-transition:height .35s ease;transition:height .35s ease}@font-face{font-family:'Glyphicons Halflings';src:url('../fonts/glyphicons-halflings-regular.eot');src:url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),url('../fonts/glyphicons-halflings-regular.woff') format('woff'),url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),url('../fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg')}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';-webkit-font-smoothing:antialiased;font-style:normal;font-weight:normal;line-height:1}.glyphicon-asterisk:before{content:"\2a"}.glyphicon-plus:before{content:"\2b"}.glyphicon-euro:before{content:"\20ac"}.glyphicon-minus:before{content:"\2212"}.glyphicon-cloud:before{content:"\2601"}.glyphicon-envelope:before{content:"\2709"}.glyphicon-pencil:before{content:"\270f"}.glyphicon-glass:before{content:"\e001"}.glyphicon-music:before{content:"\e002"}.glyphicon-search:before{content:"\e003"}.glyphicon-heart:before{content:"\e005"}.glyphicon-star:before{content:"\e006"}.glyphicon-star-empty:before{content:"\e007"}.glyphicon-user:before{content:"\e008"}.glyphicon-film:before{content:"\e009"}.glyphicon-th-large:before{content:"\e010"}.glyphicon-th:before{content:"\e011"}.glyphicon-th-list:before{content:"\e012"}.glyphicon-ok:before{content:"\e013"}.glyphicon-remove:before{content:"\e014"}.glyphicon-zoom-in:before{content:"\e015"}.glyphicon-zoom-out:before{content:"\e016"}.glyphicon-off:before{content:"\e017"}.glyphicon-signal:before{content:"\e018"}.glyphicon-cog:before{content:"\e019"}.glyphicon-trash:before{content:"\e020"}.glyphicon-home:before{content:"\e021"}.glyphicon-file:before{content:"\e022"}.glyphicon-time:before{content:"\e023"}.glyphicon-road:before{content:"\e024"}.glyphicon-download-alt:before{content:"\e025"}.glyphicon-download:before{content:"\e026"}.glyphicon-upload:before{content:"\e027"}.glyphicon-inbox:before{content:"\e028"}.glyphicon-play-circle:before{content:"\e029"}.glyphicon-repeat:before{content:"\e030"}.glyphicon-refresh:before{content:"\e031"}.glyphicon-list-alt:before{content:"\e032"}.glyphicon-flag:before{content:"\e034"}.glyphicon-headphones:before{content:"\e035"}.glyphicon-volume-off:before{content:"\e036"}.glyphicon-volume-down:before{content:"\e037"}.glyphicon-volume-up:before{content:"\e038"}.glyphicon-qrcode:before{content:"\e039"}.glyphicon-barcode:before{content:"\e040"}.glyphicon-tag:before{content:"\e041"}.glyphicon-tags:before{content:"\e042"}.glyphicon-book:before{content:"\e043"}.glyphicon-print:before{content:"\e045"}.glyphicon-font:before{content:"\e047"}.glyphicon-bold:before{content:"\e048"}.glyphicon-italic:before{content:"\e049"}.glyphicon-text-height:before{content:"\e050"}.glyphicon-text-width:before{content:"\e051"}.glyphicon-align-left:before{content:"\e052"}.glyphicon-align-center:before{content:"\e053"}.glyphicon-align-right:before{content:"\e054"}.glyphicon-align-justify:before{content:"\e055"}.glyphicon-list:before{content:"\e056"}.glyphicon-indent-left:before{content:"\e057"}.glyphicon-indent-right:before{content:"\e058"}.glyphicon-facetime-video:before{content:"\e059"}.glyphicon-picture:before{content:"\e060"}.glyphicon-map-marker:before{content:"\e062"}.glyphicon-adjust:before{content:"\e063"}.glyphicon-tint:before{content:"\e064"}.glyphicon-edit:before{content:"\e065"}.glyphicon-share:before{content:"\e066"}.glyphicon-check:before{content:"\e067"}.glyphicon-move:before{content:"\e068"}.glyphicon-step-backward:before{content:"\e069"}.glyphicon-fast-backward:before{content:"\e070"}.glyphicon-backward:before{content:"\e071"}.glyphicon-play:before{content:"\e072"}.glyphicon-pause:before{content:"\e073"}.glyphicon-stop:before{content:"\e074"}.glyphicon-forward:before{content:"\e075"}.glyphicon-fast-forward:before{content:"\e076"}.glyphicon-step-forward:before{content:"\e077"}.glyphicon-eject:before{content:"\e078"}.glyphicon-chevron-left:before{content:"\e079"}.glyphicon-chevron-right:before{content:"\e080"}.glyphicon-plus-sign:before{content:"\e081"}.glyphicon-minus-sign:before{content:"\e082"}.glyphicon-remove-sign:before{content:"\e083"}.glyphicon-ok-sign:before{content:"\e084"}.glyphicon-question-sign:before{content:"\e085"}.glyphicon-info-sign:before{content:"\e086"}.glyphicon-screenshot:before{content:"\e087"}.glyphicon-remove-circle:before{content:"\e088"}.glyphicon-ok-circle:before{content:"\e089"}.glyphicon-ban-circle:before{content:"\e090"}.glyphicon-arrow-left:before{content:"\e091"}.glyphicon-arrow-right:before{content:"\e092"}.glyphicon-arrow-up:before{content:"\e093"}.glyphicon-arrow-down:before{content:"\e094"}.glyphicon-share-alt:before{content:"\e095"}.glyphicon-resize-full:before{content:"\e096"}.glyphicon-resize-small:before{content:"\e097"}.glyphicon-exclamation-sign:before{content:"\e101"}.glyphicon-gift:before{content:"\e102"}.glyphicon-leaf:before{content:"\e103"}.glyphicon-eye-open:before{content:"\e105"}.glyphicon-eye-close:before{content:"\e106"}.glyphicon-warning-sign:before{content:"\e107"}.glyphicon-plane:before{content:"\e108"}.glyphicon-random:before{content:"\e110"}.glyphicon-comment:before{content:"\e111"}.glyphicon-magnet:before{content:"\e112"}.glyphicon-chevron-up:before{content:"\e113"}.glyphicon-chevron-down:before{content:"\e114"}.glyphicon-retweet:before{content:"\e115"}.glyphicon-shopping-cart:before{content:"\e116"}.glyphicon-folder-close:before{content:"\e117"}.glyphicon-folder-open:before{content:"\e118"}.glyphicon-resize-vertical:before{content:"\e119"}.glyphicon-resize-horizontal:before{content:"\e120"}.glyphicon-hdd:before{content:"\e121"}.glyphicon-bullhorn:before{content:"\e122"}.glyphicon-certificate:before{content:"\e124"}.glyphicon-thumbs-up:before{content:"\e125"}.glyphicon-thumbs-down:before{content:"\e126"}.glyphicon-hand-right:before{content:"\e127"}.glyphicon-hand-left:before{content:"\e128"}.glyphicon-hand-up:before{content:"\e129"}.glyphicon-hand-down:before{content:"\e130"}.glyphicon-circle-arrow-right:before{content:"\e131"}.glyphicon-circle-arrow-left:before{content:"\e132"}.glyphicon-circle-arrow-up:before{content:"\e133"}.glyphicon-circle-arrow-down:before{content:"\e134"}.glyphicon-globe:before{content:"\e135"}.glyphicon-tasks:before{content:"\e137"}.glyphicon-filter:before{content:"\e138"}.glyphicon-fullscreen:before{content:"\e140"}.glyphicon-dashboard:before{content:"\e141"}.glyphicon-heart-empty:before{content:"\e143"}.glyphicon-link:before{content:"\e144"}.glyphicon-phone:before{content:"\e145"}.glyphicon-usd:before{content:"\e148"}.glyphicon-gbp:before{content:"\e149"}.glyphicon-sort:before{content:"\e150"}.glyphicon-sort-by-alphabet:before{content:"\e151"}.glyphicon-sort-by-alphabet-alt:before{content:"\e152"}.glyphicon-sort-by-order:before{content:"\e153"}.glyphicon-sort-by-order-alt:before{content:"\e154"}.glyphicon-sort-by-attributes:before{content:"\e155"}.glyphicon-sort-by-attributes-alt:before{content:"\e156"}.glyphicon-unchecked:before{content:"\e157"}.glyphicon-expand:before{content:"\e158"}.glyphicon-collapse-down:before{content:"\e159"}.glyphicon-collapse-up:before{content:"\e160"}.glyphicon-log-in:before{content:"\e161"}.glyphicon-flash:before{content:"\e162"}.glyphicon-log-out:before{content:"\e163"}.glyphicon-new-window:before{content:"\e164"}.glyphicon-record:before{content:"\e165"}.glyphicon-save:before{content:"\e166"}.glyphicon-open:before{content:"\e167"}.glyphicon-saved:before{content:"\e168"}.glyphicon-import:before{content:"\e169"}.glyphicon-export:before{content:"\e170"}.glyphicon-send:before{content:"\e171"}.glyphicon-floppy-disk:before{content:"\e172"}.glyphicon-floppy-saved:before{content:"\e173"}.glyphicon-floppy-remove:before{content:"\e174"}.glyphicon-floppy-save:before{content:"\e175"}.glyphicon-floppy-open:before{content:"\e176"}.glyphicon-credit-card:before{content:"\e177"}.glyphicon-transfer:before{content:"\e178"}.glyphicon-cutlery:before{content:"\e179"}.glyphicon-header:before{content:"\e180"}.glyphicon-compressed:before{content:"\e181"}.glyphicon-earphone:before{content:"\e182"}.glyphicon-phone-alt:before{content:"\e183"}.glyphicon-tower:before{content:"\e184"}.glyphicon-stats:before{content:"\e185"}.glyphicon-sd-video:before{content:"\e186"}.glyphicon-hd-video:before{content:"\e187"}.glyphicon-subtitles:before{content:"\e188"}.glyphicon-sound-stereo:before{content:"\e189"}.glyphicon-sound-dolby:before{content:"\e190"}.glyphicon-sound-5-1:before{content:"\e191"}.glyphicon-sound-6-1:before{content:"\e192"}.glyphicon-sound-7-1:before{content:"\e193"}.glyphicon-copyright-mark:before{content:"\e194"}.glyphicon-registration-mark:before{content:"\e195"}.glyphicon-cloud-download:before{content:"\e197"}.glyphicon-cloud-upload:before{content:"\e198"}.glyphicon-tree-conifer:before{content:"\e199"}.glyphicon-tree-deciduous:before{content:"\e200"}.glyphicon-briefcase:before{content:"\1f4bc"}.glyphicon-calendar:before{content:"\1f4c5"}.glyphicon-pushpin:before{content:"\1f4cc"}.glyphicon-paperclip:before{content:"\1f4ce"}.glyphicon-camera:before{content:"\1f4f7"}.glyphicon-lock:before{content:"\1f512"}.glyphicon-bell:before{content:"\1f514"}.glyphicon-bookmark:before{content:"\1f516"}.glyphicon-fire:before{content:"\1f525"}.glyphicon-wrench:before{content:"\1f527"}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px solid #000;border-right:4px solid transparent;border-bottom:0 dotted;border-left:4px solid transparent;content:""}.dropdown{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;font-size:14px;list-style:none;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:4px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.428571429;color:#333;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{color:#fff;text-decoration:none;background-color:#428bca}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;background-color:#428bca;outline:0}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#999}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;cursor:not-allowed;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.428571429;color:#999}.dropdown-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0 dotted;border-bottom:4px solid #000;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:1px}@media(min-width:768px){.navbar-right .dropdown-menu{right:0;left:auto}}.btn-default .caret{border-top-color:#333}.btn-primary .caret,.btn-success .caret,.btn-warning .caret,.btn-danger .caret,.btn-info .caret{border-top-color:#fff}.dropup .btn-default .caret{border-bottom-color:#333}.dropup .btn-primary .caret,.dropup .btn-success .caret,.dropup .btn-warning .caret,.dropup .btn-danger .caret,.dropup .btn-info .caret{border-bottom-color:#fff}.btn-group,.btn-group-vertical{position:relative;display:inline-block;vertical-align:middle}.btn-group>.btn,.btn-group-vertical>.btn{position:relative;float:left}.btn-group>.btn:hover,.btn-group-vertical>.btn:hover,.btn-group>.btn:focus,.btn-group-vertical>.btn:focus,.btn-group>.btn:active,.btn-group-vertical>.btn:active,.btn-group>.btn.active,.btn-group-vertical>.btn.active{z-index:2}.btn-group>.btn:focus,.btn-group-vertical>.btn:focus{outline:0}.btn-group .btn+.btn,.btn-group .btn+.btn-group,.btn-group .btn-group+.btn,.btn-group .btn-group+.btn-group{margin-left:-1px}.btn-toolbar:before,.btn-toolbar:after{display:table;content:" "}.btn-toolbar:after{clear:both}.btn-toolbar:before,.btn-toolbar:after{display:table;content:" "}.btn-toolbar:after{clear:both}.btn-toolbar .btn-group{float:left}.btn-toolbar>.btn+.btn,.btn-toolbar>.btn-group+.btn,.btn-toolbar>.btn+.btn-group,.btn-toolbar>.btn-group+.btn-group{margin-left:5px}.btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle){border-radius:0}.btn-group>.btn:first-child{margin-left:0}.btn-group>.btn:first-child:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn:last-child:not(:first-child),.btn-group>.dropdown-toggle:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.btn-group>.btn-group{float:left}.btn-group>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group>.btn-group:first-child>.btn:last-child,.btn-group>.btn-group:first-child>.dropdown-toggle{border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn-group:last-child>.btn:first-child{border-bottom-left-radius:0;border-top-left-radius:0}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group-xs>.btn{padding:5px 10px;padding:1px 5px;font-size:12px;line-height:1.5;border-radius:3px}.btn-group-sm>.btn{padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.btn-group-lg>.btn{padding:10px 16px;font-size:18px;line-height:1.33;border-radius:6px}.btn-group>.btn+.dropdown-toggle{padding-right:8px;padding-left:8px}.btn-group>.btn-lg+.dropdown-toggle{padding-right:12px;padding-left:12px}.btn-group.open .dropdown-toggle{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}.btn .caret{margin-left:0}.btn-lg .caret{border-width:5px 5px 0;border-bottom-width:0}.dropup .btn-lg .caret{border-width:0 5px 5px}.btn-group-vertical>.btn,.btn-group-vertical>.btn-group{display:block;float:none;width:100%;max-width:100%}.btn-group-vertical>.btn-group:before,.btn-group-vertical>.btn-group:after{display:table;content:" "}.btn-group-vertical>.btn-group:after{clear:both}.btn-group-vertical>.btn-group:before,.btn-group-vertical>.btn-group:after{display:table;content:" "}.btn-group-vertical>.btn-group:after{clear:both}.btn-group-vertical>.btn-group>.btn{float:none}.btn-group-vertical>.btn+.btn,.btn-group-vertical>.btn+.btn-group,.btn-group-vertical>.btn-group+.btn,.btn-group-vertical>.btn-group+.btn-group{margin-top:-1px;margin-left:0}.btn-group-vertical>.btn:not(:first-child):not(:last-child){border-radius:0}.btn-group-vertical>.btn:first-child:not(:last-child){border-top-right-radius:4px;border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical>.btn:last-child:not(:first-child){border-top-right-radius:0;border-bottom-left-radius:4px;border-top-left-radius:0}.btn-group-vertical>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group-vertical>.btn-group:first-child>.btn:last-child,.btn-group-vertical>.btn-group:first-child>.dropdown-toggle{border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical>.btn-group:last-child>.btn:first-child{border-top-right-radius:0;border-top-left-radius:0}.btn-group-justified{display:table;width:100%;border-collapse:separate;table-layout:fixed}.btn-group-justified .btn{display:table-cell;float:none;width:1%}[data-toggle="buttons"]>.btn>input[type="radio"],[data-toggle="buttons"]>.btn>input[type="checkbox"]{display:none}.input-group{position:relative;display:table;border-collapse:separate}.input-group.col{float:none;padding-right:0;padding-left:0}.input-group .form-control{width:100%;margin-bottom:0}.input-group-lg>.form-control,.input-group-lg>.input-group-addon,.input-group-lg>.input-group-btn>.btn{height:45px;padding:10px 16px;font-size:18px;line-height:1.33;border-radius:6px}select.input-group-lg>.form-control,select.input-group-lg>.input-group-addon,select.input-group-lg>.input-group-btn>.btn{height:45px;line-height:45px}textarea.input-group-lg>.form-control,textarea.input-group-lg>.input-group-addon,textarea.input-group-lg>.input-group-btn>.btn{height:auto}.input-group-sm>.form-control,.input-group-sm>.input-group-addon,.input-group-sm>.input-group-btn>.btn{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.input-group-sm>.form-control,select.input-group-sm>.input-group-addon,select.input-group-sm>.input-group-btn>.btn{height:30px;line-height:30px}textarea.input-group-sm>.form-control,textarea.input-group-sm>.input-group-addon,textarea.input-group-sm>.input-group-btn>.btn{height:auto}.input-group-addon,.input-group-btn,.input-group .form-control{display:table-cell}.input-group-addon:not(:first-child):not(:last-child),.input-group-btn:not(:first-child):not(:last-child),.input-group .form-control:not(:first-child):not(:last-child){border-radius:0}.input-group-addon,.input-group-btn{width:1%;white-space:nowrap;vertical-align:middle}.input-group-addon{padding:6px 12px;font-size:14px;font-weight:normal;line-height:1;text-align:center;background-color:#eee;border:1px solid #ccc;border-radius:4px}.input-group-addon.input-sm{padding:5px 10px;font-size:12px;border-radius:3px}.input-group-addon.input-lg{padding:10px 16px;font-size:18px;border-radius:6px}.input-group-addon input[type="radio"],.input-group-addon input[type="checkbox"]{margin-top:0}.input-group .form-control:first-child,.input-group-addon:first-child,.input-group-btn:first-child>.btn,.input-group-btn:first-child>.dropdown-toggle,.input-group-btn:last-child>.btn:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.input-group-addon:first-child{border-right:0}.input-group .form-control:last-child,.input-group-addon:last-child,.input-group-btn:last-child>.btn,.input-group-btn:last-child>.dropdown-toggle,.input-group-btn:first-child>.btn:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.input-group-addon:last-child{border-left:0}.input-group-btn{position:relative;white-space:nowrap}.input-group-btn>.btn{position:relative}.input-group-btn>.btn+.btn{margin-left:-4px}.input-group-btn>.btn:hover,.input-group-btn>.btn:active{z-index:2}.nav{padding-left:0;margin-bottom:0;list-style:none}.nav:before,.nav:after{display:table;content:" "}.nav:after{clear:both}.nav:before,.nav:after{display:table;content:" "}.nav:after{clear:both}.nav>li{position:relative;display:block}.nav>li>a{position:relative;display:block;padding:10px 15px}.nav>li>a:hover,.nav>li>a:focus{text-decoration:none;background-color:#eee}.nav>li.disabled>a{color:#999}.nav>li.disabled>a:hover,.nav>li.disabled>a:focus{color:#999;text-decoration:none;cursor:not-allowed;background-color:transparent}.nav .open>a,.nav .open>a:hover,.nav .open>a:focus{background-color:#eee;border-color:#428bca}.nav .nav-divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.nav>li>a>img{max-width:none}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{float:left;margin-bottom:-1px}.nav-tabs>li>a{margin-right:2px;line-height:1.428571429;border:1px solid transparent;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>li.active>a,.nav-tabs>li.active>a:hover,.nav-tabs>li.active>a:focus{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-tabs.nav-justified{width:100%;border-bottom:0}.nav-tabs.nav-justified>li{float:none}.nav-tabs.nav-justified>li>a{text-align:center}@media(min-width:768px){.nav-tabs.nav-justified>li{display:table-cell;width:1%}}.nav-tabs.nav-justified>li>a{margin-right:0;border-bottom:1px solid #ddd}.nav-tabs.nav-justified>.active>a{border-bottom-color:#fff}.nav-pills>li{float:left}.nav-pills>li>a{border-radius:5px}.nav-pills>li+li{margin-left:2px}.nav-pills>li.active>a,.nav-pills>li.active>a:hover,.nav-pills>li.active>a:focus{color:#fff;background-color:#428bca}.nav-stacked>li{float:none}.nav-stacked>li+li{margin-top:2px;margin-left:0}.nav-justified{width:100%}.nav-justified>li{float:none}.nav-justified>li>a{text-align:center}@media(min-width:768px){.nav-justified>li{display:table-cell;width:1%}}.nav-tabs-justified{border-bottom:0}.nav-tabs-justified>li>a{margin-right:0;border-bottom:1px solid #ddd}.nav-tabs-justified>.active>a{border-bottom-color:#fff}.tabbable:before,.tabbable:after{display:table;content:" "}.tabbable:after{clear:both}.tabbable:before,.tabbable:after{display:table;content:" "}.tabbable:after{clear:both}.tab-content>.tab-pane,.pill-content>.pill-pane{display:none}.tab-content>.active,.pill-content>.active{display:block}.nav .caret{border-top-color:#428bca;border-bottom-color:#428bca}.nav a:hover .caret{border-top-color:#2a6496;border-bottom-color:#2a6496}.nav-tabs .dropdown-menu{margin-top:-1px;border-top-right-radius:0;border-top-left-radius:0}.navbar{position:relative;z-index:1000;min-height:50px;margin-bottom:20px;border:1px solid transparent}.navbar:before,.navbar:after{display:table;content:" "}.navbar:after{clear:both}.navbar:before,.navbar:after{display:table;content:" "}.navbar:after{clear:both}@media(min-width:768px){.navbar{border-radius:4px}}.navbar-header:before,.navbar-header:after{display:table;content:" "}.navbar-header:after{clear:both}.navbar-header:before,.navbar-header:after{display:table;content:" "}.navbar-header:after{clear:both}@media(min-width:768px){.navbar-header{float:left}}.navbar-collapse{max-height:340px;padding-right:15px;padding-left:15px;overflow-x:visible;border-top:1px solid transparent;box-shadow:inset 0 1px 0 rgba(255,255,255,0.1);-webkit-overflow-scrolling:touch}.navbar-collapse:before,.navbar-collapse:after{display:table;content:" "}.navbar-collapse:after{clear:both}.navbar-collapse:before,.navbar-collapse:after{display:table;content:" "}.navbar-collapse:after{clear:both}.navbar-collapse.in{overflow-y:auto}@media(min-width:768px){.navbar-collapse{width:auto;border-top:0;box-shadow:none}.navbar-collapse.collapse{display:block!important;height:auto!important;padding-bottom:0;overflow:visible!important}.navbar-collapse.in{overflow-y:visible}.navbar-collapse .navbar-nav.navbar-left:first-child{margin-left:-15px}.navbar-collapse .navbar-nav.navbar-right:last-child{margin-right:-15px}.navbar-collapse .navbar-text:last-child{margin-right:0}}.container>.navbar-header,.container>.navbar-collapse{margin-right:-15px;margin-left:-15px}@media(min-width:768px){.container>.navbar-header,.container>.navbar-collapse{margin-right:0;margin-left:0}}.navbar-static-top{border-width:0 0 1px}@media(min-width:768px){.navbar-static-top{border-radius:0}}.navbar-fixed-top,.navbar-fixed-bottom{position:fixed;right:0;left:0;border-width:0 0 1px}@media(min-width:768px){.navbar-fixed-top,.navbar-fixed-bottom{border-radius:0}}.navbar-fixed-top{top:0;z-index:1030}.navbar-fixed-bottom{bottom:0;margin-bottom:0}.navbar-brand{float:left;padding:15px 15px;font-size:18px;line-height:20px}.navbar-brand:hover,.navbar-brand:focus{text-decoration:none}@media(min-width:768px){.navbar>.container .navbar-brand{margin-left:-15px}}.navbar-toggle{position:relative;float:right;padding:9px 10px;margin-top:8px;margin-right:15px;margin-bottom:8px;background-color:transparent;border:1px solid transparent;border-radius:4px}.navbar-toggle .icon-bar{display:block;width:22px;height:2px;border-radius:1px}.navbar-toggle .icon-bar+.icon-bar{margin-top:4px}@media(min-width:768px){.navbar-toggle{display:none}}.navbar-nav{margin:7.5px -15px}.navbar-nav>li>a{padding-top:10px;padding-bottom:10px;line-height:20px}@media(max-width:767px){.navbar-nav .open .dropdown-menu{position:static;float:none;width:auto;margin-top:0;background-color:transparent;border:0;box-shadow:none}.navbar-nav .open .dropdown-menu>li>a,.navbar-nav .open .dropdown-menu .dropdown-header{padding:5px 15px 5px 25px}.navbar-nav .open .dropdown-menu>li>a{line-height:20px}.navbar-nav .open .dropdown-menu>li>a:hover,.navbar-nav .open .dropdown-menu>li>a:focus{background-image:none}}@media(min-width:768px){.navbar-nav{float:left;margin:0}.navbar-nav>li{float:left}.navbar-nav>li>a{padding-top:15px;padding-bottom:15px}}@media(min-width:768px){.navbar-left{float:left!important}.navbar-right{float:right!important}}.navbar-form{padding:10px 15px;margin-top:8px;margin-right:-15px;margin-bottom:8px;margin-left:-15px;border-top:1px solid transparent;border-bottom:1px solid transparent;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1)}@media(min-width:768px){.navbar-form .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.navbar-form .form-control{display:inline-block}.navbar-form .radio,.navbar-form .checkbox{display:inline-block;padding-left:0;margin-top:0;margin-bottom:0}.navbar-form .radio input[type="radio"],.navbar-form .checkbox input[type="checkbox"]{float:none;margin-left:0}}@media(max-width:767px){.navbar-form .form-group{margin-bottom:5px}}@media(min-width:768px){.navbar-form{width:auto;padding-top:0;padding-bottom:0;margin-right:0;margin-left:0;border:0;-webkit-box-shadow:none;box-shadow:none}}.navbar-nav>li>.dropdown-menu{margin-top:0;border-top-right-radius:0;border-top-left-radius:0}.navbar-fixed-bottom .navbar-nav>li>.dropdown-menu{border-bottom-right-radius:0;border-bottom-left-radius:0}.navbar-nav.pull-right>li>.dropdown-menu,.navbar-nav>li>.dropdown-menu.pull-right{right:0;left:auto}.navbar-btn{margin-top:8px;margin-bottom:8px}.navbar-text{float:left;margin-top:15px;margin-bottom:15px}@media(min-width:768px){.navbar-text{margin-right:15px;margin-left:15px}}.navbar-default{background-color:#f8f8f8;border-color:#e7e7e7}.navbar-default .navbar-brand{color:#777}.navbar-default .navbar-brand:hover,.navbar-default .navbar-brand:focus{color:#5e5e5e;background-color:transparent}.navbar-default .navbar-text{color:#777}.navbar-default .navbar-nav>li>a{color:#777}.navbar-default .navbar-nav>li>a:hover,.navbar-default .navbar-nav>li>a:focus{color:#333;background-color:transparent}.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.active>a:hover,.navbar-default .navbar-nav>.active>a:focus{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav>.disabled>a,.navbar-default .navbar-nav>.disabled>a:hover,.navbar-default .navbar-nav>.disabled>a:focus{color:#ccc;background-color:transparent}.navbar-default .navbar-toggle{border-color:#ddd}.navbar-default .navbar-toggle:hover,.navbar-default .navbar-toggle:focus{background-color:#ddd}.navbar-default .navbar-toggle .icon-bar{background-color:#ccc}.navbar-default .navbar-collapse,.navbar-default .navbar-form{border-color:#e6e6e6}.navbar-default .navbar-nav>.dropdown>a:hover .caret,.navbar-default .navbar-nav>.dropdown>a:focus .caret{border-top-color:#333;border-bottom-color:#333}.navbar-default .navbar-nav>.open>a,.navbar-default .navbar-nav>.open>a:hover,.navbar-default .navbar-nav>.open>a:focus{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav>.open>a .caret,.navbar-default .navbar-nav>.open>a:hover .caret,.navbar-default .navbar-nav>.open>a:focus .caret{border-top-color:#555;border-bottom-color:#555}.navbar-default .navbar-nav>.dropdown>a .caret{border-top-color:#777;border-bottom-color:#777}@media(max-width:767px){.navbar-default .navbar-nav .open .dropdown-menu>li>a{color:#777}.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover,.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus{color:#333;background-color:transparent}.navbar-default .navbar-nav .open .dropdown-menu>.active>a,.navbar-default .navbar-nav .open .dropdown-menu>.active>a:hover,.navbar-default .navbar-nav .open .dropdown-menu>.active>a:focus{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a,.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a:hover,.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a:focus{color:#ccc;background-color:transparent}}.navbar-default .navbar-link{color:#777}.navbar-default .navbar-link:hover{color:#333}.navbar-inverse{background-color:#222;border-color:#080808}.navbar-inverse .navbar-brand{color:#999}.navbar-inverse .navbar-brand:hover,.navbar-inverse .navbar-brand:focus{color:#fff;background-color:transparent}.navbar-inverse .navbar-text{color:#999}.navbar-inverse .navbar-nav>li>a{color:#999}.navbar-inverse .navbar-nav>li>a:hover,.navbar-inverse .navbar-nav>li>a:focus{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.active>a:hover,.navbar-inverse .navbar-nav>.active>a:focus{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav>.disabled>a,.navbar-inverse .navbar-nav>.disabled>a:hover,.navbar-inverse .navbar-nav>.disabled>a:focus{color:#444;background-color:transparent}.navbar-inverse .navbar-toggle{border-color:#333}.navbar-inverse .navbar-toggle:hover,.navbar-inverse .navbar-toggle:focus{background-color:#333}.navbar-inverse .navbar-toggle .icon-bar{background-color:#fff}.navbar-inverse .navbar-collapse,.navbar-inverse .navbar-form{border-color:#101010}.navbar-inverse .navbar-nav>.open>a,.navbar-inverse .navbar-nav>.open>a:hover,.navbar-inverse .navbar-nav>.open>a:focus{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav>.dropdown>a:hover .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .navbar-nav>.dropdown>a .caret{border-top-color:#999;border-bottom-color:#999}.navbar-inverse .navbar-nav>.open>a .caret,.navbar-inverse .navbar-nav>.open>a:hover .caret,.navbar-inverse .navbar-nav>.open>a:focus .caret{border-top-color:#fff;border-bottom-color:#fff}@media(max-width:767px){.navbar-inverse .navbar-nav .open .dropdown-menu>.dropdown-header{border-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu>li>a{color:#999}.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover,.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a,.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:hover,.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:focus{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a,.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a:hover,.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a:focus{color:#444;background-color:transparent}}.navbar-inverse .navbar-link{color:#999}.navbar-inverse .navbar-link:hover{color:#fff}.breadcrumb{padding:8px 15px;margin-bottom:20px;list-style:none;background-color:#f5f5f5;border-radius:4px}.breadcrumb>li{display:inline-block}.breadcrumb>li+li:before{padding:0 5px;color:#ccc;content:"/\00a0"}.breadcrumb>.active{color:#999}.pagination{display:inline-block;padding-left:0;margin:20px 0;border-radius:4px}.pagination>li{display:inline}.pagination>li>a,.pagination>li>span{position:relative;float:left;padding:6px 12px;margin-left:-1px;line-height:1.428571429;text-decoration:none;background-color:#fff;border:1px solid #ddd}.pagination>li:first-child>a,.pagination>li:first-child>span{margin-left:0;border-bottom-left-radius:4px;border-top-left-radius:4px}.pagination>li:last-child>a,.pagination>li:last-child>span{border-top-right-radius:4px;border-bottom-right-radius:4px}.pagination>li>a:hover,.pagination>li>span:hover,.pagination>li>a:focus,.pagination>li>span:focus{background-color:#eee}.pagination>.active>a,.pagination>.active>span,.pagination>.active>a:hover,.pagination>.active>span:hover,.pagination>.active>a:focus,.pagination>.active>span:focus{z-index:2;color:#fff;cursor:default;background-color:#428bca;border-color:#428bca}.pagination>.disabled>span,.pagination>.disabled>a,.pagination>.disabled>a:hover,.pagination>.disabled>a:focus{color:#999;cursor:not-allowed;background-color:#fff;border-color:#ddd}.pagination-lg>li>a,.pagination-lg>li>span{padding:10px 16px;font-size:18px}.pagination-lg>li:first-child>a,.pagination-lg>li:first-child>span{border-bottom-left-radius:6px;border-top-left-radius:6px}.pagination-lg>li:last-child>a,.pagination-lg>li:last-child>span{border-top-right-radius:6px;border-bottom-right-radius:6px}.pagination-sm>li>a,.pagination-sm>li>span{padding:5px 10px;font-size:12px}.pagination-sm>li:first-child>a,.pagination-sm>li:first-child>span{border-bottom-left-radius:3px;border-top-left-radius:3px}.pagination-sm>li:last-child>a,.pagination-sm>li:last-child>span{border-top-right-radius:3px;border-bottom-right-radius:3px}.pager{padding-left:0;margin:20px 0;text-align:center;list-style:none}.pager:before,.pager:after{display:table;content:" "}.pager:after{clear:both}.pager:before,.pager:after{display:table;content:" "}.pager:after{clear:both}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;border-radius:15px}.pager li>a:hover,.pager li>a:focus{text-decoration:none;background-color:#eee}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:hover,.pager .disabled>a:focus,.pager .disabled>span{color:#999;cursor:not-allowed;background-color:#fff}.label{display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:bold;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em}.label[href]:hover,.label[href]:focus{color:#fff;text-decoration:none;cursor:pointer}.label:empty{display:none}.label-default{background-color:#999}.label-default[href]:hover,.label-default[href]:focus{background-color:#808080}.label-primary{background-color:#428bca}.label-primary[href]:hover,.label-primary[href]:focus{background-color:#3071a9}.label-success{background-color:#5cb85c}.label-success[href]:hover,.label-success[href]:focus{background-color:#449d44}.label-info{background-color:#5bc0de}.label-info[href]:hover,.label-info[href]:focus{background-color:#31b0d5}.label-warning{background-color:#f0ad4e}.label-warning[href]:hover,.label-warning[href]:focus{background-color:#ec971f}.label-danger{background-color:#d9534f}.label-danger[href]:hover,.label-danger[href]:focus{background-color:#c9302c}.badge{display:inline-block;min-width:10px;padding:3px 7px;font-size:12px;font-weight:bold;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;background-color:#999;border-radius:10px}.badge:empty{display:none}a.badge:hover,a.badge:focus{color:#fff;text-decoration:none;cursor:pointer}.btn .badge{position:relative;top:-1px}a.list-group-item.active>.badge,.nav-pills>.active>a>.badge{color:#428bca;background-color:#fff}.nav-pills>li>a>.badge{margin-left:3px}.jumbotron{padding:30px;margin-bottom:30px;font-size:21px;font-weight:200;line-height:2.1428571435;color:inherit;background-color:#eee}.jumbotron h1{line-height:1;color:inherit}.jumbotron p{line-height:1.4}.container .jumbotron{border-radius:6px}@media screen and (min-width:768px){.jumbotron{padding-top:48px;padding-bottom:48px}.container .jumbotron{padding-right:60px;padding-left:60px}.jumbotron h1{font-size:63px}}.thumbnail{display:inline-block;display:block;height:auto;max-width:100%;padding:4px;line-height:1.428571429;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.thumbnail>img{display:block;height:auto;max-width:100%}a.thumbnail:hover,a.thumbnail:focus{border-color:#428bca}.thumbnail>img{margin-right:auto;margin-left:auto}.thumbnail .caption{padding:9px;color:#333}.alert{padding:15px;margin-bottom:20px;border:1px solid transparent;border-radius:4px}.alert h4{margin-top:0;color:inherit}.alert .alert-link{font-weight:bold}.alert>p,.alert>ul{margin-bottom:0}.alert>p+p{margin-top:5px}.alert-dismissable{padding-right:35px}.alert-dismissable .close{position:relative;top:-2px;right:-21px;color:inherit}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-success hr{border-top-color:#c9e2b3}.alert-success .alert-link{color:#356635}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.alert-info hr{border-top-color:#a6e1ec}.alert-info .alert-link{color:#2d6987}.alert-warning{color:#c09853;background-color:#fcf8e3;border-color:#fbeed5}.alert-warning hr{border-top-color:#f8e5be}.alert-warning .alert-link{color:#a47e3c}.alert-danger{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-danger hr{border-top-color:#e6c1c7}.alert-danger .alert-link{color:#953b39}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-moz-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:0 0}to{background-position:40px 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f5f5f5;border-radius:4px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1)}.progress-bar{float:left;width:0;height:100%;font-size:12px;color:#fff;text-align:center;background-color:#428bca;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-webkit-transition:width .6s ease;transition:width .6s ease}.progress-striped .progress-bar{background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-size:40px 40px}.progress.active .progress-bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-moz-animation:progress-bar-stripes 2s linear infinite;-ms-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-bar-success{background-color:#5cb85c}.progress-striped .progress-bar-success{background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-bar-info{background-color:#5bc0de}.progress-striped .progress-bar-info{background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-bar-warning{background-color:#f0ad4e}.progress-striped .progress-bar-warning{background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-bar-danger{background-color:#d9534f}.progress-striped .progress-bar-danger{background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.media,.media-body{overflow:hidden;zoom:1}.media,.media .media{margin-top:15px}.media:first-child{margin-top:0}.media-object{display:block}.media-heading{margin:0 0 5px}.media>.pull-left{margin-right:10px}.media>.pull-right{margin-left:10px}.media-list{padding-left:0;list-style:none}.list-group{padding-left:0;margin-bottom:20px}.list-group-item{position:relative;display:block;padding:10px 15px;margin-bottom:-1px;background-color:#fff;border:1px solid #ddd}.list-group-item:first-child{border-top-right-radius:4px;border-top-left-radius:4px}.list-group-item:last-child{margin-bottom:0;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.list-group-item>.badge{float:right}.list-group-item>.badge+.badge{margin-right:5px}a.list-group-item{color:#555}a.list-group-item .list-group-item-heading{color:#333}a.list-group-item:hover,a.list-group-item:focus{text-decoration:none;background-color:#f5f5f5}.list-group-item.active,.list-group-item.active:hover,.list-group-item.active:focus{z-index:2;color:#fff;background-color:#428bca;border-color:#428bca}.list-group-item.active .list-group-item-heading,.list-group-item.active:hover .list-group-item-heading,.list-group-item.active:focus .list-group-item-heading{color:inherit}.list-group-item.active .list-group-item-text,.list-group-item.active:hover .list-group-item-text,.list-group-item.active:focus .list-group-item-text{color:#e1edf7}.list-group-item-heading{margin-top:0;margin-bottom:5px}.list-group-item-text{margin-bottom:0;line-height:1.3}.panel{margin-bottom:20px;background-color:#fff;border:1px solid transparent;border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.05);box-shadow:0 1px 1px rgba(0,0,0,0.05)}.panel-body{padding:15px}.panel-body:before,.panel-body:after{display:table;content:" "}.panel-body:after{clear:both}.panel-body:before,.panel-body:after{display:table;content:" "}.panel-body:after{clear:both}.panel>.list-group{margin-bottom:0}.panel>.list-group .list-group-item{border-width:1px 0}.panel>.list-group .list-group-item:first-child{border-top-right-radius:0;border-top-left-radius:0}.panel>.list-group .list-group-item:last-child{border-bottom:0}.panel-heading+.list-group .list-group-item:first-child{border-top-width:0}.panel>.table{margin-bottom:0}.panel>.panel-body+.table{border-top:1px solid #ddd}.panel-heading{padding:10px 15px;border-bottom:1px solid transparent;border-top-right-radius:3px;border-top-left-radius:3px}.panel-title{margin-top:0;margin-bottom:0;font-size:16px}.panel-title>a{color:inherit}.panel-footer{padding:10px 15px;background-color:#f5f5f5;border-top:1px solid #ddd;border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel-group .panel{margin-bottom:0;overflow:hidden;border-radius:4px}.panel-group .panel+.panel{margin-top:5px}.panel-group .panel-heading{border-bottom:0}.panel-group .panel-heading+.panel-collapse .panel-body{border-top:1px solid #ddd}.panel-group .panel-footer{border-top:0}.panel-group .panel-footer+.panel-collapse .panel-body{border-bottom:1px solid #ddd}.panel-default{border-color:#ddd}.panel-default>.panel-heading{color:#333;background-color:#f5f5f5;border-color:#ddd}.panel-default>.panel-heading+.panel-collapse .panel-body{border-top-color:#ddd}.panel-default>.panel-footer+.panel-collapse .panel-body{border-bottom-color:#ddd}.panel-primary{border-color:#428bca}.panel-primary>.panel-heading{color:#fff;background-color:#428bca;border-color:#428bca}.panel-primary>.panel-heading+.panel-collapse .panel-body{border-top-color:#428bca}.panel-primary>.panel-footer+.panel-collapse .panel-body{border-bottom-color:#428bca}.panel-success{border-color:#d6e9c6}.panel-success>.panel-heading{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.panel-success>.panel-heading+.panel-collapse .panel-body{border-top-color:#d6e9c6}.panel-success>.panel-footer+.panel-collapse .panel-body{border-bottom-color:#d6e9c6}.panel-warning{border-color:#fbeed5}.panel-warning>.panel-heading{color:#c09853;background-color:#fcf8e3;border-color:#fbeed5}.panel-warning>.panel-heading+.panel-collapse .panel-body{border-top-color:#fbeed5}.panel-warning>.panel-footer+.panel-collapse .panel-body{border-bottom-color:#fbeed5}.panel-danger{border-color:#eed3d7}.panel-danger>.panel-heading{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.panel-danger>.panel-heading+.panel-collapse .panel-body{border-top-color:#eed3d7}.panel-danger>.panel-footer+.panel-collapse .panel-body{border-bottom-color:#eed3d7}.panel-info{border-color:#bce8f1}.panel-info>.panel-heading{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.panel-info>.panel-heading+.panel-collapse .panel-body{border-top-color:#bce8f1}.panel-info>.panel-footer+.panel-collapse .panel-body{border-bottom-color:#bce8f1}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);box-shadow:inset 0 1px 1px rgba(0,0,0,0.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,0.15)}.well-lg{padding:24px;border-radius:6px}.well-sm{padding:9px;border-radius:3px}.close{float:right;font-size:21px;font-weight:bold;line-height:1;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20)}.close:hover,.close:focus{color:#000;text-decoration:none;cursor:pointer;opacity:.5;filter:alpha(opacity=50)}button.close{padding:0;cursor:pointer;background:transparent;border:0;-webkit-appearance:none}.modal-open{overflow:hidden}body.modal-open,.modal-open .navbar-fixed-top,.modal-open .navbar-fixed-bottom{margin-right:15px}.modal{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;display:none;overflow:auto;overflow-y:scroll}.modal.fade .modal-dialog{-webkit-transform:translate(0,-25%);-ms-transform:translate(0,-25%);transform:translate(0,-25%);-webkit-transition:-webkit-transform .3s ease-out;-moz-transition:-moz-transform .3s ease-out;-o-transition:-o-transform .3s ease-out;transition:transform .3s ease-out}.modal.in .modal-dialog{-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0)}.modal-dialog{z-index:1050;width:auto;padding:10px;margin-right:auto;margin-left:auto}.modal-content{position:relative;background-color:#fff;border:1px solid #999;border:1px solid rgba(0,0,0,0.2);border-radius:6px;outline:0;-webkit-box-shadow:0 3px 9px rgba(0,0,0,0.5);box-shadow:0 3px 9px rgba(0,0,0,0.5);background-clip:padding-box}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1030;background-color:#000}.modal-backdrop.fade{opacity:0;filter:alpha(opacity=0)}.modal-backdrop.in{opacity:.5;filter:alpha(opacity=50)}.modal-header{min-height:16.428571429px;padding:15px;border-bottom:1px solid #e5e5e5}.modal-header .close{margin-top:-2px}.modal-title{margin:0;line-height:1.428571429}.modal-body{position:relative;padding:20px}.modal-footer{padding:19px 20px 20px;margin-top:15px;text-align:right;border-top:1px solid #e5e5e5}.modal-footer:before,.modal-footer:after{display:table;content:" "}.modal-footer:after{clear:both}.modal-footer:before,.modal-footer:after{display:table;content:" "}.modal-footer:after{clear:both}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}@media screen and (min-width:768px){.modal-dialog{right:auto;left:50%;width:600px;padding-top:30px;padding-bottom:30px}.modal-content{-webkit-box-shadow:0 5px 15px rgba(0,0,0,0.5);box-shadow:0 5px 15px rgba(0,0,0,0.5)}}.tooltip{position:absolute;z-index:1030;display:block;font-size:12px;line-height:1.4;opacity:0;filter:alpha(opacity=0);visibility:visible}.tooltip.in{opacity:.9;filter:alpha(opacity=90)}.tooltip.top{padding:5px 0;margin-top:-3px}.tooltip.right{padding:0 5px;margin-left:3px}.tooltip.bottom{padding:5px 0;margin-top:3px}.tooltip.left{padding:0 5px;margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;text-decoration:none;background-color:#000;border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-top-color:#000;border-width:5px 5px 0}.tooltip.top-left .tooltip-arrow{bottom:0;left:5px;border-top-color:#000;border-width:5px 5px 0}.tooltip.top-right .tooltip-arrow{right:5px;bottom:0;border-top-color:#000;border-width:5px 5px 0}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-right-color:#000;border-width:5px 5px 5px 0}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-left-color:#000;border-width:5px 0 5px 5px}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-bottom-color:#000;border-width:0 5px 5px}.tooltip.bottom-left .tooltip-arrow{top:0;left:5px;border-bottom-color:#000;border-width:0 5px 5px}.tooltip.bottom-right .tooltip-arrow{top:0;right:5px;border-bottom-color:#000;border-width:0 5px 5px}.popover{position:absolute;top:0;left:0;z-index:1010;display:none;max-width:276px;padding:1px;text-align:left;white-space:normal;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);background-clip:padding-box}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;font-weight:normal;line-height:18px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover .arrow,.popover .arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover .arrow{border-width:11px}.popover .arrow:after{border-width:10px;content:""}.popover.top .arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,0.25);border-bottom-width:0}.popover.top .arrow:after{bottom:1px;margin-left:-10px;border-top-color:#fff;border-bottom-width:0;content:" "}.popover.right .arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,0.25);border-left-width:0}.popover.right .arrow:after{bottom:-10px;left:1px;border-right-color:#fff;border-left-width:0;content:" "}.popover.bottom .arrow{top:-11px;left:50%;margin-left:-11px;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,0.25);border-top-width:0}.popover.bottom .arrow:after{top:1px;margin-left:-10px;border-bottom-color:#fff;border-top-width:0;content:" "}.popover.left .arrow{top:50%;right:-11px;margin-top:-11px;border-left-color:#999;border-left-color:rgba(0,0,0,0.25);border-right-width:0}.popover.left .arrow:after{right:1px;bottom:-10px;border-left-color:#fff;border-right-width:0;content:" "}.carousel{position:relative}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>img,.carousel-inner>.item>a>img{display:block;height:auto;max-width:100%;line-height:1}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:0;bottom:0;left:0;width:15%;font-size:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,0.6);opacity:.5;filter:alpha(opacity=50)}.carousel-control.left{background-image:-webkit-gradient(linear,0 top,100% top,from(rgba(0,0,0,0.5)),to(rgba(0,0,0,0.0001)));background-image:-webkit-linear-gradient(left,color-stop(rgba(0,0,0,0.5) 0),color-stop(rgba(0,0,0,0.0001) 100%));background-image:-moz-linear-gradient(left,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.0001) 100%);background-image:linear-gradient(to right,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.0001) 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000',endColorstr='#00000000',GradientType=1)}.carousel-control.right{right:0;left:auto;background-image:-webkit-gradient(linear,0 top,100% top,from(rgba(0,0,0,0.0001)),to(rgba(0,0,0,0.5)));background-image:-webkit-linear-gradient(left,color-stop(rgba(0,0,0,0.0001) 0),color-stop(rgba(0,0,0,0.5) 100%));background-image:-moz-linear-gradient(left,rgba(0,0,0,0.0001) 0,rgba(0,0,0,0.5) 100%);background-image:linear-gradient(to right,rgba(0,0,0,0.0001) 0,rgba(0,0,0,0.5) 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000',endColorstr='#80000000',GradientType=1)}.carousel-control:hover,.carousel-control:focus{color:#fff;text-decoration:none;opacity:.9;filter:alpha(opacity=90)}.carousel-control .icon-prev,.carousel-control .icon-next,.carousel-control .glyphicon-chevron-left,.carousel-control .glyphicon-chevron-right{position:absolute;top:50%;left:50%;z-index:5;display:inline-block}.carousel-control .icon-prev,.carousel-control .icon-next{width:20px;height:20px;margin-top:-10px;margin-left:-10px;font-family:serif}.carousel-control .icon-prev:before{content:'\2039'}.carousel-control .icon-next:before{content:'\203a'}.carousel-indicators{position:absolute;bottom:10px;left:50%;z-index:15;width:60%;padding-left:0;margin-left:-30%;text-align:center;list-style:none}.carousel-indicators li{display:inline-block;width:10px;height:10px;margin:1px;text-indent:-999px;cursor:pointer;border:1px solid #fff;border-radius:10px}.carousel-indicators .active{width:12px;height:12px;margin:0;background-color:#fff}.carousel-caption{position:absolute;right:15%;bottom:20px;left:15%;z-index:10;padding-top:20px;padding-bottom:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,0.6)}.carousel-caption .btn{text-shadow:none}@media screen and (min-width:768px){.carousel-control .icon-prev,.carousel-control .icon-next{width:30px;height:30px;margin-top:-15px;margin-left:-15px;font-size:30px}.carousel-caption{right:20%;left:20%;padding-bottom:30px}.carousel-indicators{bottom:20px}}.clearfix:before,.clearfix:after{display:table;content:" "}.clearfix:after{clear:both}.pull-right{float:right!important}.pull-left{float:left!important}.hide{display:none!important}.show{display:block!important}.invisible{visibility:hidden}.text-hide{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.affix{position:fixed}@-ms-viewport{width:device-width}@media screen and (max-width:400px){@-ms-viewport{width:320px}}.hidden{display:none!important;visibility:hidden!important}.visible-xs{display:none!important}tr.visible-xs{display:none!important}th.visible-xs,td.visible-xs{display:none!important}@media(max-width:767px){.visible-xs{display:block!important}tr.visible-xs{display:table-row!important}th.visible-xs,td.visible-xs{display:table-cell!important}}@media(min-width:768px) and (max-width:991px){.visible-xs.visible-sm{display:block!important}tr.visible-xs.visible-sm{display:table-row!important}th.visible-xs.visible-sm,td.visible-xs.visible-sm{display:table-cell!important}}@media(min-width:992px) and (max-width:1199px){.visible-xs.visible-md{display:block!important}tr.visible-xs.visible-md{display:table-row!important}th.visible-xs.visible-md,td.visible-xs.visible-md{display:table-cell!important}}@media(min-width:1200px){.visible-xs.visible-lg{display:block!important}tr.visible-xs.visible-lg{display:table-row!important}th.visible-xs.visible-lg,td.visible-xs.visible-lg{display:table-cell!important}}.visible-sm{display:none!important}tr.visible-sm{display:none!important}th.visible-sm,td.visible-sm{display:none!important}@media(max-width:767px){.visible-sm.visible-xs{display:block!important}tr.visible-sm.visible-xs{display:table-row!important}th.visible-sm.visible-xs,td.visible-sm.visible-xs{display:table-cell!important}}@media(min-width:768px) and (max-width:991px){.visible-sm{display:block!important}tr.visible-sm{display:table-row!important}th.visible-sm,td.visible-sm{display:table-cell!important}}@media(min-width:992px) and (max-width:1199px){.visible-sm.visible-md{display:block!important}tr.visible-sm.visible-md{display:table-row!important}th.visible-sm.visible-md,td.visible-sm.visible-md{display:table-cell!important}}@media(min-width:1200px){.visible-sm.visible-lg{display:block!important}tr.visible-sm.visible-lg{display:table-row!important}th.visible-sm.visible-lg,td.visible-sm.visible-lg{display:table-cell!important}}.visible-md{display:none!important}tr.visible-md{display:none!important}th.visible-md,td.visible-md{display:none!important}@media(max-width:767px){.visible-md.visible-xs{display:block!important}tr.visible-md.visible-xs{display:table-row!important}th.visible-md.visible-xs,td.visible-md.visible-xs{display:table-cell!important}}@media(min-width:768px) and (max-width:991px){.visible-md.visible-sm{display:block!important}tr.visible-md.visible-sm{display:table-row!important}th.visible-md.visible-sm,td.visible-md.visible-sm{display:table-cell!important}}@media(min-width:992px) and (max-width:1199px){.visible-md{display:block!important}tr.visible-md{display:table-row!important}th.visible-md,td.visible-md{display:table-cell!important}}@media(min-width:1200px){.visible-md.visible-lg{display:block!important}tr.visible-md.visible-lg{display:table-row!important}th.visible-md.visible-lg,td.visible-md.visible-lg{display:table-cell!important}}.visible-lg{display:none!important}tr.visible-lg{display:none!important}th.visible-lg,td.visible-lg{display:none!important}@media(max-width:767px){.visible-lg.visible-xs{display:block!important}tr.visible-lg.visible-xs{display:table-row!important}th.visible-lg.visible-xs,td.visible-lg.visible-xs{display:table-cell!important}}@media(min-width:768px) and (max-width:991px){.visible-lg.visible-sm{display:block!important}tr.visible-lg.visible-sm{display:table-row!important}th.visible-lg.visible-sm,td.visible-lg.visible-sm{display:table-cell!important}}@media(min-width:992px) and (max-width:1199px){.visible-lg.visible-md{display:block!important}tr.visible-lg.visible-md{display:table-row!important}th.visible-lg.visible-md,td.visible-lg.visible-md{display:table-cell!important}}@media(min-width:1200px){.visible-lg{display:block!important}tr.visible-lg{display:table-row!important}th.visible-lg,td.visible-lg{display:table-cell!important}}.hidden-xs{display:block!important}tr.hidden-xs{display:table-row!important}th.hidden-xs,td.hidden-xs{display:table-cell!important}@media(max-width:767px){.hidden-xs{display:none!important}tr.hidden-xs{display:none!important}th.hidden-xs,td.hidden-xs{display:none!important}}@media(min-width:768px) and (max-width:991px){.hidden-xs.hidden-sm{display:none!important}tr.hidden-xs.hidden-sm{display:none!important}th.hidden-xs.hidden-sm,td.hidden-xs.hidden-sm{display:none!important}}@media(min-width:992px) and (max-width:1199px){.hidden-xs.hidden-md{display:none!important}tr.hidden-xs.hidden-md{display:none!important}th.hidden-xs.hidden-md,td.hidden-xs.hidden-md{display:none!important}}@media(min-width:1200px){.hidden-xs.hidden-lg{display:none!important}tr.hidden-xs.hidden-lg{display:none!important}th.hidden-xs.hidden-lg,td.hidden-xs.hidden-lg{display:none!important}}.hidden-sm{display:block!important}tr.hidden-sm{display:table-row!important}th.hidden-sm,td.hidden-sm{display:table-cell!important}@media(max-width:767px){.hidden-sm.hidden-xs{display:none!important}tr.hidden-sm.hidden-xs{display:none!important}th.hidden-sm.hidden-xs,td.hidden-sm.hidden-xs{display:none!important}}@media(min-width:768px) and (max-width:991px){.hidden-sm{display:none!important}tr.hidden-sm{display:none!important}th.hidden-sm,td.hidden-sm{display:none!important}}@media(min-width:992px) and (max-width:1199px){.hidden-sm.hidden-md{display:none!important}tr.hidden-sm.hidden-md{display:none!important}th.hidden-sm.hidden-md,td.hidden-sm.hidden-md{display:none!important}}@media(min-width:1200px){.hidden-sm.hidden-lg{display:none!important}tr.hidden-sm.hidden-lg{display:none!important}th.hidden-sm.hidden-lg,td.hidden-sm.hidden-lg{display:none!important}}.hidden-md{display:block!important}tr.hidden-md{display:table-row!important}th.hidden-md,td.hidden-md{display:table-cell!important}@media(max-width:767px){.hidden-md.hidden-xs{display:none!important}tr.hidden-md.hidden-xs{display:none!important}th.hidden-md.hidden-xs,td.hidden-md.hidden-xs{display:none!important}}@media(min-width:768px) and (max-width:991px){.hidden-md.hidden-sm{display:none!important}tr.hidden-md.hidden-sm{display:none!important}th.hidden-md.hidden-sm,td.hidden-md.hidden-sm{display:none!important}}@media(min-width:992px) and (max-width:1199px){.hidden-md{display:none!important}tr.hidden-md{display:none!important}th.hidden-md,td.hidden-md{display:none!important}}@media(min-width:1200px){.hidden-md.hidden-lg{display:none!important}tr.hidden-md.hidden-lg{display:none!important}th.hidden-md.hidden-lg,td.hidden-md.hidden-lg{display:none!important}}.hidden-lg{display:block!important}tr.hidden-lg{display:table-row!important}th.hidden-lg,td.hidden-lg{display:table-cell!important}@media(max-width:767px){.hidden-lg.hidden-xs{display:none!important}tr.hidden-lg.hidden-xs{display:none!important}th.hidden-lg.hidden-xs,td.hidden-lg.hidden-xs{display:none!important}}@media(min-width:768px) and (max-width:991px){.hidden-lg.hidden-sm{display:none!important}tr.hidden-lg.hidden-sm{display:none!important}th.hidden-lg.hidden-sm,td.hidden-lg.hidden-sm{display:none!important}}@media(min-width:992px) and (max-width:1199px){.hidden-lg.hidden-md{display:none!important}tr.hidden-lg.hidden-md{display:none!important}th.hidden-lg.hidden-md,td.hidden-lg.hidden-md{display:none!important}}@media(min-width:1200px){.hidden-lg{display:none!important}tr.hidden-lg{display:none!important}th.hidden-lg,td.hidden-lg{display:none!important}}.visible-print{display:none!important}tr.visible-print{display:none!important}th.visible-print,td.visible-print{display:none!important}@media print{.visible-print{display:block!important}tr.visible-print{display:table-row!important}th.visible-print,td.visible-print{display:table-cell!important}.hidden-print{display:none!important}tr.hidden-print{display:none!important}th.hidden-print,td.hidden-print{display:none!important}} \ No newline at end of file diff --git a/demos/client-demo/src/main/webapp/images/logo_oltu.png b/demos/client-demo/src/main/webapp/images/logo_oltu.png new file mode 100644 index 00000000..5688b177 Binary files /dev/null and b/demos/client-demo/src/main/webapp/images/logo_oltu.png differ diff --git a/oauth-2.0/oauth2-client-demo/src/test/resources/log4j.properties b/demos/client-demo/src/test/resources/log4j.properties similarity index 100% rename from oauth-2.0/oauth2-client-demo/src/test/resources/log4j.properties rename to demos/client-demo/src/test/resources/log4j.properties diff --git a/demos/pom.xml b/demos/pom.xml new file mode 100644 index 00000000..2a6590fb --- /dev/null +++ b/demos/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + ../parent + + + org.apache.oltu.demos + org.apache.oltu.demos.parent + 1-SNAPSHOT + pom + + Apache Oltu - Demos - Parent + + + client-demo + + + diff --git a/jose/deploySite.sh b/jose/deploySite.sh new file mode 100755 index 00000000..7328d417 --- /dev/null +++ b/jose/deploySite.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +mvn clean site site:stage -P site +mvn scm-publish:publish-scm -Dusername=$1 -Dpassword=$2 -P site diff --git a/jose/jwe/pom.xml b/jose/jwe/pom.xml new file mode 100644 index 00000000..b94a8cd7 --- /dev/null +++ b/jose/jwe/pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + + org.apache.oltu.jose + org.apache.oltu.jose.parent + 2-SNAPSHOT + + + org.apache.oltu.jose.jwe + 1.0.0-SNAPSHOT + bundle + + Apache Oltu - JOSE - JWE + JWE specification implemented in Apache Oltu + + + ${project.artifactId}*;version=${project.version} + + + + + org.apache.oltu.commons + org.apache.oltu.commons.encodedtoken + 1.0.1 + + + + org.apache.oltu.commons + org.apache.oltu.commons.json + 1.0.1 + + + + diff --git a/spec-api/src/main/java/org/apache/amber/server/StorageException.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/ContentEncryptionKey.java similarity index 60% rename from spec-api/src/main/java/org/apache/amber/server/StorageException.java rename to jose/jwe/src/main/java/org/apache/oltu/jose/jwe/ContentEncryptionKey.java index 8956db3d..4aea1f7b 100644 --- a/spec-api/src/main/java/org/apache/amber/server/StorageException.java +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/ContentEncryptionKey.java @@ -14,30 +14,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.server; +package org.apache.oltu.jose.jwe; -/** - * Exception thrown when an error occurs when accessing to the Access Storage. - * - * @version $Id$ - */ -public final class StorageException extends Exception { - - /** - * The default serial version UID; - */ - private static final long serialVersionUID = 1L; - - public StorageException(String message) { - super(message); +public class ContentEncryptionKey { + + private final byte[] contentEncryptionKey; + private final String encryptedKey; + + public ContentEncryptionKey(byte[] contentEncryptionKey, String encryptedKey) { + super(); + this.contentEncryptionKey = contentEncryptionKey; + this.encryptedKey = encryptedKey; } - public StorageException(Throwable cause) { - super(cause); + public byte[] getContentEncryptionKey() { + return contentEncryptionKey; } - public StorageException(String message, Throwable cause) { - super(message, cause); + public String getEncryptedKey() { + return encryptedKey; } - } diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/Header.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/Header.java new file mode 100644 index 00000000..ffcee5e1 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/Header.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe; + +import java.util.Map; + +import org.apache.oltu.commons.json.CustomizableEntity; + +/** + * Represents the Header as defined in the section 4 of the JWE specification. + * + * @see https://tools.ietf.org/html/rfc7516#section-4 + */ +public final class Header extends CustomizableEntity { + + /** + * The {@code alg} JWE Header parameter. + */ + private final String algorithm; + + /** + * The {@code enc} JWE Header parameter. + */ + private final String encryptionAlgorithm; + + /** + * The {@code zip} JWE Header key. + */ + private final String compressionAlgorithm; + + /** + * The {@code jku} JWE Header parameter. + */ + private final String jwkSetUrl; + + /** + * The {@code jwk} JWE Header parameter. + */ + private final String jsonWebKey; + + /** + * The {@code x5u} JWE Header parameter. + */ + private final String x509url; + + /** + * The {@code x5t} JWE Header parameter. + */ + private final String x509CertificateThumbprint; + + /** + * The {@code x5c} JWE Header parameter. + */ + private final String x509CertificateChain; + + /** + * The {@code kid} JWE Header parameter. + */ + private final String keyId; + + /** + * The {@code typ} JWE Header parameter. + */ + private final String type; + + /** + * The {@code cty} JWE Header parameter. + */ + private final String contentType; + + /** + * The {@code crit} JWE Header parameter. + */ + private final String[] critical; + + Header(String algorithm, + String encryptionAlgorithm, + String compressionAlgorithm, + String jwkSetUrl, + String jsonWebKey, + String x509url, + String x509CertificateThumbprint, + String x509CertificateChain, + String keyId, + String type, + String contentType, + String[] critical, + Map customFields) { + super(customFields); + this.algorithm = algorithm; + this.encryptionAlgorithm = encryptionAlgorithm; + this.compressionAlgorithm = compressionAlgorithm; + this.jwkSetUrl = jwkSetUrl; + this.jsonWebKey = jsonWebKey; + this.x509url = x509url; + this.x509CertificateThumbprint = x509CertificateThumbprint; + this.x509CertificateChain = x509CertificateChain; + this.keyId = keyId; + this.type = type; + this.contentType = contentType; + this.critical = critical; + } + + public String getAlgorithm() { + return algorithm; + } + + public String getEncryptionAlgorithm() { + return encryptionAlgorithm; + } + + public String getCompressionAlgorithm() { + return compressionAlgorithm; + } + + public String getJwkSetUrl() { + return jwkSetUrl; + } + + public String getJsonWebKey() { + return jsonWebKey; + } + + public String getX509url() { + return x509url; + } + + public String getX509CertificateThumbprint() { + return x509CertificateThumbprint; + } + + public String getX509CertificateChain() { + return x509CertificateChain; + } + + public String getKeyId() { + return keyId; + } + + public String getType() { + return type; + } + + public String getContentType() { + return contentType; + } + + public String[] getCritical() { + return critical; + } +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/JWE.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/JWE.java new file mode 100644 index 00000000..afc6201b --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/JWE.java @@ -0,0 +1,318 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.commons.json.CustomizableBuilder; +import org.apache.oltu.jose.jwe.encryption.ContentEncryptMethod; +import org.apache.oltu.jose.jwe.encryption.DecryptingKey; +import org.apache.oltu.jose.jwe.encryption.EncryptingKey; +import org.apache.oltu.jose.jwe.encryption.KeyEncryptMethod; +import org.apache.oltu.jose.jwe.io.JWEHeaderWriter; + +public class JWE { + + /** + * The JWE Header. + */ + private final Header header; + + /** + * The JWE encryptedKey. + */ + private final String encryptedKey; + + + //TODO remove?? + /** + * The JWE Payload. + */ + private final String payload; + + /** + * The JWE Content Encryption. + */ + private final String contentEncryption; + + JWE(Header header, String encryptedKey, String payload ,String contentEncryption) { + this.header = header; + this.encryptedKey = encryptedKey; + this.payload = payload; + this.contentEncryption = contentEncryption; + } + + public Header getHeader() { + return header; + } + + public String getEncryptedKey() { + return encryptedKey; + } + + public String getPayload() { + return payload; + } + + public String getContentEncryption() { + return contentEncryption; + } + + public boolean acceptAlgorithm(KeyEncryptMethod keyEncryptMethod, ContentEncryptMethod contentEncryptMethod) { + if (keyEncryptMethod == null) { + throw new IllegalArgumentException("An encrypt method is required in order to decrypt the content encryption key."); + } + if (contentEncryptMethod == null) { + throw new IllegalArgumentException("An encrypt method is required in order to decrypt the payload."); + } + if (header == null || header.getAlgorithm() == null || header.getEncryptionAlgorithm() == null) { + throw new IllegalStateException("JWE token must have a valid JSON header with specified algorithm."); + } + + return header.getAlgorithm().equalsIgnoreCase(keyEncryptMethod.getAlgorithm()) && header.getEncryptionAlgorithm().equalsIgnoreCase(contentEncryptMethod.getAlgorithm()); + } + + public String decrypt(KeyEncryptMethod keyEncryptMethod, + DK decryptingKey, ContentEncryptMethod contentEncryptMethod) { + if (!acceptAlgorithm(keyEncryptMethod, contentEncryptMethod)) { + throw new IllegalArgumentException("Impossible to decrypt current JWE"); + } + if (decryptingKey == null) { + throw new IllegalArgumentException("A decrypting key is required in order to decrypt the JWE"); + } + + if (encryptedKey == null) { + throw new IllegalStateException("JWE token must have an encrypted key."); + } + + if (contentEncryption == null) { + throw new IllegalStateException("JWE token must have a content encryption"); + } + + return contentEncryptMethod.decrypt(new JWEHeaderWriter().write(header), contentEncryption, keyEncryptMethod.decrypt(encryptedKey, decryptingKey)); + } + + public static final class Builder extends CustomizableBuilder { + + /** + * The {@code alg} JWE Header parameter. + */ + private String algorithm; + + /** + * The {@code enc} JWE Header parameter. + */ + private String encryptionAlgorithm; + + /** + * The {@code zip} JWE Header key. + */ + private String compressionAlgorithm; + + /** + * The {@code jku} JWE Header parameter. + */ + private String jwkSetUrl; + + /** + * The {@code jwk} JWE Header parameter. + */ + private String jsonWebKey; + + /** + * The {@code x5u} JWE Header parameter. + */ + private String x509url; + + /** + * The {@code x5t} JWE Header parameter. + */ + private String x509CertificateThumbprint; + + /** + * The {@code x5c} JWE Header parameter. + */ + private String x509CertificateChain; + + /** + * The {@code kid} JWE Header parameter. + */ + private String keyId; + + /** + * The {@code typ} JWE Header parameter. + */ + private String type; + + /** + * The {@code cty} JWE Header parameter. + */ + private String contentType; + + /** + * The {@code crit} JWE Header parameter. + */ + private String[] critical; + + /** + * The JWE encryptedKey. + */ + private String encryptedKey; + + /** + * The JWE Payload. + */ + private String payload; + + /** + * The JWE Content Encryption. + */ + private String contentEncryption; + + public Builder setAlgorithm(String algorithm) { + this.algorithm = algorithm; + return this; + } + + public Builder setEncryptionAlgorithm(String encryptionAlgorithm) { + this.encryptionAlgorithm = encryptionAlgorithm; + return this; + } + + public Builder setCompressionAlgorithm(String compressionAlgorithm) { + this.compressionAlgorithm = compressionAlgorithm; + return this; + } + + public Builder setJwkSetUrl(String jwkSetUrl) { + this.jwkSetUrl = jwkSetUrl; + return this; + } + + public Builder setJsonWebKey(String jsonWebKey) { + this.jsonWebKey = jsonWebKey; + return this; + } + + public Builder setX509url(String x509url) { + this.x509url = x509url; + return this; + } + + public Builder setX509CertificateThumbprint(String x509CertificateThumbprint) { + this.x509CertificateThumbprint = x509CertificateThumbprint; + return this; + } + + public Builder setX509CertificateChain(String x509CertificateChain) { + this.x509CertificateChain = x509CertificateChain; + return this; + } + + public Builder setKeyId(String keyId) { + this.keyId = keyId; + return this; + } + + public Builder setType(String type) { + this.type = type; + return this; + } + + public Builder setContentType(String contentType) { + this.contentType = contentType; + return this; + } + + public Builder setEncryptedKey(String encryptedKey) { + this.encryptedKey = encryptedKey; + return this; + } + + public Builder setCritical(String[] critical) { + this.critical = critical; + return this; + } + + public Builder setPayload(String payload) { + this.payload = payload; + return this; + } + + public Builder setContentEncryption(String contentEncryption) { + this.contentEncryption = contentEncryption; + return this; + } + + public Builder encrypt(KeyEncryptMethod keyEncryptMethod, + EK encryptingKey, ContentEncryptMethod contentEncryptMethod) { + if (keyEncryptMethod == null) { + throw new IllegalArgumentException("A key encryption method is required in order to encrypt the content encryption key."); + } + if (encryptingKey == null) { + throw new IllegalArgumentException("An encryption key is required in order to encrypt the content encryption key."); + } + if (payload == null) { + throw new IllegalStateException("Payload needs to be set in order to encrypt it."); + } + if (contentEncryptMethod == null) { + throw new IllegalArgumentException("A key encryption method is required in order to encrypt the payload."); + } + + setAlgorithm(keyEncryptMethod.getAlgorithm()); + setEncryptionAlgorithm(contentEncryptMethod.getAlgorithm()); + + String header = new JWEHeaderWriter().write(new Header(algorithm, + encryptionAlgorithm, + compressionAlgorithm, + jwkSetUrl, + jsonWebKey, + x509url, + x509CertificateThumbprint, + x509CertificateChain, + keyId, type, + contentType, + critical, + getCustomFields())); + + ContentEncryptionKey cek = keyEncryptMethod.encrypt(encryptingKey); + + setEncryptedKey(cek.getEncryptedKey()); + + return setContentEncryption(contentEncryptMethod.encrypt(TokenDecoder.base64Encode(header), payload, cek.getContentEncryptionKey())); + } + + @Override + public JWE build() { + return new JWE(new Header(algorithm, + encryptionAlgorithm, + compressionAlgorithm, + jwkSetUrl, + jsonWebKey, + x509url, + x509CertificateThumbprint, + x509CertificateChain, + keyId, type, + contentType, + critical, + getCustomFields()), + encryptedKey, + payload, + contentEncryption); + } + + } +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/JWEConstants.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/JWEConstants.java new file mode 100644 index 00000000..01a7b61d --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/JWEConstants.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe; + +public class JWEConstants { + + public static final String A128KW = "A128KW"; + + public static final String A128CBC_HS256 = "A128CBC-HS256"; + +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/ContentEncryptMethod.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/ContentEncryptMethod.java new file mode 100644 index 00000000..20039384 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/ContentEncryptMethod.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.encryption; + + +/** + * Common definition of OAuth content encryption method algorithm. + * + * @param the {@link EncryptingKey} type. + * @param the {@link DecryptingKey} type. + */ +public interface ContentEncryptMethod extends EncryptMethod{ + + String encrypt(String header, String payload, byte[] encryptingKey); + + String decrypt(String header, String contentEncryption, byte[] decryptingKey); + + //TODO add validation?? +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/DecryptingKey.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/DecryptingKey.java new file mode 100644 index 00000000..7d4b0e61 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/DecryptingKey.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.encryption; + +/** + * A key that marks has to be used for encrypt operations. + */ +public interface DecryptingKey { + +} \ No newline at end of file diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/EncryptMethod.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/EncryptMethod.java new file mode 100644 index 00000000..6bdf085d --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/EncryptMethod.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.encryption; + +/** + * Common definition of OAuth encryption method algorithm. + * + * @param the {@link EncryptingKey} type. + * @param the {@link DecryptingKey} type. + */ +public interface EncryptMethod { + + String getAlgorithm(); + +} \ No newline at end of file diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/EncryptingKey.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/EncryptingKey.java new file mode 100644 index 00000000..7c0a034c --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/EncryptingKey.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.encryption; + +/** + * A key that marks has to be used for encrypt operations. + */ +public interface EncryptingKey { + +} \ No newline at end of file diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/KeyEncryptMethod.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/KeyEncryptMethod.java new file mode 100644 index 00000000..5f1333f3 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/KeyEncryptMethod.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.encryption; + +import org.apache.oltu.jose.jwe.ContentEncryptionKey; + +/** + * Common definition of OAuth key encryption method algorithm. + * + * @param the {@link EncryptingKey} type. + * @param the {@link DecryptingKey} type. + */ +public interface KeyEncryptMethod extends EncryptMethod { + + //TODO change to wrap? + ContentEncryptionKey encrypt(byte [] cek, EK encryptingKey); + + ContentEncryptionKey encrypt(EK encryptingKey); + + byte[] decrypt(String encryptedKey, DK decryptingKey); + + byte[] decrypt(String encryptedKey); + + //TODO add validation?? + +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/SymmetricKey.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/SymmetricKey.java new file mode 100644 index 00000000..f5df76e1 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/SymmetricKey.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.encryption; + +/** + * A key that marks can be used for both sign and verify + * operations. + */ +public interface SymmetricKey extends EncryptingKey, DecryptingKey { + +} \ No newline at end of file diff --git a/spec-api/src/main/java/org/apache/amber/server/TemporaryCredentialsGenerator.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/package-info.java similarity index 74% rename from spec-api/src/main/java/org/apache/amber/server/TemporaryCredentialsGenerator.java rename to jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/package-info.java index 217a0868..2832d70b 100644 --- a/spec-api/src/main/java/org/apache/amber/server/TemporaryCredentialsGenerator.java +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/encryption/package-info.java @@ -14,20 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.server; /** - * Temporary credentials generator. * - * @version $Id$ */ -public interface TemporaryCredentialsGenerator { - - /** - * Generates a new temporary credentials. - * - * @return a new temporary credentials. - */ - String generate(); - -} +package org.apache.oltu.jose.jwe.encryption; diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEConstants.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEConstants.java new file mode 100644 index 00000000..d7095979 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEConstants.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +interface JWEConstants { + + // header defined in the JWE specification + // https://tools.ietf.org/html/rfc7516 + + /** + * The {@code alg} JWE Header key. + */ + public static final String ALGORITHM = "alg"; + + /** + * The {@code enc} JWE Header key. + */ + public static final String ENCRYPTION_ALGORITHM = "enc"; + + /** + * The {@code zip} JWE Header key. + */ + public static final String COMPRESSION = "zip"; + + /** + * The {@code jku} JWE Header key. + */ + public static final String JWK_SET_URL = "jku"; + + /** + * The {@code jwk} JWE Header key. + */ + public static final String JSON_WEB_KEY = "jwk"; + + /** + * The {@code kid} JWE Header key. + */ + public static final String KEY_ID = "kid"; + + /** + * The {@code x5u} JWE Header key. + */ + public static final String X509_URL = "x5u"; + + /** + * The {@code x5t} JWE Header key. + */ + public static final String X509_CERTIFICATE_THUMBPRINT = "x5t"; + + /** + * The {@code x5c} JWE Header key. + */ + public static final String X509_CERTIFICATE_CHAIN = "x5c"; + + /** + * The {@code typ} JWE Header key. + */ + public static final String TYPE = "typ"; + + /** + * The {@code cty} JWE Header key. + */ + public static final String CONTENT_TYPE = "cty"; + + /** + * The {@code crit} JWE Header key. + */ + public static final String CRITICAL = "crit"; + +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEHeaderParser.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEHeaderParser.java new file mode 100644 index 00000000..b5d17fa7 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEHeaderParser.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +import org.apache.oltu.commons.json.CustomizableEntityReader; +import org.apache.oltu.jose.jwe.JWE; +import org.apache.oltu.jose.jwe.JWE.Builder; + +final class JWEHeaderParser extends CustomizableEntityReader implements JWEConstants { + + public JWEHeaderParser(Builder builder) { + super(builder); + } + + @Override + protected boolean handleProperty(String key, T value) { + boolean handled = true; + + if (ALGORITHM.equals(key)) { + getBuilder().setAlgorithm(String.valueOf(value)); + }else if (ENCRYPTION_ALGORITHM.equals(key)) { + getBuilder().setEncryptionAlgorithm(String.valueOf(value)); + } else if (COMPRESSION.equals(key)) { + getBuilder().setCompressionAlgorithm(String.valueOf(value)); + } else if (JWK_SET_URL.equals(key)) { + getBuilder().setJwkSetUrl(String.valueOf(value)); + } else if (JSON_WEB_KEY.equals(key)) { + getBuilder().setJsonWebKey(String.valueOf(value)); + } else if (X509_URL.equals(key)) { + getBuilder().setX509url(String.valueOf(value)); + } else if (X509_CERTIFICATE_THUMBPRINT.equals(key)) { + getBuilder().setX509CertificateThumbprint(String.valueOf(value)); + } else if (X509_CERTIFICATE_CHAIN.equals(key)) { + getBuilder().setX509CertificateChain(String.valueOf(value)); + } else if (KEY_ID.equals(key)) { + getBuilder().setKeyId(String.valueOf(value)); + } else if (TYPE.equals(key)) { + getBuilder().setType(String.valueOf(value)); + } else if (CONTENT_TYPE.equals(key)) { + getBuilder().setContentType(String.valueOf(value)); + } else if (CRITICAL.equals(key)) { + Object[] criticalValues = (Object[]) value; + String[] critical = new String[criticalValues.length]; + for (int i = 0; i < critical.length; i++) { + critical[i] = String.valueOf(criticalValues[i]); + } + getBuilder().setCritical(critical); + } else { + handled = false; + } + return handled; + } + +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEHeaderWriter.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEHeaderWriter.java new file mode 100644 index 00000000..4aa6cf6b --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEHeaderWriter.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +import org.apache.oltu.commons.json.CustomizableEntityWriter; +import org.apache.oltu.jose.jwe.Header; + +public final class JWEHeaderWriter extends CustomizableEntityWriter
implements JWEConstants { + + @Override + protected void handleProperties(Header header) { + set(ALGORITHM, header.getAlgorithm()); + set(ENCRYPTION_ALGORITHM, header.getEncryptionAlgorithm()); + set(COMPRESSION, header.getCompressionAlgorithm()); + set(JWK_SET_URL, header.getJwkSetUrl()); + set(JSON_WEB_KEY, header.getJsonWebKey()); + set(X509_URL, header.getX509url()); + set(X509_CERTIFICATE_THUMBPRINT, header.getX509CertificateThumbprint()); + set(X509_CERTIFICATE_CHAIN, header.getX509CertificateChain()); + set(KEY_ID, header.getKeyId()); + set(TYPE, header.getType()); + set(CONTENT_TYPE, header.getContentType()); + set(CRITICAL, header.getCritical()); + } + +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEReader.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEReader.java new file mode 100644 index 00000000..070826d6 --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEReader.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jwe.JWE; + +public class JWEReader extends TokenDecoder { + /** + * The Base64 JSON string default separator. + */ + private final Pattern base64urlTokenPattern = Pattern.compile("([a-zA-Z0-9-_=]+)\\.([a-zA-Z0-9-_=]+)\\.([a-zA-Z0-9-_=]+)\\.([a-zA-Z0-9-_=]+)\\.([a-zA-Z0-9-_=]+)"); + + /** + * Read the base64url token string + * @param base64String + * @return + */ + public JWE read(String base64String) { + if (base64String == null || base64String.isEmpty()) { + throw new IllegalArgumentException("Impossible to obtain a Token from a null or empty string"); + } + + // TODO improve multi-line tokens + StringBuilder buffer = new StringBuilder(); + BufferedReader reader = new BufferedReader(new StringReader(base64String)); + String line = null; + try { + while ((line = reader.readLine()) != null) { + buffer.append(line.trim()); + } + } catch (IOException e) { + // it cannot happen + } finally { + try { + reader.close(); + } catch (IOException e) { + // swallow it + } + } + + Matcher matcher = base64urlTokenPattern.matcher(buffer.toString()); + if (!matcher.matches()) { + throw new IllegalArgumentException(base64String + + "is not a valid Token, it does not match with the pattern: " + + base64urlTokenPattern.pattern()); + } + + // HEADER + String header = matcher.group(1); + String decodedHeader = base64Decode(header); + + // ENCRYPTED KEY + String encryptedKey = matcher.group(2); + + StringBuilder contentEncryption = new StringBuilder(); + // IV + contentEncryption.append(matcher.group(3)).append("."); + + // CIPHER TEXT + contentEncryption.append(matcher.group(4)).append("."); + + // AUTHENTICATION TAG + contentEncryption.append(matcher.group(5)); + + return build(decodedHeader, encryptedKey, contentEncryption.toString()); + } + + protected JWE build(String decodedHeader, String encryptedKey, String contentEncryption) { + final JWE.Builder jweBuilder = new JWE.Builder(); + + new JWEHeaderParser(jweBuilder).read(decodedHeader); + + return jweBuilder + .setEncryptedKey(encryptedKey) + .setContentEncryption(contentEncryption) + .build(); + } + + +} diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEWriter.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEWriter.java new file mode 100644 index 00000000..fbbb1dca --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/JWEWriter.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jwe.JWE; + +public final class JWEWriter extends TokenDecoder { + + public final String write(JWE token) { + if (token == null) { + throw new IllegalArgumentException("Impossible to build a Token from a null JWS representation."); + } + + String header = writeHeader(token); + String encodedHeader = base64Encode(header); + String encryptedKey = writeEncryptedKey(token); + String contentEncryption = writeContentEncryption(token); + + return new StringBuilder() + .append(encodedHeader) + .append('.') + .append(encryptedKey) + .append('.') + .append(contentEncryption) + .toString(); + } + + protected String writeHeader(JWE token) { + return new JWEHeaderWriter().write(token.getHeader()); + } + + protected String writeEncryptedKey(JWE token) { + return token.getEncryptedKey(); + } + + protected String writeContentEncryption(JWE token) { + return token.getContentEncryption(); + } +} diff --git a/server/src/main/java/org/apache/amber/server/TemporaryCredentialsGenerator.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/package-info.java similarity index 74% rename from server/src/main/java/org/apache/amber/server/TemporaryCredentialsGenerator.java rename to jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/package-info.java index 217a0868..e302ff0c 100644 --- a/server/src/main/java/org/apache/amber/server/TemporaryCredentialsGenerator.java +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/io/package-info.java @@ -14,20 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.server; /** - * Temporary credentials generator. * - * @version $Id$ */ -public interface TemporaryCredentialsGenerator { - - /** - * Generates a new temporary credentials. - * - * @return a new temporary credentials. - */ - String generate(); - -} +package org.apache.oltu.jose.jwe.io; diff --git a/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/package-info.java b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/package-info.java new file mode 100644 index 00000000..0954190a --- /dev/null +++ b/jose/jwe/src/main/java/org/apache/oltu/jose/jwe/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.oltu.jose.jwe; diff --git a/jose/jwe/src/test/java/org/apache/oltu/jose/jwe/io/JWEReaderTestCase.java b/jose/jwe/src/test/java/org/apache/oltu/jose/jwe/io/JWEReaderTestCase.java new file mode 100644 index 00000000..adbb6e60 --- /dev/null +++ b/jose/jwe/src/test/java/org/apache/oltu/jose/jwe/io/JWEReaderTestCase.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +import static org.junit.Assert.assertEquals; +import org.apache.oltu.jose.jwe.JWE; +import org.apache.oltu.jose.jwe.JWEConstants; +import org.junit.Test; + +public class JWEReaderTestCase { + + private JWEReader reader = new JWEReader(); + + @Test + public void parse() { + String specJWE = "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0."+ + "6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ."+ + "AxY8DCtDaGlsbGljb3RoZQ."+ + "KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY."+ + "U0m_YmjN04DJvceFICbCVQ"; + JWE jwe = reader.read(specJWE); + + assertEquals(JWEConstants.A128KW, jwe.getHeader().getAlgorithm()); + assertEquals(JWEConstants.A128CBC_HS256, jwe.getHeader().getEncryptionAlgorithm()); + assertEquals("6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ", jwe.getEncryptedKey()); + assertEquals("AxY8DCtDaGlsbGljb3RoZQ.KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY.U0m_YmjN04DJvceFICbCVQ", jwe.getContentEncryption()); + } + +} diff --git a/jose/jwe/src/test/java/org/apache/oltu/jose/jwe/io/JWEWriterTestCase.java b/jose/jwe/src/test/java/org/apache/oltu/jose/jwe/io/JWEWriterTestCase.java new file mode 100644 index 00000000..45bfeec6 --- /dev/null +++ b/jose/jwe/src/test/java/org/apache/oltu/jose/jwe/io/JWEWriterTestCase.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jwe.io; + +import static org.junit.Assert.assertEquals; +import org.apache.oltu.jose.jwe.JWE; +import org.apache.oltu.jose.jwe.JWEConstants; +import org.junit.Test; + +public class JWEWriterTestCase { + + private final JWEWriter jweWriter = new JWEWriter(); + + @Test + public void serialize() { + JWE jwe = new JWE.Builder().setAlgorithm(JWEConstants.A128KW) + .setEncryptionAlgorithm(JWEConstants.A128CBC_HS256) + .setEncryptedKey("6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ") + .setContentEncryption("AxY8DCtDaGlsbGljb3RoZQ.KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY.U0m_YmjN04DJvceFICbCVQ") + .build(); + String actual = jweWriter.write(jwe); + String specJWE = "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0."+ + "6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ."+ + "AxY8DCtDaGlsbGljb3RoZQ."+ + "KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY."+ + "U0m_YmjN04DJvceFICbCVQ"; + assertEquals(specJWE, + actual); + } +} diff --git a/jose/jws/pom.xml b/jose/jws/pom.xml new file mode 100644 index 00000000..0e931bd5 --- /dev/null +++ b/jose/jws/pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + + org.apache.oltu.jose + org.apache.oltu.jose.parent + 3-SNAPSHOT + + + org.apache.oltu.jose.jws + 1.0.2-SNAPSHOT + bundle + + Apache Oltu - JOSE - JWS + JWS specification implemented in Apache Oltu + + + ${project.artifactId}*;version=${project.version} + + + + + org.apache.oltu.commons + org.apache.oltu.commons.encodedtoken + 1.0.1 + + + + org.apache.oltu.commons + org.apache.oltu.commons.json + 1.0.1 + + + + diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/Header.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/Header.java new file mode 100644 index 00000000..22879a1b --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/Header.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws; + +import java.util.Map; + +import org.apache.oltu.commons.json.CustomizableEntity; + +/** + * Represents the Header as defined in the section 4 of the JWS specification. + * + * @see http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-15#section-4 + */ +public final class Header extends CustomizableEntity { + + /** + * The {@code alg} JWS Header parameter. + */ + private final String algorithm; + + /** + * The {@code jku} JWS Header parameter. + */ + private final String jwkSetUrl; + + /** + * The {@code jwk} JWS Header parameter. + */ + private final String jsonWebKey; + + /** + * The {@code x5u} JWS Header parameter. + */ + private final String x509url; + + /** + * The {@code x5t} JWS Header parameter. + */ + private final String x509CertificateThumbprint; + + /** + * The {@code x5c} JWS Header parameter. + */ + private final String x509CertificateChain; + + /** + * The {@code kid} JWS Header parameter. + */ + private final String keyId; + + /** + * The {@code typ} JWS Header parameter. + */ + private final String type; + + /** + * The {@code cty} JWS Header parameter. + */ + private final String contentType; + + /** + * The {@code crit} JWS Header parameter. + */ + private final String[] critical; + + Header(String algorithm, + String jwkSetUrl, + String jsonWebKey, + String x509url, + String x509CertificateThumbprint, + String x509CertificateChain, + String keyId, + String type, + String contentType, + String[] critical, + Map customFields) { + super(customFields); + this.algorithm = algorithm; + this.jwkSetUrl = jwkSetUrl; + this.jsonWebKey = jsonWebKey; + this.x509url = x509url; + this.x509CertificateThumbprint = x509CertificateThumbprint; + this.x509CertificateChain = x509CertificateChain; + this.keyId = keyId; + this.type = type; + this.contentType = contentType; + this.critical = critical; + } + + public String getAlgorithm() { + return algorithm; + } + + public String getJwkSetUrl() { + return jwkSetUrl; + } + + public String getJsonWebKey() { + return jsonWebKey; + } + + public String getX509url() { + return x509url; + } + + public String getX509CertificateThumbprint() { + return x509CertificateThumbprint; + } + + public String getX509CertificateChain() { + return x509CertificateChain; + } + + public String getKeyId() { + return keyId; + } + + public String getType() { + return type; + } + + public String getContentType() { + return contentType; + } + + public String[] getCritical() { + return critical; + } + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java new file mode 100644 index 00000000..a761a3e5 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java @@ -0,0 +1,288 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.commons.json.CustomizableBuilder; +import org.apache.oltu.jose.jws.io.JWSHeaderWriter; +import org.apache.oltu.jose.jws.signature.SignatureMethod; +import org.apache.oltu.jose.jws.signature.SigningKey; +import org.apache.oltu.jose.jws.signature.VerifyingKey; + +public class JWS { + + /** + * The raw JWS String + */ + private String rawString; + + /** + * The JWS Header. + */ + private final Header header; + + /** + * The JWS Payload. + */ + private final String payload; + + /** + * The JWS Signature. + */ + private final String signature; + + JWS(Header header, String payload, String signature) { + this(null, header, payload, signature); + } + + JWS(String rawString, Header header, String payload, String signature) { + this.rawString = rawString; + this.header = header; + this.payload = payload; + this.signature = signature; + } + + public Header getHeader() { + return header; + } + + public String getPayload() { + return payload; + } + + public String getSignature() { + return signature; + } + + public boolean acceptAlgorithm(SignatureMethod method) { + if (method == null) { + throw new IllegalArgumentException("A signature method is required in order to verify the signature."); + } + if (header == null || header.getAlgorithm() == null) { + throw new IllegalStateException("JWS token must have a valid JSON header with specified algorithm."); + } + + return header.getAlgorithm().equalsIgnoreCase(method.getAlgorithm()); + } + + public boolean validate(SignatureMethod method, + VK verifyingKey) { + if (!acceptAlgorithm(method)) { + throw new IllegalArgumentException("Impossible to verify current JWS signature with algorithm '" + + method.getAlgorithm() + + "', JWS header specifies message has been signed with '" + + header.getAlgorithm() + + "' algorithm."); + } + + if (verifyingKey == null) { + throw new IllegalArgumentException("A verifying key is required in order to verify the signature."); + } + + if (payload == null) { + throw new IllegalStateException("JWS token must have a payload."); + } + if (signature == null) { + throw new IllegalStateException("JWS token must have a signature to be verified."); + } + + if (rawString == null) { + return method.verify(signature, TokenDecoder.base64Encode(new JWSHeaderWriter().write(header)), TokenDecoder.base64Encode(payload), verifyingKey); + } else { + String jwt[] = rawString.split("\\."); + return method.verify(jwt[2], jwt[0], jwt[1], verifyingKey); + } + } + + public static final class Builder extends CustomizableBuilder { + + public Builder(){} + + public Builder(String rawString) { + this.rawString = rawString; + } + + /** + * The raw JWS String + */ + private String rawString; + + /** + * The {@code alg} JWS Header parameter. + */ + private String algorithm; + + /** + * The {@code jku} JWS Header parameter. + */ + private String jwkSetUrl; + + /** + * The {@code jwk} JWS Header parameter. + */ + private String jsonWebKey; + + /** + * The {@code x5u} JWS Header parameter. + */ + private String x509url; + + /** + * The {@code x5t} JWS Header parameter. + */ + private String x509CertificateThumbprint; + + /** + * The {@code x5c} JWS Header parameter. + */ + private String x509CertificateChain; + + /** + * The {@code kid} JWS Header parameter. + */ + private String keyId; + + /** + * The {@code typ} JWS Header parameter. + */ + private String type; + + /** + * The {@code cty} JWS Header parameter. + */ + private String contentType; + + /** + * The {@code crit} JWS Header parameter. + */ + private String[] critical; + + /** + * The JWS Payload. + */ + private String payload; + + /** + * The JWS Signature. + */ + private String signature; + + public Builder setAlgorithm(String algorithm) { + this.algorithm = algorithm; + return this; + } + + public Builder setJwkSetUrl(String jwkSetUrl) { + this.jwkSetUrl = jwkSetUrl; + return this; + } + + public Builder setJsonWebKey(String jsonWebKey) { + this.jsonWebKey = jsonWebKey; + return this; + } + + public Builder setX509url(String x509url) { + this.x509url = x509url; + return this; + } + + public Builder setX509CertificateThumbprint(String x509CertificateThumbprint) { + this.x509CertificateThumbprint = x509CertificateThumbprint; + return this; + } + + public Builder setX509CertificateChain(String x509CertificateChain) { + this.x509CertificateChain = x509CertificateChain; + return this; + } + + public Builder setKeyId(String keyId) { + this.keyId = keyId; + return this; + } + + public Builder setType(String type) { + this.type = type; + return this; + } + + public Builder setContentType(String contentType) { + this.contentType = contentType; + return this; + } + + public Builder setCritical(String[] critical) { + this.critical = critical; + return this; + } + + public Builder setPayload(String payload) { + this.payload = payload; + return this; + } + + public Builder setSignature(String signature) { + this.signature = signature; + return this; + } + + public Builder sign(SignatureMethod method, + SK signingKey) { + if (method == null) { + throw new IllegalArgumentException("A signature method is required in order to calculate the signature."); + } + if (signingKey == null) { + throw new IllegalArgumentException("A signing key is required in order to calculate the signature."); + } + if (payload == null) { + throw new IllegalStateException("Payload needs to be set in order to sign the current JWT"); + } + setAlgorithm(method.getAlgorithm()); + + String header = new JWSHeaderWriter().write(new Header(algorithm, + jwkSetUrl, + jsonWebKey, + x509url, + x509CertificateThumbprint, + x509CertificateChain, + keyId, type, + contentType, + critical, + getCustomFields())); + + return setSignature(method.calculate(TokenDecoder.base64Encode(header), TokenDecoder.base64Encode(payload), signingKey)); + } + + public JWS build() { + return new JWS(rawString, new Header(algorithm, + jwkSetUrl, + jsonWebKey, + x509url, + x509CertificateThumbprint, + x509CertificateChain, + keyId, type, + contentType, + critical, + getCustomFields()), + payload, + signature); + } + + } + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWSConstants.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWSConstants.java new file mode 100644 index 00000000..a3386026 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWSConstants.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws; + +public class JWSConstants { + + public static final String RS256 = "RS256"; + + public static final String RS384 = "RS384"; + + public static final String RS512 = "RS512"; + + public static final String HS256 = "HS256"; +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSConstants.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSConstants.java new file mode 100644 index 00000000..18a0ad82 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSConstants.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.io; + +interface JWSConstants { + + // header defined in the JWT specification + + /** + * The {@code alg} JWT Header key. + */ + public static final String ALGORITHM = "alg"; + + /** + * The {@code jku} JWT Header key. + */ + public static final String JWK_SET_URL = "jku"; + + /** + * The {@code jwk} JWT Header key. + */ + public static final String JSON_WEB_KEY = "jwk"; + + /** + * The {@code x5u} JWT Header key. + */ + public static final String X509_URL = "x5u"; + + /** + * The {@code x5t} JWT Header key. + */ + public static final String X509_CERTIFICATE_THUMBPRINT = "x5t"; + + /** + * The {@code x5c} JWT Header key. + */ + public static final String X509_CERTIFICATE_CHAIN = "x5c"; + + /** + * The {@code kid} JWT Header key. + */ + public static final String KEY_ID = "kid"; + + /** + * The {@code typ} JWT Header key. + */ + public static final String TYPE = "typ"; + + /** + * The {@code cty} JWT Header key. + */ + public static final String CONTENT_TYPE = "cty"; + + /** + * The {@code crit} JWT Header key. + */ + public static final String CRITICAL = "crit"; + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSHeaderParser.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSHeaderParser.java new file mode 100644 index 00000000..8d7a04ca --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSHeaderParser.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.io; + +import org.apache.oltu.commons.json.CustomizableEntityReader; +import org.apache.oltu.jose.jws.JWS; + +final class JWSHeaderParser extends CustomizableEntityReader implements JWSConstants { + + public JWSHeaderParser(JWS.Builder builder) { + super(builder); + } + + @Override + protected boolean handleProperty(String key, T value) { + boolean handled = true; + + if (ALGORITHM.equals(key)) { + getBuilder().setAlgorithm(String.valueOf(value)); + } else if (JWK_SET_URL.equals(key)) { + getBuilder().setJwkSetUrl(String.valueOf(value)); + } else if (JSON_WEB_KEY.equals(key)) { + getBuilder().setJsonWebKey(String.valueOf(value)); + } else if (X509_URL.equals(key)) { + getBuilder().setX509url(String.valueOf(value)); + } else if (X509_CERTIFICATE_THUMBPRINT.equals(key)) { + getBuilder().setX509CertificateThumbprint(String.valueOf(value)); + } else if (X509_CERTIFICATE_CHAIN.equals(key)) { + getBuilder().setX509CertificateChain(String.valueOf(value)); + } else if (KEY_ID.equals(key)) { + getBuilder().setKeyId(String.valueOf(value)); + } else if (TYPE.equals(key)) { + getBuilder().setType(String.valueOf(value)); + } else if (CONTENT_TYPE.equals(key)) { + getBuilder().setContentType(String.valueOf(value)); + } else if (CRITICAL.equals(key)) { + Object[] criticalValues = (Object[]) value; + String[] critical = new String[criticalValues.length]; + for (int i = 0; i < critical.length; i++) { + critical[i] = String.valueOf(criticalValues[i]); + } + getBuilder().setCritical(critical); + } else { + handled = false; + } + + return handled; + } + + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSHeaderWriter.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSHeaderWriter.java new file mode 100644 index 00000000..fd3ebfb5 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSHeaderWriter.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.io; + +import org.apache.oltu.commons.json.CustomizableEntityWriter; +import org.apache.oltu.jose.jws.Header; + +public final class JWSHeaderWriter extends CustomizableEntityWriter
implements JWSConstants { + + @Override + protected void handleProperties(Header header) { + set(ALGORITHM, header.getAlgorithm()); + set(JWK_SET_URL, header.getJwkSetUrl()); + set(JSON_WEB_KEY, header.getJsonWebKey()); + set(X509_URL, header.getX509url()); + set(X509_CERTIFICATE_THUMBPRINT, header.getX509CertificateThumbprint()); + set(X509_CERTIFICATE_CHAIN, header.getX509CertificateChain()); + set(KEY_ID, header.getKeyId()); + set(TYPE, header.getType()); + set(CONTENT_TYPE, header.getContentType()); + set(CRITICAL, header.getCritical()); + } + +} diff --git a/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSReader.java similarity index 55% rename from signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java rename to jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSReader.java index 127ae8ce..db6b91f1 100644 --- a/signature-api/src/test/java/org/apache/amber/signature/rsa/RsaSha1MethodTestCase.java +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSReader.java @@ -14,29 +14,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.signature.rsa; +package org.apache.oltu.jose.jws.io; -import org.apache.amber.signature.AbstractMethodTestCase; -import org.junit.Test; +import org.apache.oltu.commons.encodedtoken.TokenReader; +import org.apache.oltu.jose.jws.JWS; /** - * + * A {@link JWS} reader. * - * @version $Id$ + * TODO understand if JWT can be reused to avoid code duplication! */ -public final class RsaSha1MethodTestCase extends AbstractMethodTestCase { +public final class JWSReader extends TokenReader { - // TODO delete me once next test will be re-enabled - @Test - public void doNothing() { - // do nothing - } + @Override + protected JWS build(String rawString, String decodedHeader, String decodedBody, String encodedSignature) { + final JWS.Builder jwsBuilder = new JWS.Builder(rawString); + + new JWSHeaderParser(jwsBuilder).read(decodedHeader); - // TODO test disabled, expected signature has to be calculated - public void verifyRsaSha1MethodAlgorithm() throws Exception { - this.verifySignature(new PemRsaSha1VerifyingKey("kd94hf93k423kf44"), - new RsaSha1Method(), - "kd94hf93k423kf44&pfkkdhi9sl3r4s00"); + return jwsBuilder + .setPayload(decodedBody) + .setSignature(encodedSignature) + .build(); } } diff --git a/server/src/main/java/org/apache/amber/server/StorageException.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSWriter.java similarity index 60% rename from server/src/main/java/org/apache/amber/server/StorageException.java rename to jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSWriter.java index 8956db3d..13687bc8 100644 --- a/server/src/main/java/org/apache/amber/server/StorageException.java +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/JWSWriter.java @@ -14,30 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.server; +package org.apache.oltu.jose.jws.io; -/** - * Exception thrown when an error occurs when accessing to the Access Storage. - * - * @version $Id$ - */ -public final class StorageException extends Exception { +import org.apache.oltu.commons.encodedtoken.TokenWriter; +import org.apache.oltu.jose.jws.JWS; - /** - * The default serial version UID; - */ - private static final long serialVersionUID = 1L; +public final class JWSWriter extends TokenWriter { - public StorageException(String message) { - super(message); + @Override + protected String writeHeader(JWS token) { + return new JWSHeaderWriter().write(token.getHeader()); } - public StorageException(Throwable cause) { - super(cause); + @Override + protected String writeBody(JWS token) { + return token.getPayload(); } - public StorageException(String message, Throwable cause) { - super(message, cause); + @Override + protected String writeSignature(JWS token) { + return token.getSignature(); } } diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/package-info.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/package-info.java new file mode 100644 index 00000000..969da9e9 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/io/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.oltu.jose.jws.io; diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/package-info.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/package-info.java new file mode 100644 index 00000000..8f241fc6 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.oltu.jose.jws; diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SignatureMethod.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SignatureMethod.java new file mode 100644 index 00000000..aa1eae2a --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SignatureMethod.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature; + +/** + * Common definition of OAuth signature method algorithm. + * + * @param the {@link SigningKey} type. + * @param the {@link VerifyingKey} type. + */ +public interface SignatureMethod { + + String calculate(String header, String payload, S signingKey); + + boolean verify(String signature, String header, String payload, V verifyingKey); + + String getAlgorithm(); + +} diff --git a/spec-api/src/main/java/org/apache/amber/signature/SigningKey.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SigningKey.java similarity index 83% rename from spec-api/src/main/java/org/apache/amber/signature/SigningKey.java rename to jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SigningKey.java index 27abd233..a86702a2 100644 --- a/spec-api/src/main/java/org/apache/amber/signature/SigningKey.java +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SigningKey.java @@ -14,13 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.signature; +package org.apache.oltu.jose.jws.signature; /** - * Identifies that the key has to be used to sign requests. - * - * @version $Id$ + * A key that marks has to be used for sign operations. */ -public interface SigningKey extends Key { +public interface SigningKey { } diff --git a/spec-api/src/main/java/org/apache/amber/server/TokenCredentialsGenerator.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SymmetricKey.java similarity index 75% rename from spec-api/src/main/java/org/apache/amber/server/TokenCredentialsGenerator.java rename to jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SymmetricKey.java index 30d9bb2b..750591e4 100644 --- a/spec-api/src/main/java/org/apache/amber/server/TokenCredentialsGenerator.java +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/SymmetricKey.java @@ -14,20 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.server; +package org.apache.oltu.jose.jws.signature; /** - * Token credentials generator. - * - * @version $Id$ + * A key that marks can be used for both sign and verify operations. */ -public interface TokenCredentialsGenerator { - - /** - * Generates a new token credentials. - * - * @return a new token credentials. - */ - String generate(); +public interface SymmetricKey extends SigningKey, VerifyingKey { } diff --git a/spec-api/src/main/java/org/apache/amber/signature/VerifyingKey.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/VerifyingKey.java similarity index 83% rename from spec-api/src/main/java/org/apache/amber/signature/VerifyingKey.java rename to jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/VerifyingKey.java index 1e261367..e9be51c5 100644 --- a/spec-api/src/main/java/org/apache/amber/signature/VerifyingKey.java +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/VerifyingKey.java @@ -14,13 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.signature; +package org.apache.oltu.jose.jws.signature; /** - * Identifies that the key has to be used to verify requests. - * - * @version $Id$ + * A key that marks has to be used for verify operations. */ -public interface VerifyingKey extends Key { +public interface VerifyingKey { } diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/PrivateKey.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/PrivateKey.java new file mode 100644 index 00000000..94067c01 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/PrivateKey.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import org.apache.oltu.jose.jws.signature.SigningKey; + +public class PrivateKey implements SigningKey { + + java.security.PrivateKey privateKey; + + public PrivateKey(java.security.PrivateKey privateKey) { + this.privateKey = privateKey; + } + + public java.security.PrivateKey getPrivateKey() { + return privateKey; + } + +} \ No newline at end of file diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/PublicKey.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/PublicKey.java new file mode 100644 index 00000000..9063a438 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/PublicKey.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import org.apache.oltu.jose.jws.signature.VerifyingKey; + +public class PublicKey implements VerifyingKey { + + java.security.PublicKey publicKey; + + public PublicKey(java.security.PublicKey publicKey) { + this.publicKey = publicKey; + } + + public java.security.PublicKey getPublicKey() { + return publicKey; + } + +} \ No newline at end of file diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodRSAImpl.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodRSAImpl.java new file mode 100644 index 00000000..afd33792 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodRSAImpl.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import java.security.Signature; +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jws.JWSConstants; +import org.apache.oltu.jose.jws.signature.SignatureMethod; + +/** + * Class that asymmetrically sign and verify the issued token. + */ +public class SignatureMethodRSAImpl implements SignatureMethod{ + + private String algorithm; + + public SignatureMethodRSAImpl(String algorithm) { + this.algorithm = algorithm; + } + + /** + * Calculate the signature of given header.payload as for + * appendix-A.2.1 + * + * {@inheritDoc} + */ + @Override + public String calculate(String header, String payload, PrivateKey signingKey) { + byte[] token = toToken(header, payload); + try { + Signature signature = Signature.getInstance(getAlgorithmInternal()); + + signature.initSign(signingKey.getPrivateKey()); + signature.update(token); + token = signature.sign(); + + return TokenDecoder.base64Encode(token); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Verify the signature of given header.payload as for + * appendix-A.2.2 + * + * {@inheritDoc} + */ + @Override + public boolean verify(String signature, String header, String payload, PublicKey verifyingKey) { + byte[] token = toToken(header, payload); + try { + Signature sign = Signature.getInstance(getAlgorithmInternal()); + sign.initVerify(verifyingKey.getPublicKey()); + sign.update(token); + + return sign.verify(decode(signature)); + } catch (Exception e) { + return false; + } + } + + @Override + public String getAlgorithm() { + return algorithm; + } + + // ---------- Private methods --------------------------------------------- + + private static byte[] toToken(String header, String payload) { + return new StringBuilder() + .append(header) + .append(".") + .append(payload) + .toString() + .getBytes(); + } + + private String getAlgorithmInternal() { + String alg = null; + if (JWSConstants.RS256.equals(algorithm)) { + alg = "SHA256withRSA"; + } else if (JWSConstants.RS384.equals(algorithm)) { + alg = "SHA384withRSA"; + } else if (JWSConstants.RS512.equals(algorithm)) { + alg = "SHA512withRSA"; + } + return alg; + } + + private static byte[] decode(String arg) throws Exception { + String s = arg; + s = s.replace('-', '+'); // 62nd char of encoding + s = s.replace('_', '/'); // 63rd char of encoding + + switch (s.length() % 4) // Pad with trailing '='s + { + case 0: // No pad chars in this case + break; + + case 2: // Two pad chars + s += "=="; + break; + + case 3: // One pad char + s += "="; + break; + + default: + throw new Exception("Illegal base64url string!"); + } + + return TokenDecoder.base64DecodeToByte(s); + } + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodsHMAC256Impl.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodsHMAC256Impl.java new file mode 100644 index 00000000..f24abe4f --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodsHMAC256Impl.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jws.JWSConstants; +import org.apache.oltu.jose.jws.signature.SignatureMethod; + +public class SignatureMethodsHMAC256Impl implements SignatureMethod { + + @Override + public String calculate(String header, String payload, SymmetricKeyImpl signingKey) { + StringBuilder sb = new StringBuilder(); + sb.append(header).append(".").append(payload); + String stringToSign = sb.toString(); + byte[] bytes = stringToSign.getBytes(); + + try { + Mac mac = Mac.getInstance("HMACSHA256"); + mac.init(new SecretKeySpec(signingKey.getKey(), mac.getAlgorithm())); + mac.update(bytes); + bytes = mac.doFinal(); + + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } catch (InvalidKeyException e) { + throw new RuntimeException(e); + } + + return TokenDecoder.base64Encode(bytes); + } + + @Override + public boolean verify(String signature, String header, String payload, SymmetricKeyImpl verifyingKey) { + String signed = calculate(header, payload, verifyingKey); + return signed.equals(signature); + } + + @Override + public String getAlgorithm() { + return JWSConstants.HS256; + } + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SymmetricKeyImpl.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SymmetricKeyImpl.java new file mode 100644 index 00000000..c5e4efe0 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/impl/SymmetricKeyImpl.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import org.apache.oltu.jose.jws.signature.SymmetricKey; + +/** + * Symmetric key implementation used for both sign and verify + * operations. + */ +public class SymmetricKeyImpl implements SymmetricKey { + + private byte[] key; + + public SymmetricKeyImpl(byte[] key) { + this.key = key; + } + + public byte[] getKey() { + return key; + } + +} diff --git a/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/package-info.java b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/package-info.java new file mode 100644 index 00000000..dec47bb1 --- /dev/null +++ b/jose/jws/src/main/java/org/apache/oltu/jose/jws/signature/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.oltu.jose.jws.signature; diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/JWSTest.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/JWSTest.java new file mode 100644 index 00000000..d672367c --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/JWSTest.java @@ -0,0 +1,236 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws; + +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.RSAPrivateKeySpec; +import java.security.spec.RSAPublicKeySpec; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jws.io.JWSReader; +import org.apache.oltu.jose.jws.signature.SignatureMethod; +import org.apache.oltu.jose.jws.signature.impl.PublicKey; +import org.apache.oltu.jose.jws.signature.impl.SignatureMethodRSAImpl; +import org.junit.Assert; +import org.junit.Test; + +public class JWSTest { + + @Test + public void testValidate() throws InvalidKeySpecException, NoSuchAlgorithmException { + + final byte[] n = { (byte) 161, (byte) 248, (byte) 22, (byte) 10, (byte) 226, (byte) 227, (byte) 201, (byte) 180, + (byte) 101, (byte) 206, (byte) 141, (byte) 45, (byte) 101, (byte) 98, (byte) 99, (byte) 54, (byte) 43, + (byte) 146, (byte) 125, (byte) 190, (byte) 41, (byte) 225, (byte) 240, (byte) 36, (byte) 119, (byte) 252, + (byte) 22, (byte) 37, (byte) 204, (byte) 144, (byte) 161, (byte) 54, (byte) 227, (byte) 139, (byte) 217, + (byte) 52, (byte) 151, (byte) 197, (byte) 182, (byte) 234, (byte) 99, (byte) 221, (byte) 119, (byte) 17, + (byte) 230, (byte) 124, (byte) 116, (byte) 41, (byte) 249, (byte) 86, (byte) 176, (byte) 251, (byte) 138, + (byte) 143, (byte) 8, (byte) 154, (byte) 220, (byte) 75, (byte) 105, (byte) 137, (byte) 60, (byte) 193, + (byte) 51, (byte) 63, (byte) 83, (byte) 237, (byte) 208, (byte) 25, (byte) 184, (byte) 119, (byte) 132, + (byte) 37, (byte) 47, (byte) 236, (byte) 145, (byte) 79, (byte) 228, (byte) 133, (byte) 119, (byte) 105, + (byte) 89, (byte) 75, (byte) 234, (byte) 66, (byte) 128, (byte) 211, (byte) 44, (byte) 15, (byte) 85, + (byte) 191, (byte) 98, (byte) 148, (byte) 79, (byte) 19, (byte) 3, (byte) 150, (byte) 188, (byte) 110, + (byte) 155, (byte) 223, (byte) 110, (byte) 189, (byte) 210, (byte) 189, (byte) 163, (byte) 103, (byte) 142, + (byte) 236, (byte) 160, (byte) 198, (byte) 104, (byte) 247, (byte) 1, (byte) 179, (byte) 141, (byte) 191, + (byte) 251, (byte) 56, (byte) 200, (byte) 52, (byte) 44, (byte) 226, (byte) 254, (byte) 109, (byte) 39, + (byte) 250, (byte) 222, (byte) 74, (byte) 90, (byte) 72, (byte) 116, (byte) 151, (byte) 157, (byte) 212, + (byte) 185, (byte) 207, (byte) 154, (byte) 222, (byte) 196, (byte) 199, (byte) 91, (byte) 5, (byte) 133, + (byte) 44, (byte) 44, (byte) 15, (byte) 94, (byte) 248, (byte) 165, (byte) 193, (byte) 117, (byte) 3, + (byte) 146, (byte) 249, (byte) 68, (byte) 232, (byte) 237, (byte) 100, (byte) 193, (byte) 16, (byte) 198, + (byte) 182, (byte) 71, (byte) 96, (byte) 154, (byte) 164, (byte) 120, (byte) 58, (byte) 235, (byte) 156, + (byte) 108, (byte) 154, (byte) 215, (byte) 85, (byte) 49, (byte) 48, (byte) 80, (byte) 99, (byte) 139, + (byte) 131, (byte) 102, (byte) 92, (byte) 111, (byte) 111, (byte) 122, (byte) 130, (byte) 163, (byte) 150, + (byte) 112, (byte) 42, (byte) 31, (byte) 100, (byte) 27, (byte) 130, (byte) 211, (byte) 235, (byte) 242, + (byte) 57, (byte) 34, (byte) 25, (byte) 73, (byte) 31, (byte) 182, (byte) 134, (byte) 135, (byte) 44, + (byte) 87, (byte) 22, (byte) 245, (byte) 10, (byte) 248, (byte) 53, (byte) 141, (byte) 154, (byte) 139, + (byte) 157, (byte) 23, (byte) 195, (byte) 64, (byte) 114, (byte) 143, (byte) 127, (byte) 135, (byte) 216, + (byte) 154, (byte) 24, (byte) 216, (byte) 252, (byte) 171, (byte) 103, (byte) 173, (byte) 132, (byte) 89, + (byte) 12, (byte) 46, (byte) 207, (byte) 117, (byte) 147, (byte) 57, (byte) 54, (byte) 60, (byte) 7, + (byte) 3, (byte) 77, (byte) 111, (byte) 96, (byte) 111, (byte) 158, (byte) 33, (byte) 224, (byte) 84, + (byte) 86, (byte) 202, (byte) 229, (byte) 233, (byte) 161 }; + final byte[] e = { 1, 0, 1 }; + final byte[] d = { 18, (byte) 174, (byte) 113, (byte) 164, (byte) 105, (byte) 205, (byte) 10, (byte) 43, + (byte) 195, (byte) 126, (byte) 82, (byte) 108, (byte) 69, (byte) 0, (byte) 87, (byte) 31, (byte) 29, + (byte) 97, (byte) 117, (byte) 29, (byte) 100, (byte) 233, (byte) 73, (byte) 112, (byte) 123, (byte) 98, + (byte) 89, (byte) 15, (byte) 157, (byte) 11, (byte) 165, (byte) 124, (byte) 150, (byte) 60, (byte) 64, + (byte) 30, (byte) 63, (byte) 207, (byte) 47, (byte) 44, (byte) 211, (byte) 189, (byte) 236, (byte) 136, + (byte) 229, (byte) 3, (byte) 191, (byte) 198, (byte) 67, (byte) 155, (byte) 11, (byte) 40, (byte) 200, + (byte) 47, (byte) 125, (byte) 55, (byte) 151, (byte) 103, (byte) 31, (byte) 82, (byte) 19, (byte) 238, + (byte) 216, (byte) 193, (byte) 90, (byte) 37, (byte) 216, (byte) 213, (byte) 206, (byte) 160, (byte) 2, + (byte) 94, (byte) 227, (byte) 171, (byte) 46, (byte) 139, (byte) 127, (byte) 121, (byte) 33, (byte) 111, + (byte) 198, (byte) 59, (byte) 234, (byte) 86, (byte) 39, (byte) 83, (byte) 180, (byte) 6, (byte) 68, + (byte) 198, (byte) 161, (byte) 81, (byte) 39, (byte) 217, (byte) 178, (byte) 149, (byte) 69, (byte) 64, + (byte) 160, (byte) 187, (byte) 225, (byte) 163, (byte) 5, (byte) 86, (byte) 152, (byte) 45, (byte) 78, + (byte) 159, (byte) 222, (byte) 95, (byte) 100, (byte) 37, (byte) 241, (byte) 77, (byte) 75, (byte) 113, + (byte) 52, (byte) 65, (byte) 181, (byte) 93, (byte) 199, (byte) 59, (byte) 155, (byte) 74, (byte) 237, + (byte) 204, (byte) 146, (byte) 172, (byte) 227, (byte) 146, (byte) 126, (byte) 55, (byte) 245, (byte) 125, + (byte) 12, (byte) 253, (byte) 94, (byte) 117, (byte) 129, (byte) 250, (byte) 81, (byte) 44, (byte) 143, + (byte) 73, (byte) 97, (byte) 169, (byte) 235, (byte) 11, (byte) 128, (byte) 248, (byte) 168, (byte) 7, + (byte) 70, (byte) 114, (byte) 138, (byte) 85, (byte) 255, (byte) 70, (byte) 71, (byte) 31, (byte) 52, + (byte) 37, (byte) 6, (byte) 59, (byte) 157, (byte) 83, (byte) 100, (byte) 47, (byte) 94, (byte) 222, + (byte) 30, (byte) 132, (byte) 214, (byte) 19, (byte) 8, (byte) 26, (byte) 250, (byte) 92, (byte) 34, + (byte) 208, (byte) 81, (byte) 40, (byte) 91, (byte) 214, (byte) 59, (byte) 148, (byte) 59, (byte) 86, + (byte) 93, (byte) 137, (byte) 138, (byte) 5, (byte) 104, (byte) 84, (byte) 19, (byte) 229, (byte) 60, + (byte) 60, (byte) 108, (byte) 101, (byte) 37, (byte) 255, (byte) 31, (byte) 227, (byte) 78, (byte) 61, + (byte) 220, (byte) 112, (byte) 240, (byte) 213, (byte) 100, (byte) 80, (byte) 253, (byte) 164, (byte) 139, + (byte) 161, (byte) 46, (byte) 16, (byte) 78, (byte) 157, (byte) 235, (byte) 159, (byte) 184, (byte) 24, + (byte) 129, (byte) 225, (byte) 196, (byte) 189, (byte) 242, (byte) 93, (byte) 146, (byte) 71, (byte) 244, + (byte) 80, (byte) 200, (byte) 101, (byte) 146, (byte) 121, (byte) 104, (byte) 231, (byte) 115, (byte) 52, + (byte) 244, (byte) 65, (byte) 79, (byte) 117, (byte) 167, (byte) 80, (byte) 225, (byte) 57, (byte) 84, + (byte) 110, (byte) 58, (byte) 138, (byte) 115, (byte) 157 }; + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + String accessToken = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"; + JWS jws = new JWSReader().read(accessToken); + + SignatureMethod signatureMethod = new SignatureMethodRSAImpl("RS256"); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + + RSAPublicKey rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + + Assert.assertTrue(jws.validate(signatureMethod, new PublicKey(rsaPublicKey))); + } + + @Test + public void testValidate2() throws InvalidKeySpecException, NoSuchAlgorithmException { + + final byte[] n = { (byte) 161, (byte) 248, (byte) 22, (byte) 10, (byte) 226, (byte) 227, (byte) 201, (byte) 180, + (byte) 101, (byte) 206, (byte) 141, (byte) 45, (byte) 101, (byte) 98, (byte) 99, (byte) 54, (byte) 43, + (byte) 146, (byte) 125, (byte) 190, (byte) 41, (byte) 225, (byte) 240, (byte) 36, (byte) 119, (byte) 252, + (byte) 22, (byte) 37, (byte) 204, (byte) 144, (byte) 161, (byte) 54, (byte) 227, (byte) 139, (byte) 217, + (byte) 52, (byte) 151, (byte) 197, (byte) 182, (byte) 234, (byte) 99, (byte) 221, (byte) 119, (byte) 17, + (byte) 230, (byte) 124, (byte) 116, (byte) 41, (byte) 249, (byte) 86, (byte) 176, (byte) 251, (byte) 138, + (byte) 143, (byte) 8, (byte) 154, (byte) 220, (byte) 75, (byte) 105, (byte) 137, (byte) 60, (byte) 193, + (byte) 51, (byte) 63, (byte) 83, (byte) 237, (byte) 208, (byte) 25, (byte) 184, (byte) 119, (byte) 132, + (byte) 37, (byte) 47, (byte) 236, (byte) 145, (byte) 79, (byte) 228, (byte) 133, (byte) 119, (byte) 105, + (byte) 89, (byte) 75, (byte) 234, (byte) 66, (byte) 128, (byte) 211, (byte) 44, (byte) 15, (byte) 85, + (byte) 191, (byte) 98, (byte) 148, (byte) 79, (byte) 19, (byte) 3, (byte) 150, (byte) 188, (byte) 110, + (byte) 155, (byte) 223, (byte) 110, (byte) 189, (byte) 210, (byte) 189, (byte) 163, (byte) 103, (byte) 142, + (byte) 236, (byte) 160, (byte) 198, (byte) 104, (byte) 247, (byte) 1, (byte) 179, (byte) 141, (byte) 191, + (byte) 251, (byte) 56, (byte) 200, (byte) 52, (byte) 44, (byte) 226, (byte) 254, (byte) 109, (byte) 39, + (byte) 250, (byte) 222, (byte) 74, (byte) 90, (byte) 72, (byte) 116, (byte) 151, (byte) 157, (byte) 212, + (byte) 185, (byte) 207, (byte) 154, (byte) 222, (byte) 196, (byte) 199, (byte) 91, (byte) 5, (byte) 133, + (byte) 44, (byte) 44, (byte) 15, (byte) 94, (byte) 248, (byte) 165, (byte) 193, (byte) 117, (byte) 3, + (byte) 146, (byte) 249, (byte) 68, (byte) 232, (byte) 237, (byte) 100, (byte) 193, (byte) 16, (byte) 198, + (byte) 182, (byte) 71, (byte) 96, (byte) 154, (byte) 164, (byte) 120, (byte) 58, (byte) 235, (byte) 156, + (byte) 108, (byte) 154, (byte) 215, (byte) 85, (byte) 49, (byte) 48, (byte) 80, (byte) 99, (byte) 139, + (byte) 131, (byte) 102, (byte) 92, (byte) 111, (byte) 111, (byte) 122, (byte) 130, (byte) 163, (byte) 150, + (byte) 112, (byte) 42, (byte) 31, (byte) 100, (byte) 27, (byte) 130, (byte) 211, (byte) 235, (byte) 242, + (byte) 57, (byte) 34, (byte) 25, (byte) 73, (byte) 31, (byte) 182, (byte) 134, (byte) 135, (byte) 44, + (byte) 87, (byte) 22, (byte) 245, (byte) 10, (byte) 248, (byte) 53, (byte) 141, (byte) 154, (byte) 139, + (byte) 157, (byte) 23, (byte) 195, (byte) 64, (byte) 114, (byte) 143, (byte) 127, (byte) 135, (byte) 216, + (byte) 154, (byte) 24, (byte) 216, (byte) 252, (byte) 171, (byte) 103, (byte) 173, (byte) 132, (byte) 89, + (byte) 12, (byte) 46, (byte) 207, (byte) 117, (byte) 147, (byte) 57, (byte) 54, (byte) 60, (byte) 7, + (byte) 3, (byte) 77, (byte) 111, (byte) 96, (byte) 111, (byte) 158, (byte) 33, (byte) 224, (byte) 84, + (byte) 86, (byte) 202, (byte) 229, (byte) 233, (byte) 161 }; + final byte[] e = { 1, 0, 1 }; + final byte[] d = { 18, (byte) 174, (byte) 113, (byte) 164, (byte) 105, (byte) 205, (byte) 10, (byte) 43, + (byte) 195, (byte) 126, (byte) 82, (byte) 108, (byte) 69, (byte) 0, (byte) 87, (byte) 31, (byte) 29, + (byte) 97, (byte) 117, (byte) 29, (byte) 100, (byte) 233, (byte) 73, (byte) 112, (byte) 123, (byte) 98, + (byte) 89, (byte) 15, (byte) 157, (byte) 11, (byte) 165, (byte) 124, (byte) 150, (byte) 60, (byte) 64, + (byte) 30, (byte) 63, (byte) 207, (byte) 47, (byte) 44, (byte) 211, (byte) 189, (byte) 236, (byte) 136, + (byte) 229, (byte) 3, (byte) 191, (byte) 198, (byte) 67, (byte) 155, (byte) 11, (byte) 40, (byte) 200, + (byte) 47, (byte) 125, (byte) 55, (byte) 151, (byte) 103, (byte) 31, (byte) 82, (byte) 19, (byte) 238, + (byte) 216, (byte) 193, (byte) 90, (byte) 37, (byte) 216, (byte) 213, (byte) 206, (byte) 160, (byte) 2, + (byte) 94, (byte) 227, (byte) 171, (byte) 46, (byte) 139, (byte) 127, (byte) 121, (byte) 33, (byte) 111, + (byte) 198, (byte) 59, (byte) 234, (byte) 86, (byte) 39, (byte) 83, (byte) 180, (byte) 6, (byte) 68, + (byte) 198, (byte) 161, (byte) 81, (byte) 39, (byte) 217, (byte) 178, (byte) 149, (byte) 69, (byte) 64, + (byte) 160, (byte) 187, (byte) 225, (byte) 163, (byte) 5, (byte) 86, (byte) 152, (byte) 45, (byte) 78, + (byte) 159, (byte) 222, (byte) 95, (byte) 100, (byte) 37, (byte) 241, (byte) 77, (byte) 75, (byte) 113, + (byte) 52, (byte) 65, (byte) 181, (byte) 93, (byte) 199, (byte) 59, (byte) 155, (byte) 74, (byte) 237, + (byte) 204, (byte) 146, (byte) 172, (byte) 227, (byte) 146, (byte) 126, (byte) 55, (byte) 245, (byte) 125, + (byte) 12, (byte) 253, (byte) 94, (byte) 117, (byte) 129, (byte) 250, (byte) 81, (byte) 44, (byte) 143, + (byte) 73, (byte) 97, (byte) 169, (byte) 235, (byte) 11, (byte) 128, (byte) 248, (byte) 168, (byte) 7, + (byte) 70, (byte) 114, (byte) 138, (byte) 85, (byte) 255, (byte) 70, (byte) 71, (byte) 31, (byte) 52, + (byte) 37, (byte) 6, (byte) 59, (byte) 157, (byte) 83, (byte) 100, (byte) 47, (byte) 94, (byte) 222, + (byte) 30, (byte) 132, (byte) 214, (byte) 19, (byte) 8, (byte) 26, (byte) 250, (byte) 92, (byte) 34, + (byte) 208, (byte) 81, (byte) 40, (byte) 91, (byte) 214, (byte) 59, (byte) 148, (byte) 59, (byte) 86, + (byte) 93, (byte) 137, (byte) 138, (byte) 5, (byte) 104, (byte) 84, (byte) 19, (byte) 229, (byte) 60, + (byte) 60, (byte) 108, (byte) 101, (byte) 37, (byte) 255, (byte) 31, (byte) 227, (byte) 78, (byte) 61, + (byte) 220, (byte) 112, (byte) 240, (byte) 213, (byte) 100, (byte) 80, (byte) 253, (byte) 164, (byte) 139, + (byte) 161, (byte) 46, (byte) 16, (byte) 78, (byte) 157, (byte) 235, (byte) 159, (byte) 184, (byte) 24, + (byte) 129, (byte) 225, (byte) 196, (byte) 189, (byte) 242, (byte) 93, (byte) 146, (byte) 71, (byte) 244, + (byte) 80, (byte) 200, (byte) 101, (byte) 146, (byte) 121, (byte) 104, (byte) 231, (byte) 115, (byte) 52, + (byte) 244, (byte) 65, (byte) 79, (byte) 117, (byte) 167, (byte) 80, (byte) 225, (byte) 57, (byte) 84, + (byte) 110, (byte) 58, (byte) 138, (byte) 115, (byte) 157 }; + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + String wrong_accessToken = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rwww"; + JWS jws = new JWSReader().read(wrong_accessToken); + + SignatureMethod signatureMethod = new SignatureMethodRSAImpl("RS256"); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + + RSAPublicKey rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + + Assert.assertFalse(jws.validate(signatureMethod, new PublicKey(rsaPublicKey))); + } + + @Test + public void testValidate3() throws InvalidKeySpecException, NoSuchAlgorithmException { + + final byte[] n = TokenDecoder.base64DecodeToByte("n4EPtAOCc9AlkeQHPzHStgAbgs7bTZLwUBZdR8_KuKPEHLd4rHVTeT-O-XV2jRojdNhxJWTDvNd7nqQ0VEiZQHz_AJmSCpMaJMRBSFKrKb2wqVwGU_NsYOYL-QtiWN2lbzcEe6XC0dApr5ydQLrHqkHHig3RBordaZ6Aj-oBHqFEHYpPe7Tpe-OfVfHd1E6cS6M1FZcD1NNLYD5lFHpPI9bTwJlsde3uhGqC0ZCuEHg8lhzwOHrtIQbS0FVbb9k3-tVTU4fg_3L_vniUFAKwuCLqKnS2BYwdq_mzSnbLY7h_qixoR7jig3__kRhuaxwUkRz5iaiQkqgc5gHdrNP5zw"); + final byte[] e =TokenDecoder.base64DecodeToByte("AQAB"); + final byte[] d = TokenDecoder.base64DecodeToByte("bWUC9B-EFRIo8kpGfh0ZuyGPvMNKvYWNtB_ikiH9k20eT-O1q_I78eiZkpXxXQ0UTEs2LsNRS-8uJbvQ-A1irkwMSMkK1J3XTGgdrhCku9gRldY7sNA_AKZGh-Q661_42rINLRCe8W-nZ34ui_qOfkLnK9QWDDqpaIsA-bMwWWSDFu2MUBYwkHTMEzLYGqOe04noqeq1hExBTHBOBdkMXiuFhUq1BU6l-DqEiWxqg82sXt2h-LMnT3046AOYJoRioz75tSUQfGCshWTBnP5uDjd18kKhyv07lhfSJdrPdM5Plyl21hsFf4L_mHCuoFau7gdsPfHPxxjVOcOpBrQzwQ"); + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(N, D); + + String rsa256 = "{\"kid\":\"bilbo.baggins@hobbiton.example\", \"alg\":\"RS256\"}"; + + String accessToken = + //header + TokenDecoder.base64Encode(rsa256)+ + "."+ + //payload + "SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH"+ + "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk"+ + "b24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcm"+ + "UgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4"+ + "."+ + //signature + "CQKOXffDcqJ490YwuiHW7JfsLNxrRXKzCYFIDZtvznxtfxUMkcvriV4y-2_UGPqqzLNF67ps3VfI_J_OYSIfeoNfawa9bDNKtoqflRyGlDSaNIJYVjvNqVSvTFwcPcUqyVACcABosJMuAd9UWPAvNkGwRuXQEU8dD4_5KTilLbogLB4-rkQnQUq29vfA3VTOw8btMimSrsx0OrUaaOB3U9b3EpWilBEpPqndHRmgL_BPktn9gfk9xSoeGybmQGXOMZrvzH3DOAb4Ga6gzZeZImcDw5O48GiO78ARk_PJ7JXj0ebYn7m0svK-meFQRUVIfcnYxOopde9QwG6rit3Nmg"; + + JWS jws = new JWSReader().read(accessToken); + + SignatureMethod signatureMethod = new SignatureMethodRSAImpl("RS256"); + + RSAPublicKey rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + + Assert.assertTrue(jws.validate(signatureMethod, new PublicKey(rsaPublicKey))); + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/io/JWSReaderTestCase.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/io/JWSReaderTestCase.java new file mode 100644 index 00000000..1b04afe5 --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/io/JWSReaderTestCase.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.io; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import org.apache.oltu.jose.jws.JWS; +import org.junit.Test; + +public final class JWSReaderTestCase { + + private JWSReader reader = new JWSReader(); + + @Test + public void parse() { + JWS jws = reader.read("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImNyaXQiOlsiZXhwIl19.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftO-_ve-_ve-_vSVP77-9YH3Yre-_ve-_vRbvv70lTWnWv--_vVtYBVhT77-977-9eQ"); + + assertEquals("JWT", jws.getHeader().getType()); + assertEquals("HS256", jws.getHeader().getAlgorithm()); + assertArrayEquals(new String[]{ "exp" }, jws.getHeader().getCritical()); + assertEquals("{\"iss\":\"joe\",\r\n \"exp\":1300819380,\r\n \"http://example.com/is_root\":true}", jws.getPayload()); + assertEquals("dBjftO-_ve-_ve-_vSVP77-9YH3Yre-_ve-_vRbvv70lTWnWv--_vVtYBVhT77-977-9eQ", jws.getSignature()); + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/io/JWSWriterTestCase.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/io/JWSWriterTestCase.java new file mode 100644 index 00000000..735b9921 --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/io/JWSWriterTestCase.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.io; + +import static org.junit.Assert.assertEquals; + +import org.apache.oltu.jose.jws.JWS; +import org.junit.Test; + +public final class JWSWriterTestCase { + + private final JWSWriter jwsWriter = new JWSWriter(); + + @Test + public void serialize() { + JWS jws = new JWS.Builder() + .setAlgorithm("HS256") + .setType("JWT") + .setCritical(new String[]{ "exp" }) + .setPayload("{\"iss\":\"joe\",\r\n \"exp\":1300819380,\r\n \"http://example.com/is_root\":true}") + .setSignature("dBjftO-_ve-_ve-_vSVP77-9YH3Yre-_ve-_vRbvv70lTWnWv--_vVtYBVhT77-977-9eQ") + .build(); + String actual = jwsWriter.write(jws); + assertEquals("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImNyaXQiOlsiZXhwIl19.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftO-_ve-_ve-_vSVP77-9YH3Yre-_ve-_vRbvv70lTWnWv--_vVtYBVhT77-977-9eQ", + actual); + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java new file mode 100644 index 00000000..8def0e84 --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature; + +import static org.junit.Assert.*; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jws.JWS; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public final class SignatureMethodTestCase { + + private String hs256; + + private String payload; + + private TestSymetricKey key; + + private String signature; + + private TestDummySignatureMethod method; + + @Before + public void setUp() { + payload = "{\"iss\":\"joe\",\r\n \"exp\":1300819380,\r\n \"http://example.com/is_root\":true}"; + hs256 = "{\"alg\":\"TEST\",\"typ\":\"JWT\"}"; + + key = new TestSymetricKey("supercalifragilistichespiralidoso1234567890"); + signature = TokenDecoder.base64Encode(hs256) + TokenDecoder.base64Encode(payload) + key.getValue(); + + method = new TestDummySignatureMethod(); + } + + @After + public void tearDown() { + payload = null; + key = null; + signature = null; + method = null; + } + + @Test + public void simpleSignatureVerification() { + assertEquals(hs256 + payload + key.getValue(), method.calculate(hs256, payload, key)); + assertTrue(method.verify(hs256 + payload + key.getValue(), hs256, payload, key)); + } + + @Test + public void signJWS() { + JWS jws = new JWS.Builder() + .setType("JWT"). + setAlgorithm("TEST") + .setPayload(payload) + .sign(method, key) + .build(); + + assertEquals("TEST", jws.getHeader().getAlgorithm()); + assertEquals(signature, jws.getSignature()); + } + + @Test + public void validateJWS() { + JWS jws = new JWS.Builder() + .setType("JWT") + .setAlgorithm("TEST") + .setPayload(payload) + .sign(method, key) + .build(); + assertTrue(jws.validate(method, key)); + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestDummySignatureMethod.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestDummySignatureMethod.java new file mode 100644 index 00000000..530f3d86 --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestDummySignatureMethod.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature; + +final class TestDummySignatureMethod implements SignatureMethod { + + @Override + public String calculate(String header, String payload, TestSymetricKey signingKey) { + return header + payload + signingKey.getValue(); + } + + @Override + public boolean verify(String signature, String header, String payload, TestSymetricKey verifyingKey) { + return signature.equals(calculate(header, payload, verifyingKey)); + } + + @Override + public String getAlgorithm() { + return "TEST"; + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java new file mode 100644 index 00000000..c254c22c --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature; + +final class TestSymetricKey implements SymmetricKey { + + private final String value; + + public TestSymetricKey(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodRSAImplTest.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodRSAImplTest.java new file mode 100644 index 00000000..d6bc71bc --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodRSAImplTest.java @@ -0,0 +1,294 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.RSAPrivateKeySpec; +import java.security.spec.RSAPublicKeySpec; +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * Unit test based on the example contained in + * http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-25#appendix-A.2 and + * http://tools.ietf.org/html/draft-ietf-jose-cookbook-01#section-3.1 + * + */ +public class SignatureMethodRSAImplTest { + + private String rsa256; + + private SignatureMethodRSAImpl sRsaImpl; + + private String payload; + + private RSAPrivateKey rsaPrivKey; + + private RSAPublicKey rsaPublicKey; + + @Before + public void setUp() throws Exception { + sRsaImpl = new SignatureMethodRSAImpl("RS256"); + } + + @After + public void tearDown() { + payload = null; + rsa256 = null; + rsaPrivKey = null; + rsaPublicKey = null; + sRsaImpl= null; + } + + //validates the example in http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-25#appendix-A.2 + @Test + public void testCalculate() throws Exception{ + final byte[] n = { (byte) 161, (byte) 248, (byte) 22, (byte) 10, (byte) 226, (byte) 227, (byte) 201, (byte) 180, + (byte) 101, (byte) 206, (byte) 141, (byte) 45, (byte) 101, (byte) 98, (byte) 99, (byte) 54, (byte) 43, + (byte) 146, (byte) 125, (byte) 190, (byte) 41, (byte) 225, (byte) 240, (byte) 36, (byte) 119, (byte) 252, + (byte) 22, (byte) 37, (byte) 204, (byte) 144, (byte) 161, (byte) 54, (byte) 227, (byte) 139, (byte) 217, + (byte) 52, (byte) 151, (byte) 197, (byte) 182, (byte) 234, (byte) 99, (byte) 221, (byte) 119, (byte) 17, + (byte) 230, (byte) 124, (byte) 116, (byte) 41, (byte) 249, (byte) 86, (byte) 176, (byte) 251, (byte) 138, + (byte) 143, (byte) 8, (byte) 154, (byte) 220, (byte) 75, (byte) 105, (byte) 137, (byte) 60, (byte) 193, + (byte) 51, (byte) 63, (byte) 83, (byte) 237, (byte) 208, (byte) 25, (byte) 184, (byte) 119, (byte) 132, + (byte) 37, (byte) 47, (byte) 236, (byte) 145, (byte) 79, (byte) 228, (byte) 133, (byte) 119, (byte) 105, + (byte) 89, (byte) 75, (byte) 234, (byte) 66, (byte) 128, (byte) 211, (byte) 44, (byte) 15, (byte) 85, + (byte) 191, (byte) 98, (byte) 148, (byte) 79, (byte) 19, (byte) 3, (byte) 150, (byte) 188, (byte) 110, + (byte) 155, (byte) 223, (byte) 110, (byte) 189, (byte) 210, (byte) 189, (byte) 163, (byte) 103, (byte) 142, + (byte) 236, (byte) 160, (byte) 198, (byte) 104, (byte) 247, (byte) 1, (byte) 179, (byte) 141, (byte) 191, + (byte) 251, (byte) 56, (byte) 200, (byte) 52, (byte) 44, (byte) 226, (byte) 254, (byte) 109, (byte) 39, + (byte) 250, (byte) 222, (byte) 74, (byte) 90, (byte) 72, (byte) 116, (byte) 151, (byte) 157, (byte) 212, + (byte) 185, (byte) 207, (byte) 154, (byte) 222, (byte) 196, (byte) 199, (byte) 91, (byte) 5, (byte) 133, + (byte) 44, (byte) 44, (byte) 15, (byte) 94, (byte) 248, (byte) 165, (byte) 193, (byte) 117, (byte) 3, + (byte) 146, (byte) 249, (byte) 68, (byte) 232, (byte) 237, (byte) 100, (byte) 193, (byte) 16, (byte) 198, + (byte) 182, (byte) 71, (byte) 96, (byte) 154, (byte) 164, (byte) 120, (byte) 58, (byte) 235, (byte) 156, + (byte) 108, (byte) 154, (byte) 215, (byte) 85, (byte) 49, (byte) 48, (byte) 80, (byte) 99, (byte) 139, + (byte) 131, (byte) 102, (byte) 92, (byte) 111, (byte) 111, (byte) 122, (byte) 130, (byte) 163, (byte) 150, + (byte) 112, (byte) 42, (byte) 31, (byte) 100, (byte) 27, (byte) 130, (byte) 211, (byte) 235, (byte) 242, + (byte) 57, (byte) 34, (byte) 25, (byte) 73, (byte) 31, (byte) 182, (byte) 134, (byte) 135, (byte) 44, + (byte) 87, (byte) 22, (byte) 245, (byte) 10, (byte) 248, (byte) 53, (byte) 141, (byte) 154, (byte) 139, + (byte) 157, (byte) 23, (byte) 195, (byte) 64, (byte) 114, (byte) 143, (byte) 127, (byte) 135, (byte) 216, + (byte) 154, (byte) 24, (byte) 216, (byte) 252, (byte) 171, (byte) 103, (byte) 173, (byte) 132, (byte) 89, + (byte) 12, (byte) 46, (byte) 207, (byte) 117, (byte) 147, (byte) 57, (byte) 54, (byte) 60, (byte) 7, + (byte) 3, (byte) 77, (byte) 111, (byte) 96, (byte) 111, (byte) 158, (byte) 33, (byte) 224, (byte) 84, + (byte) 86, (byte) 202, (byte) 229, (byte) 233, (byte) 161 }; + final byte[] e = { 1, 0, 1 }; + final byte[] d = { 18, (byte) 174, (byte) 113, (byte) 164, (byte) 105, (byte) 205, (byte) 10, (byte) 43, + (byte) 195, (byte) 126, (byte) 82, (byte) 108, (byte) 69, (byte) 0, (byte) 87, (byte) 31, (byte) 29, + (byte) 97, (byte) 117, (byte) 29, (byte) 100, (byte) 233, (byte) 73, (byte) 112, (byte) 123, (byte) 98, + (byte) 89, (byte) 15, (byte) 157, (byte) 11, (byte) 165, (byte) 124, (byte) 150, (byte) 60, (byte) 64, + (byte) 30, (byte) 63, (byte) 207, (byte) 47, (byte) 44, (byte) 211, (byte) 189, (byte) 236, (byte) 136, + (byte) 229, (byte) 3, (byte) 191, (byte) 198, (byte) 67, (byte) 155, (byte) 11, (byte) 40, (byte) 200, + (byte) 47, (byte) 125, (byte) 55, (byte) 151, (byte) 103, (byte) 31, (byte) 82, (byte) 19, (byte) 238, + (byte) 216, (byte) 193, (byte) 90, (byte) 37, (byte) 216, (byte) 213, (byte) 206, (byte) 160, (byte) 2, + (byte) 94, (byte) 227, (byte) 171, (byte) 46, (byte) 139, (byte) 127, (byte) 121, (byte) 33, (byte) 111, + (byte) 198, (byte) 59, (byte) 234, (byte) 86, (byte) 39, (byte) 83, (byte) 180, (byte) 6, (byte) 68, + (byte) 198, (byte) 161, (byte) 81, (byte) 39, (byte) 217, (byte) 178, (byte) 149, (byte) 69, (byte) 64, + (byte) 160, (byte) 187, (byte) 225, (byte) 163, (byte) 5, (byte) 86, (byte) 152, (byte) 45, (byte) 78, + (byte) 159, (byte) 222, (byte) 95, (byte) 100, (byte) 37, (byte) 241, (byte) 77, (byte) 75, (byte) 113, + (byte) 52, (byte) 65, (byte) 181, (byte) 93, (byte) 199, (byte) 59, (byte) 155, (byte) 74, (byte) 237, + (byte) 204, (byte) 146, (byte) 172, (byte) 227, (byte) 146, (byte) 126, (byte) 55, (byte) 245, (byte) 125, + (byte) 12, (byte) 253, (byte) 94, (byte) 117, (byte) 129, (byte) 250, (byte) 81, (byte) 44, (byte) 143, + (byte) 73, (byte) 97, (byte) 169, (byte) 235, (byte) 11, (byte) 128, (byte) 248, (byte) 168, (byte) 7, + (byte) 70, (byte) 114, (byte) 138, (byte) 85, (byte) 255, (byte) 70, (byte) 71, (byte) 31, (byte) 52, + (byte) 37, (byte) 6, (byte) 59, (byte) 157, (byte) 83, (byte) 100, (byte) 47, (byte) 94, (byte) 222, + (byte) 30, (byte) 132, (byte) 214, (byte) 19, (byte) 8, (byte) 26, (byte) 250, (byte) 92, (byte) 34, + (byte) 208, (byte) 81, (byte) 40, (byte) 91, (byte) 214, (byte) 59, (byte) 148, (byte) 59, (byte) 86, + (byte) 93, (byte) 137, (byte) 138, (byte) 5, (byte) 104, (byte) 84, (byte) 19, (byte) 229, (byte) 60, + (byte) 60, (byte) 108, (byte) 101, (byte) 37, (byte) 255, (byte) 31, (byte) 227, (byte) 78, (byte) 61, + (byte) 220, (byte) 112, (byte) 240, (byte) 213, (byte) 100, (byte) 80, (byte) 253, (byte) 164, (byte) 139, + (byte) 161, (byte) 46, (byte) 16, (byte) 78, (byte) 157, (byte) 235, (byte) 159, (byte) 184, (byte) 24, + (byte) 129, (byte) 225, (byte) 196, (byte) 189, (byte) 242, (byte) 93, (byte) 146, (byte) 71, (byte) 244, + (byte) 80, (byte) 200, (byte) 101, (byte) 146, (byte) 121, (byte) 104, (byte) 231, (byte) 115, (byte) 52, + (byte) 244, (byte) 65, (byte) 79, (byte) 117, (byte) 167, (byte) 80, (byte) 225, (byte) 57, (byte) 84, + (byte) 110, (byte) 58, (byte) 138, (byte) 115, (byte) 157 }; + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(N, D); + rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + rsaPrivKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec); + + rsa256 = "{\"alg\":\"RS256\"}"; + payload = "{\"iss\":\"joe\",\r\n \"exp\":1300819380,\r\n \"http://example.com/is_root\":true}"; + + assertEquals("cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7"+ + "AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4"+ + "BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K"+ + "0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv"+ + "hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB"+ + "p0igcN_IoypGlUPQGe77Rw", + sRsaImpl.calculate(TokenDecoder.base64Encode(rsa256), + TokenDecoder.base64Encode(payload), new PrivateKey(rsaPrivKey))); + } + + //validates the example in http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-25#appendix-A.2 + @Test + public void testVerify() throws Exception{ + final byte[] n = { (byte) 161, (byte) 248, (byte) 22, (byte) 10, (byte) 226, (byte) 227, (byte) 201, (byte) 180, + (byte) 101, (byte) 206, (byte) 141, (byte) 45, (byte) 101, (byte) 98, (byte) 99, (byte) 54, (byte) 43, + (byte) 146, (byte) 125, (byte) 190, (byte) 41, (byte) 225, (byte) 240, (byte) 36, (byte) 119, (byte) 252, + (byte) 22, (byte) 37, (byte) 204, (byte) 144, (byte) 161, (byte) 54, (byte) 227, (byte) 139, (byte) 217, + (byte) 52, (byte) 151, (byte) 197, (byte) 182, (byte) 234, (byte) 99, (byte) 221, (byte) 119, (byte) 17, + (byte) 230, (byte) 124, (byte) 116, (byte) 41, (byte) 249, (byte) 86, (byte) 176, (byte) 251, (byte) 138, + (byte) 143, (byte) 8, (byte) 154, (byte) 220, (byte) 75, (byte) 105, (byte) 137, (byte) 60, (byte) 193, + (byte) 51, (byte) 63, (byte) 83, (byte) 237, (byte) 208, (byte) 25, (byte) 184, (byte) 119, (byte) 132, + (byte) 37, (byte) 47, (byte) 236, (byte) 145, (byte) 79, (byte) 228, (byte) 133, (byte) 119, (byte) 105, + (byte) 89, (byte) 75, (byte) 234, (byte) 66, (byte) 128, (byte) 211, (byte) 44, (byte) 15, (byte) 85, + (byte) 191, (byte) 98, (byte) 148, (byte) 79, (byte) 19, (byte) 3, (byte) 150, (byte) 188, (byte) 110, + (byte) 155, (byte) 223, (byte) 110, (byte) 189, (byte) 210, (byte) 189, (byte) 163, (byte) 103, (byte) 142, + (byte) 236, (byte) 160, (byte) 198, (byte) 104, (byte) 247, (byte) 1, (byte) 179, (byte) 141, (byte) 191, + (byte) 251, (byte) 56, (byte) 200, (byte) 52, (byte) 44, (byte) 226, (byte) 254, (byte) 109, (byte) 39, + (byte) 250, (byte) 222, (byte) 74, (byte) 90, (byte) 72, (byte) 116, (byte) 151, (byte) 157, (byte) 212, + (byte) 185, (byte) 207, (byte) 154, (byte) 222, (byte) 196, (byte) 199, (byte) 91, (byte) 5, (byte) 133, + (byte) 44, (byte) 44, (byte) 15, (byte) 94, (byte) 248, (byte) 165, (byte) 193, (byte) 117, (byte) 3, + (byte) 146, (byte) 249, (byte) 68, (byte) 232, (byte) 237, (byte) 100, (byte) 193, (byte) 16, (byte) 198, + (byte) 182, (byte) 71, (byte) 96, (byte) 154, (byte) 164, (byte) 120, (byte) 58, (byte) 235, (byte) 156, + (byte) 108, (byte) 154, (byte) 215, (byte) 85, (byte) 49, (byte) 48, (byte) 80, (byte) 99, (byte) 139, + (byte) 131, (byte) 102, (byte) 92, (byte) 111, (byte) 111, (byte) 122, (byte) 130, (byte) 163, (byte) 150, + (byte) 112, (byte) 42, (byte) 31, (byte) 100, (byte) 27, (byte) 130, (byte) 211, (byte) 235, (byte) 242, + (byte) 57, (byte) 34, (byte) 25, (byte) 73, (byte) 31, (byte) 182, (byte) 134, (byte) 135, (byte) 44, + (byte) 87, (byte) 22, (byte) 245, (byte) 10, (byte) 248, (byte) 53, (byte) 141, (byte) 154, (byte) 139, + (byte) 157, (byte) 23, (byte) 195, (byte) 64, (byte) 114, (byte) 143, (byte) 127, (byte) 135, (byte) 216, + (byte) 154, (byte) 24, (byte) 216, (byte) 252, (byte) 171, (byte) 103, (byte) 173, (byte) 132, (byte) 89, + (byte) 12, (byte) 46, (byte) 207, (byte) 117, (byte) 147, (byte) 57, (byte) 54, (byte) 60, (byte) 7, + (byte) 3, (byte) 77, (byte) 111, (byte) 96, (byte) 111, (byte) 158, (byte) 33, (byte) 224, (byte) 84, + (byte) 86, (byte) 202, (byte) 229, (byte) 233, (byte) 161 }; + final byte[] e = { 1, 0, 1 }; + final byte[] d = { 18, (byte) 174, (byte) 113, (byte) 164, (byte) 105, (byte) 205, (byte) 10, (byte) 43, + (byte) 195, (byte) 126, (byte) 82, (byte) 108, (byte) 69, (byte) 0, (byte) 87, (byte) 31, (byte) 29, + (byte) 97, (byte) 117, (byte) 29, (byte) 100, (byte) 233, (byte) 73, (byte) 112, (byte) 123, (byte) 98, + (byte) 89, (byte) 15, (byte) 157, (byte) 11, (byte) 165, (byte) 124, (byte) 150, (byte) 60, (byte) 64, + (byte) 30, (byte) 63, (byte) 207, (byte) 47, (byte) 44, (byte) 211, (byte) 189, (byte) 236, (byte) 136, + (byte) 229, (byte) 3, (byte) 191, (byte) 198, (byte) 67, (byte) 155, (byte) 11, (byte) 40, (byte) 200, + (byte) 47, (byte) 125, (byte) 55, (byte) 151, (byte) 103, (byte) 31, (byte) 82, (byte) 19, (byte) 238, + (byte) 216, (byte) 193, (byte) 90, (byte) 37, (byte) 216, (byte) 213, (byte) 206, (byte) 160, (byte) 2, + (byte) 94, (byte) 227, (byte) 171, (byte) 46, (byte) 139, (byte) 127, (byte) 121, (byte) 33, (byte) 111, + (byte) 198, (byte) 59, (byte) 234, (byte) 86, (byte) 39, (byte) 83, (byte) 180, (byte) 6, (byte) 68, + (byte) 198, (byte) 161, (byte) 81, (byte) 39, (byte) 217, (byte) 178, (byte) 149, (byte) 69, (byte) 64, + (byte) 160, (byte) 187, (byte) 225, (byte) 163, (byte) 5, (byte) 86, (byte) 152, (byte) 45, (byte) 78, + (byte) 159, (byte) 222, (byte) 95, (byte) 100, (byte) 37, (byte) 241, (byte) 77, (byte) 75, (byte) 113, + (byte) 52, (byte) 65, (byte) 181, (byte) 93, (byte) 199, (byte) 59, (byte) 155, (byte) 74, (byte) 237, + (byte) 204, (byte) 146, (byte) 172, (byte) 227, (byte) 146, (byte) 126, (byte) 55, (byte) 245, (byte) 125, + (byte) 12, (byte) 253, (byte) 94, (byte) 117, (byte) 129, (byte) 250, (byte) 81, (byte) 44, (byte) 143, + (byte) 73, (byte) 97, (byte) 169, (byte) 235, (byte) 11, (byte) 128, (byte) 248, (byte) 168, (byte) 7, + (byte) 70, (byte) 114, (byte) 138, (byte) 85, (byte) 255, (byte) 70, (byte) 71, (byte) 31, (byte) 52, + (byte) 37, (byte) 6, (byte) 59, (byte) 157, (byte) 83, (byte) 100, (byte) 47, (byte) 94, (byte) 222, + (byte) 30, (byte) 132, (byte) 214, (byte) 19, (byte) 8, (byte) 26, (byte) 250, (byte) 92, (byte) 34, + (byte) 208, (byte) 81, (byte) 40, (byte) 91, (byte) 214, (byte) 59, (byte) 148, (byte) 59, (byte) 86, + (byte) 93, (byte) 137, (byte) 138, (byte) 5, (byte) 104, (byte) 84, (byte) 19, (byte) 229, (byte) 60, + (byte) 60, (byte) 108, (byte) 101, (byte) 37, (byte) 255, (byte) 31, (byte) 227, (byte) 78, (byte) 61, + (byte) 220, (byte) 112, (byte) 240, (byte) 213, (byte) 100, (byte) 80, (byte) 253, (byte) 164, (byte) 139, + (byte) 161, (byte) 46, (byte) 16, (byte) 78, (byte) 157, (byte) 235, (byte) 159, (byte) 184, (byte) 24, + (byte) 129, (byte) 225, (byte) 196, (byte) 189, (byte) 242, (byte) 93, (byte) 146, (byte) 71, (byte) 244, + (byte) 80, (byte) 200, (byte) 101, (byte) 146, (byte) 121, (byte) 104, (byte) 231, (byte) 115, (byte) 52, + (byte) 244, (byte) 65, (byte) 79, (byte) 117, (byte) 167, (byte) 80, (byte) 225, (byte) 57, (byte) 84, + (byte) 110, (byte) 58, (byte) 138, (byte) 115, (byte) 157 }; + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(N, D); + rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + rsaPrivKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec); + + String accessToken = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"; + String jwt[] = accessToken.split("\\."); + assertTrue(sRsaImpl.verify(jwt[2], jwt[0], jwt[1], new PublicKey(rsaPublicKey))); + } + + //validates the example in http://tools.ietf.org/html/draft-ietf-jose-cookbook-01#section-3.1 + @Test + public void testCalculateCookbook() throws Exception{ + final byte[] n = TokenDecoder.base64DecodeToByte("n4EPtAOCc9AlkeQHPzHStgAbgs7bTZLwUBZdR8_KuKPEHLd4rHVTeT-O-XV2jRojdNhxJWTDvNd7nqQ0VEiZQHz_AJmSCpMaJMRBSFKrKb2wqVwGU_NsYOYL-QtiWN2lbzcEe6XC0dApr5ydQLrHqkHHig3RBordaZ6Aj-oBHqFEHYpPe7Tpe-OfVfHd1E6cS6M1FZcD1NNLYD5lFHpPI9bTwJlsde3uhGqC0ZCuEHg8lhzwOHrtIQbS0FVbb9k3-tVTU4fg_3L_vniUFAKwuCLqKnS2BYwdq_mzSnbLY7h_qixoR7jig3__kRhuaxwUkRz5iaiQkqgc5gHdrNP5zw"); + final byte[] e =TokenDecoder.base64DecodeToByte("AQAB"); + final byte[] d = TokenDecoder.base64DecodeToByte("bWUC9B-EFRIo8kpGfh0ZuyGPvMNKvYWNtB_ikiH9k20eT-O1q_I78eiZkpXxXQ0UTEs2LsNRS-8uJbvQ-A1irkwMSMkK1J3XTGgdrhCku9gRldY7sNA_AKZGh-Q661_42rINLRCe8W-nZ34ui_qOfkLnK9QWDDqpaIsA-bMwWWSDFu2MUBYwkHTMEzLYGqOe04noqeq1hExBTHBOBdkMXiuFhUq1BU6l-DqEiWxqg82sXt2h-LMnT3046AOYJoRioz75tSUQfGCshWTBnP5uDjd18kKhyv07lhfSJdrPdM5Plyl21hsFf4L_mHCuoFau7gdsPfHPxxjVOcOpBrQzwQ"); + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(N, D); + rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + rsaPrivKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec); + + + rsa256 = "{\"alg\":\"RS256\",\"kid\":\"bilbo.baggins@hobbiton.example\"}"; + + assertEquals("MRjdkly7_-oTPTS3AXP41iQIGKa80A0ZmTuV5MEaHoxnW2e5CZ5NlKtainoFmK"+ + "ZopdHM1O2U4mwzJdQx996ivp83xuglII7PNDi84wnB-BDkoBwA78185hX-Es4J"+ + "IwmDLJK3lfWRa-XtL0RnltuYv746iYTh_qHRD68BNt1uSNCrUCTJDt5aAE6x8w"+ + "W1Kt9eRo4QPocSadnHXFxnt8Is9UzpERV0ePPQdLuW3IS_de3xyIrDaLGdjluP"+ + "xUAhb6L2aXic1U12podGU0KLUQSE_oI-ZnmKJ3F4uOZDnd6QZWJushZ41Axf_f"+ + "cIe8u9ipH84ogoree7vjbU5y18kDquDg", + sRsaImpl.calculate(TokenDecoder.base64Encode(rsa256), + "SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH"+ + "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk"+ + "b24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcm"+ + "UgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4", new PrivateKey(rsaPrivKey))); + } + + //validates the example in http://tools.ietf.org/html/draft-ietf-jose-cookbook-01#section-3.1 + @Test + public void testVerifyCookbook() throws Exception{ + final byte[] n = TokenDecoder.base64DecodeToByte("n4EPtAOCc9AlkeQHPzHStgAbgs7bTZLwUBZdR8_KuKPEHLd4rHVTeT-O-XV2jRojdNhxJWTDvNd7nqQ0VEiZQHz_AJmSCpMaJMRBSFKrKb2wqVwGU_NsYOYL-QtiWN2lbzcEe6XC0dApr5ydQLrHqkHHig3RBordaZ6Aj-oBHqFEHYpPe7Tpe-OfVfHd1E6cS6M1FZcD1NNLYD5lFHpPI9bTwJlsde3uhGqC0ZCuEHg8lhzwOHrtIQbS0FVbb9k3-tVTU4fg_3L_vniUFAKwuCLqKnS2BYwdq_mzSnbLY7h_qixoR7jig3__kRhuaxwUkRz5iaiQkqgc5gHdrNP5zw"); + final byte[] e =TokenDecoder.base64DecodeToByte("AQAB"); + final byte[] d = TokenDecoder.base64DecodeToByte("bWUC9B-EFRIo8kpGfh0ZuyGPvMNKvYWNtB_ikiH9k20eT-O1q_I78eiZkpXxXQ0UTEs2LsNRS-8uJbvQ-A1irkwMSMkK1J3XTGgdrhCku9gRldY7sNA_AKZGh-Q661_42rINLRCe8W-nZ34ui_qOfkLnK9QWDDqpaIsA-bMwWWSDFu2MUBYwkHTMEzLYGqOe04noqeq1hExBTHBOBdkMXiuFhUq1BU6l-DqEiWxqg82sXt2h-LMnT3046AOYJoRioz75tSUQfGCshWTBnP5uDjd18kKhyv07lhfSJdrPdM5Plyl21hsFf4L_mHCuoFau7gdsPfHPxxjVOcOpBrQzwQ"); + + BigInteger N = new BigInteger(1, n); + BigInteger E = new BigInteger(1, e); + BigInteger D = new BigInteger(1, d); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(N, E); + RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(N, D); + rsaPublicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); + rsaPrivKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec); + + String accessToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJpbGJvLmJhZ2dpbnNAaG9iYml0b24uZXhhbXBsZSJ9." + + "SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH" + + "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk" + + "b24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcm" + + "UgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4." + + "MRjdkly7_-oTPTS3AXP41iQIGKa80A0ZmTuV5MEaHoxnW2e5CZ5NlKtainoFmK" + + "ZopdHM1O2U4mwzJdQx996ivp83xuglII7PNDi84wnB-BDkoBwA78185hX-Es4J" + + "IwmDLJK3lfWRa-XtL0RnltuYv746iYTh_qHRD68BNt1uSNCrUCTJDt5aAE6x8w" + + "W1Kt9eRo4QPocSadnHXFxnt8Is9UzpERV0ePPQdLuW3IS_de3xyIrDaLGdjluP" + + "xUAhb6L2aXic1U12podGU0KLUQSE_oI-ZnmKJ3F4uOZDnd6QZWJushZ41Axf_f" + + "cIe8u9ipH84ogoree7vjbU5y18kDquDg"; + String jwt[] = accessToken.split("\\."); + assertTrue(sRsaImpl.verify(jwt[2], jwt[0], jwt[1], new PublicKey(rsaPublicKey))); + } + +} diff --git a/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodsHMAC256ImplTest.java b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodsHMAC256ImplTest.java new file mode 100644 index 00000000..d7fcf733 --- /dev/null +++ b/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/impl/SignatureMethodsHMAC256ImplTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.jose.jws.signature.impl; + +import org.apache.oltu.commons.encodedtoken.TokenDecoder; +import org.apache.oltu.jose.jws.signature.impl.SignatureMethodsHMAC256Impl; +import org.apache.oltu.jose.jws.signature.impl.SymmetricKeyImpl; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class SignatureMethodsHMAC256ImplTest { + + private final byte[] hsKey = { 3, (byte) 35, (byte) 53, (byte) 75, + (byte) 43, (byte) 15, (byte) 165, (byte) 188, (byte) 131, + (byte) 126, (byte) 6, (byte) 101, (byte) 119, (byte) 123, + (byte) 166, (byte) 143, (byte) 90, (byte) 179, (byte) 40, + (byte) 230, (byte) 240, (byte) 84, (byte) 201, (byte) 40, + (byte) 169, (byte) 15, (byte) 132, (byte) 178, (byte) 210, + (byte) 80, (byte) 46, (byte) 191, (byte) 211, (byte) 251, + (byte) 90, (byte) 146, (byte) 210, (byte) 6, (byte) 71, (byte) 239, + (byte) 150, (byte) 138, (byte) 180, (byte) 195, (byte) 119, + (byte) 98, (byte) 61, (byte) 34, (byte) 61, (byte) 46, (byte) 33, + (byte) 114, (byte) 5, (byte) 46, (byte) 79, (byte) 8, (byte) 192, + (byte) 205, (byte) 154, (byte) 245, (byte) 103, (byte) 208, + (byte) 128, (byte) 163 }; + + private String hs256; + + private String payload; + + private SymmetricKeyImpl key; + + private SignatureMethodsHMAC256Impl sHmacImpl; + + @Before + public void setUp() { + payload = "{\"iss\":\"joe\",\r\n \"exp\":1300819380,\r\n \"http://example.com/is_root\":true}"; + hs256 = "{\"typ\":\"JWT\",\r\n" + " \"alg\":\"HS256\"}"; + key = new SymmetricKeyImpl(hsKey); + sHmacImpl = new SignatureMethodsHMAC256Impl(); + } + + @After + public void tearDown() { + payload = null; + hs256 = null; + key = null; + sHmacImpl = null; + } + + @Test + public void testCalculate() { + assertEquals("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk", + sHmacImpl.calculate(TokenDecoder.base64Encode(hs256), + TokenDecoder.base64Encode(payload), key)); + } + + @Test + public void testVerify() { + String accessToken = "eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"; + String jwt[] = accessToken.split("\\."); + assertTrue(sHmacImpl.verify(jwt[2], jwt[0], jwt[1], key)); + } + +} diff --git a/jose/pom.xml b/jose/pom.xml new file mode 100644 index 00000000..95893579 --- /dev/null +++ b/jose/pom.xml @@ -0,0 +1,88 @@ + + + + 4.0.0 + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + ../parent + + + org.apache.oltu.jose + org.apache.oltu.jose.parent + 3-SNAPSHOT + pom + + Apache Oltu - JOSE + JOSE working group specifications in Apache Oltu + + + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/jose + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/jose + https://svn.apache.org/repos/asf/oltu/trunk/jose + + + + + apache.website + ${siteUrlDeployment} + + + + + ${user.home}/oltu-sites/oltu-jose-site/ + file://${siteFilePath} + ${user.home}/oltu-sites/oltu-jose + + + + jws + + + + + site + + + + org.apache.maven.plugins + maven-site-plugin + + ${project.reporting.outputDirectory}/apidocs + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${scmPubCheckoutDirectory} + scm:svn:https://svn.apache.org/repos/asf/oltu/site/apidocs/jose + Oltu JOSE apidocs deployment + ${project.build.directory}/staging + true + + + + + + + + diff --git a/oauth-1.0/pom.xml b/oauth-1.0/pom.xml deleted file mode 100644 index 580da22f..00000000 --- a/oauth-1.0/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - org.apache.amber - amber-parent - 0.10-incubating-SNAPSHOT - - - 4.0.0 - org.apache.amber - amber-oauth-1.0 - jar - Apache Amber: OAuth 1.0 Implementation - - - - org.apache.amber - amber-signature-api - ${project.version} - compile - - - org.apache.amber - amber-spec-api - ${project.version} - compile - - - - diff --git a/oauth-2.0/authzserver/pom.xml b/oauth-2.0/authzserver/pom.xml new file mode 100644 index 00000000..9a98ebb3 --- /dev/null +++ b/oauth-2.0/authzserver/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.authzserver + bundle + + Apache Oltu - OAuth 2.0 - Authorization Server + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + org.apache.johnzon + johnzon-core + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf.version} + test + + + + org.apache.cxf + cxf-testutils + ${cxf.version} + test + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/authzserver/src/main/assembly/LICENSE-with-deps b/oauth-2.0/authzserver/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..c2622deb --- /dev/null +++ b/oauth-2.0/authzserver/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,234 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/authzserver/src/main/assembly/NOTICE-with-deps b/oauth-2.0/authzserver/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/authzserver/src/main/assembly/bin.xml b/oauth-2.0/authzserver/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/MD5Generator.java similarity index 74% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/MD5Generator.java index b46c30a1..fe5871f3 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/MD5Generator.java @@ -19,20 +19,19 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.issuer; +package org.apache.oltu.oauth2.as.issuer; import java.security.MessageDigest; import java.util.UUID; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** * Exemplar OAuth Token Generator * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * */ public class MD5Generator implements ValueGenerator { @@ -41,6 +40,20 @@ public String generateValue() throws OAuthSystemException { return generateValue(UUID.randomUUID().toString()); } + private static final char[] hexCode = "0123456789abcdef".toCharArray(); + + public static String toHexString(byte[] data) { + if(data == null) { + return null; + } + StringBuilder r = new StringBuilder(data.length*2); + for ( byte b : data) { + r.append(hexCode[(b >> 4) & 0xF]); + r.append(hexCode[(b & 0xF)]); + } + return r.toString(); + } + @Override public String generateValue(String param) throws OAuthSystemException { try { @@ -48,12 +61,7 @@ public String generateValue(String param) throws OAuthSystemException { algorithm.reset(); algorithm.update(param.getBytes()); byte[] messageDigest = algorithm.digest(); - StringBuffer hexString = new StringBuffer(); - for (int i = 0; i < messageDigest.length; i++) { - hexString.append(Integer.toHexString(0xFF & messageDigest[i])); - } - - return hexString.toString(); + return toHexString(messageDigest); } catch (Exception e) { throw new OAuthSystemException("OAuth Token cannot be generated.", e); } diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/OAuthIssuer.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/OAuthIssuer.java similarity index 80% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/OAuthIssuer.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/OAuthIssuer.java index fb4b6f86..d4b0d018 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/OAuthIssuer.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/OAuthIssuer.java @@ -19,14 +19,14 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.issuer; +package org.apache.oltu.oauth2.as.issuer; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface OAuthIssuer { public String accessToken() throws OAuthSystemException; diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/OAuthIssuerImpl.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/OAuthIssuerImpl.java similarity index 83% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/OAuthIssuerImpl.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/OAuthIssuerImpl.java index 03622077..7ee95460 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/OAuthIssuerImpl.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/OAuthIssuerImpl.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.issuer; +package org.apache.oltu.oauth2.as.issuer; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthIssuerImpl implements OAuthIssuer { diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/UUIDValueGenerator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/UUIDValueGenerator.java similarity index 83% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/UUIDValueGenerator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/UUIDValueGenerator.java index 02292bdc..1fcdf1f0 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/UUIDValueGenerator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/UUIDValueGenerator.java @@ -19,18 +19,18 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.issuer; +package org.apache.oltu.oauth2.as.issuer; import java.util.UUID; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** * Exemplar OAuth Token Generator * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class UUIDValueGenerator implements ValueGenerator { diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/ValueGenerator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/ValueGenerator.java similarity index 80% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/ValueGenerator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/ValueGenerator.java index c03a1ee5..24a84058 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/ValueGenerator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/issuer/ValueGenerator.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.issuer; +package org.apache.oltu.oauth2.as.issuer; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface ValueGenerator { public String generateValue() throws OAuthSystemException; diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/AbstractOAuthTokenRequest.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/AbstractOAuthTokenRequest.java new file mode 100644 index 00000000..20c47531 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/AbstractOAuthTokenRequest.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.request; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; + +/** + * Abstract OAuth Token request class + */ +public abstract class AbstractOAuthTokenRequest extends OAuthRequest { + + protected AbstractOAuthTokenRequest(HttpServletRequest request) throws OAuthSystemException, OAuthProblemException { + super(request); + } + + protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException { + final String requestTypeValue = getParam(OAuth.OAUTH_GRANT_TYPE); + if (OAuthUtils.isEmpty(requestTypeValue)) { + throw OAuthUtils.handleOAuthProblemException("Missing grant_type parameter value"); + } + final Class> clazz = validators.get(requestTypeValue); + if (clazz == null) { + throw OAuthUtils.handleOAuthProblemException("Invalid grant_type parameter value"); + } + return OAuthUtils.instantiateClass(clazz); + } + + public String getPassword() { + return getParam(OAuth.OAUTH_PASSWORD); + } + + public String getUsername() { + return getParam(OAuth.OAUTH_USERNAME); + } + + public String getRefreshToken() { + return getParam(OAuth.OAUTH_REFRESH_TOKEN); + } + + public String getCode() { + return getParam(OAuth.OAUTH_CODE); + } + + public String getGrantType() { + return getParam(OAuth.OAUTH_GRANT_TYPE); + } +} diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthAuthzRequest.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthAuthzRequest.java similarity index 60% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthAuthzRequest.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthAuthzRequest.java index 3b4cde1c..b9883db6 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthAuthzRequest.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthAuthzRequest.java @@ -19,24 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.request; +package org.apache.oltu.oauth2.as.request; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.as.validator.CodeTokenValidator; -import org.apache.amber.oauth2.as.validator.CodeValidator; -import org.apache.amber.oauth2.as.validator.TokenValidator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.types.ResponseType; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.OAuthValidator; +import org.apache.oltu.oauth2.as.validator.CodeValidator; +import org.apache.oltu.oauth2.as.validator.TokenValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.ResponseType; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthAuthzRequest extends OAuthRequest { @@ -45,25 +44,28 @@ public OAuthAuthzRequest(HttpServletRequest request) throws OAuthSystemException } @Override - protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException { + protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException { //end user authorization validators validators.put(ResponseType.CODE.toString(), CodeValidator.class); validators.put(ResponseType.TOKEN.toString(), TokenValidator.class); - validators.put(ResponseType.CODE_AND_TOKEN.toString(), CodeTokenValidator.class); - String requestTypeValue = getParam(OAuth.OAUTH_RESPONSE_TYPE); + final String requestTypeValue = getParam(OAuth.OAUTH_RESPONSE_TYPE); if (OAuthUtils.isEmpty(requestTypeValue)) { throw OAuthUtils.handleOAuthProblemException("Missing response_type parameter value"); } - Class clazz = validators.get(requestTypeValue); + final Class> clazz = validators.get(requestTypeValue); if (clazz == null) { throw OAuthUtils.handleOAuthProblemException("Invalid response_type parameter value"); } - return (OAuthValidator)OAuthUtils.instantiateClass(clazz); + return OAuthUtils.instantiateClass(clazz); } public String getState() { return getParam(OAuth.OAUTH_STATE); } + public String getResponseType() { + return getParam(OAuth.OAUTH_RESPONSE_TYPE); + } + } diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthRequest.java similarity index 65% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthRequest.java index e041df70..8898a568 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthRequest.java @@ -19,33 +19,33 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.request; +package org.apache.oltu.oauth2.as.request; import java.util.HashMap; import java.util.Map; import java.util.Set; + import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.OAuthValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * The Abstract OAuth request for the Authorization server. */ public abstract class OAuthRequest { private Logger log = LoggerFactory.getLogger(OAuthRequest.class); protected HttpServletRequest request; - protected OAuthValidator validator; - protected Map validators = new HashMap(); + protected OAuthValidator validator; + protected Map>> validators = + new HashMap>>(); public OAuthRequest(HttpServletRequest request) throws OAuthSystemException, OAuthProblemException { this.request = request; @@ -61,6 +61,7 @@ protected void validate() throws OAuthSystemException, OAuthProblemException { validator.validateMethod(request); validator.validateContentType(request); validator.validateRequiredParameters(request); + validator.validateClientAuthenticationCredentials(request); } catch (OAuthProblemException e) { try { String redirectUri = request.getParameter(OAuth.OAUTH_REDIRECT_URI); @@ -69,8 +70,7 @@ protected void validate() throws OAuthSystemException, OAuthProblemException { } } catch (Exception ex) { if (log.isDebugEnabled()) { - log.debug("Cannot read redirect_url from the request: {}", - new String[] {ex.getMessage()}); + log.debug("Cannot read redirect_url from the request: {}", new String[] {ex.getMessage()}); } } @@ -79,17 +79,18 @@ protected void validate() throws OAuthSystemException, OAuthProblemException { } - protected abstract OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException; + protected abstract OAuthValidator initValidator() throws OAuthProblemException, + OAuthSystemException; public String getParam(String name) { return request.getParameter(name); } - public String getRefreshToken() { - return getParam(OAuth.OAUTH_REFRESH_TOKEN); - } - public String getClientId() { + String[] creds = OAuthUtils.decodeClientAuthenticationHeader(request.getHeader(OAuth.HeaderType.AUTHORIZATION)); + if (creds != null) { + return creds[0]; + } return getParam(OAuth.OAUTH_CLIENT_ID); } @@ -98,9 +99,21 @@ public String getRedirectURI() { } public String getClientSecret() { + String[] creds = OAuthUtils.decodeClientAuthenticationHeader(request.getHeader(OAuth.HeaderType.AUTHORIZATION)); + if (creds != null) { + return creds[1]; + } return getParam(OAuth.OAUTH_CLIENT_SECRET); } + /** + * + * @return + */ + public boolean isClientAuthHeaderUsed() { + return OAuthUtils.decodeClientAuthenticationHeader(request.getHeader(OAuth.HeaderType.AUTHORIZATION)) != null; + } + public Set getScopes() { String scopes = getParam(OAuth.OAUTH_SCOPE); return OAuthUtils.decodeScopes(scopes); diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthTokenRequest.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthTokenRequest.java new file mode 100644 index 00000000..dc00f2c8 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthTokenRequest.java @@ -0,0 +1,64 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.request; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.as.validator.AuthorizationCodeValidator; +import org.apache.oltu.oauth2.as.validator.ClientCredentialValidator; +import org.apache.oltu.oauth2.as.validator.PasswordValidator; +import org.apache.oltu.oauth2.as.validator.RefreshTokenValidator; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; + + +/** + * The Default OAuth Authorization Server class that validates whether a given HttpServletRequest is a valid + * OAuth Token request. + *

+ * IMPORTANT: This OAuthTokenRequest assumes that a token request requires client authentication. + * Please see section 3.2.1 of the OAuth Specification: http://tools.ietf.org/html/rfc6749#section-3.2.1 + */ +public class OAuthTokenRequest extends AbstractOAuthTokenRequest { + + /** + * Create an OAuth Token request from a given HttpSerlvetRequest + * + * @param request the httpservletrequest that is validated and transformed into the OAuth Token Request + * @throws OAuthSystemException if an unexpected exception was thrown + * @throws OAuthProblemException if the request was not a valid Token request this exception is thrown. + */ + public OAuthTokenRequest(HttpServletRequest request) throws OAuthSystemException, OAuthProblemException { + super(request); + } + + @Override + protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException { + validators.put(GrantType.PASSWORD.toString(), PasswordValidator.class); + validators.put(GrantType.CLIENT_CREDENTIALS.toString(), ClientCredentialValidator.class); + validators.put(GrantType.AUTHORIZATION_CODE.toString(), AuthorizationCodeValidator.class); + validators.put(GrantType.REFRESH_TOKEN.toString(), RefreshTokenValidator.class); + return super.initValidator(); + } +} diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthUnauthenticatedTokenRequest.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthUnauthenticatedTokenRequest.java new file mode 100644 index 00000000..0e70af85 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/request/OAuthUnauthenticatedTokenRequest.java @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.request; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.as.validator.PasswordValidator; +import org.apache.oltu.oauth2.as.validator.UnauthenticatedAuthorizationCodeValidator; +import org.apache.oltu.oauth2.as.validator.UnauthenticatedPasswordValidator; +import org.apache.oltu.oauth2.as.validator.UnauthenticatedRefreshTokenValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; + +/** + * The Unauthenticated OAuth Authorization Server class that validates whether a given HttpServletRequest is a valid + * OAuth Token request. + *

+ * This class accepts requests that are NOT authenticated, that is requests that do not contain a client_secret. + *

+ * IMPORTANT: The ClientCredentials Grant Type is NOT supported by this class since client authentication is required + * for this grant type. In order to support the client credentials grant type please use the {@link OAuthTokenRequest} + * class. + */ +public class OAuthUnauthenticatedTokenRequest extends AbstractOAuthTokenRequest { + + public OAuthUnauthenticatedTokenRequest(HttpServletRequest request) throws OAuthSystemException, + OAuthProblemException { + super(request); + } + + @Override + protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException { + validators.put(GrantType.PASSWORD.toString(), UnauthenticatedPasswordValidator.class); + validators.put(GrantType.AUTHORIZATION_CODE.toString(), UnauthenticatedAuthorizationCodeValidator.class); + validators.put(GrantType.REFRESH_TOKEN.toString(), UnauthenticatedRefreshTokenValidator.class); + return super.initValidator(); + } +} diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/response/OAuthASResponse.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java similarity index 72% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/response/OAuthASResponse.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java index c0cf7f54..747ca4c5 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/response/OAuthASResponse.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java @@ -19,16 +19,18 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.response; +package org.apache.oltu.oauth2.as.response; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.message.OAuthResponse; +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.message.OAuthResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthASResponse extends OAuthResponse { @@ -36,8 +38,8 @@ protected OAuthASResponse(String uri, int responseStatus) { super(uri, responseStatus); } - public static OAuthAuthorizationResponseBuilder authorizationResponse(int code) { - return new OAuthAuthorizationResponseBuilder(code); + public static OAuthAuthorizationResponseBuilder authorizationResponse(HttpServletRequest request,int code) { + return new OAuthAuthorizationResponseBuilder(request,code); } public static OAuthTokenResponseBuilder tokenResponse(int code) { @@ -46,11 +48,16 @@ public static OAuthTokenResponseBuilder tokenResponse(int code) { public static class OAuthAuthorizationResponseBuilder extends OAuthResponseBuilder { - public OAuthAuthorizationResponseBuilder(int responseCode) { + public OAuthAuthorizationResponseBuilder(HttpServletRequest request,int responseCode) { super(responseCode); + //AMBER-45 + String state=request.getParameter(OAuth.OAUTH_STATE); + if (state!=null){ + this.setState(state); + } } - public OAuthAuthorizationResponseBuilder setState(String state) { + OAuthAuthorizationResponseBuilder setState(String state) { this.parameters.put(OAuth.OAUTH_STATE, state); return this; } @@ -65,10 +72,20 @@ public OAuthAuthorizationResponseBuilder setAccessToken(String token) { return this; } + public OAuthAuthorizationResponseBuilder setTokenType(String tokenType) { + this.parameters.put(OAuth.OAUTH_TOKEN_TYPE, tokenType); + return this; + } + public OAuthAuthorizationResponseBuilder setExpiresIn(String expiresIn) { - this.parameters.put(OAuth.OAUTH_EXPIRES_IN, expiresIn); + this.parameters.put(OAuth.OAUTH_EXPIRES_IN, expiresIn == null ? null : Long.valueOf(expiresIn)); return this; } + + public OAuthAuthorizationResponseBuilder setExpiresIn(Long expiresIn) { + this.parameters.put(OAuth.OAUTH_EXPIRES_IN, expiresIn); + return this; + } public OAuthAuthorizationResponseBuilder location(String location) { this.location = location; @@ -94,7 +111,7 @@ public OAuthTokenResponseBuilder setAccessToken(String token) { } public OAuthTokenResponseBuilder setExpiresIn(String expiresIn) { - this.parameters.put(OAuth.OAUTH_EXPIRES_IN, expiresIn); + this.parameters.put(OAuth.OAUTH_EXPIRES_IN, expiresIn == null ? null : Long.valueOf(expiresIn)); return this; } @@ -102,6 +119,11 @@ public OAuthTokenResponseBuilder setRefreshToken(String refreshToken) { this.parameters.put(OAuth.OAUTH_REFRESH_TOKEN, refreshToken); return this; } + + public OAuthTokenResponseBuilder setTokenType(String tokenType) { + this.parameters.put(OAuth.OAUTH_TOKEN_TYPE, tokenType); + return this; + } public OAuthTokenResponseBuilder setParam(String key, String value) { this.parameters.put(key, value); diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/AssertionValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/AssertionValidator.java similarity index 78% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/AssertionValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/AssertionValidator.java index d28e1298..82d74df3 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/AssertionValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/AssertionValidator.java @@ -19,16 +19,16 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class AssertionValidator extends AbstractValidator { diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/AuthorizationCodeValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/AuthorizationCodeValidator.java similarity index 70% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/AuthorizationCodeValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/AuthorizationCodeValidator.java index 865a18f4..c6727671 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/AuthorizationCodeValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/AuthorizationCodeValidator.java @@ -19,25 +19,25 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * Validator that checks for the required fields in an OAuth Token request with the Authorization Code grant type. + * This validator enforces client authentication either through basic authentication or body parameters. */ -public class AuthorizationCodeValidator extends AbstractValidator { +public class AuthorizationCodeValidator extends AbstractValidator { public AuthorizationCodeValidator() { requiredParams.add(OAuth.OAUTH_GRANT_TYPE); - requiredParams.add(OAuth.OAUTH_CLIENT_ID); requiredParams.add(OAuth.OAUTH_CODE); requiredParams.add(OAuth.OAUTH_REDIRECT_URI); - requiredParams.add(OAuth.OAUTH_CLIENT_SECRET); - } + enforceClientAuthentication = true; + } } diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/ClientCredentialValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/ClientCredentialValidator.java new file mode 100644 index 00000000..20b5f8c7 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/ClientCredentialValidator.java @@ -0,0 +1,35 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.validator; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; + +public class ClientCredentialValidator extends AbstractValidator { + public ClientCredentialValidator() { + requiredParams.add(OAuth.OAUTH_GRANT_TYPE); + + enforceClientAuthentication = true; + } +} diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/CodeTokenValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/CodeTokenValidator.java similarity index 77% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/CodeTokenValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/CodeTokenValidator.java index 0a7720e3..5938c3e6 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/CodeTokenValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/CodeTokenValidator.java @@ -1,3 +1,4 @@ + /** * Copyright 2010 Newcastle University * @@ -19,22 +20,22 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class CodeTokenValidator extends AbstractValidator { +public class CodeTokenValidator extends AbstractValidator { public CodeTokenValidator() { requiredParams.add(OAuth.OAUTH_RESPONSE_TYPE); diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/CodeValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/CodeValidator.java similarity index 74% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/CodeValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/CodeValidator.java index aae9ab9f..b2931899 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/CodeValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/CodeValidator.java @@ -19,27 +19,26 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class CodeValidator extends AbstractValidator { +public class CodeValidator extends AbstractValidator { public CodeValidator() { requiredParams.add(OAuth.OAUTH_RESPONSE_TYPE); requiredParams.add(OAuth.OAUTH_CLIENT_ID); - requiredParams.add(OAuth.OAUTH_REDIRECT_URI); } @Override diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/PasswordValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/PasswordValidator.java new file mode 100644 index 00000000..e4e36f37 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/PasswordValidator.java @@ -0,0 +1,44 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.validator; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; + +/** + * + * + * + */ +public class PasswordValidator extends AbstractValidator { + + public PasswordValidator() { + requiredParams.add(OAuth.OAUTH_GRANT_TYPE); + requiredParams.add(OAuth.OAUTH_USERNAME); + requiredParams.add(OAuth.OAUTH_PASSWORD); + + enforceClientAuthentication = true; + } + +} diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/RefreshTokenValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/RefreshTokenValidator.java similarity index 65% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/RefreshTokenValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/RefreshTokenValidator.java index f55e7905..a9ba1dfc 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/RefreshTokenValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/RefreshTokenValidator.java @@ -19,24 +19,27 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * Validator that checks for the required fields in an OAuth Token request with the Refresh token grant type. + * This validator enforces client authentication either through basic authentication or body parameters. + * + * */ -public class RefreshTokenValidator extends AbstractValidator { +public class RefreshTokenValidator extends AbstractValidator { public RefreshTokenValidator() { requiredParams.add(OAuth.OAUTH_GRANT_TYPE); - requiredParams.add(OAuth.OAUTH_CLIENT_ID); requiredParams.add(OAuth.OAUTH_REFRESH_TOKEN); - requiredParams.add(OAuth.OAUTH_CLIENT_SECRET); + + enforceClientAuthentication = true; } } diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/TokenValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/TokenValidator.java similarity index 70% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/TokenValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/TokenValidator.java index 81ac760d..feea7b46 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/TokenValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/TokenValidator.java @@ -19,21 +19,21 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class TokenValidator extends AbstractValidator { +public class TokenValidator extends AbstractValidator { public TokenValidator() { requiredParams.add(OAuth.OAUTH_RESPONSE_TYPE); @@ -44,9 +44,9 @@ public TokenValidator() { @Override public void validateMethod(HttpServletRequest request) throws OAuthProblemException { String method = request.getMethod(); - if (!method.equals(OAuth.HttpMethod.GET) && !method.equals(OAuth.HttpMethod.POST)) { + if (!OAuth.HttpMethod.GET.equals(method) && !OAuth.HttpMethod.POST.equals(method)) { throw OAuthProblemException.error(OAuthError.CodeResponse.INVALID_REQUEST) - .description("Method not correct."); + .description("Method not correct."); } } diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedAuthorizationCodeValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedAuthorizationCodeValidator.java new file mode 100644 index 00000000..6882972b --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedAuthorizationCodeValidator.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.validator; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; + +import javax.servlet.http.HttpServletRequest; + +/** + * Validator that checks for the required fields for an OAuth Token request with the Authorization Code grant type. + * This validator does NOT enforce client authentication. + * + */ +public class UnauthenticatedAuthorizationCodeValidator extends AbstractValidator { + + public UnauthenticatedAuthorizationCodeValidator() { + requiredParams.add(OAuth.OAUTH_GRANT_TYPE); + requiredParams.add(OAuth.OAUTH_CLIENT_ID); + requiredParams.add(OAuth.OAUTH_CODE); + + enforceClientAuthentication = false; + } +} diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/PasswordValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedPasswordValidator.java similarity index 73% rename from oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/PasswordValidator.java rename to oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedPasswordValidator.java index 54f116af..d8017366 100644 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/validator/PasswordValidator.java +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedPasswordValidator.java @@ -19,24 +19,27 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class PasswordValidator extends AbstractValidator { - - public PasswordValidator() { +public class UnauthenticatedPasswordValidator extends AbstractValidator { + public UnauthenticatedPasswordValidator() { requiredParams.add(OAuth.OAUTH_GRANT_TYPE); requiredParams.add(OAuth.OAUTH_CLIENT_ID); requiredParams.add(OAuth.OAUTH_USERNAME); requiredParams.add(OAuth.OAUTH_PASSWORD); + + enforceClientAuthentication = false; } } diff --git a/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedRefreshTokenValidator.java b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedRefreshTokenValidator.java new file mode 100644 index 00000000..ceb65818 --- /dev/null +++ b/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/validator/UnauthenticatedRefreshTokenValidator.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.validator; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; + +import javax.servlet.http.HttpServletRequest; + +/** + * Validator that checks for the required fields in an OAuth Token request with the Refresh token grant type. + * This validator does NOT enforce client authentication. + * + */ +public class UnauthenticatedRefreshTokenValidator extends AbstractValidator { + public UnauthenticatedRefreshTokenValidator() { + requiredParams.add(OAuth.OAUTH_GRANT_TYPE); + requiredParams.add(OAuth.OAUTH_CLIENT_ID); + requiredParams.add(OAuth.OAUTH_REFRESH_TOKEN); + + enforceClientAuthentication = false; + + } +} diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/MD5GeneratorTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/MD5GeneratorTest.java similarity index 56% rename from oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/MD5GeneratorTest.java rename to oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/MD5GeneratorTest.java index bf1d0d0c..d9f2d7b7 100644 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/MD5GeneratorTest.java +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/MD5GeneratorTest.java @@ -19,34 +19,31 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as; +package org.apache.oltu.oauth2.as; -import junit.framework.Assert; - -import org.apache.amber.oauth2.as.issuer.MD5Generator; -import org.apache.amber.oauth2.as.issuer.ValueGenerator; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.as.issuer.MD5Generator; +import org.apache.oltu.oauth2.as.issuer.ValueGenerator; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; import org.junit.Test; +import static org.junit.Assert.assertNotNull; + +public class MD5GeneratorTest { + + private final ValueGenerator g = new MD5Generator(); -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class MD5GeneratorTest extends Assert { @Test public void testGenerateValue() throws Exception { - ValueGenerator g = new MD5Generator(); - Assert.assertNotNull(g.generateValue()); + assertNotNull(g.generateValue()); + } - Assert.assertNotNull(g.generateValue("test")); + @Test + public void testGenerateValueWithParameter() throws Exception { + assertNotNull(g.generateValue("test")); + } - try { - g.generateValue(null); - fail("Exception not thrown"); - } catch (OAuthSystemException e) { - //ok - } + @Test(expected = OAuthSystemException.class) + public void testGenerateValueFailsWithParameterNull() throws Exception { + g.generateValue(null); } } diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthIssuerImplTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthIssuerImplTest.java similarity index 69% rename from oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthIssuerImplTest.java rename to oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthIssuerImplTest.java index b86d35d3..bfef89b9 100644 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthIssuerImplTest.java +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthIssuerImplTest.java @@ -19,35 +19,30 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as; +package org.apache.oltu.oauth2.as; -import junit.framework.Assert; - -import org.apache.amber.oauth2.as.issuer.MD5Generator; +import org.apache.oltu.oauth2.as.issuer.MD5Generator; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl; import org.junit.Test; -import org.apache.amber.oauth2.as.issuer.OAuthIssuer; -import org.apache.amber.oauth2.as.issuer.OAuthIssuerImpl; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ +import static org.junit.Assert.assertNotNull; + public class OAuthIssuerImplTest { private OAuthIssuer issuer = new OAuthIssuerImpl(new MD5Generator()); @Test public void testAccessToken() throws Exception { - Assert.assertNotNull(issuer.accessToken()); + assertNotNull(issuer.accessToken()); } @Test public void testRefreshToken() throws Exception { - Assert.assertNotNull(issuer.refreshToken()); + assertNotNull(issuer.refreshToken()); } @Test public void testAuthorizationCode() throws Exception { - Assert.assertNotNull(issuer.authorizationCode()); + assertNotNull(issuer.authorizationCode()); } } diff --git a/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthRequestTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthRequestTest.java new file mode 100644 index 00000000..c68abf15 --- /dev/null +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthRequestTest.java @@ -0,0 +1,589 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as; + +import org.apache.commons.codec.binary.Base64; +import org.apache.oltu.oauth2.as.request.OAuthAuthzRequest; +import org.apache.oltu.oauth2.as.request.OAuthRequest; +import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.message.types.ResponseType; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.junit.Test; + +import javax.servlet.http.HttpServletRequest; +import java.util.Set; + +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.*; + + +public class OAuthRequestTest { + public static final String REDIRECT_URI = "http://www.example.com/callback"; + public static final String CLIENT_ID = "test_client"; + public static final String ACCESS_GRANT = "test_code"; + public static final String SECRET = "secret"; + public static final String USERNAME = "test_username"; + public static final String PASSWORD = "test_password"; + public static final String REFRESH_TOKEN = "refresh_token"; + + @Test + public void testWrongResponseGetRequestParam() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectOauthResponseType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectParam("param", "someparam") + .build(); + + replay(request); + + assertInvalidOAuthRequest(request); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectOauthResponseType(null) + .expectRedirectUri(REDIRECT_URI) + .expectParam("param", "someparam") + .build(); + replay(request); + + assertInvalidOAuthRequest(request); + verify(request); + } + + private void assertInvalidOAuthRequest(HttpServletRequest request) throws OAuthSystemException { + try { + new OAuthAuthzRequest(request); + fail("Exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + } + } + + @Test + public void testCodeRequestInvalidMethod() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectHttpMethod(OAuth.HttpMethod.PUT) + .expectOauthResponseType(ResponseType.CODE.toString()) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .build(); + + replay(request); + + assertInvalidOAuthRequest(request); + verify(request); + } + + + @Test + public void testCodeRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectHttpMethod(OAuth.HttpMethod.GET) + .expectOauthResponseType(ResponseType.CODE.toString()) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .build(); + + replay(request); + + assertInvalidOAuthRequest(request); + verify(request); + } + + @Test + public void testValidCodeRequest() throws Exception { + assertValidCodeRequest(OAuth.HttpMethod.GET); + + assertValidCodeRequest(OAuth.HttpMethod.POST); + } + + private void assertValidCodeRequest(String httpMethod) throws OAuthSystemException { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectHttpMethod(httpMethod) + .expectOauthResponseType(ResponseType.CODE.toString()) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .build(); + + replay(request); + + try { + new OAuthAuthzRequest(request); + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + + verify(request); + } + + @Test + public void testTokenWrongGrantType() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectGrantType(OAuth.ContentType.URL_ENCODED) + .expectParam("param", "someparam") + .build(); + + replay(request); + assertInvalidTokenRequest(request); + + request = new OauthMockRequestBuilder() + .expectRedirectUri(REDIRECT_URI) + .expectGrantType(null) + .expectParam("param", "someparam") + .build(); + + replay(request); + assertInvalidTokenRequest(request); + } + + private void assertInvalidTokenRequest(HttpServletRequest request) throws OAuthSystemException { + try { + new OAuthTokenRequest(request); + fail("Exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + } + + verify(request); + } + + @Test + public void testTokenRequestInvalidMethod() throws Exception { + HttpServletRequest request = mockTokenRequestInvalidMethod(GrantType.AUTHORIZATION_CODE.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidMethod(GrantType.PASSWORD.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidMethod(GrantType.REFRESH_TOKEN.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidMethod(null); + assertInvalidTokenRequest(request); + } + + private HttpServletRequest mockTokenRequestInvalidMethod(String grantType) { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectHttpMethod(OAuth.HttpMethod.GET) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectGrantType(grantType) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .build(); + replay(request); + + return request; + } + + @Test + public void testTokenRequestInvalidContentType() throws Exception { + HttpServletRequest request = mockTokenRequestInvalidContentType(GrantType.AUTHORIZATION_CODE.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidContentType(GrantType.PASSWORD.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidContentType(GrantType.REFRESH_TOKEN.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidContentType(null); + assertInvalidTokenRequest(request); + } + + private HttpServletRequest mockTokenRequestInvalidContentType(String grantType) { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(grantType) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.JSON) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .build(); + + replay(request); + return request; + } + + @Test + public void testTokenAuthCodeRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectBasicAuthHeader(null) + .expectGrantType(OAuth.OAUTH_GRANT_TYPE) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .expectClientSecret(SECRET) + .expectAccessGrant(ACCESS_GRANT) + .build(); + + replay(request); + assertInvalidTokenRequest(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectBasicAuthHeader(null) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectRedirectUri(null) + .expectAccessGrant(null) + .build(); + + replay(request); + assertInvalidTokenRequest(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectBasicAuthHeader(null) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectAccessGrant(null) + .build(); + + replay(request); + assertInvalidTokenRequest(request); + } + + @Test + public void testTokenAuthCodeRequestWithBasicAuthenticationMissingParameter() throws Exception { + HttpServletRequest request = mockOAuthTokenRequestBasicAuth(CLIENT_ID, null); + assertInvalidTokenRequest(request); + + request = mockOAuthTokenRequestBasicAuth(null, SECRET); + assertInvalidTokenRequest(request); + + + // Don't allow to mix basic auth header and body params. + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectClientSecret(null) + .expectRedirectUri(REDIRECT_URI) + .expectAccessGrant(ACCESS_GRANT) + .expectBasicAuthHeader(createBasicAuthHeader(null, SECRET)) + .build(); + + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + } + + private HttpServletRequest mockOAuthTokenRequestBasicAuth(String clientId, String clientSecret) { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(null) + .expectClientSecret(null) + .expectRedirectUri(REDIRECT_URI) + .expectAccessGrant(ACCESS_GRANT) + .expectBasicAuthHeader(createBasicAuthHeader(clientId, clientSecret)) + .build(); + + replay(request); + return request; + } + + private String createBasicAuthHeader(String clientId, String clientSecret) { + clientSecret = OAuthUtils.isEmpty(clientSecret) ? "" : clientSecret; + clientId = OAuthUtils.isEmpty(clientId) ? "" : clientId; + final String authString = clientId + ":" + clientSecret; + return "basic " + Base64.encodeBase64String(authString.getBytes()); + } + + @Test + public void testTokenPasswordRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectBasicAuthHeader(createBasicAuthHeader(null, SECRET)) + .expectOauthUsername(null) + .expectOauthPassword(SECRET) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectBasicAuthHeader(createBasicAuthHeader(null, SECRET)) + .expectOauthUsername(USERNAME) + .expectOauthPassword("") + .build(); + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .expectClientSecret("") + .expectBasicAuthHeader(null) + .expectOauthUsername(USERNAME) + .expectOauthPassword(PASSWORD) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + } + + @Test + public void testRefreshTokenRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectBasicAuthHeader(null) + .expectOauthRefreshToken(null) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId("") + .expectClientSecret(SECRET) + .expectBasicAuthHeader(null) + .expectOauthRefreshToken(REFRESH_TOKEN) + .build(); + + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .expectClientSecret(SECRET) + .expectBasicAuthHeader(SECRET) + .expectOauthRefreshToken(null) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + } + + @Test + public void testValidTokenRequest() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectBasicAuthHeader(null) + .expectAccessGrant(ACCESS_GRANT) + .expectRedirectUri(REDIRECT_URI) + .build(); + replay(request); + + OAuthTokenRequest req = null; + try { + req = new OAuthTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType()); + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(REDIRECT_URI, req.getRedirectURI()); + assertEquals(ACCESS_GRANT, req.getCode()); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectBasicAuthHeader(null) + .expectOauthUsername(USERNAME) + .expectOauthPassword(PASSWORD) + .build(); + replay(request); + + try { + req = new OAuthTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(USERNAME, req.getUsername()); + assertEquals(PASSWORD, req.getPassword()); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.CLIENT_CREDENTIALS.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectBasicAuthHeader(createBasicAuthHeader(CLIENT_ID, SECRET)) + .build(); + replay(request); + + try { + req = new OAuthTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectClientSecret(SECRET) + .expectBasicAuthHeader(null) + .expectOauthRefreshToken(REFRESH_TOKEN) + .build(); + replay(request); + + try { + req = new OAuthTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(REFRESH_TOKEN, req.getRefreshToken()); + assertEquals(SECRET, req.getClientSecret()); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId("") + .expectClientSecret("") + .expectBasicAuthHeader(createBasicAuthHeader(CLIENT_ID, SECRET)) + .expectOauthRefreshToken(REFRESH_TOKEN) + .build(); + replay(request); + + try { + req = new OAuthTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(REFRESH_TOKEN, req.getRefreshToken()); + assertEquals(SECRET, req.getClientSecret()); + + verify(request); + } + + + @Test + public void testScopes() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectOauthResponseType(ResponseType.CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.GET) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectRedirectUri(REDIRECT_URI) + .expectScopes("album photo") + .build(); + replay(request); + + OAuthRequest req = null; + try { + req = new OAuthAuthzRequest(request); + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + + Set scopes = req.getScopes(); + + assertTrue(findScope(scopes, "album")); + assertTrue(findScope(scopes, "photo")); + + verify(request); + } + + private boolean findScope(Set scopes, String scope) { + for (String s : scopes) { + if (s.equals(scope)) { + return true; + } + } + return false; + } +} diff --git a/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthUnauthenticatedRequestTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthUnauthenticatedRequestTest.java new file mode 100644 index 00000000..bc6751ca --- /dev/null +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OAuthUnauthenticatedRequestTest.java @@ -0,0 +1,338 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.as.request.OAuthUnauthenticatedTokenRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.junit.Test; + +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class OAuthUnauthenticatedRequestTest { + public static final String REDIRECT_URI = "http://www.example.com/callback"; + public static final String CLIENT_ID = "test_client"; + public static final String ACCESS_GRANT = "test_code"; + public static final String USERNAME = "test_username"; + public static final String PASSWORD = "test_password"; + public static final String REFRESH_TOKEN = "refresh_token"; + public static final String SECRET = ""; + + @Test + public void testTokenWrongGrantType() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectGrantType(OAuth.ContentType.URL_ENCODED) + .expectParam("param", "someparam") + .build(); + + replay(request); + assertInvalidTokenRequest(request); + + request = new OauthMockRequestBuilder() + .expectRedirectUri(REDIRECT_URI) + .expectGrantType(null) + .expectParam("param", "someparam") + .build(); + + replay(request); + assertInvalidTokenRequest(request); + } + + private void assertInvalidTokenRequest(HttpServletRequest request) throws OAuthSystemException { + try { + new OAuthUnauthenticatedTokenRequest(request); + fail("Exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + } + + verify(request); + } + + @Test + public void testTokenRequestInvalidMethod() throws Exception { + HttpServletRequest request = mockTokenRequestInvalidMethod(GrantType.AUTHORIZATION_CODE.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidMethod(GrantType.PASSWORD.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidMethod(GrantType.REFRESH_TOKEN.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidMethod(null); + assertInvalidTokenRequest(request); + } + + private HttpServletRequest mockTokenRequestInvalidMethod(String grantType) { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectHttpMethod(OAuth.HttpMethod.GET) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectGrantType(grantType) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .build(); + replay(request); + + return request; + } + + @Test + public void testTokenRequestInvalidContentType() throws Exception { + HttpServletRequest request = mockTokenRequestInvalidContentType(GrantType.AUTHORIZATION_CODE.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidContentType(GrantType.PASSWORD.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidContentType(GrantType.REFRESH_TOKEN.toString()); + assertInvalidTokenRequest(request); + + request = mockTokenRequestInvalidContentType(null); + assertInvalidTokenRequest(request); + } + + private HttpServletRequest mockTokenRequestInvalidContentType(String grantType) { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(grantType) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.JSON) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .build(); + + replay(request); + return request; + } + + @Test + public void testTokenAuthCodeRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectGrantType(OAuth.OAUTH_GRANT_TYPE) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .expectAccessGrant(ACCESS_GRANT) + .build(); + + replay(request); + assertInvalidTokenRequest(request); + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectRedirectUri(null) + .expectAccessGrant(null) + .build(); + + replay(request); + + assertInvalidTokenRequest(request); + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectAccessGrant(null) + .build(); + + replay(request); + assertInvalidTokenRequest(request); + verify(request); + } + + @Test + public void testTokenPasswordRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectOauthUsername(null) + .expectOauthPassword(PASSWORD) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectOauthUsername(USERNAME) + .expectOauthPassword("") + .build(); + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .expectOauthUsername(USERNAME) + .expectOauthPassword(PASSWORD) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + + verify(request); + } + + @Test + public void testRefreshTokenRequestMissingParameter() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(CLIENT_ID) + .expectOauthRefreshToken(null) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId("") + .expectOauthRefreshToken(REFRESH_TOKEN) + .build(); + + replay(request); + + assertInvalidTokenRequest(request); + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectRedirectUri(REDIRECT_URI) + .expectClientId(null) + .expectOauthRefreshToken(null) + .build(); + replay(request); + + assertInvalidTokenRequest(request); + verify(request); + } + + @Test + public void testValidTokenRequest() throws Exception { + HttpServletRequest request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.AUTHORIZATION_CODE.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectAccessGrant(ACCESS_GRANT) + .expectRedirectUri(REDIRECT_URI) + .expectBasicAuthHeader(null) + .build(); + replay(request); + + OAuthUnauthenticatedTokenRequest req = null; + try { + req = new OAuthUnauthenticatedTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType()); + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(REDIRECT_URI, req.getRedirectURI()); + assertEquals(ACCESS_GRANT, req.getCode()); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.PASSWORD.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectBasicAuthHeader(null) + .expectOauthUsername(USERNAME) + .expectOauthPassword(PASSWORD) + .build(); + replay(request); + + try { + req = new OAuthUnauthenticatedTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(USERNAME, req.getUsername()); + assertEquals(PASSWORD, req.getPassword()); + + verify(request); + + request = new OauthMockRequestBuilder() + .expectGrantType(GrantType.REFRESH_TOKEN.toString()) + .expectHttpMethod(OAuth.HttpMethod.POST) + .expectContentType(OAuth.ContentType.URL_ENCODED) + .expectClientId(CLIENT_ID) + .expectOauthRefreshToken(REFRESH_TOKEN) + .expectBasicAuthHeader(null) + .build(); + replay(request); + + try { + req = new OAuthUnauthenticatedTokenRequest(request); + + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + assertEquals(CLIENT_ID, req.getClientId()); + assertEquals(REFRESH_TOKEN, req.getRefreshToken()); + + verify(request); + } +} diff --git a/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OauthMockRequestBuilder.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OauthMockRequestBuilder.java new file mode 100644 index 00000000..f3855972 --- /dev/null +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/OauthMockRequestBuilder.java @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; + +public class OauthMockRequestBuilder { + + private HttpServletRequest request; + + public OauthMockRequestBuilder() { + request = createMock(HttpServletRequest.class); + } + + public OauthMockRequestBuilder expectOauthResponseType(String oauthResponseType) { + expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(oauthResponseType); + + return this; + } + + public OauthMockRequestBuilder expectRedirectUri(String redirectUri) { + expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn(redirectUri); + + return this; + } + + public OauthMockRequestBuilder expectParam(String paramName, String paramValue) { + expect(request.getParameter(paramName)).andStubReturn(paramValue); + + return this; + } + + public HttpServletRequest build() { + return request; + } + + public OauthMockRequestBuilder expectContentType(String contentType) { + expect(request.getContentType()).andStubReturn(contentType); + + return this; + } + + public OauthMockRequestBuilder expectHttpMethod(String method) { + expect(request.getMethod()).andStubReturn(method); + + return this; + } + + public OauthMockRequestBuilder expectClientId(String clientId) { + expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(clientId); + + return this; + } + + public OauthMockRequestBuilder expectClientSecret(String secret) { + expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn(secret); + + return this; + } + + public OauthMockRequestBuilder expectGrantType(String grantType) { + expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(grantType); + + return this; + } + + public OauthMockRequestBuilder expectBasicAuthHeader(String authorizationHeader) { + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn(authorizationHeader); + + return this; + } + + public OauthMockRequestBuilder expectAccessGrant(String accessGrant) { + expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn(accessGrant); + + return this; + } + + public OauthMockRequestBuilder expectOauthUsername(String oauthUsername) { + expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn(oauthUsername); + + return this; + } + + public OauthMockRequestBuilder expectOauthPassword(String secret) { + expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn(secret); + + return this; + } + + public OauthMockRequestBuilder expectOauthRefreshToken(String refreshToken) { + expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(refreshToken); + + return this; + } + + public OauthMockRequestBuilder expectScopes(String scopes) { + expect(request.getParameter(OAuth.OAUTH_SCOPE)).andStubReturn(scopes); + + return this; + } +} diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/UUIDValueGeneratorTest.java similarity index 83% rename from oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java rename to oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/UUIDValueGeneratorTest.java index daa2f495..3f189fdc 100644 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/UUIDValueGeneratorTest.java @@ -19,17 +19,17 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as; +package org.apache.oltu.oauth2.as; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.as.issuer.UUIDValueGenerator; +import org.apache.oltu.oauth2.as.issuer.UUIDValueGenerator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class UUIDValueGeneratorTest extends Assert { @Test diff --git a/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java new file mode 100644 index 00000000..73acd584 --- /dev/null +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java @@ -0,0 +1,178 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.as.response; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.junit.Assert.assertEquals; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.junit.Test; + +/** + * + * + * + */ +public class OAuthASResponseTest { + + @Test + public void testAuthzResponse() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,200) + .location("http://www.example.com") + .setCode("code") + .setState("ok") + .setParam("testValue", "value2") + .buildQueryMessage(); + + String url = oAuthResponse.getLocationUri(); + + assertEquals("http://www.example.com?code=code&state=ok&testValue=value2", url); + assertEquals(200, oAuthResponse.getResponseStatus()); + + } + + @Test + public void testAuthzResponseWithState() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getParameter(OAuth.OAUTH_STATE)).andStubReturn("ok"); + replay(request); + OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,200) + .location("http://www.example.com") + .setCode("code") + .setParam("testValue", "value2") + .buildQueryMessage(); + + String url = oAuthResponse.getLocationUri(); + + assertEquals("http://www.example.com?code=code&state=ok&testValue=value2", url); + assertEquals(200, oAuthResponse.getResponseStatus()); + + } + + @Test + public void testAuthzImplicitResponseWithState() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getParameter(OAuth.OAUTH_STATE)).andStubReturn("ok"); + replay(request); + OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request, 200) + .location("http://www.example.com") + .setAccessToken("access_111") + .setTokenType("bearer") + .setExpiresIn("400") + .setParam("testValue", "value2") + .buildQueryMessage(); + + String url = oAuthResponse.getLocationUri(); + assertEquals("http://www.example.com#access_token=access_111&state=ok&token_type=bearer&expires_in=400&testValue=value2", url); + assertEquals(200, oAuthResponse.getResponseStatus()); + } + + @Test + public void testTokenResponse() throws Exception { + + OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token") + .setTokenType("bearer").setExpiresIn("200").setRefreshToken("refresh_token2") + .buildBodyMessage(); + + String body = oAuthResponse.getBody(); + assertEquals( + "access_token=access_token&refresh_token=refresh_token2&token_type=bearer&expires_in=200", + body); + + } + + @Test + public void testTokenResponseAdditionalParam() throws Exception { + + OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token") + .setTokenType("bearer").setExpiresIn("200").setRefreshToken("refresh_token2").setParam("some_param", "new_param") + .buildBodyMessage(); + + String body = oAuthResponse.getBody(); + + assertEquals( + "access_token=access_token&refresh_token=refresh_token2&some_param=new_param&token_type=bearer&expires_in=200", + body); + + } + + @Test + public void testErrorResponse() throws Exception { + + OAuthProblemException ex = OAuthProblemException + .error(OAuthError.CodeResponse.ACCESS_DENIED, "Access denied") + .setParameter("testparameter", "testparameter_value") + .scope("album") + .uri("http://www.example.com/error"); + + OAuthResponse oAuthResponse = OAuthResponse.errorResponse(400).error(ex).buildJSONMessage(); + assertEquals( + "{\"error_description\":\"Access denied\",\"error\":\"access_denied\",\"error_uri\":\"http://www.example.com/error\"}", + oAuthResponse.getBody()); + + + oAuthResponse = OAuthResponse.errorResponse(500) + .location("http://www.example.com/redirect?param2=true").error(ex).buildQueryMessage(); + assertEquals( + "http://www.example.com/redirect?param2=true&error_description=Access+denied&error=access_denied&error_uri=http%3A%2F%2Fwww.example.com%2Ferror", + oAuthResponse.getLocationUri()); + } + + @Test + public void testErrorResponse2() throws Exception { + OAuthProblemException ex = OAuthProblemException + .error(OAuthError.CodeResponse.ACCESS_DENIED, "Access denied") + .setParameter("testparameter", "testparameter_value") + .scope("album") + .uri("http://www.example.com/error"); + + OAuthResponse oAuthResponse = OAuthResponse.errorResponse(500) + .location("http://www.example.com/redirect?param2=true").error(ex).buildQueryMessage(); + + assertEquals( + "http://www.example.com/redirect?param2=true&error_description=Access+denied&error=access_denied&error_uri=http%3A%2F%2Fwww.example.com%2Ferror", + oAuthResponse.getLocationUri()); + } + + @Test + public void testHeaderResponse() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,400).setCode("oauth_code") + .setState("state_ok") + .buildHeaderMessage(); + + String header = oAuthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE); + assertEquals("Bearer code=\"oauth_code\",state=\"state_ok\"", header); + + header = oAuthResponse.getHeaders().get(OAuth.HeaderType.WWW_AUTHENTICATE); + assertEquals("Bearer code=\"oauth_code\",state=\"state_ok\"", header); + } + +} diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/validator/TokenValidatorTest.java similarity index 89% rename from oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java rename to oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/validator/TokenValidatorTest.java index adf92c76..f67ad859 100644 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java +++ b/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/validator/TokenValidatorTest.java @@ -19,13 +19,13 @@ * limitations under the License. */ -package org.apache.amber.oauth2.as.validator; +package org.apache.oltu.oauth2.as.validator; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.as.validator.TokenValidator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.as.validator.TokenValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.junit.Assert; import org.junit.Test; @@ -37,9 +37,9 @@ /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class TokenValidatorTest { @Test diff --git a/oauth-2.0/client/pom.xml b/oauth-2.0/client/pom.xml new file mode 100644 index 00000000..5f70af2a --- /dev/null +++ b/oauth-2.0/client/pom.xml @@ -0,0 +1,97 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.client + bundle + + Apache Oltu - OAuth 2.0 - Client + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + commons-io + commons-io + 2.4 + test + + + org.apache.johnzon + johnzon-core + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/utils/* + **/OAuthClientTest.java + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/client/src/main/assembly/LICENSE-with-deps b/oauth-2.0/client/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..c2622deb --- /dev/null +++ b/oauth-2.0/client/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,234 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/client/src/main/assembly/NOTICE-with-deps b/oauth-2.0/client/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/client/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/client/src/main/assembly/bin.xml b/oauth-2.0/client/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/client/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/HttpClient.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/HttpClient.java similarity index 74% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/HttpClient.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/HttpClient.java index 8abfa1e0..f6440ff7 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/HttpClient.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/HttpClient.java @@ -19,19 +19,19 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client; +package org.apache.oltu.oauth2.client; import java.util.Map; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface HttpClient { diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/OAuthClient.java similarity index 56% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/OAuthClient.java index b2cddd17..f737c102 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/OAuthClient.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/OAuthClient.java @@ -19,24 +19,25 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client; +package org.apache.oltu.oauth2.client; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse; -import org.apache.amber.oauth2.client.response.OAuthJSONAccessTokenResponse; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** * OAuth Client - exposes a high-level API for Client Applications * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClient { @@ -51,11 +52,17 @@ public T accessToken( Class responseClass) throws OAuthSystemException, OAuthProblemException { - String method = OAuth.HttpMethod.POST; + return accessToken(request, OAuth.HttpMethod.POST, responseClass); + } + + public T accessToken( + OAuthClientRequest request, String requestMethod, Class responseClass) + throws OAuthSystemException, OAuthProblemException { + Map headers = new HashMap(); headers.put(OAuth.HeaderType.CONTENT_TYPE, OAuth.ContentType.URL_ENCODED); - return httpClient.execute(request, headers, method, responseClass); + return httpClient.execute(request, headers, requestMethod, responseClass); } public OAuthJSONAccessTokenResponse accessToken( @@ -63,7 +70,17 @@ public OAuthJSONAccessTokenResponse accessToken( throws OAuthSystemException, OAuthProblemException { return accessToken(request, OAuthJSONAccessTokenResponse.class); } - + + public OAuthJSONAccessTokenResponse accessToken( + OAuthClientRequest request, String requestMethod) + throws OAuthSystemException, OAuthProblemException { + return accessToken(request, requestMethod, OAuthJSONAccessTokenResponse.class); + } + + public T resource(OAuthClientRequest request, String requestMethod,Class responseClass) throws OAuthSystemException, OAuthProblemException{ + return httpClient.execute(request, null, requestMethod, responseClass); + } + public void shutdown() { httpClient.shutdown(); } diff --git a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java new file mode 100644 index 00000000..70af5f29 --- /dev/null +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java @@ -0,0 +1,145 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.client; + +import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; +import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.Proxy; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; + + +/** + * Implementation of the Oltu OAuth HttpClient using URL Connection + * + * + * + * + */ +public class URLConnectionClient implements HttpClient { + + private Proxy proxy = Proxy.NO_PROXY; + + public URLConnectionClient() { + } + + public URLConnectionClient(final Proxy proxy) { + this.proxy = proxy; + } + + @Override + public T execute(final OAuthClientRequest request, final Map headers, + final String requestMethod, final Class responseClass) + throws OAuthSystemException, OAuthProblemException { + + InputStream responseBody = null; + URLConnection c; + Map> responseHeaders = new HashMap>(); + int responseCode; + try { + URL url = new URL(request.getLocationUri()); + + c = url.openConnection(proxy); + responseCode = -1; + if (c instanceof HttpURLConnection) { + HttpURLConnection httpURLConnection = (HttpURLConnection) c; + + if (headers != null && !headers.isEmpty()) { + for (Map.Entry header : headers.entrySet()) { + httpURLConnection.addRequestProperty(header.getKey(), header.getValue()); + } + } + + if (request.getHeaders() != null) { + for (Map.Entry header : request.getHeaders().entrySet()) { + httpURLConnection.addRequestProperty(header.getKey(), header.getValue()); + } + } + + if (OAuthUtils.isEmpty(requestMethod)) { + httpURLConnection.setRequestMethod(OAuth.HttpMethod.GET); + } else { + httpURLConnection.setRequestMethod(requestMethod); + setRequestBody(request, requestMethod, httpURLConnection); + } + + httpURLConnection.connect(); + + InputStream inputStream; + responseCode = httpURLConnection.getResponseCode(); + if (responseCode == SC_BAD_REQUEST || responseCode == SC_UNAUTHORIZED) { + inputStream = httpURLConnection.getErrorStream(); + } else { + inputStream = httpURLConnection.getInputStream(); + } + + responseHeaders = httpURLConnection.getHeaderFields(); + responseBody = inputStream; + } + } catch (IOException e) { + throw new OAuthSystemException(e); + } + + return OAuthClientResponseFactory + .createCustomResponse(responseBody, c.getContentType(), responseCode, responseHeaders, responseClass); + } + + private void setRequestBody(OAuthClientRequest request, String requestMethod, HttpURLConnection httpURLConnection) + throws IOException { + String requestBody = request.getBody(); + if (OAuthUtils.isEmpty(requestBody)) { + return; + } + + if (OAuth.HttpMethod.POST.equals(requestMethod) || OAuth.HttpMethod.PUT.equals(requestMethod)) { + httpURLConnection.setDoOutput(true); + OutputStream ost = httpURLConnection.getOutputStream(); + PrintWriter pw = new PrintWriter(ost); + pw.print(requestBody); + pw.flush(); + pw.close(); + } + } + + @Override + public void shutdown() { + // Nothing to do here + } + +} diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/ClientHeaderParametersApplier.java similarity index 66% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/ClientHeaderParametersApplier.java index 127e8c98..a1a69a5e 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/request/ClientHeaderParametersApplier.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/ClientHeaderParametersApplier.java @@ -19,27 +19,27 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.request; +package org.apache.oltu.oauth2.client.request; import java.util.Map; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.parameters.OAuthParametersApplier; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.parameters.OAuthParametersApplier; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class ClientHeaderParametersApplier implements OAuthParametersApplier { - public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) + public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws OAuthSystemException { - String header = OAuthUtils.encodeOAuthHeader(params); + String header = OAuthUtils.encodeAuthorizationBearerHeader(params); message.addHeader(OAuth.HeaderType.AUTHORIZATION, header); return message; diff --git a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthBearerClientRequest.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthBearerClientRequest.java new file mode 100644 index 00000000..ea27f89c --- /dev/null +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthBearerClientRequest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.client.request; + +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.OAuthRequestBuilder; +import org.apache.oltu.oauth2.common.OAuth; + +public class OAuthBearerClientRequest extends OAuthRequestBuilder { + + public OAuthBearerClientRequest(String url) { + super(url); + } + + public OAuthBearerClientRequest setAccessToken(String accessToken) { + this.parameters.put(OAuth.OAUTH_BEARER_TOKEN, accessToken); + return this; + } + +} diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/request/OAuthClientRequest.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java similarity index 86% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/request/OAuthClientRequest.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java index dc7dfa0c..69e132a3 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/request/OAuthClientRequest.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/request/OAuthClientRequest.java @@ -19,25 +19,26 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.request; +package org.apache.oltu.oauth2.client.request; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.parameters.OAuthParametersApplier; -import org.apache.amber.oauth2.common.parameters.QueryParameterApplier; -import org.apache.amber.oauth2.common.message.types.GrantType; -import org.apache.amber.oauth2.common.parameters.BodyURLEncodedParametersApplier; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuthProviderType; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.parameters.BodyURLEncodedParametersApplier; +import org.apache.oltu.oauth2.common.parameters.OAuthParametersApplier; +import org.apache.oltu.oauth2.common.parameters.QueryParameterApplier; /** * OAuth Client Request * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClientRequest implements OAuthMessage { @@ -48,16 +49,25 @@ public class OAuthClientRequest implements OAuthMessage { protected OAuthClientRequest(String url) { this.url = url; + this.headers=new HashMap(); } public static AuthenticationRequestBuilder authorizationLocation(String url) { return new AuthenticationRequestBuilder(url); } + public static AuthenticationRequestBuilder authorizationProvider(OAuthProviderType provider) { + return authorizationLocation(provider.getAuthzEndpoint()); + } + public static TokenRequestBuilder tokenLocation(String url) { return new TokenRequestBuilder(url); } + public static TokenRequestBuilder tokenProvider(OAuthProviderType provider) { + return tokenLocation(provider.getTokenEndpoint()); + } + public String getBody() { return body; } @@ -98,7 +108,7 @@ public void setHeader(String name, String value) { public abstract static class OAuthRequestBuilder { protected OAuthParametersApplier applier; - protected Map parameters = new HashMap(); + protected Map parameters = new HashMap(); protected String url; @@ -169,7 +179,7 @@ public TokenRequestBuilder(String url) { } public TokenRequestBuilder setGrantType(GrantType grantType) { - this.parameters.put(OAuth.OAUTH_GRANT_TYPE, grantType.toString()); + this.parameters.put(OAuth.OAUTH_GRANT_TYPE, grantType == null ? null : grantType.toString()); return this; } diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/GitHubTokenResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java similarity index 62% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/GitHubTokenResponse.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java index 3748f34a..3a3cc610 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/GitHubTokenResponse.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java @@ -19,59 +19,62 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; - -import org.apache.amber.oauth2.common.token.BasicOAuthToken; -import org.apache.amber.oauth2.common.token.OAuthToken; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.OAuth; +package org.apache.oltu.oauth2.client.response; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.token.BasicOAuthToken; +import org.apache.oltu.oauth2.common.token.OAuthToken; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * Custom response class */ public class GitHubTokenResponse extends OAuthAccessTokenResponse { - + @Override public String getAccessToken() { - return parameters.get(OAuth.OAUTH_ACCESS_TOKEN); + return getParam(OAuth.OAUTH_ACCESS_TOKEN); } - public String getExpiresIn() { - return parameters.get(OAuth.OAUTH_EXPIRES_IN); + @Override + public String getTokenType() { + return getParam(OAuth.OAUTH_TOKEN_TYPE); } + @Override + public Long getExpiresIn() { + String value = getParam(OAuth.OAUTH_EXPIRES_IN); + return value == null? null: Long.valueOf(value); + } + + @Override public String getRefreshToken() { - return parameters.get(OAuth.OAUTH_EXPIRES_IN); + return getParam(OAuth.OAUTH_REFRESH_TOKEN); } + @Override public String getScope() { - return parameters.get(OAuth.OAUTH_SCOPE); + return getParam(OAuth.OAUTH_SCOPE); } + @Override public OAuthToken getOAuthToken() { - return new BasicOAuthToken(getAccessToken(), getExpiresIn(), getRefreshToken(), getScope()); + return new BasicOAuthToken(getAccessToken(), getTokenType(), getExpiresIn(), getRefreshToken(), getScope()); } + @Override protected void setBody(String body) { this.body = body; parameters = OAuthUtils.decodeForm(body); } + @Override protected void setContentType(String contentType) { this.contentType = contentType; } + @Override protected void setResponseCode(int code) { this.responseCode = code; } - - public String getParam(String name) { - return parameters.get(name); - } - - - } diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthAccessTokenResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java similarity index 69% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthAccessTokenResponse.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java index 96032687..da190561 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthAccessTokenResponse.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java @@ -19,22 +19,31 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; -import org.apache.amber.oauth2.client.validator.TokenValidator; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.token.OAuthToken; +import org.apache.oltu.oauth2.client.validator.TokenValidator; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.token.OAuthToken; + +import java.util.List; +import java.util.Map; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public abstract class OAuthAccessTokenResponse extends OAuthClientResponse { + public OAuthAccessTokenResponse() { + validator = new TokenValidator(); + } + public abstract String getAccessToken(); - public abstract String getExpiresIn(); + public abstract String getTokenType(); + + public abstract Long getExpiresIn(); public abstract String getRefreshToken(); @@ -48,7 +57,11 @@ public String getBody() { @Override protected void init(String body, String contentType, int responseCode) throws OAuthProblemException { - validator = new TokenValidator(); super.init(body, contentType, responseCode); } + + @Override + protected void init(String body, String contentType, int responseCode, Map> headers) throws OAuthProblemException { + super.init(body, contentType, responseCode, headers); + } } diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthAuthzResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAuthzResponse.java similarity index 79% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthAuthzResponse.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAuthzResponse.java index fc5881f2..1cc684ef 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthAuthzResponse.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAuthzResponse.java @@ -19,24 +19,25 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; import java.util.Map; + import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.client.validator.CodeTokenValidator; -import org.apache.amber.oauth2.client.validator.CodeValidator; -import org.apache.amber.oauth2.client.validator.OAuthClientValidator; -import org.apache.amber.oauth2.client.validator.TokenValidator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.client.validator.CodeTokenValidator; +import org.apache.oltu.oauth2.client.validator.CodeValidator; +import org.apache.oltu.oauth2.client.validator.OAuthClientValidator; +import org.apache.oltu.oauth2.client.validator.TokenValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthAuthzResponse extends OAuthClientResponse { @@ -80,8 +81,9 @@ public String getAccessToken() { return getParam(OAuth.OAUTH_ACCESS_TOKEN); } - public String getExpiresIn() { - return getParam(OAuth.OAUTH_EXPIRES_IN); + public Long getExpiresIn() { + String value = getParam(OAuth.OAUTH_EXPIRES_IN); + return value == null? null: Long.valueOf(value); } public String getScope() { @@ -100,10 +102,6 @@ public HttpServletRequest getRequest() { return request; } - public String getParam(String key) { - return this.parameters.get(key); - } - protected void setBody(String body) { this.body = body; } diff --git a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthClientResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthClientResponse.java new file mode 100644 index 00000000..0949a998 --- /dev/null +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthClientResponse.java @@ -0,0 +1,130 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.client.response; + +import org.apache.oltu.oauth2.client.validator.OAuthClientValidator; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * + * + */ +public abstract class OAuthClientResponse { + + protected String body; + protected String contentType; + protected int responseCode; + protected Map> headers; + + protected OAuthClientValidator validator; + protected Map parameters = new HashMap(); + + public String getParam(String param) { + Object value = parameters.get(param); + return value == null ? null : String.valueOf(value); + } + + public int getResponseCode() { + return responseCode; + } + + public void setHeaders(Map> headers) { + this.headers = headers; + } + + /** + * Allows setting the response body to a String value. + * + * @param body A String representing the response body. + * @throws OAuthProblemException + * @throws UnsupportedOperationException for subclasses that only + * support InputStream as body + */ + protected void setBody(String body) throws OAuthProblemException { + throw new UnsupportedOperationException(); + } + + /** + * Allows setting the response body to an InputStream value. + * + * @param body An InputStream representing the response body. + * @throws OAuthProblemException + * @throws UnsupportedOperationException for subclasses that only + * support String as body + */ + protected void setBody(InputStream body) throws OAuthProblemException { + throw new UnsupportedOperationException(); + } + + protected abstract void setContentType(String contentType); + + protected abstract void setResponseCode(int responseCode); + + protected void init(String body, String contentType, int responseCode, Map> headers) + throws OAuthProblemException { + this.setBody(body); + this.setContentType(contentType); + this.setResponseCode(responseCode); + this.setHeaders(headers); + this.validate(); + } + + protected void init(String body, String contentType, int responseCode) + throws OAuthProblemException { + init(body, contentType, responseCode, new HashMap>()); + } + + /** + * Default implementation that converts the body InputStream to a String and delegates + * to {@link #init(String, String, int)}. + *
+ * This implementation ensures backwards compatibility, as many subclasses expect String + * type bodies. At the same time it can be overridden to also deal with binary InputStreams. + * + * @param body an InputStream representing the response body + * @param contentType the content type of the response. + * @param responseCode the HTTP response code of the response. + * @param headers The HTTP response headers + * @throws OAuthProblemException + */ + protected void init(InputStream body, String contentType, int responseCode, Map> headers) + throws OAuthProblemException { + try { + init(OAuthUtils.saveStreamAsString(body), contentType, responseCode); + } catch (final IOException e) { + throw OAuthProblemException.error(e.getMessage()); + } + } + + protected void validate() throws OAuthProblemException { + validator.validate(this); + } + +} diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthClientResponseFactory.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthClientResponseFactory.java similarity index 55% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthClientResponseFactory.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthClientResponseFactory.java index 31732a97..872435be 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthClientResponseFactory.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthClientResponseFactory.java @@ -19,23 +19,28 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import java.util.List; +import java.util.Map; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClientResponseFactory { public static OAuthClientResponse createGitHubTokenResponse(String body, String contentType, int responseCode) - throws OAuthProblemException { + throws OAuthProblemException { GitHubTokenResponse resp = new GitHubTokenResponse(); resp.init(body, contentType, responseCode); return resp; @@ -43,7 +48,7 @@ public static OAuthClientResponse createGitHubTokenResponse(String body, String public static OAuthClientResponse createJSONTokenResponse(String body, String contentType, int responseCode) - throws OAuthProblemException { + throws OAuthProblemException { OAuthJSONAccessTokenResponse resp = new OAuthJSONAccessTokenResponse(); resp.init(body, contentType, responseCode); return resp; @@ -51,16 +56,31 @@ public static OAuthClientResponse createJSONTokenResponse(String body, String co public static T createCustomResponse(String body, String contentType, int responseCode, + Map> headers, Class clazz) - throws OAuthSystemException, OAuthProblemException { + throws OAuthSystemException, OAuthProblemException { - OAuthClientResponse resp = (OAuthClientResponse)OAuthUtils - .instantiateClassWithParameters(clazz, null, null); + OAuthClientResponse resp = OAuthUtils + .instantiateClassWithParameters(clazz, null, null); - resp.init(body, contentType, responseCode); + resp.init(body, contentType, responseCode, headers); - return (T)resp; + return (T) resp; } + public static T createCustomResponse(InputStream body, String contentType, + int responseCode, + Map> headers, + Class clazz) + throws OAuthSystemException, OAuthProblemException { + + T resp = OAuthUtils.instantiateClassWithParameters(clazz, null, null); + + if (body == null) { + body = new ByteArrayInputStream(new byte[0]); + } + resp.init(body, contentType, responseCode, headers); + return resp; + } } diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthErrorResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthErrorResponse.java similarity index 85% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthErrorResponse.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthErrorResponse.java index 48410939..90b5db24 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthErrorResponse.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthErrorResponse.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthErrorResponse { diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthJSONAccessTokenResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java similarity index 63% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthJSONAccessTokenResponse.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java index 8b82ee06..a1f6604b 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthJSONAccessTokenResponse.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java @@ -19,46 +19,52 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.token.BasicOAuthToken; -import org.apache.amber.oauth2.common.token.OAuthToken; -import org.apache.amber.oauth2.common.utils.JSONUtils; -import org.codehaus.jettison.json.JSONException; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.token.BasicOAuthToken; +import org.apache.oltu.oauth2.common.token.OAuthToken; +import org.apache.oltu.oauth2.common.utils.JSONUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthJSONAccessTokenResponse extends OAuthAccessTokenResponse { public OAuthJSONAccessTokenResponse() { + super(); } @Override public String getAccessToken() { - return parameters.get(OAuth.OAUTH_ACCESS_TOKEN); + return getParam(OAuth.OAUTH_ACCESS_TOKEN); + } + + @Override + public String getTokenType() { + return getParam(OAuth.OAUTH_TOKEN_TYPE); } @Override - public String getExpiresIn() { - return parameters.get(OAuth.OAUTH_EXPIRES_IN); + public Long getExpiresIn() { + String value = getParam(OAuth.OAUTH_EXPIRES_IN); + return value == null? null: Long.valueOf(value); } public String getScope() { - return parameters.get(OAuth.OAUTH_SCOPE); + return getParam(OAuth.OAUTH_SCOPE); } public OAuthToken getOAuthToken() { - return new BasicOAuthToken(getAccessToken(), getExpiresIn(), getRefreshToken(), getScope()); + return new BasicOAuthToken(getAccessToken(), getTokenType(), getExpiresIn(), getRefreshToken(), getScope()); } public String getRefreshToken() { - return parameters.get(OAuth.OAUTH_REFRESH_TOKEN); + return getParam(OAuth.OAUTH_REFRESH_TOKEN); } protected void setBody(String body) throws OAuthProblemException { @@ -66,7 +72,7 @@ protected void setBody(String body) throws OAuthProblemException { try { this.body = body; parameters = JSONUtils.parseJSON(body); - } catch (JSONException e) { + } catch (Throwable e) { throw OAuthProblemException.error(OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE, "Invalid response! Response body is not " + OAuth.ContentType.JSON + " encoded"); } @@ -81,8 +87,4 @@ protected void setResponseCode(int code) { this.responseCode = code; } - public String getParam(String name) { - return parameters.get(name); - } - } diff --git a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthResourceResponse.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthResourceResponse.java new file mode 100644 index 00000000..7e6f26ad --- /dev/null +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthResourceResponse.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.client.response; + +import org.apache.oltu.oauth2.client.validator.ResourceValidator; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +public class OAuthResourceResponse extends OAuthClientResponse { + + private static final Logger LOG = LoggerFactory.getLogger(OAuthResourceResponse.class); + + private InputStream inputStream; + + private boolean bodyRetrieved = false; + + public OAuthResourceResponse() { + this.validator = new ResourceValidator(); + } + + public String getBody() { + if (bodyRetrieved && body == null) { + throw new IllegalStateException("Cannot call getBody() after getBodyAsInputStream()"); + } + + if (body == null) { + try { + body = OAuthUtils.saveStreamAsString(getBodyAsInputStream()); + inputStream = null; + } catch (IOException e) { + LOG.error("Failed to convert InputStream to String", e); + } + } + return body; + } + + public int getResponseCode() { + return responseCode; + } + + public String getContentType() { + return contentType; + } + + @Override + protected void setBody(InputStream body) throws OAuthProblemException { + this.inputStream = body; + } + + @Override + protected void setBody(String body) throws OAuthProblemException { + this.body = body; + } + + public Map> getHeaders() { + return headers; + } + + public InputStream getBodyAsInputStream() { + if (bodyRetrieved && inputStream == null) { + throw new IllegalStateException("Cannot call getBodyAsInputStream() after getBody()"); + } + bodyRetrieved = true; + return inputStream; + } + + protected void setContentType(String contentType) { + this.contentType = contentType; + } + + @Override + protected void setResponseCode(int responseCode) { + this.responseCode = responseCode; + } + + @Override + protected void init(InputStream body, String contentType, int responseCode, Map> headers) throws OAuthProblemException { + this.setBody(body); + this.setContentType(contentType); + this.setResponseCode(responseCode); + this.setHeaders(headers); + } +} diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/CodeTokenValidator.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/CodeTokenValidator.java similarity index 82% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/CodeTokenValidator.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/CodeTokenValidator.java index 4cb06b9e..957d9f12 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/CodeTokenValidator.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/CodeTokenValidator.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class CodeTokenValidator extends OAuthClientValidator { diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/CodeValidator.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/CodeValidator.java similarity index 82% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/CodeValidator.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/CodeValidator.java index 9c3583fe..3caa80b3 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/CodeValidator.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/CodeValidator.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class CodeValidator extends OAuthClientValidator { diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/OAuthClientValidator.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/OAuthClientValidator.java similarity index 87% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/OAuthClientValidator.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/OAuthClientValidator.java index 4a7a40bf..ee9fa60d 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/OAuthClientValidator.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/OAuthClientValidator.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; import java.util.ArrayList; import java.util.HashMap; @@ -28,16 +28,16 @@ import java.util.Map; import java.util.Set; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public abstract class OAuthClientValidator { @@ -60,7 +60,7 @@ public void validateErrorResponse(OAuthClientResponse response) throws OAuthProb String errorDesc = response.getParam(OAuthError.OAUTH_ERROR_DESCRIPTION); String errorUri = response.getParam(OAuthError.OAUTH_ERROR_URI); String state = response.getParam(OAuth.OAUTH_STATE); - throw OAuthProblemException.error(error).description(errorDesc).uri(errorUri).state(state); + throw OAuthProblemException.error(error).description(errorDesc).uri(errorUri).responseStatus(response.getResponseCode()).state(state); } } diff --git a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/ResourceValidator.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/ResourceValidator.java new file mode 100644 index 00000000..d35cfcef --- /dev/null +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/ResourceValidator.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.client.validator; + +public class ResourceValidator extends OAuthClientValidator { + + public ResourceValidator() { + } +} diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/TokenValidator.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/TokenValidator.java similarity index 81% rename from oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/TokenValidator.java rename to oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/TokenValidator.java index 7ccc20f0..6b73d05e 100644 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/validator/TokenValidator.java +++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/validator/TokenValidator.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class TokenValidator extends OAuthClientValidator { diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/OAuthClientTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java similarity index 79% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/OAuthClientTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java index f9f9afdd..b247ccdd 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/OAuthClientTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/OAuthClientTest.java @@ -19,29 +19,30 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client; +package org.apache.oltu.oauth2.client; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import org.apache.amber.oauth2.client.OAuthClient; -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; import org.junit.Test; -import org.apache.amber.oauth2.client.response.GitHubTokenResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.GitHubTokenResponse; +import org.apache.oltu.oauth2.common.OAuthProviderType; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; /** * Simple example that shows how to get OAuth 2.0 access token from Facebook * using Amber OAuth 2.0 library * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClientTest { @@ -49,7 +50,7 @@ public static void main(String[] args) throws OAuthSystemException, IOException try { OAuthClientRequest request = OAuthClientRequest - .authorizationLocation("https://graph.facebook.com/oauth/authorize") + .authorizationProvider(OAuthProviderType.FACEBOOK) .setClientId("131804060198305") .setRedirectURI("http://localhost:8080/") .buildQueryMessage(); @@ -62,7 +63,7 @@ public static void main(String[] args) throws OAuthSystemException, IOException String code = br.readLine(); request = OAuthClientRequest - .tokenLocation("https://graph.facebook.com/oauth/access_token") + .tokenProvider(OAuthProviderType.FACEBOOK) .setGrantType(GrantType.AUTHORIZATION_CODE) .setClientId("131804060198305") .setClientSecret("3acb294b071c9aec86d60ae3daf32a93") diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/GitHubTokenResponseTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponseTest.java similarity index 87% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/GitHubTokenResponseTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponseTest.java index 01e95856..ee1c8981 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/GitHubTokenResponseTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponseTest.java @@ -19,14 +19,14 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; import org.junit.Test; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class GitHubTokenResponseTest { @Test diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthAuthorizationResponseImplTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthAuthorizationResponseImplTest.java similarity index 96% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthAuthorizationResponseImplTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthAuthorizationResponseImplTest.java index 24c0d248..e834a46b 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthAuthorizationResponseImplTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthAuthorizationResponseImplTest.java @@ -19,18 +19,19 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.client.utils.TestUtils; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse; +import org.apache.oltu.oauth2.client.utils.TestUtils; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import static org.easymock.EasyMock.createStrictMock; import static org.easymock.EasyMock.expect; @@ -40,9 +41,9 @@ import static org.junit.Assert.fail; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthAuthorizationResponseImplTest { diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthClientResponseFactoryTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthClientResponseFactoryTest.java similarity index 70% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthClientResponseFactoryTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthClientResponseFactoryTest.java index 5d192185..a8c8a21d 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthClientResponseFactoryTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthClientResponseFactoryTest.java @@ -19,19 +19,18 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.client.response.OAuthClientResponseFactory; -import org.junit.Assert; +import static org.junit.Assert.assertNotNull; + +import org.apache.oltu.oauth2.common.OAuth; import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClientResponseFactoryTest { @@ -39,14 +38,14 @@ public class OAuthClientResponseFactoryTest { public void testCreateGitHubTokenResponse() throws Exception { OAuthClientResponse gitHubTokenResponse = OAuthClientResponseFactory .createGitHubTokenResponse("access_token=123", OAuth.ContentType.URL_ENCODED, 200); - Assert.assertNotNull(gitHubTokenResponse); + assertNotNull(gitHubTokenResponse); } @Test public void testCreateJSONTokenResponse() throws Exception { OAuthClientResponse jsonTokenResponse = OAuthClientResponseFactory - .createJSONTokenResponse("{'access_token':'123'}", OAuth.ContentType.JSON, 200); - Assert.assertNotNull(jsonTokenResponse); + .createJSONTokenResponse("{\"access_token\":\"123\"}", OAuth.ContentType.JSON, 200); + assertNotNull(jsonTokenResponse); } @Test diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java similarity index 83% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java index ad50a9a5..205235e8 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java @@ -19,21 +19,22 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.response; +package org.apache.oltu.oauth2.client.response; -import org.apache.amber.oauth2.client.utils.TestUtils; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.client.utils.TestUtils; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.amber.oauth2.common.error.OAuthError; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthJSONAccessTokenResponseTest extends Assert { @@ -41,7 +42,6 @@ public class OAuthJSONAccessTokenResponseTest extends Assert { @Test public void testGetAccessToken() throws Exception { - logger.info("Running test: testGetAccessToken " + this.getClass().getName()); OAuthJSONAccessTokenResponse r = null; try { r = new OAuthJSONAccessTokenResponse(); @@ -64,9 +64,8 @@ public void testGetAccessToken() throws Exception { } @Test - public void testGetExpiresIn() throws Exception { + public void testGetTokenType() throws Exception { OAuthJSONAccessTokenResponse r = null; - try { r = new OAuthJSONAccessTokenResponse(); r.init(TestUtils.VALID_JSON_RESPONSE, @@ -75,10 +74,10 @@ public void testGetExpiresIn() throws Exception { fail("Exception not expected"); } - Assert.assertEquals(TestUtils.EXPIRES_IN, r.getExpiresIn()); + Assert.assertEquals(TestUtils.TOKEN_TYPE, r.getTokenType()); try { - new OAuthJSONAccessTokenResponse(); + r = new OAuthJSONAccessTokenResponse(); r.init(TestUtils.ERROR_JSON_BODY, OAuth.ContentType.JSON, 200); fail("Exception expected"); @@ -87,6 +86,23 @@ public void testGetExpiresIn() throws Exception { } } + @Test + public void testGetExpiresIn() throws Exception { + OAuthJSONAccessTokenResponse r = null; + + try { + r = new OAuthJSONAccessTokenResponse(); + r.init(TestUtils.VALID_JSON_RESPONSE, + OAuth.ContentType.JSON, 200); + } catch (OAuthProblemException e) { + fail("Exception not expected"); + } + + Assert.assertEquals(TestUtils.EXPIRES_IN, r.getExpiresIn()); + + initAndAssertError(r); + } + @Test public void testGetScope() throws Exception { OAuthJSONAccessTokenResponse r = null; @@ -100,6 +116,10 @@ public void testGetScope() throws Exception { Assert.assertEquals(TestUtils.SCOPE, r.getScope()); + initAndAssertError(r); + } + + private void initAndAssertError(OAuthJSONAccessTokenResponse r) { try { new OAuthJSONAccessTokenResponse(); r.init(TestUtils.ERROR_JSON_BODY, @@ -107,7 +127,6 @@ public void testGetScope() throws Exception { fail("Exception expected"); } catch (OAuthProblemException e) { Assert.assertNotNull(e.getError()); - } } @@ -124,14 +143,7 @@ public void testGetRefreshToken() throws Exception { Assert.assertEquals(TestUtils.REFRESH_TOKEN, r.getRefreshToken()); - try { - new OAuthJSONAccessTokenResponse(); - r.init(TestUtils.ERROR_JSON_BODY, - OAuth.ContentType.JSON, 200); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertNotNull(e.getError()); - } + initAndAssertError(r); } @Test @@ -147,7 +159,7 @@ public void testSetBody() throws Exception { } String accessToken = r.getAccessToken(); - String expiresIn = r.getExpiresIn(); + Long expiresIn = r.getExpiresIn(); Assert.assertEquals(TestUtils.EXPIRES_IN, expiresIn); Assert.assertEquals(TestUtils.ACCESS_TOKEN, accessToken); diff --git a/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthResourceResponseTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthResourceResponseTest.java new file mode 100644 index 00000000..67bfca7f --- /dev/null +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthResourceResponseTest.java @@ -0,0 +1,97 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.client.response; + +import org.apache.commons.codec.Charsets; +import org.apache.commons.io.IOUtils; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +/** + * + * + * + */ +public class OAuthResourceResponseTest { + + private static final byte[] BINARY = new byte[]{ 0, 1, 2, 3, 4, 5 }; + + public static final String STRING = "roundtrip"; + + private static final byte[] STRING_BYTES = STRING.getBytes(Charsets.UTF_8); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void allowBinaryResponseBody() throws OAuthProblemException, OAuthSystemException, IOException { + final OAuthResourceResponse resp = createBinaryResponse(BINARY); + final byte[] bytes = IOUtils.toByteArray(resp.getBodyAsInputStream()); + assertArrayEquals(BINARY, bytes); + } + + @Test + public void allowStringAsBinaryResponseBody() throws OAuthProblemException, OAuthSystemException, IOException { + final OAuthResourceResponse resp = createBinaryResponse(STRING_BYTES); + final byte[] bytes = IOUtils.toByteArray(resp.getBodyAsInputStream()); + assertArrayEquals(STRING_BYTES, bytes); + } + + @Test + public void allowStringResponseBody() throws OAuthProblemException, OAuthSystemException, IOException { + final OAuthResourceResponse resp = createBinaryResponse(STRING_BYTES); + assertEquals("getBody() should return correct string", STRING, resp.getBody()); + } + + @Test + public void errorRetrievingBodyAfterStream() throws OAuthProblemException, OAuthSystemException, IOException { + final OAuthResourceResponse resp = createBinaryResponse(STRING_BYTES); + resp.getBodyAsInputStream(); + expectedException.expect(IllegalStateException.class); + resp.getBody(); + } + + @Test + public void errorRetrievingStreamAfterBody() throws OAuthProblemException, OAuthSystemException, IOException { + final OAuthResourceResponse resp = createBinaryResponse(STRING_BYTES); + resp.getBody(); + expectedException.expect(IllegalStateException.class); + resp.getBodyAsInputStream(); + } + + private OAuthResourceResponse createBinaryResponse(byte[] bytes) throws OAuthSystemException, OAuthProblemException { + final ByteArrayInputStream binaryStream = new ByteArrayInputStream(bytes); + return OAuthClientResponseFactory.createCustomResponse(binaryStream, null, 200, new HashMap>(), OAuthResourceResponse.class); + } + +} diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/utils/TestUtils.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java similarity index 79% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/utils/TestUtils.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java index 7e39625b..7f694fbd 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/utils/TestUtils.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java @@ -19,19 +19,19 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.utils; +package org.apache.oltu.oauth2.client.utils; + +import static org.easymock.EasyMock.expect; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.error.OAuthError; - -import static org.easymock.EasyMock.expect; +import org.apache.oltu.oauth2.common.error.OAuthError; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public final class TestUtils { private TestUtils() { @@ -39,10 +39,11 @@ private TestUtils() { public static final String VALID_JSON_RESPONSE = "{\"expires_in\":3600,\"access_token\":\"b52d434791fd52316232b6cf2d3\",\"scope\":\"read\"," - + "\"refresh_token\":\"test_refresh_token\"}"; + + "\"token_type\":\"bearer\",\"refresh_token\":\"test_refresh_token\"}"; - public static final String EXPIRES_IN = "3600"; + public static final Long EXPIRES_IN = 3600l; public static final String ACCESS_TOKEN = "b52d434791fd52316232b6cf2d3"; + public static final String TOKEN_TYPE = "bearer"; public static final String SCOPE = "read"; public static final String REFRESH_TOKEN = "test_refresh_token"; @@ -50,11 +51,6 @@ private TestUtils() { = "{\"error_uri\":\"null\",\"error\":\"invalid_request\",\"state\":\"null\",\"error_description\":" + "\"Invalid grant_type parameter value\"}"; - public static final String INVALID_JSON - = "\"expires_in\":3600,\"access_token\":\"b52d434791fd52316232b6cf2d3\"}"; - -// public static final String - public static void expectNoErrorParameters(HttpServletRequest request) { expect(request.getParameter(OAuthError.OAUTH_ERROR)) .andStubReturn(null); diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/CodeTokenValidatorTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/CodeTokenValidatorTest.java similarity index 71% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/CodeTokenValidatorTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/CodeTokenValidatorTest.java index 80dc691a..f5fa2036 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/CodeTokenValidatorTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/CodeTokenValidatorTest.java @@ -19,19 +19,17 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; -import org.apache.amber.oauth2.client.validator.CodeTokenValidator; -import org.apache.amber.oauth2.client.validator.OAuthClientValidator; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; import org.junit.Assert; import org.junit.Test; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class CodeTokenValidatorTest { @@ -42,8 +40,8 @@ public void testValidator() { OAuthClientValidator validator = new CodeTokenValidator(); Assert.assertNotNull(validator.requiredParams); Assert.assertEquals(2, validator.requiredParams.size()); - Assert.assertArrayEquals(new String[] {}, validator.requiredParams.get(OAuth.OAUTH_CODE)); - Assert.assertArrayEquals(new String[] {}, validator.requiredParams.get(OAuth.OAUTH_ACCESS_TOKEN)); + Assert.assertArrayEquals(new String[]{}, validator.requiredParams.get(OAuth.OAUTH_CODE)); + Assert.assertArrayEquals(new String[]{}, validator.requiredParams.get(OAuth.OAUTH_ACCESS_TOKEN)); Assert.assertNotNull(validator.notAllowedParams); Assert.assertEquals(1, validator.notAllowedParams.size()); Assert.assertTrue(validator.notAllowedParams.contains(OAuth.OAUTH_ACCESS_TOKEN)); diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/CodeValidatorTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/CodeValidatorTest.java similarity index 80% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/CodeValidatorTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/CodeValidatorTest.java index 8048a474..77e113c4 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/CodeValidatorTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/CodeValidatorTest.java @@ -19,18 +19,18 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; -import org.apache.amber.oauth2.client.validator.CodeValidator; -import org.apache.amber.oauth2.client.validator.OAuthClientValidator; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.client.validator.CodeValidator; +import org.apache.oltu.oauth2.client.validator.OAuthClientValidator; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class CodeValidatorTest { diff --git a/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/OAuthClientValidatorTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/OAuthClientValidatorTest.java new file mode 100644 index 00000000..b3c3029b --- /dev/null +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/OAuthClientValidatorTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.client.validator; + +import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class OAuthClientValidatorTest { + + private static final String OAUTH_ERROR_JSON = "{\"error\":\"invalid_client\"}"; + + @Test + public void shouldReturnExceptionWithSpecificResponseCode() throws OAuthProblemException { + try { + OAuthClientResponseFactory.createJSONTokenResponse(OAUTH_ERROR_JSON, OAuth.ContentType.JSON, 401); + fail(); + } catch (OAuthProblemException e) { + assertEquals(401, e.getResponseStatus()); + } + } +} \ No newline at end of file diff --git a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/TokenValidatorTest.java b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/TokenValidatorTest.java similarity index 80% rename from oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/TokenValidatorTest.java rename to oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/TokenValidatorTest.java index fafc073c..be9b2746 100644 --- a/oauth-2.0/oauth2-client/src/test/java/org/apache/amber/oauth2/client/validator/TokenValidatorTest.java +++ b/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/validator/TokenValidatorTest.java @@ -19,19 +19,19 @@ * limitations under the License. */ -package org.apache.amber.oauth2.client.validator; +package org.apache.oltu.oauth2.client.validator; -import org.apache.amber.oauth2.client.validator.OAuthClientValidator; -import org.apache.amber.oauth2.client.validator.TokenValidator; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.client.validator.OAuthClientValidator; +import org.apache.oltu.oauth2.client.validator.TokenValidator; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class TokenValidatorTest { diff --git a/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties b/oauth-2.0/client/src/test/resources/log4j.properties similarity index 100% rename from oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties rename to oauth-2.0/client/src/test/resources/log4j.properties diff --git a/oauth-2.0/common/pom.xml b/oauth-2.0/common/pom.xml new file mode 100644 index 00000000..7243e783 --- /dev/null +++ b/oauth-2.0/common/pom.xml @@ -0,0 +1,90 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.common + bundle + + Apache Oltu - OAuth 2.0 - Common + OAuth 2.0 library - Common + + + + org.apache.geronimo.specs + geronimo-json_1.1_spec + + + + commons-codec + commons-codec + + + + + org.apache.johnzon + johnzon-core + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/TestOAuthClient.java + **/TestOAuthClient.java + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + org/apache/oltu/oauth2/common/message/types/**.class + org/apache/oltu/oauth2/common/OAuth**.class + + + + + + + + diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/OAuth.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuth.java similarity index 85% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/OAuth.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuth.java index dfeb3046..7b466c3a 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/OAuth.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuth.java @@ -19,14 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common; +package org.apache.oltu.oauth2.common; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.message.types.TokenType; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public final class OAuth { @@ -64,18 +65,25 @@ public static final class ContentType { public static final String OAUTH_STATE = "state"; public static final String OAUTH_GRANT_TYPE = "grant_type"; - public static final String OAUTH_HEADER_NAME = "OAuth"; + public static final String OAUTH_HEADER_NAME = "Bearer"; //Authorization response params public static final String OAUTH_CODE = "code"; public static final String OAUTH_ACCESS_TOKEN = "access_token"; public static final String OAUTH_EXPIRES_IN = "expires_in"; public static final String OAUTH_REFRESH_TOKEN = "refresh_token"; + + public static final String OAUTH_TOKEN_TYPE = "token_type"; public static final String OAUTH_TOKEN = "oauth_token"; public static final String OAUTH_TOKEN_DRAFT_0 = "access_token"; + public static final String OAUTH_BEARER_TOKEN = "access_token"; public static final ParameterStyle DEFAULT_PARAMETER_STYLE = ParameterStyle.HEADER; + public static final TokenType DEFAULT_TOKEN_TYPE = TokenType.BEARER; + public static final String OAUTH_VERSION_DIFFER = "oauth_signature_method"; + + public static final String ASSERTION ="assertion"; } diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java new file mode 100644 index 00000000..a6524e37 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/OAuthProviderType.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common; + +/** + * An enumeration of pre-identified and well known OAuth 2 providers, along + * with their authorization and token endpoints. + */ +public enum OAuthProviderType { + + FACEBOOK( + "facebook", + "https://graph.facebook.com/oauth/authorize", + "https://graph.facebook.com/oauth/access_token"), + + FOURSQUARE( + "foursquare", + "https://foursquare.com/oauth2/authenticate", + "https://foursquare.com/oauth2/access_token"), + + GITHUB( + "GitHub", + "https://github.com/login/oauth/authorize", + "https://github.com/login/oauth/access_token"), + + GOOGLE( + "Google", + "https://accounts.google.com/o/oauth2/auth", + "https://accounts.google.com/o/oauth2/token"), + + INSTAGRAM( + "Instagram", + "https://api.instagram.com/oauth/authorize", + "https://api.instagram.com/oauth/access_token"), + + LINKEDIN( + "LinkedIn", + "https://www.linkedin.com/uas/oauth2/authorization", + "https://www.linkedin.com/uas/oauth2/accessToken"), + + MICROSOFT( + "Microsoft", + "https://login.live.com/oauth20_authorize.srf", + "https://login.live.com/oauth20_token.srf"), + + PAYPAL( + "PayPal", + "https://identity.x.com/xidentity/resources/authorize", + "https://identity.x.com/xidentity/oauthtokenservice"), + + REDDIT( + "reddit", + "https://ssl.reddit.com/api/v1/authorize", + "https://ssl.reddit.com/api/v1/access_token"), + + SALESFORCE( + "salesforce", + "https://login.salesforce.com/services/oauth2/authorize", + "https://login.salesforce.com/services/oauth2/token"), + + YAMMER( + "Yammer", + "https://www.yammer.com/dialog/oauth", + "https://www.yammer.com/oauth2/access_token.json"); + + private String providerName; + + private String authzEndpoint; + + private String tokenEndpoint; + + /** + * Get the provider name + * + * @return Returns the provider name + */ + public String getProviderName() { + return providerName; + } + + /** + * Get the authorization endpoint + * + * @return Returns the authorization endpoint + */ + public String getAuthzEndpoint() { + return authzEndpoint; + } + + /** + * Get the access token endpoint + * + * @return Returns the access token endpoint + */ + public String getTokenEndpoint() { + return tokenEndpoint; + } + + /** + * Full private constructor + * + * @param providerName The provider name + * @param authzEndpoint The authorization endpoint + * @param tokenEndpoint The token endpoint + */ + private OAuthProviderType( + final String providerName, + final String authzEndpoint, + final String tokenEndpoint) { + + this.providerName = providerName; + this.authzEndpoint = authzEndpoint; + this.tokenEndpoint = tokenEndpoint; + } + +} \ No newline at end of file diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/BasicClientInfo.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/BasicClientInfo.java similarity index 92% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/BasicClientInfo.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/BasicClientInfo.java index 4cad9aa9..ee9986bf 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/BasicClientInfo.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/BasicClientInfo.java @@ -18,12 +18,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.oauth2.common.domain.client; +package org.apache.oltu.oauth2.common.domain.client; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class BasicClientInfo implements ClientInfo { diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/BasicClientInfoBuilder.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/BasicClientInfoBuilder.java similarity index 93% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/BasicClientInfoBuilder.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/BasicClientInfoBuilder.java index f9bbceca..f1260683 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/BasicClientInfoBuilder.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/BasicClientInfoBuilder.java @@ -18,10 +18,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.oauth2.common.domain.client; +package org.apache.oltu.oauth2.common.domain.client; /** - * @author Maciej Machulak */ public class BasicClientInfoBuilder { diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/ClientInfo.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/ClientInfo.java similarity index 82% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/ClientInfo.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/ClientInfo.java index 01ef1175..fda61719 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/client/ClientInfo.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/client/ClientInfo.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.domain.client; +package org.apache.oltu.oauth2.common.domain.client; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface ClientInfo { diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/BasicCredentials.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/BasicCredentials.java similarity index 69% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/BasicCredentials.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/BasicCredentials.java index 63b25eb4..924fceb1 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/BasicCredentials.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/BasicCredentials.java @@ -1,16 +1,29 @@ /** - * Copyright 2011 Newcastle University. All rights reserved. - * Maciej Machulak, Lukasz Moren, Aad van Moorsel + * Copyright 2010 Newcastle University * - * http://research.ncl.ac.uk/smart/ + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - -package org.apache.amber.oauth2.common.domain.credentials; +package org.apache.oltu.oauth2.common.domain.credentials; import java.lang.Long;import java.lang.Object;import java.lang.Override;import java.lang.String; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class BasicCredentials implements Credentials { diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/BasicCredentialsBuilder.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/BasicCredentialsBuilder.java new file mode 100644 index 00000000..ddea8983 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/BasicCredentialsBuilder.java @@ -0,0 +1,60 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.domain.credentials; + +/** + */ +public class BasicCredentialsBuilder { + + protected BasicCredentials credentials; + + private BasicCredentialsBuilder() { + credentials = new BasicCredentials(); + } + + public static BasicCredentialsBuilder credentials() { + return new BasicCredentialsBuilder(); + } + + public BasicCredentials build() { + return credentials; + } + + public BasicCredentialsBuilder setClientId(String value) { + credentials.setClientId(value); + return this; + } + + public BasicCredentialsBuilder setClientSecret(String value) { + credentials.setClientSecret(value); + return this; + } + + public BasicCredentialsBuilder setExpiresIn(Long value) { + credentials.setExpiresIn(value); + return this; + } + + public BasicCredentialsBuilder setIssuedAt(Long value) { + credentials.setIssuedAt(value); + return this; + } +} diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/Credentials.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/Credentials.java new file mode 100644 index 00000000..bff5c625 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/domain/credentials/Credentials.java @@ -0,0 +1,37 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.domain.credentials; + +import java.lang.Long;import java.lang.String; /** + * + * + * + */ +public interface Credentials { + + String getClientId(); + + String getClientSecret(); + + Long getIssuedAt(); + + Long getExpiresIn(); +} diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/error/OAuthError.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/error/OAuthError.java new file mode 100644 index 00000000..7b428c8e --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/error/OAuthError.java @@ -0,0 +1,157 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.common.error; + +/** + * + * + * + */ +public abstract class OAuthError { + + //error response params + public static final String OAUTH_ERROR = "error"; + public static final String OAUTH_ERROR_DESCRIPTION = "error_description"; + public static final String OAUTH_ERROR_URI = "error_uri"; + + public static final class CodeResponse { + /** + * The request is missing a required parameter, includes an + unsupported parameter value, or is otherwise malformed. + */ + public static final String INVALID_REQUEST = "invalid_request"; + + /** + * The client is not authorized to request an authorization + code using this method. + */ + public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; + + /** + * The resource owner or authorization server denied the + request. + */ + public static final String ACCESS_DENIED = "access_denied"; + + /** + * The authorization server does not support obtaining an + authorization code using this method. + */ + public static final String UNSUPPORTED_RESPONSE_TYPE = "unsupported_response_type"; + + /** + * The requested scope is invalid, unknown, or malformed. + */ + public static final String INVALID_SCOPE = "invalid_scope"; + + /** + * The authorization server encountered an unexpected + condition which prevented it from fulfilling the request. + */ + public static final String SERVER_ERROR = "server_error"; + + /** + * The authorization server is currently unable to handle + the request due to a temporary overloading or maintenance + of the server. + */ + public static final String TEMPORARILY_UNAVAILABLE = "temporarily_unavailable"; + + } + + public static final class TokenResponse { + /** + The request is missing a required parameter, includes an + unsupported parameter value, repeats a parameter, + includes multiple credentials, utilizes more than one + mechanism for authenticating the client, or is otherwise + malformed. + */ + public static final String INVALID_REQUEST = "invalid_request"; + /** + Client authentication failed (e.g. unknown client, no + client authentication included, or unsupported + authentication method). The authorization server MAY + return an HTTP 401 (Unauthorized) status code to indicate + which HTTP authentication schemes are supported. If the + client attempted to authenticate via the "Authorization" + request header field, the authorization server MUST + respond with an HTTP 401 (Unauthorized) status code, and + include the "WWW-Authenticate" response header field + matching the authentication scheme used by the client. + */ + public static final String INVALID_CLIENT = "invalid_client"; + + /** + The provided authorization grant (e.g. authorization + code, resource owner credentials, client credentials) is + invalid, expired, revoked, does not match the redirection + URI used in the authorization request, or was issued to + another client. + */ + public static final String INVALID_GRANT = "invalid_grant"; + + /** + The authenticated client is not authorized to use this + authorization grant type. + */ + public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; + + /** + The authorization grant type is not supported by the + authorization server. + */ + public static final String UNSUPPORTED_GRANT_TYPE = "unsupported_grant_type"; + + /** + * The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner. + */ + public static final String INVALID_SCOPE = "invalid_scope"; + } + + public static final class ResourceResponse { + /** + The request is missing a required parameter, includes an + unsupported parameter value, repeats a parameter, + includes multiple credentials, utilizes more than one + mechanism for authenticating the client, or is otherwise + malformed. + */ + public static final String INVALID_REQUEST = "invalid_request"; + + + public static final String EXPIRED_TOKEN = "expired_token"; + + /** + * The request requires higher privileges than provided by the + * access token. + */ + public static final String INSUFFICIENT_SCOPE = "insufficient_scope"; + + /** + * The access token provided is expired, revoked, malformed, or + * invalid for other reasons. + */ + public static final String INVALID_TOKEN = "invalid_token"; + } + +} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthProblemException.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthProblemException.java similarity index 76% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthProblemException.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthProblemException.java index f8aec02f..ca0cc134 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthProblemException.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthProblemException.java @@ -19,19 +19,19 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.exception; +package org.apache.oltu.oauth2.common.exception; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public final class OAuthProblemException extends Exception { +public class OAuthProblemException extends Exception { private String error; private String description; @@ -40,13 +40,15 @@ public final class OAuthProblemException extends Exception { private String scope; private String redirectUri; + private int responseStatus; + private Map parameters = new HashMap(); - private OAuthProblemException(String error) { + protected OAuthProblemException(String error) { this(error, ""); } - private OAuthProblemException(String error, String description) { + protected OAuthProblemException(String error, String description) { super(error + " " + description); this.description = description; this.error = error; @@ -81,6 +83,11 @@ public OAuthProblemException scope(String scope) { return this; } + public OAuthProblemException responseStatus(int responseStatus) { + this.responseStatus = responseStatus; + return this; + } + public OAuthProblemException setParameter(String name, String value) { parameters.put(name, value); return this; @@ -106,6 +113,10 @@ public String getScope() { return scope; } + public int getResponseStatus() { + return responseStatus == 0 ? 400 : responseStatus; + } + public String get(String name) { return parameters.get(name); } @@ -124,7 +135,7 @@ public void setRedirectUri(String redirectUri) { @Override public String getMessage() { - StringBuffer b = new StringBuffer(); + StringBuilder b = new StringBuilder(); if (!OAuthUtils.isEmpty(error)) { b.append(error); } @@ -152,12 +163,15 @@ public String getMessage() { @Override public String toString() { - return "OAuthProblemException{" - + "description='" + description + '\'' - + ", error='" + error + '\'' - + ", uri='" + uri + '\'' - + ", state='" + state + '\'' - + ", scope='" + scope + '\'' - + '}'; + return "OAuthProblemException{" + + "error='" + error + '\'' + + ", description='" + description + '\'' + + ", uri='" + uri + '\'' + + ", state='" + state + '\'' + + ", scope='" + scope + '\'' + + ", redirectUri='" + redirectUri + '\'' + + ", responseStatus=" + responseStatus + + ", parameters=" + parameters + + '}'; } } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthRuntimeException.java similarity index 91% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthRuntimeException.java index 4db85eed..9cd3d342 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthRuntimeException.java @@ -18,10 +18,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.oauth2.common.exception; +package org.apache.oltu.oauth2.common.exception; /** - * @author Lukasz Moren */ public class OAuthRuntimeException extends RuntimeException { public OAuthRuntimeException() { diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthSystemException.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthSystemException.java similarity index 70% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthSystemException.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthSystemException.java index b6dca4a4..76916db4 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthSystemException.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/exception/OAuthSystemException.java @@ -19,27 +19,27 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.exception; +package org.apache.oltu.oauth2.common.exception; /** - * @author Maciej Machulak - * @author Lukasz Moren + * + * */ public class OAuthSystemException extends Exception { public OAuthSystemException() { - super(); //To change body of overridden methods use File | Settings | File Templates. + super(); } public OAuthSystemException(String s) { - super(s); //To change body of overridden methods use File | Settings | File Templates. + super(s); } public OAuthSystemException(Throwable throwable) { - super(throwable); //To change body of overridden methods use File | Settings | File Templates. + super(throwable); } public OAuthSystemException(String s, Throwable throwable) { - super(s, throwable); //To change body of overridden methods use File | Settings | File Templates. + super(s, throwable); } } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/OAuthMessage.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/OAuthMessage.java similarity index 86% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/OAuthMessage.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/OAuthMessage.java index 154ced65..c4905d5a 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/OAuthMessage.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/OAuthMessage.java @@ -19,14 +19,14 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.message; +package org.apache.oltu.oauth2.common.message; import java.util.Map; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface OAuthMessage { diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/OAuthResponse.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/OAuthResponse.java similarity index 85% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/OAuthResponse.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/OAuthResponse.java index 219aa238..3514ebc2 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/OAuthResponse.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/OAuthResponse.java @@ -19,25 +19,26 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.message; +package org.apache.oltu.oauth2.common.message; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.parameters.BodyURLEncodedParametersApplier; -import org.apache.amber.oauth2.common.parameters.JSONBodyParametersApplier; -import org.apache.amber.oauth2.common.parameters.OAuthParametersApplier; -import org.apache.amber.oauth2.common.parameters.QueryParameterApplier; -import org.apache.amber.oauth2.common.parameters.WWWAuthHeaderParametersApplier; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.parameters.BodyURLEncodedParametersApplier; +import org.apache.oltu.oauth2.common.parameters.FragmentParametersApplier; +import org.apache.oltu.oauth2.common.parameters.JSONBodyParametersApplier; +import org.apache.oltu.oauth2.common.parameters.OAuthParametersApplier; +import org.apache.oltu.oauth2.common.parameters.QueryParameterApplier; +import org.apache.oltu.oauth2.common.parameters.WWWAuthHeaderParametersApplier; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthResponse implements OAuthMessage { @@ -107,7 +108,7 @@ public void addHeader(String name, String header) { public static class OAuthResponseBuilder { protected OAuthParametersApplier applier; - protected Map parameters = new HashMap(); + protected Map parameters = new HashMap(); protected int responseCode; protected String location; @@ -133,6 +134,13 @@ public OAuthResponseBuilder setParam(String key, String value) { public OAuthResponse buildQueryMessage() throws OAuthSystemException { OAuthResponse msg = new OAuthResponse(location, responseCode); this.applier = new QueryParameterApplier(); + + if (parameters.containsKey(OAuth.OAUTH_ACCESS_TOKEN)) { + this.applier = new FragmentParametersApplier(); + }else{ + this.applier = new QueryParameterApplier(); + } + return (OAuthResponse)applier.applyOAuthParameters(msg, parameters); } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/GrantType.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/GrantType.java similarity index 82% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/GrantType.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/GrantType.java index 92d05b99..01491739 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/GrantType.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/GrantType.java @@ -19,19 +19,21 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.message.types; +package org.apache.oltu.oauth2.common.message.types; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public enum GrantType { + // NONE("none"), AUTHORIZATION_CODE("authorization_code"), + IMPLICIT("implicit"), PASSWORD("password"), - ASSERTION("assertion"), REFRESH_TOKEN("refresh_token"), - NONE("none"); + CLIENT_CREDENTIALS("client_credentials"), + JWT_BEARER("urn:ietf:params:oauth:grant-type:jwt-bearer"); private String grantType; diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/ParameterStyle.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/ParameterStyle.java similarity index 85% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/ParameterStyle.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/ParameterStyle.java index 5d1a1d01..4a8b3f35 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/ParameterStyle.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/ParameterStyle.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.message.types; +package org.apache.oltu.oauth2.common.message.types; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public enum ParameterStyle { BODY("body"), diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/ResponseType.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/ResponseType.java similarity index 80% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/ResponseType.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/ResponseType.java index d6166bb6..f32d0970 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/message/types/ResponseType.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/ResponseType.java @@ -19,18 +19,17 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.message.types; +package org.apache.oltu.oauth2.common.message.types; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public enum ResponseType { CODE("code"), - TOKEN("token"), - CODE_AND_TOKEN("code_and_token"); + TOKEN("token"); private String code; diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/TokenType.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/TokenType.java new file mode 100644 index 00000000..da18ae40 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/message/types/TokenType.java @@ -0,0 +1,43 @@ +package org.apache.oltu.oauth2.common.message.types; +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * + * + * + */ +public enum TokenType { + BEARER("Bearer"), + MAC("MAC"); + + private String tokenType; + + TokenType(String grantType) { + this.tokenType = grantType; + } + + @Override + public String toString() { + return tokenType; + } +} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplier.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/BodyURLEncodedParametersApplier.java similarity index 74% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplier.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/BodyURLEncodedParametersApplier.java index 5f4bd068..dcb162d4 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplier.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/BodyURLEncodedParametersApplier.java @@ -19,22 +19,22 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; import java.util.Map; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class BodyURLEncodedParametersApplier implements OAuthParametersApplier { - public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) + public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws OAuthSystemException { String body = OAuthUtils.format(params.entrySet(), "UTF-8"); diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/FragmentParametersApplier.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/FragmentParametersApplier.java new file mode 100644 index 00000000..6d64e192 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/FragmentParametersApplier.java @@ -0,0 +1,53 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.parameters; + +import java.util.Map; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; + +public class FragmentParametersApplier implements OAuthParametersApplier { + + public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws OAuthSystemException { + + String messageUrl = message.getLocationUri(); + if (messageUrl != null) { + StringBuilder url = new StringBuilder(messageUrl); + + if (params.containsKey(OAuth.OAUTH_REFRESH_TOKEN)) { + params.remove(OAuth.OAUTH_REFRESH_TOKEN); + } + + String fragmentQuery = OAuthUtils.format(params.entrySet(), "UTF-8"); + + if (!OAuthUtils.isEmpty(fragmentQuery)) { + if (params.size() > 0) { + url.append("#").append(fragmentQuery); + } + } + message.setLocationUri(url.toString()); + } + return message; + } +} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplier.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/JSONBodyParametersApplier.java similarity index 72% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplier.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/JSONBodyParametersApplier.java index 96bb940c..bf9ea2ee 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplier.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/JSONBodyParametersApplier.java @@ -19,31 +19,31 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; import java.util.Map; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.utils.JSONUtils; -import org.codehaus.jettison.json.JSONException; - -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.JSONUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class JSONBodyParametersApplier implements OAuthParametersApplier { - public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) + + public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws OAuthSystemException { String json = null; try { json = JSONUtils.buildJSON(params); message.setBody(json); return message; - } catch (JSONException e) { + } catch (Throwable e) { throw new OAuthSystemException(e); } } + } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/OAuthParametersApplier.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/OAuthParametersApplier.java similarity index 80% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/OAuthParametersApplier.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/OAuthParametersApplier.java index 82683220..ef7b361d 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/OAuthParametersApplier.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/OAuthParametersApplier.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; import java.util.Map; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; /** * Applies given parameters to the OAuth message. @@ -38,12 +38,12 @@ *

* Additional implementations can be provided. * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface OAuthParametersApplier { - OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws + OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws OAuthSystemException; } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplier.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/QueryParameterApplier.java similarity index 57% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplier.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/QueryParameterApplier.java index c5d25654..4680d349 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplier.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/QueryParameterApplier.java @@ -19,57 +19,35 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; -import java.util.HashMap; import java.util.Map; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class QueryParameterApplier implements OAuthParametersApplier { - public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) { + public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) { String messageUrl = message.getLocationUri(); if (messageUrl != null) { boolean containsQuestionMark = messageUrl.contains("?"); StringBuffer url = new StringBuffer(messageUrl); - - //apply uri fragment component if exist access_toke param - Map fragmentParams = new HashMap(); - if (params.containsKey(OAuth.OAUTH_ACCESS_TOKEN)) { - fragmentParams.put(OAuth.OAUTH_ACCESS_TOKEN, params.remove(OAuth.OAUTH_ACCESS_TOKEN)); - - if (params.containsKey(OAuth.OAUTH_EXPIRES_IN)) { - fragmentParams.put(OAuth.OAUTH_EXPIRES_IN, params.remove(OAuth.OAUTH_EXPIRES_IN)); - } - } - + StringBuffer query = new StringBuffer(OAuthUtils.format(params.entrySet(), "UTF-8")); - String fragmentQuery = ""; - if (fragmentParams.containsKey(OAuth.OAUTH_ACCESS_TOKEN)) { - fragmentQuery = OAuthUtils.format(fragmentParams.entrySet(), "UTF-8"); - } - + if (!OAuthUtils.isEmpty(query.toString())) { if (containsQuestionMark) { url.append("&").append(query); } else { url.append("?").append(query); } - } - - if (!OAuthUtils.isEmpty(fragmentQuery)) { - url.append("#").append(fragmentQuery); - } - + } message.setLocationUri(url.toString()); } return message; diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplier.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/WWWAuthHeaderParametersApplier.java similarity index 73% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplier.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/WWWAuthHeaderParametersApplier.java index 06d95a26..2bfa7a59 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplier.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/parameters/WWWAuthHeaderParametersApplier.java @@ -19,23 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; import java.util.Map; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class WWWAuthHeaderParametersApplier implements OAuthParametersApplier { - public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) + public OAuthMessage applyOAuthParameters(OAuthMessage message, Map params) throws OAuthSystemException { String header = OAuthUtils.encodeOAuthHeader(params); message.addHeader(OAuth.HeaderType.WWW_AUTHENTICATE, header); diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java new file mode 100644 index 00000000..26c90d29 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java @@ -0,0 +1,76 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.token; + +/** + * + */ +public class BasicOAuthToken implements OAuthToken { + protected String accessToken; + protected String tokenType; + protected Long expiresIn; + protected String refreshToken; + protected String scope; + + public BasicOAuthToken() { + } + + public BasicOAuthToken(String accessToken, String tokenType, Long expiresIn, String refreshToken, String scope) { + this.accessToken = accessToken; + this.tokenType = tokenType; + this.expiresIn = expiresIn; + this.refreshToken = refreshToken; + this.scope = scope; + } + + public BasicOAuthToken(String accessToken, String tokenType) { + this(accessToken, tokenType, null, null, null); + } + + public BasicOAuthToken(String accessToken, String tokenType, Long expiresIn) { + this(accessToken, tokenType, expiresIn, null, null); + } + + public BasicOAuthToken(String accessToken, String tokenType, Long expiresIn, String scope) { + this(accessToken, tokenType, expiresIn, null, scope); + } + + public String getAccessToken() { + return accessToken; + } + + @Override + public String getTokenType() { + return tokenType; + } + + public Long getExpiresIn() { + return expiresIn; + } + + public String getRefreshToken() { + return refreshToken; + } + + public String getScope() { + return scope; + } +} diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java new file mode 100644 index 00000000..72088627 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java @@ -0,0 +1,41 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.token; + +/** + * Interface declaring accessor methods for the basic fields of + * an access token response. + *

+ * See: + * http://tools.ietf.org/html/rfc6749#section-5.1 + */ +public interface OAuthToken { + + public String getAccessToken(); + + public String getTokenType(); + + public Long getExpiresIn(); + + public String getRefreshToken(); + + public String getScope(); +} diff --git a/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/utils/JSONUtils.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/utils/JSONUtils.java new file mode 100644 index 00000000..607138c3 --- /dev/null +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/utils/JSONUtils.java @@ -0,0 +1,207 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.common.utils; + +import static java.lang.String.format; + +import java.io.StringReader; +import java.io.StringWriter; +import java.lang.reflect.Array; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonNumber; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonString; +import javax.json.JsonStructure; +import javax.json.JsonValue; +import javax.json.stream.JsonGenerator; +import javax.json.stream.JsonGeneratorFactory; + +/** + * + * + * + */ +public final class JSONUtils { + + private static final JsonGeneratorFactory GENERATOR_FACTORY = Json.createGeneratorFactory(null); + + public static String buildJSON(Map params) { + final StringWriter stringWriter = new StringWriter(); + final JsonGenerator generator = GENERATOR_FACTORY.createGenerator(stringWriter); + + generator.writeStartObject(); + + for (Map.Entry param : params.entrySet()) { + String key = param.getKey(); + Object value = param.getValue(); + if (key != null && value != null) { + if (value instanceof Boolean) { + generator.write(key, (Boolean) value); + } else if (value instanceof Double) { + generator.write(key, (Double) value); + } else if (value instanceof Integer) { + generator.write(key, (Integer) value); + } else if (value instanceof BigDecimal) { + generator.write(key, (BigDecimal) value); + } else if (value instanceof BigInteger) { + generator.write(key, (BigInteger) value); + } else if (value instanceof Long) { + generator.write(key, (Long) value); + } else if (value instanceof String) { + String string = (String) value; + if (!string.isEmpty()) { + generator.write(key, string); + } + } else if (value.getClass().isArray()) { + generator.writeStartArray(key); + + for (int i = 0; i < Array.getLength(value); i++) { + witeItem(generator, Array.get(value, i)); + } + + generator.writeEnd(); + } else if (value instanceof Collection) { + generator.writeStartArray(key); + + Collection collection = (Collection) value; + for (Object item : collection) { + witeItem(generator, item); + } + + generator.writeEnd(); + } + } + } + + generator.writeEnd().close(); + + return stringWriter.toString(); + } + + private static void witeItem(JsonGenerator generator, T item) { + if (item != null) { + if (item instanceof Boolean) { + generator.write((Boolean) item); + } else if (item instanceof Double) { + generator.write((Double) item); + } else if (item instanceof Integer) { + generator.write((Integer) item); + } else if (item instanceof BigDecimal) { + generator.write((BigDecimal) item); + } else if (item instanceof BigInteger) { + generator.write((BigInteger) item); + } else if (item instanceof Long) { + generator.write((Long) item); + } else if (item instanceof String) { + generator.write((String) item); + } + } + } + + public static Map parseJSON(String jsonBody) { + final Map params = new HashMap(); + + StringReader reader = new StringReader(jsonBody); + JsonReader jsonReader = Json.createReader(reader); + JsonStructure structure = jsonReader.read(); + + if (structure == null || structure instanceof JsonArray) { + throw new IllegalArgumentException(format("String '%s' is not a valid JSON object representation", + jsonBody)); + } + + JsonObject object = (JsonObject) structure; + for (Entry entry : object.entrySet()) { + String key = entry.getKey(); + if (key != null && !key.isEmpty()) { + JsonValue jsonValue = entry.getValue(); + + // guard from null values + if (jsonValue != null) { + Object value = toJavaObject(jsonValue); + + params.put(key, value); + } + } + } + + jsonReader.close(); + return params; + } + + private static Object toJavaObject(JsonValue jsonValue) { + Object value = null; + + switch (jsonValue.getValueType()) { + case ARRAY: + JsonArray array = (JsonArray) jsonValue; + Object[] values = new Object[array.size()]; + for (int i = 0; i < array.size(); i++) { + JsonValue current = array.get(i); + values[i] = toJavaObject(current); + } + value = values; + break; + + case FALSE: + value = false; + break; + + case NULL: + value = null; + break; + + case NUMBER: + JsonNumber jsonNumber = (JsonNumber) jsonValue; + value = jsonNumber.numberValue(); + break; + + case OBJECT: + // not supported in this version + break; + + case STRING: + JsonString jsonString = (JsonString) jsonValue; + value = jsonString.getString(); + break; + + case TRUE: + value = true; + break; + + default: + break; + } + + return value; + } + +} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/utils/OAuthUtils.java similarity index 76% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/utils/OAuthUtils.java index cdbd95d3..2e705599 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/utils/OAuthUtils.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.utils; +package org.apache.oltu.oauth2.common.utils; import java.io.IOException; import java.io.InputStream; @@ -39,12 +39,14 @@ import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.commons.codec.binary.Base64; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; /** * Common OAuth Utils class. @@ -52,9 +54,9 @@ * Some methods based on the Utils class from OAuth V1.0a library available at: * http://oauth.googlecode.com/svn/code/java/core/ * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public final class OAuthUtils { @@ -62,7 +64,7 @@ public final class OAuthUtils { private static final String PARAMETER_SEPARATOR = "&"; private static final String NAME_VALUE_SEPARATOR = "="; - public static final String AUTH_SCHEME = "OAuth"; + public static final String AUTH_SCHEME = OAuth.OAUTH_HEADER_NAME; private static final Pattern OAUTH_HEADER = Pattern.compile("\\s*(\\w*)\\s+(.*)"); private static final Pattern NVP = Pattern.compile("(\\S*)\\s*\\=\\s*\"([^\"]*)\""); @@ -81,14 +83,14 @@ public final class OAuthUtils { * @return Translated string */ public static String format( - final Collection> parameters, + final Collection> parameters, final String encoding) { final StringBuilder result = new StringBuilder(); - for (final Map.Entry parameter : parameters) { + for (final Map.Entry parameter : parameters) { + String value = parameter.getValue() == null? null : String.valueOf(parameter.getValue()); if (!OAuthUtils.isEmpty(parameter.getKey()) - && !OAuthUtils.isEmpty(parameter.getValue())) { + && !OAuthUtils.isEmpty(value)) { final String encodedName = encode(parameter.getKey(), encoding); - final String value = parameter.getValue(); final String encodedValue = value != null ? encode(value, encoding) : ""; if (result.length() > 0) { result.append(PARAMETER_SEPARATOR); @@ -203,8 +205,8 @@ public static OAuthProblemException handleNotAllowedParametersOAuthException( /** * Parse a form-urlencoded document. */ - public static Map decodeForm(String form) { - Map params = new HashMap(); + public static Map decodeForm(String form) { + Map params = new HashMap(); if (!OAuthUtils.isEmpty(form)) { for (String nvp : form.split("\\&")) { int equals = nvp.indexOf('='); @@ -246,23 +248,6 @@ public static String decodePercent(String s) { } } - /** - * Construct a &-separated list of the given values, percentEncoded. - */ - public static String percentEncode(Iterable values) { - StringBuilder p = new StringBuilder(); - for (Object v : values) { - String stringValue = toString(v); - if (!isEmpty(stringValue)) { - if (p.length() > 0) { - p.append("&"); - } - p.append(OAuthUtils.percentEncode(toString(v))); - } - } - return p.toString(); - } - public static String percentEncode(String s) { if (s == null) { return ""; @@ -278,10 +263,6 @@ public static String percentEncode(String s) { } } - private static final String toString(Object from) { - return (from == null) ? null : from.toString(); - } - private static boolean isEmpty(Set missingParams) { if (missingParams == null || missingParams.size() == 0) { return true; @@ -289,16 +270,12 @@ private static boolean isEmpty(Set missingParams) { return false; } - public static Object instantiateClass(Class clazz) throws OAuthSystemException { - try { - return (Object)clazz.newInstance(); - } catch (Exception e) { - throw new OAuthSystemException(e); - } + public static T instantiateClass(Class clazz) throws OAuthSystemException { + return instantiateClassWithParameters(clazz, null, null); } - public static Object instantiateClassWithParameters(Class clazz, Class[] paramsTypes, - Object[] paramValues) throws OAuthSystemException { + public static T instantiateClassWithParameters(Class clazz, Class[] paramsTypes, + Object[] paramValues) throws OAuthSystemException { try { if (paramsTypes != null && paramValues != null) { @@ -309,7 +286,7 @@ public static Object instantiateClassWithParameters(Class clazz, Class[] paramsT if (paramsTypes.length == 0 && paramValues.length == 0) { return clazz.newInstance(); } - Constructor clazzConstructor = clazz.getConstructor(paramsTypes); + Constructor clazzConstructor = clazz.getConstructor(paramsTypes); return clazzConstructor.newInstance(paramValues); } return clazz.newInstance(); @@ -363,16 +340,69 @@ public static Map decodeOAuthHeader(String header) { // todo: implement method to decode header form (with no challenge) /** - * Construct a WWW-Authenticate or Authorization header with the OAuth challenge/credentials + * Decodes the Basic Authentication header into a username and password + * + * @param authenticationHeader {@link String} containing the encoded header value. + * e.g. "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" + * @return a {@link String[]} if the header could be decoded into a non null username and password or null. + */ + public static String[] decodeClientAuthenticationHeader(String authenticationHeader) { + if (isEmpty(authenticationHeader)) { + return null; + } + String[] tokens = authenticationHeader.split(" "); + if (tokens.length != 2) { + return null; + } + String authType = tokens[0]; + if (!"basic".equalsIgnoreCase(authType)) { + return null; + } + String encodedCreds = tokens[1]; + return decodeBase64EncodedCredentials(encodedCreds); + } + + private static String[] decodeBase64EncodedCredentials(String encodedCreds) { + String decodedCreds = new String(Base64.decodeBase64(encodedCreds)); + String[] creds = decodedCreds.split(":", 2); + if (creds.length != 2) { + return null; + } + if (!OAuthUtils.isEmpty(creds[0]) && !OAuthUtils.isEmpty(creds[1])) { + return creds; + } + return null; + } + + /** + * Construct a WWW-Authenticate header */ - public static String encodeOAuthHeader(Map entries) { + public static String encodeOAuthHeader(Map entries) { StringBuffer sb = new StringBuffer(); sb.append(OAuth.OAUTH_HEADER_NAME).append(" "); - for (Map.Entry entry : entries.entrySet()) { - if (!OAuthUtils.isEmpty(entry.getKey()) && !OAuthUtils.isEmpty(entry.getValue())) { + /* + * Android 4.1 requires realm as first parameter! + * If not set, it will throw an IOException + * see parseChallenges in + * https://android.googlesource.com/platform/libcore/+/android-4.1.2_r2/luni/src/main/java/libcore/net/http/HeaderParser.java + * more information: + * http://stackoverflow.com/questions/11810447/httpurlconnection-worked-fine-in-android-2-x-but-not-in-4-1-no-authentication-c + */ + if (entries.get("realm") != null) { + String value = String.valueOf(entries.get("realm")); + if (!OAuthUtils.isEmpty(value)) { + sb.append("realm=\""); + sb.append(value); + sb.append("\","); + } + entries.remove("realm"); + } + for (Map.Entry entry : entries.entrySet()) { + String value = entry.getValue() == null? null: String.valueOf(entry.getValue()); + if (!OAuthUtils.isEmpty(entry.getKey()) && !OAuthUtils.isEmpty(value)) { sb.append(entry.getKey()); sb.append("=\""); - sb.append(entry.getValue()); + sb.append(value); sb.append("\","); } } @@ -380,6 +410,22 @@ public static String encodeOAuthHeader(Map entries) { return sb.substring(0, sb.length() - 1); } + /** + * Construct an Authorization Bearer header + */ + public static String encodeAuthorizationBearerHeader(Map entries) { + StringBuffer sb = new StringBuffer(); + sb.append(OAuth.OAUTH_HEADER_NAME).append(" "); + for (Map.Entry entry : entries.entrySet()) { + String value = entry.getValue() == null? null: String.valueOf(entry.getValue()); + if (!OAuthUtils.isEmpty(entry.getKey()) && !OAuthUtils.isEmpty(value)) { + sb.append(value); + } + } + + return sb.toString(); + } + public static boolean isEmpty(String value) { return value == null || "".equals(value); } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/validators/AbstractValidator.java similarity index 71% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/validators/AbstractValidator.java index a748af34..5a777bde 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/validators/AbstractValidator.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.validators; +package org.apache.oltu.oauth2.common.validators; import java.util.ArrayList; import java.util.HashMap; @@ -29,22 +29,21 @@ import java.util.Set; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -//todo add client secret in header, sect 2.1 public abstract class AbstractValidator implements OAuthValidator { protected List requiredParams = new ArrayList(); protected Map optionalParams = new HashMap(); protected List notAllowedParams = new ArrayList(); - + protected boolean enforceClientAuthentication; @Override public void validateMethod(T request) throws OAuthProblemException { @@ -64,7 +63,7 @@ public void validateContentType(T request) throws OAuthProblemException { @Override public void validateRequiredParameters(T request) throws OAuthProblemException { - Set missingParameters = new HashSet(); + final Set missingParameters = new HashSet(); for (String requiredParam : requiredParams) { String val = request.getParameter(requiredParam); if (OAuthUtils.isEmpty(val)) { @@ -78,11 +77,10 @@ public void validateRequiredParameters(T request) throws OAuthProblemException { @Override public void validateOptionalParameters(T request) throws OAuthProblemException { - - Set missingParameters = new HashSet(); + final Set missingParameters = new HashSet(); for (Map.Entry requiredParam : optionalParams.entrySet()) { - String paramName = requiredParam.getKey(); + final String paramName = requiredParam.getKey(); String val = request.getParameter(paramName); if (!OAuthUtils.isEmpty(val)) { String[] dependentParams = requiredParam.getValue(); @@ -116,6 +114,30 @@ public void validateNotAllowedParameters(T request) throws OAuthProblemException } } + @Override + public void validateClientAuthenticationCredentials(T request) throws OAuthProblemException { + if (enforceClientAuthentication) { + Set missingParameters = new HashSet(); + String clientAuthHeader = request.getHeader(OAuth.HeaderType.AUTHORIZATION); + String[] clientCreds = OAuthUtils.decodeClientAuthenticationHeader(clientAuthHeader); + + // Only fallback to params if the auth header is not correct. Don't allow a mix of auth header vs params + if (clientCreds == null || OAuthUtils.isEmpty(clientCreds[0]) || OAuthUtils.isEmpty(clientCreds[1])) { + + if (OAuthUtils.isEmpty(request.getParameter(OAuth.OAUTH_CLIENT_ID))) { + missingParameters.add(OAuth.OAUTH_CLIENT_ID); + } + if (OAuthUtils.isEmpty(request.getParameter(OAuth.OAUTH_CLIENT_SECRET))) { + missingParameters.add(OAuth.OAUTH_CLIENT_SECRET); + } + } + + if (!missingParameters.isEmpty()) { + throw OAuthUtils.handleMissingParameters(missingParameters); + } + } + } + @Override public void performAllValidations(T request) throws OAuthProblemException { this.validateContentType(request); @@ -123,5 +145,6 @@ public void performAllValidations(T request) throws OAuthProblemException { this.validateRequiredParameters(request); this.validateOptionalParameters(request); this.validateNotAllowedParameters(request); + this.validateClientAuthenticationCredentials(request); } } diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/validators/OAuthValidator.java similarity index 84% rename from oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java rename to oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/validators/OAuthValidator.java index 8cead043..8eac0950 100644 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java +++ b/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/validators/OAuthValidator.java @@ -19,16 +19,16 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.validators; +package org.apache.oltu.oauth2.common.validators; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface OAuthValidator { @@ -42,6 +42,8 @@ public interface OAuthValidator { public void validateNotAllowedParameters(T request) throws OAuthProblemException; + public void validateClientAuthenticationCredentials(T request) throws OAuthProblemException; + public void performAllValidations(T request) throws OAuthProblemException; } diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/domain/BasicClientInfoBuilderTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/domain/BasicClientInfoBuilderTest.java similarity index 55% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/domain/BasicClientInfoBuilderTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/domain/BasicClientInfoBuilderTest.java index 819d4aaa..bf2c15c0 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/domain/BasicClientInfoBuilderTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/domain/BasicClientInfoBuilderTest.java @@ -1,12 +1,32 @@ -package org.apache.amber.oauth2.common.domain; +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.domain; -import org.apache.amber.oauth2.common.domain.client.BasicClientInfo; -import org.apache.amber.oauth2.common.domain.client.BasicClientInfoBuilder; +import org.apache.oltu.oauth2.common.domain.client.BasicClientInfo; +import org.apache.oltu.oauth2.common.domain.client.BasicClientInfoBuilder; import org.junit.Assert; import org.junit.Test; /** - * @author Lukasz Moren + * */ public class BasicClientInfoBuilderTest { diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/message/OAuthResponseTest.java similarity index 73% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/message/OAuthResponseTest.java index 0b0dcc4b..2aa910ae 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/message/OAuthResponseTest.java @@ -18,21 +18,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.apache.oltu.oauth2.common.message; -package org.apache.amber.oauth2.common.message; +import static org.junit.Assert.assertEquals; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.junit.Assert; +import org.apache.oltu.oauth2.common.message.OAuthResponse; import org.junit.Test; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthResponseTest { - @Test public void testErrorResponse() throws Exception { OAuthResponse oAuthResponse = OAuthResponse.errorResponse(400) @@ -45,11 +44,9 @@ public void testErrorResponse() throws Exception { .buildJSONMessage(); String body = oAuthResponse.getBody(); - Assert.assertEquals( - "{\"error_uri\":\"http:\\/\\/example-uri\",\"error\":\"error\",\"param\":\"value\"," - + "\"realm\":\"album\",\"state\":\"ok\",\"error_description\":\"error_description\"}", + assertEquals( + "{\"param\":\"value\",\"error_description\":\"error_description\",\"realm\":\"album\",\"state\":\"ok\",\"error\":\"error\",\"error_uri\":\"http://example-uri\"}", body); } - } diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java similarity index 81% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java index a137e847..c8d716a4 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java @@ -19,21 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.utils.DummyOAuthMessage; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.parameters.BodyURLEncodedParametersApplier; +import org.apache.oltu.oauth2.common.parameters.OAuthParametersApplier; +import org.apache.oltu.oauth2.common.utils.DummyOAuthMessage; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.message.OAuthMessage; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class BodyURLEncodedParametersApplierTest { @@ -42,8 +44,8 @@ public void testApplyOAuthParameters() throws Exception { OAuthParametersApplier app = new BodyURLEncodedParametersApplier(); - Map params = new HashMap(); - params.put(OAuth.OAUTH_EXPIRES_IN, "3600"); + Map params = new HashMap(); + params.put(OAuth.OAUTH_EXPIRES_IN, 3600l); params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz"); params.put(OAuth.OAUTH_CODE, "code_"); params.put(OAuth.OAUTH_SCOPE, "read"); diff --git a/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/FragmentParametersApplierTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/FragmentParametersApplierTest.java new file mode 100644 index 00000000..90c27a1f --- /dev/null +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/FragmentParametersApplierTest.java @@ -0,0 +1,65 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.common.parameters; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.DummyOAuthMessage; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class FragmentParametersApplierTest { + + @Test + public void testApplyOAuthParameters() throws Exception { + + OAuthParametersApplier app = new FragmentParametersApplier(); + + Map params = new HashMap(); + params.put(OAuth.OAUTH_EXPIRES_IN, 3600l); + params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz"); + params.put(OAuth.OAUTH_CODE, "code_"); + params.put(OAuth.OAUTH_SCOPE, "read"); + params.put(OAuth.OAUTH_STATE, "state"); + params.put(OAuth.OAUTH_REFRESH_TOKEN, "token_refresh"); + params.put("empty_param", ""); + params.put("null_param", null); + + OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200); + + app.applyOAuthParameters(message, params); + + String locationURI = message.getLocationUri(); + + Assert.assertTrue(locationURI.contains("3600")); + Assert.assertTrue(locationURI.contains("token_authz")); + Assert.assertTrue(locationURI.contains("code_")); + Assert.assertTrue(locationURI.contains("read")); + Assert.assertTrue(locationURI.contains("state")); + + Assert.assertFalse(locationURI.contains("token_refresh")); + Assert.assertFalse(locationURI.contains("empty_param")); + Assert.assertFalse(locationURI.contains("null_param")); + } +} \ No newline at end of file diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/JSONBodyParametersApplierTest.java similarity index 59% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/JSONBodyParametersApplierTest.java index 99bb90f2..a657fd44 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/JSONBodyParametersApplierTest.java @@ -19,22 +19,24 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.message.OAuthMessage; -import org.apache.amber.oauth2.common.utils.DummyOAuthMessage; -import org.apache.amber.oauth2.common.utils.JSONUtils; -import org.junit.Assert; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.utils.DummyOAuthMessage; +import org.apache.oltu.oauth2.common.utils.JSONUtils; import org.junit.Test; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class JSONBodyParametersApplierTest { @@ -43,8 +45,8 @@ public void testApplyOAuthParameters() throws Exception { OAuthParametersApplier app = new JSONBodyParametersApplier(); - Map params = new HashMap(); - params.put(OAuth.OAUTH_EXPIRES_IN, "3600"); + Map params = new HashMap(); + params.put(OAuth.OAUTH_EXPIRES_IN, 3600l); params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz"); params.put(OAuth.OAUTH_CODE, "code_"); params.put(OAuth.OAUTH_SCOPE, "read"); @@ -58,15 +60,15 @@ public void testApplyOAuthParameters() throws Exception { app.applyOAuthParameters(message, params); String msgBody = message.getBody(); - Map map = JSONUtils.parseJSON(msgBody); - Assert.assertEquals("3600", map.get(OAuth.OAUTH_EXPIRES_IN)); - Assert.assertEquals("token_authz", map.get(OAuth.OAUTH_ACCESS_TOKEN)); - Assert.assertEquals("code_", map.get(OAuth.OAUTH_CODE)); - Assert.assertEquals("read", map.get(OAuth.OAUTH_SCOPE)); - Assert.assertEquals("state", map.get(OAuth.OAUTH_STATE)); - Assert.assertNull(map.get("empty_param")); - Assert.assertNull(map.get("null_param")); - Assert.assertNull(map.get("")); - Assert.assertNull(map.get(null)); + Map map = JSONUtils.parseJSON(msgBody); + assertEquals(3600L, map.get(OAuth.OAUTH_EXPIRES_IN)); + assertEquals("token_authz", map.get(OAuth.OAUTH_ACCESS_TOKEN)); + assertEquals("code_", map.get(OAuth.OAUTH_CODE)); + assertEquals("read", map.get(OAuth.OAUTH_SCOPE)); + assertEquals("state", map.get(OAuth.OAUTH_STATE)); + assertNull(map.get("empty_param")); + assertNull(map.get("null_param")); + assertNull(map.get("")); + assertNull(map.get(null)); } } diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/QueryParameterApplierTest.java similarity index 81% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/QueryParameterApplierTest.java index 98cb7f78..b6e582a9 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/QueryParameterApplierTest.java @@ -19,21 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.utils.DummyOAuthMessage; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.message.OAuthMessage; +import org.apache.oltu.oauth2.common.parameters.OAuthParametersApplier; +import org.apache.oltu.oauth2.common.parameters.QueryParameterApplier; +import org.apache.oltu.oauth2.common.utils.DummyOAuthMessage; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.common.message.OAuthMessage; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class QueryParameterApplierTest { @@ -42,8 +44,8 @@ public void testApplyOAuthParameters() throws Exception { OAuthParametersApplier app = new QueryParameterApplier(); - Map params = new HashMap(); - params.put(OAuth.OAUTH_EXPIRES_IN, "3600"); + Map params = new HashMap(); + params.put(OAuth.OAUTH_EXPIRES_IN, 3600l); params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz"); params.put(OAuth.OAUTH_CODE, "code_"); params.put(OAuth.OAUTH_SCOPE, "read"); diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java similarity index 69% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java index b1a96294..b24abffb 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java @@ -19,29 +19,29 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.parameters; +package org.apache.oltu.oauth2.common.parameters; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.common.parameters.OAuthParametersApplier; -import org.apache.amber.oauth2.common.parameters.WWWAuthHeaderParametersApplier; -import org.junit.Assert; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.message.OAuthResponse; import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class WWWAuthHeaderParametersApplierTest { @Test public void testApplyOAuthParameters() throws Exception { - Map params = new HashMap(); + Map params = new HashMap(); params.put("error", "invalid_token"); params.put("error_uri", "http://www.example.com/error"); params.put("scope", "s1 s2 s3"); @@ -54,14 +54,12 @@ public void testApplyOAuthParameters() throws Exception { OAuthParametersApplier applier = new WWWAuthHeaderParametersApplier(); res = (OAuthResponse)applier.applyOAuthParameters(res, params); - Assert.assertNotNull(res); + assertNotNull(res); String header = res.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE); - Assert.assertNotNull(header); - Assert.assertEquals(OAuth.OAUTH_HEADER_NAME - + " scope=\"s1 s2 s3\",error_uri=\"http://www.example.com/error\",error=\"invalid_token\"", + assertNotNull(header); + assertEquals(OAuth.OAUTH_HEADER_NAME + + " scope=\"s1 s2 s3\",error=\"invalid_token\",error_uri=\"http://www.example.com/error\"", header); - - } } diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/DummyOAuthMessage.java similarity index 80% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/DummyOAuthMessage.java index 9a3cd61a..ed3d5d5d 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/DummyOAuthMessage.java @@ -19,14 +19,14 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.utils; +package org.apache.oltu.oauth2.common.utils; -import org.apache.amber.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.OAuthResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class DummyOAuthMessage extends OAuthResponse { diff --git a/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/JSONUtilsTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/JSONUtilsTest.java new file mode 100644 index 00000000..2d8a4e2b --- /dev/null +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/JSONUtilsTest.java @@ -0,0 +1,61 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.common.utils; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.junit.Test; + +/** + * + * + * + */ +public class JSONUtilsTest { + + @Test + public void testBuildJSON() throws Exception { + Map params = new HashMap(); + params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST); + + String json = JSONUtils.buildJSON(params); + + assertEquals("{\"error\":\"invalid_request\"}", json); + } + + @Test + public void testParseJson() throws Exception { + Map jsonParams = new HashMap(); + jsonParams.put("author", "John B. Smith"); + jsonParams.put("year", "2000"); + + String s = JSONUtils.buildJSON(jsonParams); + Map map = JSONUtils.parseJSON(s); + assertEquals("John B. Smith", map.get("author")); + assertEquals("2000", map.get("year")); + } + +} diff --git a/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/OAuthUtilsTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/OAuthUtilsTest.java new file mode 100644 index 00000000..cfc5211b --- /dev/null +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/utils/OAuthUtilsTest.java @@ -0,0 +1,399 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.common.utils; + +import org.apache.commons.codec.binary.Base64; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.junit.Ignore; +import org.junit.Test; + +import javax.servlet.http.HttpServletRequest; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.*; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; +/** + * + * + * + */ +public class OAuthUtilsTest { + + private static final String BASIC_PREFIX = "Basic "; + + @Test + @Ignore + // TODO what are testing here? + public void testBuildJSON() throws Exception { + Map params = new HashMap(); + params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST); + + String json = JSONUtils.buildJSON(params); + } + + @Test + public void testFormat() throws Exception { + Map parameters = new HashMap(); + parameters.put("movie", "Kiler"); + parameters.put("director", "Machulski"); + + + String format = OAuthUtils.format(parameters.entrySet(), "UTF-8"); + assertEquals("movie=Kiler&director=Machulski", format); + } + + @Test + public void testSaveStreamAsString() throws Exception { + String sampleTest = "It is raining again today"; + + InputStream is = new ByteArrayInputStream(sampleTest.getBytes("UTF-8")); + assertEquals(sampleTest, OAuthUtils.saveStreamAsString(is)); + } + + @Test + public void testHandleOAuthProblemException() throws Exception { + OAuthProblemException exception = OAuthUtils.handleOAuthProblemException("missing parameter"); + + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, exception.getError()); + assertEquals("missing parameter", exception.getDescription()); + } + + @Test + public void testHandleMissingParameters() throws Exception { + Set missingParameters = new HashSet(); + missingParameters.add(OAuth.OAUTH_CLIENT_ID); + missingParameters.add(OAuth.OAUTH_CLIENT_SECRET); + + OAuthUtils.handleMissingParameters(missingParameters); + } + + @Test + public void testHandleNotAllowedParametersOAuthException() throws Exception { + List notAllowedParametersList = new LinkedList(); + notAllowedParametersList.add("Parameter1"); + notAllowedParametersList.add("Parameter2"); + + OAuthProblemException exception = OAuthUtils.handleNotAllowedParametersOAuthException(notAllowedParametersList); + assertEquals("Not allowed parameters: Parameter1 Parameter2", exception.getDescription()); + } + + @Test + public void testDecodeForm() throws Exception { + String formUrlEncoded = "MyVariableOne=ValueOne&MyVariableTwo=ValueTwo"; + Map formDecoded = OAuthUtils.decodeForm(formUrlEncoded); + + assertEquals(2, formDecoded.size()); + assertEquals("ValueOne", formDecoded.get("MyVariableOne")); + assertEquals("ValueTwo", formDecoded.get("MyVariableTwo")); + } + + @Test + public void testIsFormEncoded() throws Exception { + String anotherContentType = "text/html; charset=ISO-8859-4"; + String urlEncodedType = "application/x-www-form-urlencoded; charset=UTF-8"; + + Boolean falseExpected = OAuthUtils.isFormEncoded(anotherContentType); + Boolean trueExpected = OAuthUtils.isFormEncoded(urlEncodedType); + + assertEquals(false, falseExpected); + assertEquals(true, trueExpected); + } + + @Test + public void testDecodePercent() throws Exception { + String encoded = "It%20is%20sunny%20today%2C%20spring%20is%20coming!%3A)"; + String decoded = OAuthUtils.decodePercent(encoded); + + assertEquals("It is sunny today, spring is coming!:)", decoded); + } + + @Test + public void testPercentEncode() throws Exception { + + String decoded = "some!@#%weird\"value1"; + + String encoded = OAuthUtils.percentEncode(decoded); + + assertEquals("some%21%40%23%25weird%22value1", encoded); + } + + @Test + public void testInstantiateClass() throws Exception { + StringBuilder builder = OAuthUtils.instantiateClass(StringBuilder.class); + + assertNotNull(builder); + } + + @Test + public void testInstantiateClassWithParameters() throws Exception { + StringBuilder builder = OAuthUtils.instantiateClassWithParameters(StringBuilder.class, new Class[]{String.class}, new Object[]{"something"}); + + assertNotNull(builder); + assertEquals("something", builder.toString()); + } + + @Test + public void testGetAuthHeaderField() throws Exception { + String token = OAuthUtils.getAuthHeaderField("Bearer 312ewqdsad"); + + assertEquals("312ewqdsad", token); + } + + @Test + public void testDecodeOAuthHeader() throws Exception { + Map parameters = OAuthUtils.decodeOAuthHeader("Bearer realm=\"example\""); + + Map expected = new HashMap(); + expected.put("realm", "example"); + + assertEquals(expected, parameters); + } + + @Test + public void testEncodeOAuthHeader() throws Exception { + Map parameters = new HashMap(); + parameters.put("realm", "example"); + + ///rfc6750#section-3 + String header = OAuthUtils.encodeOAuthHeader(parameters); + assertEquals("Bearer realm=\"example\"", header); + + } + + @Test + public void testEncodeOAuthHeaderWithError() throws Exception { + + Map entries = new HashMap(); + entries.put("realm", "Some Example Realm"); + entries.put("error", "invalid_token"); + + String header = OAuthUtils.encodeOAuthHeader(entries); + assertEquals("Bearer realm=\"Some Example Realm\",error=\"invalid_token\"", header); + } + + @Test + public void testEncodeAuthorizationBearerHeader() throws Exception { + Map parameters = new HashMap(); + parameters.put("accessToken", "mF_9.B5f-4.1JqM"); + + //rfc6749#section-7.1 + String header = OAuthUtils.encodeAuthorizationBearerHeader(parameters); + assertEquals("Bearer mF_9.B5f-4.1JqM", header); + + } + + @Test + public void testIsEmpty() throws Exception { + + Boolean trueExpected = OAuthUtils.isEmpty(""); + Boolean trueExpected2 = OAuthUtils.isEmpty(null); + + Boolean falseExpected = OAuthUtils.isEmpty("."); + + assertEquals(true, trueExpected); + assertEquals(true, trueExpected2); + assertEquals(false, falseExpected); + } + + @Test + public void testHasEmptyValues() throws Exception { + + Boolean trueExpected = OAuthUtils.hasEmptyValues(new String[]{"", "dsadas"}); + Boolean trueExpected2 = OAuthUtils.hasEmptyValues(new String[]{null, "dsadas"}); + Boolean trueExpected3 = OAuthUtils.hasEmptyValues(new String[]{}); + + Boolean falseExpected = OAuthUtils.hasEmptyValues(new String[]{"qwerty", "dsadas"}); + + assertEquals(true, trueExpected); + assertEquals(true, trueExpected2); + assertEquals(true, trueExpected3); + assertEquals(false, falseExpected); + + } + + @Test + public void testGetAuthzMethod() throws Exception { + + String authzMethod = OAuthUtils.getAuthzMethod("Basic dXNlcjpwYXNzd29yZA=="); + + assertEquals("Basic", authzMethod); + + } + + @Test + public void testHandleOAuthError() throws Exception { + + } + + @Test + public void testDecodeScopes() throws Exception { + + Set expected = new HashSet(); + expected.add("email"); + expected.add("full_profile"); + + Set scopes = OAuthUtils.decodeScopes("email full_profile"); + + assertEquals(expected, scopes); + + } + + @Test + public void testEncodeScopes() throws Exception { + Set actual = new HashSet(); + actual.add("photo"); + actual.add("birth_date"); + + String actualString = OAuthUtils.encodeScopes(actual); + + assertEquals("birth_date photo", actualString); + + } + + @Test + public void testIsExpired() throws Exception { + + } + + @Test + public void testGetIssuedTimeInSec() throws Exception { + + } + + @Test + public void testIsMultipart() throws Exception { + + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getContentType()).andStubReturn("multipart/form-data"); + expect(request.getMethod()).andStubReturn("POST"); + replay(request); + + Boolean actual = OAuthUtils.isMultipart(request); + + assertEquals(true, actual); + + verify(request); + + request = createMock(HttpServletRequest.class); + expect(request.getContentType()).andStubReturn("multipart/form-data"); + expect(request.getMethod()).andStubReturn("GET"); + replay(request); + + actual = OAuthUtils.isMultipart(request); + + assertEquals(false, actual); + + request = createMock(HttpServletRequest.class); + expect(request.getContentType()).andStubReturn("application/json"); + expect(request.getMethod()).andStubReturn("POST"); + replay(request); + + actual = OAuthUtils.isMultipart(request); + + assertEquals(false, actual); + } + + @Test + public void testHasContentType() throws Exception { + + Boolean falseExpected = OAuthUtils.hasContentType("application/x-www-form-urlencoded; charset=UTF-8", "application/json"); + Boolean trueExpected = OAuthUtils.hasContentType("application/json; charset=UTF-8", "application/json"); + + assertEquals(false, falseExpected); + assertEquals(true, trueExpected); + + } + + + @Test + public void testDecodeValidClientAuthnHeader() throws Exception { + String header = "clientId:secret"; + String encodedHeader = BASIC_PREFIX + encodeHeader(header); + + String[] credentials = OAuthUtils.decodeClientAuthenticationHeader(encodedHeader); + + assertNotNull(credentials); + assertEquals("clientId", credentials[0]); + assertEquals("secret", credentials[1]); + } + + @Test + public void testDecodeValidClientAuthnHeaderWithColonInPassword() throws Exception { + String header = "clientId:sec:re:t"; + String encodedHeader = BASIC_PREFIX + encodeHeader(header); + + String[] credentials = OAuthUtils.decodeClientAuthenticationHeader(encodedHeader); + + assertNotNull(credentials); + assertEquals("clientId", credentials[0]); + assertEquals("sec:re:t", credentials[1]); + } + + @Test + public void testDecodeEmptyClientAuthnHeader() throws Exception { + assertNull(OAuthUtils.decodeClientAuthenticationHeader(null)); + assertNull(OAuthUtils.decodeClientAuthenticationHeader("")); + } + + @Test + public void testDecodeInvalidClientAuthnHeader() throws Exception { + assertNull(OAuthUtils.decodeClientAuthenticationHeader(BASIC_PREFIX)); + assertNull(OAuthUtils.decodeClientAuthenticationHeader("invalid_header")); + assertNull(OAuthUtils.decodeClientAuthenticationHeader("Authorization dXNlcm5hbWU6cGFzc3dvcmQ=")); + } + + @Test + public void testDecodeClientAuthnHeaderNoClientIdOrSecret() throws Exception { + String header = ":"; + String encodedHeader = BASIC_PREFIX + encodeHeader(header); + assertNull(OAuthUtils.decodeClientAuthenticationHeader(encodedHeader)); + } + + @Test + public void testDecodeClientAuthnHeaderNoClientId() throws Exception { + String header = ":secret"; + String encodedHeader = BASIC_PREFIX + encodeHeader(header); + assertNull(OAuthUtils.decodeClientAuthenticationHeader(encodedHeader)); + } + + @Test + public void testDecodeClientAuthnHeaderNoSecret() throws Exception { + String header = "clientId:"; + String encodedHeader = BASIC_PREFIX + encodeHeader(header); + assertNull(OAuthUtils.decodeClientAuthenticationHeader(encodedHeader)); + } + + @Test + public void testDecodeClientAuthnHeaderNoSeparator() throws Exception { + String header = "clientId"; + String encodedHeader = BASIC_PREFIX + encodeHeader(header); + assertNull(OAuthUtils.decodeClientAuthenticationHeader(encodedHeader)); + } + + private String encodeHeader(String header) { + return new String(Base64.encodeBase64(header.getBytes())); + } +} diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/validators/AbstractValidatorImpl.java similarity index 84% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/validators/AbstractValidatorImpl.java index 2d39720e..7c3b4472 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/validators/AbstractValidatorImpl.java @@ -19,17 +19,17 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.validators; +package org.apache.oltu.oauth2.common.validators; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class AbstractValidatorImpl extends AbstractValidator { diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/validators/AbstractValidatorTest.java similarity index 88% rename from oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java rename to oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/validators/AbstractValidatorTest.java index 0ce87175..90a68b7d 100644 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java +++ b/oauth-2.0/common/src/test/java/org/apache/oltu/oauth2/common/validators/AbstractValidatorTest.java @@ -19,12 +19,13 @@ * limitations under the License. */ -package org.apache.amber.oauth2.common.validators; +package org.apache.oltu.oauth2.common.validators; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; import org.junit.Test; import static org.easymock.EasyMock.createStrictMock; @@ -34,9 +35,9 @@ import static org.easymock.EasyMock.verify; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class AbstractValidatorTest { diff --git a/oauth-2.0/deploySite.sh b/oauth-2.0/deploySite.sh new file mode 100755 index 00000000..7328d417 --- /dev/null +++ b/oauth-2.0/deploySite.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +mvn clean site site:stage -P site +mvn scm-publish:publish-scm -Dusername=$1 -Dpassword=$2 -P site diff --git a/oauth-2.0/dynamicreg-client/pom.xml b/oauth-2.0/dynamicreg-client/pom.xml new file mode 100644 index 00000000..27fa7b2d --- /dev/null +++ b/oauth-2.0/dynamicreg-client/pom.xml @@ -0,0 +1,87 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.dynamicreg.client + bundle + + Apache Oltu - OAuth 2.0 - Dynamic Registration Client + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.dynamicreg.common + ${project.version} + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/dynamicreg-client/src/main/assembly/LICENSE-with-deps b/oauth-2.0/dynamicreg-client/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..c2622deb --- /dev/null +++ b/oauth-2.0/dynamicreg-client/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,234 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/dynamicreg-client/src/main/assembly/NOTICE-with-deps b/oauth-2.0/dynamicreg-client/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/dynamicreg-client/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/dynamicreg-client/src/main/assembly/bin.xml b/oauth-2.0/dynamicreg-client/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/dynamicreg-client/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java similarity index 71% rename from oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java rename to oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java index 35552dad..720e9ba3 100644 --- a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java +++ b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java @@ -19,25 +19,25 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.client; +package org.apache.oltu.oauth2.ext.dynamicreg.client; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.apache.amber.oauth2.client.HttpClient; -import org.apache.amber.oauth2.client.OAuthClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; +import org.apache.oltu.oauth2.client.HttpClient; +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthRegistrationClient extends OAuthClient { diff --git a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java similarity index 84% rename from oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java rename to oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java index a4a1dd1a..43e3f215 100644 --- a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java +++ b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java @@ -19,20 +19,20 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.client.request; +package org.apache.oltu.oauth2.ext.dynamicreg.client.request; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.parameters.JSONBodyParametersApplier; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.parameters.JSONBodyParametersApplier; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; /** * OAuth Registration Request * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClientRegistrationRequest extends OAuthClientRequest { diff --git a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java similarity index 64% rename from oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java rename to oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java index 0854bb9b..36ac22e2 100644 --- a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java +++ b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java @@ -19,43 +19,45 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.client.response; +package org.apache.oltu.oauth2.ext.dynamicreg.client.response; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.JSONUtils; -import org.apache.amber.oauth2.ext.dynamicreg.client.validators.RegistrationValidator; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; -import org.codehaus.jettison.json.JSONException; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.JSONUtils; +import org.apache.oltu.oauth2.ext.dynamicreg.client.validators.RegistrationValidator; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; + +import java.util.List; +import java.util.Map; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthClientRegistrationResponse extends OAuthClientResponse { public OAuthClientRegistrationResponse() { + validator = new RegistrationValidator(); } @Override protected void init(String body, String contentType, int responseCode) throws OAuthProblemException { - validator = new RegistrationValidator(); super.init(body, contentType, responseCode); } @Override - public String getParam(String param) { - return parameters.get(param); + protected void init(String body, String contentType, int responseCode, Map> headers) throws OAuthProblemException { + super.init(body, contentType, responseCode, headers); } protected void setBody(String body) throws OAuthProblemException { try { this.body = body; parameters = JSONUtils.parseJSON(body); - } catch (JSONException e) { + } catch (Throwable e) { throw OAuthProblemException.error(OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE, "Invalid response! Response body is not application/json encoded"); } @@ -70,19 +72,20 @@ protected void setContentType(String contentType) { } public String getClientId() { - return parameters.get(OAuthRegistration.Response.CLIENT_ID); + return getParam(OAuthRegistration.Response.CLIENT_ID); } public String getClientSecret() { - return parameters.get(OAuthRegistration.Response.CLIENT_SECRET); + return getParam(OAuthRegistration.Response.CLIENT_SECRET); } public String getIssuedAt() { - return parameters.get(OAuthRegistration.Response.ISSUED_AT); + return getParam(OAuthRegistration.Response.ISSUED_AT); } - public String getExpiresIn() { - return parameters.get(OAuthRegistration.Response.EXPIRES_IN); + public Long getExpiresIn() { + String value = getParam(OAuthRegistration.Response.EXPIRES_IN); + return value == null? null: Long.valueOf(value); } } diff --git a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java similarity index 82% rename from oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java rename to oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java index b0c1825e..85e77427 100644 --- a/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java +++ b/oauth-2.0/dynamicreg-client/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java @@ -19,23 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.client.validators; +package org.apache.oltu.oauth2.ext.dynamicreg.client.validators; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.client.validator.OAuthClientValidator; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.validator.OAuthClientValidator; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class RegistrationValidator extends OAuthClientValidator { diff --git a/oauth-2.0/dynamicreg-common/pom.xml b/oauth-2.0/dynamicreg-common/pom.xml new file mode 100644 index 00000000..faecb752 --- /dev/null +++ b/oauth-2.0/dynamicreg-common/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.dynamicreg.common + bundle + + Apache Oltu - OAuth 2.0 - Dynamic Registration Common + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + diff --git a/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java b/oauth-2.0/dynamicreg-common/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/common/OAuthRegistration.java similarity index 90% rename from oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java rename to oauth-2.0/dynamicreg-common/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/common/OAuthRegistration.java index 9971f8f4..949f95a4 100644 --- a/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java +++ b/oauth-2.0/dynamicreg-common/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/common/OAuthRegistration.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.common; +package org.apache.oltu.oauth2.ext.dynamicreg.common; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public final class OAuthRegistration { private OAuthRegistration() { diff --git a/oauth-2.0/dynamicreg-server/pom.xml b/oauth-2.0/dynamicreg-server/pom.xml new file mode 100644 index 00000000..ace28ed8 --- /dev/null +++ b/oauth-2.0/dynamicreg-server/pom.xml @@ -0,0 +1,99 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.dynamicreg.server + bundle + + Apache Oltu - OAuth 2.0 - Dynamic Registration Server + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.authzserver + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.dynamicreg.common + ${project.version} + + + + org.apache.johnzon + johnzon-core + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.test-utils + ${project.version} + test + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/dynamicreg-server/src/main/assembly/LICENSE-with-deps b/oauth-2.0/dynamicreg-server/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..c2622deb --- /dev/null +++ b/oauth-2.0/dynamicreg-server/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,234 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/dynamicreg-server/src/main/assembly/NOTICE-with-deps b/oauth-2.0/dynamicreg-server/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/dynamicreg-server/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/dynamicreg-server/src/main/assembly/bin.xml b/oauth-2.0/dynamicreg-server/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/dynamicreg-server/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java new file mode 100644 index 00000000..2a6875e7 --- /dev/null +++ b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java @@ -0,0 +1,192 @@ +/** + * Copyright 2011 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.ext.dynamicreg.server.request; + +import static java.lang.String.format; + +import java.io.StringReader; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonNumber; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonString; +import javax.json.JsonStructure; +import javax.json.JsonValue; +import javax.json.JsonValue.ValueType; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthRuntimeException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class JSONHttpServletRequestWrapper extends HttpServletRequestWrapper { + + private Logger log = LoggerFactory.getLogger(JSONHttpServletRequestWrapper.class); + + private boolean bodyRead = false; + + final Map parameters = new HashMap(); + + public JSONHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + } + + public String getParameter(String name) { + final String[] values = getParameterMap().get(name); + if (values == null || values.length == 0) { + return null; + } + return values[0]; + } + + public Map getParameterMap() { + if (!bodyRead) { + String body = readJsonBody(); + + StringReader reader = new StringReader(body); + JsonReader jsonReader = Json.createReader(reader); + JsonStructure structure = jsonReader.read(); + + if (structure == null || structure instanceof JsonArray) { + throw new IllegalArgumentException(format("String '%s' is not a valid JSON object representation", + body)); + } + + JsonObject object = (JsonObject) structure; + for (Entry entry : object.entrySet()) { + String key = entry.getKey(); + if (key != null) { + JsonValue jsonValue = entry.getValue(); + + // guard from null values + if (jsonValue != null) { + String[] values; + + if (ValueType.ARRAY == jsonValue.getValueType()) { + JsonArray array = (JsonArray) jsonValue; + values = new String[array.size()]; + for (int i = 0; i < array.size(); i++) { + JsonValue current = array.get(i); + values[i] = toJavaObject(current); + } + } else { + values = new String[]{ toJavaObject(jsonValue) }; + } + + parameters.put(key, values); + } + } + } + + jsonReader.close(); + } + + return Collections.unmodifiableMap(parameters); + } + + private static String toJavaObject(JsonValue jsonValue) { + String value = null; + + switch (jsonValue.getValueType()) { + case FALSE: + value = Boolean.FALSE.toString(); + break; + + case NULL: + value = null; + break; + + case NUMBER: + JsonNumber jsonNumber = (JsonNumber) jsonValue; + value = jsonNumber.numberValue().toString(); + break; + + case OBJECT: + // not supported in this version + break; + + case STRING: + JsonString jsonString = (JsonString) jsonValue; + value = jsonString.getString(); + break; + + case TRUE: + value = Boolean.TRUE.toString(); + break; + + default: + break; + } + + return value; + } + + public Enumeration getParameterNames() { + return Collections.enumeration(getParameterMap().keySet()); + } + + public String[] getParameterValues(String name) { + return getParameterMap().get(name); + } + + /** + * Lazily read JSON from request + * + * @throws OAuthProblemException + */ + private String readJsonBody() { + try { + final ServletRequest request = getRequest(); + String contentType = request.getContentType(); + final String expectedContentType = OAuth.ContentType.JSON; + if (!OAuthUtils.hasContentType(contentType, expectedContentType)) { + return ""; + } + + final ServletInputStream inputStream = request.getInputStream(); + if (inputStream == null) { + return ""; + } + + bodyRead = true; + return OAuthUtils.saveStreamAsString(inputStream); + } catch (Exception e) { + log.error("Dynamic client registration error: ", e); + throw new OAuthRuntimeException("OAuth server error"); + } + } +} diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java similarity index 80% rename from oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java rename to oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java index 79819b1c..6cc9c011 100644 --- a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java +++ b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java @@ -19,22 +19,22 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.server.request; +package org.apache.oltu.oauth2.ext.dynamicreg.server.request; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.validators.OAuthValidator; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; -import org.apache.amber.oauth2.as.request.OAuthRequest; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.ext.dynamicreg.server.validator.PushPullValidator; +import org.apache.oltu.oauth2.as.request.OAuthRequest; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.apache.oltu.oauth2.ext.dynamicreg.server.validator.PushPullValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthServerRegistrationRequest extends OAuthRequest { diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/response/OAuthServerRegistrationResponse.java b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/response/OAuthServerRegistrationResponse.java similarity index 85% rename from oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/response/OAuthServerRegistrationResponse.java rename to oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/response/OAuthServerRegistrationResponse.java index 5def5153..8791cbbd 100644 --- a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/response/OAuthServerRegistrationResponse.java +++ b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/response/OAuthServerRegistrationResponse.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.server.response; +package org.apache.oltu.oauth2.ext.dynamicreg.server.response; -import org.apache.amber.oauth2.as.response.OAuthASResponse; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.apache.oltu.oauth2.as.response.OAuthASResponse; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthServerRegistrationResponse extends OAuthASResponse { @@ -61,6 +61,11 @@ public OAuthRegistrationResponseBuilder setIssuedAt(String value) { } public OAuthRegistrationResponseBuilder setExpiresIn(String value) { + this.parameters.put(OAuthRegistration.Response.EXPIRES_IN, Long.parseLong(value)); + return this; + } + + public OAuthRegistrationResponseBuilder setExpiresIn(Long value) { this.parameters.put(OAuthRegistration.Response.EXPIRES_IN, value); return this; } diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java similarity index 81% rename from oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java rename to oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java index e548bb47..d6ccaf64 100644 --- a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java +++ b/oauth-2.0/dynamicreg-server/src/main/java/org/apache/oltu/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java @@ -19,21 +19,21 @@ * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.server.validator; +package org.apache.oltu.oauth2.ext.dynamicreg.server.validator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.AbstractValidator; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; -import org.apache.amber.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.apache.oltu.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class PushPullValidator extends AbstractValidator { @@ -78,7 +78,7 @@ private void initializeValidationParameter(JSONHttpServletRequestWrapper request } if (log.isDebugEnabled()) { - log.debug("OAuth dynamic client registration type is: {}", new String[] {requestType}); + log.debug("OAuth dynamic client registration type is: {}", new Object[] {requestType}); } } } diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java b/oauth-2.0/dynamicreg-server/src/test/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java similarity index 78% rename from oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java rename to oauth-2.0/dynamicreg-server/src/test/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java index 29d1032d..6103e244 100644 --- a/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java +++ b/oauth-2.0/dynamicreg-server/src/test/java/org/apache/oltu/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java @@ -18,17 +18,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.oauth2.ext.dynamicreg.server.request; +package org.apache.oltu.oauth2.ext.dynamicreg.server.request; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.utils.test.FileUtils; -import org.junit.Assert; +import static org.junit.Assert.assertEquals; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.utils.test.FileUtils; import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; /** - * @author Lukasz Moren + * */ public class OAuthServerRegistrationRequestTest { @@ -43,14 +44,13 @@ public void testValidOAuthPushRequest() throws Exception { final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request); OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper); - Assert.assertEquals("Uploading and also editing capabilities!", + assertEquals("Uploading and also editing capabilities!", registrationRequest.getClientDescription()); - Assert.assertEquals("http://onlinephotogallery.com/icon.png", registrationRequest.getClientIcon()); - Assert.assertEquals("Online Photo Gallery", registrationRequest.getClientName()); - Assert - .assertEquals("https://onlinephotogallery.com/client_reg", registrationRequest.getRedirectURI()); - Assert.assertEquals("push", registrationRequest.getType()); - Assert.assertEquals("http://onlinephotogallery.com", registrationRequest.getClientUrl()); + assertEquals("http://onlinephotogallery.com/icon.png", registrationRequest.getClientIcon()); + assertEquals("Online Photo Gallery", registrationRequest.getClientName()); + assertEquals("https://onlinephotogallery.com/client_reg", registrationRequest.getRedirectURI()); + assertEquals("push", registrationRequest.getType()); + assertEquals("http://onlinephotogallery.com", registrationRequest.getClientUrl()); } @Test(expected = OAuthProblemException.class) diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json b/oauth-2.0/dynamicreg-server/src/test/resources/json/push_invalid.json similarity index 100% rename from oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json rename to oauth-2.0/dynamicreg-server/src/test/resources/json/push_invalid.json diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json b/oauth-2.0/dynamicreg-server/src/test/resources/json/push_valid.json similarity index 100% rename from oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json rename to oauth-2.0/dynamicreg-server/src/test/resources/json/push_valid.json diff --git a/oauth-2.0/oauth2-integration-tests/src/test/resources/log4j.properties b/oauth-2.0/dynamicreg-server/src/test/resources/log4j.properties similarity index 94% rename from oauth-2.0/oauth2-integration-tests/src/test/resources/log4j.properties rename to oauth-2.0/dynamicreg-server/src/test/resources/log4j.properties index 29a09b41..01632066 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/resources/log4j.properties +++ b/oauth-2.0/dynamicreg-server/src/test/resources/log4j.properties @@ -1,29 +1,29 @@ -# -# Copyright 2010 Newcastle University -# -# http://research.ncl.ac.uk/smart/ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -log4j.rootCategory=INFO, CONSOLE - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n - -#log4j.logger.org.hibernate.search=TRACE \ No newline at end of file +# +# Copyright 2010 Newcastle University +# +# http://research.ncl.ac.uk/smart/ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +log4j.rootCategory=INFO, CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n + +log4j.logger.org.apache.oltu.oauth2=DEBUG \ No newline at end of file diff --git a/oauth-2.0/httpclient4/pom.xml b/oauth-2.0/httpclient4/pom.xml new file mode 100644 index 00000000..113e32df --- /dev/null +++ b/oauth-2.0/httpclient4/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.httpclient4 + bundle + + Apache Oltu - OAuth 2.0 - HttpClient + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${project.version} + + + + org.apache.httpcomponents + httpclient + 4.5.1 + + + + org.apache.commons + commons-collections4 + 4.1 + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/httpclient4/src/main/assembly/LICENSE-with-deps b/oauth-2.0/httpclient4/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..cf02f4cd --- /dev/null +++ b/oauth-2.0/httpclient4/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,243 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above + +For the Apache HttpClient components (http://hc.apache.org/) +This is licensed under the The Apache Software License, Version 2.0, see above + +For the Apache Commons-Logging component (http://commons.apache.org/logging/) +This is licensed under the The Apache Software License, Version 2.0, see above + +For the Apache Commons-Codec component (http://commons.apache.org/codec/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/httpclient4/src/main/assembly/NOTICE-with-deps b/oauth-2.0/httpclient4/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/httpclient4/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/httpclient4/src/main/assembly/bin.xml b/oauth-2.0/httpclient4/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/httpclient4/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java b/oauth-2.0/httpclient4/src/main/java/org/apache/oltu/oauth2/httpclient4/HttpClient4.java similarity index 64% rename from oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java rename to oauth-2.0/httpclient4/src/main/java/org/apache/oltu/oauth2/httpclient4/HttpClient4.java index f688e40a..b4cad0b8 100644 --- a/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java +++ b/oauth-2.0/httpclient4/src/main/java/org/apache/oltu/oauth2/httpclient4/HttpClient4.java @@ -19,19 +19,16 @@ * limitations under the License. */ -package org.apache.amber.oauth2.httpclient4; +package org.apache.oltu.oauth2.httpclient4; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.net.URI; +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import org.apache.amber.oauth2.client.HttpClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.client.response.OAuthClientResponseFactory; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.commons.collections4.map.CaseInsensitiveMap; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -42,14 +39,22 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; +import org.apache.oltu.oauth2.client.HttpClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * Exemplar HttpClient4 + * Example Oltu HttpClient based on the Apache HttpComponents HttpClient + * + * + * * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) */ public class HttpClient4 implements HttpClient { @@ -62,7 +67,7 @@ public HttpClient4() { public HttpClient4(org.apache.http.client.HttpClient client) { this.client = client; } - + public void shutdown() { if (client != null) { ClientConnectionManager connectionManager = client.getConnectionManager(); @@ -81,7 +86,7 @@ public T execute(OAuthClientRequest request, try { URI location = new URI(request.getLocationUri()); HttpRequestBase req = null; - String responseBody = ""; + InputStream responseBody = new ByteArrayInputStream(new byte[0]); if (!OAuthUtils.isEmpty(requestMethod) && OAuth.HttpMethod.POST.equals(requestMethod)) { req = new HttpPost(location); @@ -95,11 +100,17 @@ public T execute(OAuthClientRequest request, req.setHeader(header.getKey(), header.getValue()); } } + if (request.getHeaders() != null) { + for (Map.Entry header : request.getHeaders().entrySet()) { + req.setHeader(header.getKey(), header.getValue()); + } + } HttpResponse response = client.execute(req); Header contentTypeHeader = null; + HttpEntity entity = response.getEntity(); if (entity != null) { - responseBody = EntityUtils.toString(entity); + responseBody = entity.getContent(); contentTypeHeader = entity.getContentType(); } String contentType = null; @@ -108,11 +119,28 @@ public T execute(OAuthClientRequest request, } return OAuthClientResponseFactory - .createCustomResponse(responseBody, contentType, response.getStatusLine().getStatusCode(), - responseClass); + .createCustomResponse(responseBody, contentType, response.getStatusLine().getStatusCode(), getHeaders(response.getAllHeaders()), + responseClass); } catch (Exception e) { throw new OAuthSystemException(e); } + } + + protected Map> getHeaders(Header[] headers) { + Map> headersMap = new CaseInsensitiveMap>(); + for (Header header : headers) { + String headerKey = header.getName(); + String headerValue = header.getValue(); + if (headersMap.containsKey(headerKey)) { + final List headerValues = headersMap.get(headerKey); + headerValues.add(headerValue); + } else { + List headerValues = new ArrayList(); + headerValues.add(headerValue); + headersMap.put(headerKey, headerValues); + } + } + return headersMap; } } diff --git a/oauth-2.0/integration-tests/pom.xml b/oauth-2.0/integration-tests/pom.xml new file mode 100644 index 00000000..1490adfb --- /dev/null +++ b/oauth-2.0/integration-tests/pom.xml @@ -0,0 +1,154 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + Apache Oltu - OAuth 2.0 - Integration Tests + + org.apache.oltu.oauth2.integration-tests + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.authzserver + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.httpclient4 + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.resourceserver + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.dynamicreg.client + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.dynamicreg.server + ${project.version} + + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf.version} + test + + + + org.eclipse.jetty + jetty-webapp + ${jetty.version} + test + + + + org.apache.cxf + cxf-rt-transports-http + ${cxf.version} + test + + + + org.apache.cxf + cxf-rt-transports-http-jetty + ${cxf.version} + test + + + + org.springframework + spring-context + ${org.springframework.version} + test + + + + org.springframework + spring-core + ${org.springframework.version} + test + + + + org.springframework + spring-beans + ${org.springframework.version} + test + + + + org.apache.johnzon + johnzon-core + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/utils/* + + + + + + + diff --git a/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/httpclient4/HttpClient4Test.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/httpclient4/HttpClient4Test.java new file mode 100644 index 00000000..b754fcbb --- /dev/null +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/httpclient4/HttpClient4Test.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.httpclient4; + +import org.apache.http.Header; +import org.apache.http.message.BasicHeader; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class HttpClient4Test { + + private static final Header[] SIMPLE_HEADERS = + new Header[]{new BasicHeader("Location", "test-location"), new BasicHeader("Cache-Control", "no-cache")}; + private static final Header[] MULTI_VALUE_HEADERS_WITH_STRANGE_CASING = + new Header[]{new BasicHeader("CACHE-CONTROL", "no-cache"), new BasicHeader("Cache-Control", "no-store")}; + + private HttpClient4 httpClient4 = new HttpClient4(); + + @Test + public void shouldGetHeaders() { + final Map> headers = httpClient4.getHeaders(SIMPLE_HEADERS); + assertEquals(2, headers.size()); + } + + @Test + public void shouldGetMultiValueHeaders() { + final Map> headers = httpClient4.getHeaders(MULTI_VALUE_HEADERS_WITH_STRANGE_CASING); + assertEquals(1, headers.size()); + final List cacheControlHeader = headers.get("cache-control"); + assertEquals(2, cacheControlHeader.size()); + + assertEquals(true, cacheControlHeader.contains("no-cache")); + assertEquals(true, cacheControlHeader.contains("no-store")); + } + + @Test + public void shouldGetEmptyHeaders() { + final Map> headers = httpClient4.getHeaders(new Header[]{}); + assertEquals(0, headers.size()); + } + +} \ No newline at end of file diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/AccessTokenPasswordCredentialsTest.java similarity index 82% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/AccessTokenPasswordCredentialsTest.java index e8a8f272..9ab19a24 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/AccessTokenPasswordCredentialsTest.java @@ -19,25 +19,25 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; - -import org.apache.amber.oauth2.client.OAuthClient; -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.types.GrantType; +package org.apache.oltu.oauth2.integration; + import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.amber.oauth2.client.response.OAuthJSONAccessTokenResponse; -import org.apache.amber.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class AccessTokenPasswordCredentialsTest extends ClientServerOAuthTest { private static Logger logger = LoggerFactory.getLogger(AccessTokenPasswordCredentialsTest.class); diff --git a/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/AccessTokenTestAuthCodeTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/AccessTokenTestAuthCodeTest.java new file mode 100644 index 00000000..6fd1f6e9 --- /dev/null +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/AccessTokenTestAuthCodeTest.java @@ -0,0 +1,177 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.integration; + +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.junit.Test; + +/** + * + * + * + */ +public class AccessTokenTestAuthCodeTest extends ClientServerOAuthTest { + + @Test + public void testSuccessfullAccesToken() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setGrantType(GrantType.AUTHORIZATION_CODE) + .setCode(Common.AUTHORIZATION_CODE) + .setRedirectURI(Common.REDIRECT_URL) + .setClientId(Common.CLIENT_ID) + .setClientSecret(Common.CLIENT_SECRET) + .buildBodyMessage(); + + OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); + OAuthAccessTokenResponse response = oAuthClient.accessToken(request); + assertNotNull(response.getAccessToken()); + assertNotNull(response.getExpiresIn()); + } + + @Test + public void testInvalidClientCredentials() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setGrantType(GrantType.AUTHORIZATION_CODE) + .setRedirectURI(Common.REDIRECT_URL) + .setCode(Common.AUTHORIZATION_CODE) + .setClientId(Common.CLIENT_ID) + .setClientSecret("wrongSecret") + .buildBodyMessage(); + + OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); + + try { + oAuthClient.accessToken(request); + fail("exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.UNAUTHORIZED_CLIENT, e.getError()); + } + } + + @Test + public void testNoneGrantType() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setGrantType(null) + .setClientId(Common.CLIENT_ID) + .setClientSecret(Common.CLIENT_SECRET) + .buildBodyMessage(); + + OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); + + try { + oAuthClient.accessToken(request); + fail("exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + } + } + + @Test + public void testInvalidRequest() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setClientId(Common.CLIENT_ID) + .buildBodyMessage(); + + OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); + + try { + oAuthClient.accessToken(request); + fail("exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + } + } + + @Test + public void testInvalidClient() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setGrantType(GrantType.AUTHORIZATION_CODE) + .setCode(Common.AUTHORIZATION_CODE) + .setClientId("unknownid") + .setClientSecret(Common.CLIENT_SECRET) + .setRedirectURI(Common.REDIRECT_URL) + .buildBodyMessage(); + + OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); + + try { + oAuthClient.accessToken(request); + fail("exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_CLIENT, e.getError()); + } + } + + @Test + public void testInvalidGrantType() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setParameter(OAuth.OAUTH_GRANT_TYPE, "unknown_grant_type") + .setCode(Common.AUTHORIZATION_CODE) + .setRedirectURI(Common.REDIRECT_URL) + .setClientId(Common.CLIENT_ID) + .setClientSecret(Common.CLIENT_SECRET) + .buildBodyMessage(); + + OAuthClient oAuthclient = new OAuthClient(new URLConnectionClient()); + + try { + oAuthclient.accessToken(request); + fail("exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + } + } + + @Test + public void testInvalidCode() throws Exception { + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .setGrantType(GrantType.AUTHORIZATION_CODE) + .setRedirectURI(Common.REDIRECT_URL) + .setCode("unknown_code") + .setClientId(Common.CLIENT_ID) + .setClientSecret(Common.CLIENT_SECRET) + .buildBodyMessage(); + + OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); + + try { + oAuthClient.accessToken(request); + fail("exception expected"); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_GRANT, e.getError()); + } + } +} \ No newline at end of file diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientRegistrationOAuthTest.java similarity index 95% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientRegistrationOAuthTest.java index d63f4f8f..31c5acee 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientRegistrationOAuthTest.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; import org.apache.cxf.endpoint.Server; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; @@ -28,7 +28,6 @@ import org.junit.BeforeClass; /** - * @author Maciej P. Machulak */ public abstract class ClientRegistrationOAuthTest extends ClientServerOAuthTest { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientRegistrationTest.java similarity index 72% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientRegistrationTest.java index 0df48f8e..c2b42800 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientRegistrationTest.java @@ -19,22 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.ext.dynamicreg.client.OAuthRegistrationClient; -import org.apache.amber.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest; import org.junit.Test; -import org.apache.amber.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; -import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.ext.dynamicreg.client.OAuthRegistrationClient; +import org.apache.oltu.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest; +import org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; +import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class ClientRegistrationTest extends ClientServerOAuthTest { @@ -60,7 +61,7 @@ public void testPushMetadataRegistration() throws Exception { } - @Test + @Test(expected = OAuthSystemException.class) public void testInvalidType() throws Exception { OAuthClientRequest request = OAuthClientRegistrationRequest @@ -73,12 +74,7 @@ public void testInvalidType() throws Exception { .buildBodyMessage(); OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient()); - try { - OAuthClientRegistrationResponse response = oauthclient.clientInfo(request); - fail("exception expected"); - } catch (OAuthProblemException e) { - assertNotNull(e.getError()); - } + OAuthClientRegistrationResponse response = oauthclient.clientInfo(request); } diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientResourceOAuthTest.java similarity index 88% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientResourceOAuthTest.java index 2259a77d..7327b2fb 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientResourceOAuthTest.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; import org.apache.cxf.endpoint.Server; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; @@ -28,9 +28,9 @@ import org.junit.BeforeClass; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public abstract class ClientResourceOAuthTest extends ClientServerOAuthTest { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientServerOAuthTest.java similarity index 89% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientServerOAuthTest.java index b25f877a..6b94906d 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ClientServerOAuthTest.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; import org.apache.cxf.endpoint.Server; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; @@ -28,9 +28,9 @@ import org.junit.BeforeClass; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public abstract class ClientServerOAuthTest extends JUnit4SpringContextTests { protected static Server s2; diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/Common.java similarity index 89% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/Common.java index 03885b3e..9d4d053f 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/Common.java @@ -19,18 +19,18 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public final class Common { private Common() { @@ -48,15 +48,15 @@ private Common() { public static final String OAUTH_VERSION_2_INSUFFICIENT = ACCESS_TOKEN_INSUFFICIENT; public static final String OAUTH_URL_ENCODED_VERSION_1 = OAUTH_VERSION_1; - public static final String OAUTH_URL_ENCODED_VERSION_2 = "oauth_token=" + OAUTH_VERSION_2; - public static final String OAUTH_URL_ENCODED_VERSION_2_EXPIRED = "oauth_token=" + OAUTH_VERSION_2_EXPIRED; - public static final String OAUTH_URL_ENCODED_VERSION_2_INSUFFICIENT = "oauth_token=" + public static final String OAUTH_URL_ENCODED_VERSION_2 = "access_token=" + OAUTH_VERSION_2; + public static final String OAUTH_URL_ENCODED_VERSION_2_EXPIRED = "access_token=" + OAUTH_VERSION_2_EXPIRED; + public static final String OAUTH_URL_ENCODED_VERSION_2_INSUFFICIENT = "access_token=" + OAUTH_VERSION_2_INSUFFICIENT; public static final String AUTHORIZATION_HEADER_OAUTH1 = "OAuth " + OAUTH_VERSION_1; - public static final String AUTHORIZATION_HEADER_OAUTH2 = "OAuth " + OAUTH_VERSION_2; - public static final String AUTHORIZATION_HEADER_OAUTH2_EXPIRED = "OAuth " + OAUTH_VERSION_2_EXPIRED; - public static final String AUTHORIZATION_HEADER_OAUTH2_INSUFFICIENT = "OAuth " + public static final String AUTHORIZATION_HEADER_OAUTH2 = "Bearer " + OAUTH_VERSION_2; + public static final String AUTHORIZATION_HEADER_OAUTH2_EXPIRED = "Bearer " + OAUTH_VERSION_2_EXPIRED; + public static final String AUTHORIZATION_HEADER_OAUTH2_INSUFFICIENT = "Bearer " + OAUTH_VERSION_2_INSUFFICIENT; public static final String BODY_OAUTH1 = OAUTH_URL_ENCODED_VERSION_1; @@ -78,7 +78,7 @@ private Common() { public static final String HEADER_AUTHORIZATION = "Authorization"; public static final String AUTHORIZATION_CODE = "known_authz_code"; - + public static final String STATE = "abcde"; public static final String ASSERTION = " map = OAuthUtils.decodeForm(queryString); + assertNotNull(map.get(OAuth.OAUTH_CODE)); + assertEquals(Common.STATE, map.get(OAuth.OAUTH_STATE)); } @Test @@ -83,21 +85,21 @@ public void testTokenResponse() throws Exception { .setClientId(Common.CLIENT_ID) .setRedirectURI(Common.REDIRECT_URL + "2") .setResponseType(ResponseType.TOKEN.toString()) + .setState(Common.STATE) .buildQueryMessage(); HttpURLConnection c = Common.doRequest(request); String fragment = c.getURL().toURI().getFragment(); - Map map = OAuthUtils.decodeForm(fragment); + Map map = OAuthUtils.decodeForm(fragment); assertNotNull(map.get(OAuth.OAUTH_EXPIRES_IN)); assertNotNull(map.get(OAuth.OAUTH_ACCESS_TOKEN)); - + assertEquals(Common.STATE, map.get(OAuth.OAUTH_STATE)); } @GET @Path("/redirect") public Response callback(@Context HttpServletRequest request) throws Exception { - OAuthClientResponse resp = null; try { OAuthAuthzResponse.oauthCodeAuthzResponse(request); @@ -106,7 +108,6 @@ public Response callback(@Context HttpServletRequest request) throws Exception { assertEquals(OAuthError.CodeResponse.INVALID_REQUEST, e.getError()); } - return Response.ok().build(); } @@ -121,7 +122,6 @@ public Response callback1(@Context HttpServletRequest request) throws Exception fail("exception not expected"); } - return Response.ok().build(); } diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/JUnit4SpringContextTests.java similarity index 86% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/JUnit4SpringContextTests.java index a29e12e7..f5c7f030 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/JUnit4SpringContextTests.java @@ -19,16 +19,16 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; import org.junit.Assert; import org.junit.BeforeClass; import org.springframework.context.support.ClassPathXmlApplicationContext; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class JUnit4SpringContextTests extends Assert { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ResourceTest.java similarity index 95% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ResourceTest.java index 73e04c73..9e3bbeb9 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/ResourceTest.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; +package org.apache.oltu.oauth2.integration; import java.io.InputStream; import java.io.OutputStream; @@ -29,17 +29,17 @@ import java.net.URLConnection; import java.util.Map; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; import org.junit.Test; /** * This tests against Section 5 of the OAuth 2.0 Draft 10 implementation * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class ResourceTest extends ClientResourceOAuthTest { @@ -80,10 +80,10 @@ public void testResourceAccessBodyInvalidToken() throws Exception { httpURLConnection.setAllowUserInteraction(false); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpURLConnection.setRequestProperty("Content-Length", - Integer.toString("oauth_token=randominvalidtoken".length())); + Integer.toString("access_token=randominvalidtoken".length())); OutputStream ost = httpURLConnection.getOutputStream(); PrintWriter pw = new PrintWriter(ost); - pw.print("oauth_token=randominvalidtoken"); + pw.print("access_token=randominvalidtoken"); pw.flush(); pw.close(); @@ -123,10 +123,10 @@ public void testResourceAccessBodyOAuthWrongVersionToken() throws Exception { httpURLConnection.setAllowUserInteraction(false); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpURLConnection.setRequestProperty("Content-Length", - Integer.toString("oauth_token=randominvalidtoken&oauth_signature_method=HMAC-SHA1".length())); + Integer.toString("access_token=randominvalidtoken&oauth_signature_method=HMAC-SHA1".length())); OutputStream ost = httpURLConnection.getOutputStream(); PrintWriter pw = new PrintWriter(ost); - pw.print("oauth_token=randominvalidtoken&oauth_signature_method=HMAC-SHA1"); + pw.print("access_token=randominvalidtoken&oauth_signature_method=HMAC-SHA1"); pw.flush(); pw.close(); @@ -215,7 +215,7 @@ public void testResourceAccessQueryValidToken() throws Exception { public void testResourceAccessQueryInvalidToken() throws Exception { URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_QUERY + "?" - + "oauth_token=randominvalidtoken"); + + "access_token=randominvalidtoken"); URLConnection c = url.openConnection(); if (c instanceof HttpURLConnection) { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/UnauthenticatedAccessTokenTestAuthCodeTest.java similarity index 75% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/UnauthenticatedAccessTokenTestAuthCodeTest.java index 22ee67c3..333019bf 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/UnauthenticatedAccessTokenTestAuthCodeTest.java @@ -19,58 +19,51 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration; - -import org.apache.amber.oauth2.client.OAuthClient; -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +package org.apache.oltu.oauth2.integration; + +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.URLConnectionClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; import org.junit.Test; -import org.apache.amber.oauth2.common.message.types.GrantType; - /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class AccessTokenTestAuthCodeTest extends ClientServerOAuthTest { - +public class UnauthenticatedAccessTokenTestAuthCodeTest extends ClientServerOAuthTest { @Test - public void testSuccessfullAccesToken() throws Exception { - + public void testSuccessfulAccessToken() throws Exception { OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT) .setGrantType(GrantType.AUTHORIZATION_CODE) .setCode(Common.AUTHORIZATION_CODE) .setRedirectURI(Common.REDIRECT_URL) .setClientId(Common.CLIENT_ID) - .setClientSecret(Common.CLIENT_SECRET) .buildBodyMessage(); OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); OAuthAccessTokenResponse response = oAuthClient.accessToken(request); assertNotNull(response.getAccessToken()); assertNotNull(response.getExpiresIn()); - - } @Test public void testNoneGrantType() throws Exception { OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) - .setGrantType(GrantType.NONE) + .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT) + .setGrantType(null) .setClientId(Common.CLIENT_ID) .buildBodyMessage(); OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); - try { oAuthClient.accessToken(request); fail("exception expected"); @@ -82,13 +75,12 @@ public void testNoneGrantType() throws Exception { @Test public void testInvalidRequest() throws Exception { OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT) .setClientId(Common.CLIENT_ID) .buildBodyMessage(); OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); - try { oAuthClient.accessToken(request); fail("exception expected"); @@ -100,7 +92,7 @@ public void testInvalidRequest() throws Exception { @Test public void testInvalidClient() throws Exception { OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT) .setGrantType(GrantType.AUTHORIZATION_CODE) .setCode(Common.AUTHORIZATION_CODE) .setClientId("unknownid") @@ -109,19 +101,18 @@ public void testInvalidClient() throws Exception { OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); - try { oAuthClient.accessToken(request); fail("exception expected"); } catch (OAuthProblemException e) { - assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals(OAuthError.TokenResponse.INVALID_CLIENT, e.getError()); } } @Test public void testInvalidGrantType() throws Exception { OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT) .setParameter(OAuth.OAUTH_GRANT_TYPE, "unknown_grant_type") .setCode(Common.AUTHORIZATION_CODE) .setRedirectURI(Common.REDIRECT_URL) @@ -130,20 +121,18 @@ public void testInvalidGrantType() throws Exception { OAuthClient oAuthclient = new OAuthClient(new URLConnectionClient()); - try { oAuthclient.accessToken(request); fail("exception expected"); } catch (OAuthProblemException e) { assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); } - } @Test public void testInvalidCode() throws Exception { OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) + .tokenLocation(Common.UNAUTHENTICATED_ACCESS_TOKEN_ENDPOINT) .setGrantType(GrantType.AUTHORIZATION_CODE) .setRedirectURI(Common.REDIRECT_URL) .setCode("unknown_code") @@ -156,8 +145,7 @@ public void testInvalidCode() throws Exception { oAuthClient.accessToken(request); fail("exception expected"); } catch (OAuthProblemException e) { - assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals(OAuthError.TokenResponse.INVALID_GRANT, e.getError()); } - } } \ No newline at end of file diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java similarity index 74% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java index 42de80e1..234b327a 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java @@ -19,10 +19,11 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.endpoints; +package org.apache.oltu.oauth2.integration.endpoints; import java.net.URI; import java.net.URISyntaxException; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.GET; @@ -31,21 +32,21 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import org.apache.amber.oauth2.as.issuer.MD5Generator; -import org.apache.amber.oauth2.as.request.OAuthAuthzRequest; -import org.apache.amber.oauth2.as.response.OAuthASResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.types.ResponseType; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.as.issuer.OAuthIssuerImpl; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.as.issuer.MD5Generator; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl; +import org.apache.oltu.oauth2.as.request.OAuthAuthzRequest; +import org.apache.oltu.oauth2.as.response.OAuthASResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.ResponseType; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ @Path("/authz") public class AuthzEndpoint { @@ -65,16 +66,15 @@ public Response authorize(@Context HttpServletRequest request) String responseType = oauthRequest.getParam(OAuth.OAUTH_RESPONSE_TYPE); OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse - .authorizationResponse(HttpServletResponse.SC_FOUND); + .authorizationResponse(request,HttpServletResponse.SC_FOUND); - if (responseType.equals(ResponseType.CODE.toString()) || responseType - .equals(ResponseType.CODE_AND_TOKEN.toString())) { + if (responseType.equals(ResponseType.CODE.toString())) { builder.setCode(oauthIssuerImpl.authorizationCode()); } - if (responseType.equals(ResponseType.TOKEN.toString()) || responseType - .equals(ResponseType.CODE_AND_TOKEN.toString())) { + if (responseType.equals(ResponseType.TOKEN.toString())) { builder.setAccessToken(oauthIssuerImpl.accessToken()); - builder.setExpiresIn(String.valueOf(3600)); + builder.setTokenType(OAuth.DEFAULT_TOKEN_TYPE.toString()); + builder.setExpiresIn(3600l); } String redirectURI = oauthRequest.getParam(OAuth.OAUTH_REDIRECT_URI); diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/RegistrationEndpoint.java similarity index 78% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/RegistrationEndpoint.java index 5340670b..97735b46 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/RegistrationEndpoint.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.endpoints; +package org.apache.oltu.oauth2.integration.endpoints; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,18 +30,18 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper; -import org.apache.amber.oauth2.ext.dynamicreg.server.request.OAuthServerRegistrationRequest; -import org.apache.amber.oauth2.ext.dynamicreg.server.response.OAuthServerRegistrationResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.integration.CommonExt; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper; +import org.apache.oltu.oauth2.ext.dynamicreg.server.request.OAuthServerRegistrationRequest; +import org.apache.oltu.oauth2.ext.dynamicreg.server.response.OAuthServerRegistrationResponse; +import org.apache.oltu.oauth2.integration.CommonExt; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ @Path("/register") public class RegistrationEndpoint { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceBodyEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceBodyEndpoint.java similarity index 87% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceBodyEndpoint.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceBodyEndpoint.java index 13113f32..5936240b 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceBodyEndpoint.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceBodyEndpoint.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.endpoints; +package org.apache.oltu.oauth2.integration.endpoints; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,21 +30,21 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.integration.Common; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.rs.response.OAuthRSResponse; -import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.integration.Common; +import org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest; +import org.apache.oltu.oauth2.rs.response.OAuthRSResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ @Path("/resource_body") public class ResourceBodyEndpoint { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceHeaderEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceHeaderEndpoint.java similarity index 82% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceHeaderEndpoint.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceHeaderEndpoint.java index e06978bb..0c427b50 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceHeaderEndpoint.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceHeaderEndpoint.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.endpoints; +package org.apache.oltu.oauth2.integration.endpoints; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -29,21 +29,21 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.integration.Common; -import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest; -import org.apache.amber.oauth2.rs.response.OAuthRSResponse; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.integration.Common; +import org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest; +import org.apache.oltu.oauth2.rs.response.OAuthRSResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ @Path("/resource_header") public class ResourceHeaderEndpoint { @@ -105,7 +105,7 @@ public Response get(@Context HttpServletRequest request) throws OAuthSystemExcep .setRealm(Common.RESOURCE_SERVER_NAME) .setError(e.getError()) .setErrorDescription(e.getDescription()) - .setErrorUri(e.getDescription()) + .setErrorUri(e.getUri()) .buildHeaderMessage(); return Response.status(Response.Status.BAD_REQUEST) diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceQueryEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceQueryEndpoint.java similarity index 83% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceQueryEndpoint.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceQueryEndpoint.java index 3389052a..2caa1cec 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceQueryEndpoint.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/ResourceQueryEndpoint.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.endpoints; +package org.apache.oltu.oauth2.integration.endpoints; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -29,22 +29,22 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.integration.Common; -import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest; -import org.apache.amber.oauth2.rs.response.OAuthRSResponse; -import org.apache.amber.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.integration.Common; +import org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest; +import org.apache.oltu.oauth2.rs.response.OAuthRSResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ @Path("/resource_query") public class ResourceQueryEndpoint { diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java similarity index 67% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java index f3c81c65..b374784e 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java @@ -19,38 +19,41 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.endpoints; +package org.apache.oltu.oauth2.integration.endpoints; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import org.apache.amber.oauth2.as.issuer.MD5Generator; -import org.apache.amber.oauth2.as.issuer.OAuthIssuerImpl; -import org.apache.amber.oauth2.as.issuer.OAuthIssuer; -import org.apache.amber.oauth2.as.request.OAuthTokenRequest; -import org.apache.amber.oauth2.as.response.OAuthASResponse; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.common.message.types.GrantType; -import org.apache.amber.oauth2.integration.Common; +import org.apache.oltu.oauth2.as.issuer.MD5Generator; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl; +import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; +import org.apache.oltu.oauth2.as.response.OAuthASResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.integration.Common; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ @Path("/token") public class TokenEndpoint { + public static final String INVALID_CLIENT_DESCRIPTION = "Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method)."; + @POST @Consumes("application/x-www-form-urlencoded") @Produces("application/json") @@ -63,19 +66,25 @@ public Response authorize(@Context HttpServletRequest request) throws OAuthSyste try { oauthRequest = new OAuthTokenRequest(request); - //check if clientid is valid - if (!GrantType.ASSERTION.toString().equals(oauthRequest.getGrantType())) { - if (!Common.CLIENT_ID.equals(oauthRequest.getParam(OAuth.OAUTH_CLIENT_ID))) { - OAuthResponse response = OAuthASResponse - .errorResponse(HttpServletResponse.SC_BAD_REQUEST) - .setError(OAuthError.TokenResponse.INVALID_CLIENT) - .setErrorDescription("client_id not found") + // check if clientid is valid + if (!Common.CLIENT_ID.equals(oauthRequest.getClientId())) { + OAuthResponse response = + OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST) + .setError(OAuthError.TokenResponse.INVALID_CLIENT).setErrorDescription(INVALID_CLIENT_DESCRIPTION) .buildJSONMessage(); - return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); - } + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } - //do checking for different grant types + // check if client_secret is valid + if (!Common.CLIENT_SECRET.equals(oauthRequest.getClientSecret())) { + OAuthResponse response = + OAuthASResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED) + .setError(OAuthError.TokenResponse.UNAUTHORIZED_CLIENT).setErrorDescription(INVALID_CLIENT_DESCRIPTION) + .buildJSONMessage(); + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } + + // do checking for different grant types if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE) .equals(GrantType.AUTHORIZATION_CODE.toString())) { if (!Common.AUTHORIZATION_CODE.equals(oauthRequest.getParam(OAuth.OAUTH_CODE))) { @@ -97,19 +106,9 @@ public Response authorize(@Context HttpServletRequest request) throws OAuthSyste .buildJSONMessage(); return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } - } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE) - .equals(GrantType.ASSERTION.toString())) { - if (!Common.ASSERTION.equals(oauthRequest.getAssertion())) { - OAuthResponse response = OAuthASResponse - .errorResponse(HttpServletResponse.SC_BAD_REQUEST) - .setError(OAuthError.TokenResponse.INVALID_GRANT) - .setErrorDescription("invalid assertion") - .buildJSONMessage(); - return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); - } - } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE) .equals(GrantType.REFRESH_TOKEN.toString())) { + // refresh token is not supported in this implementation OAuthResponse response = OAuthASResponse .errorResponse(HttpServletResponse.SC_BAD_REQUEST) .setError(OAuthError.TokenResponse.INVALID_GRANT) @@ -121,10 +120,11 @@ public Response authorize(@Context HttpServletRequest request) throws OAuthSyste OAuthResponse response = OAuthASResponse .tokenResponse(HttpServletResponse.SC_OK) .setAccessToken(oauthIssuerImpl.accessToken()) + .setTokenType(OAuth.DEFAULT_TOKEN_TYPE.toString()) .setExpiresIn("3600") .buildJSONMessage(); - return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } catch (OAuthProblemException e) { OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e) .buildJSONMessage(); @@ -132,4 +132,4 @@ public Response authorize(@Context HttpServletRequest request) throws OAuthSyste } } -} \ No newline at end of file +} diff --git a/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/UnauthenticatedTokenEndpoint.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/UnauthenticatedTokenEndpoint.java new file mode 100644 index 00000000..2c6a89a7 --- /dev/null +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/UnauthenticatedTokenEndpoint.java @@ -0,0 +1,123 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.integration.endpoints; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; + +import org.apache.oltu.oauth2.as.issuer.MD5Generator; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; +import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl; +import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; +import org.apache.oltu.oauth2.as.request.OAuthUnauthenticatedTokenRequest; +import org.apache.oltu.oauth2.as.response.OAuthASResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.integration.Common; + +/** + * + * + * + */ +@Path("/unauth-token") +public class UnauthenticatedTokenEndpoint { + + @POST + @Consumes("application/x-www-form-urlencoded") + @Produces("application/json") + public Response token(@Context HttpServletRequest request) throws OAuthSystemException { + + OAuthUnauthenticatedTokenRequest oauthRequest = null; + + OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator()); + + try { + oauthRequest = new OAuthUnauthenticatedTokenRequest(request); + + // check if clientid is valid + if (!Common.CLIENT_ID.equals(oauthRequest.getParam(OAuth.OAUTH_CLIENT_ID))) { + OAuthResponse response = + OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST) + .setError(OAuthError.TokenResponse.INVALID_CLIENT).setErrorDescription("client_id not found") + .buildJSONMessage(); + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } + + // do checking for different grant types + if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE) + .equals(GrantType.AUTHORIZATION_CODE.toString())) { + if (!Common.AUTHORIZATION_CODE.equals(oauthRequest.getParam(OAuth.OAUTH_CODE))) { + OAuthResponse response = OAuthASResponse + .errorResponse(HttpServletResponse.SC_BAD_REQUEST) + .setError(OAuthError.TokenResponse.INVALID_GRANT) + .setErrorDescription("invalid authorization code") + .buildJSONMessage(); + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } + } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE) + .equals(GrantType.PASSWORD.toString())) { + if (!Common.PASSWORD.equals(oauthRequest.getPassword()) + || !Common.USERNAME.equals(oauthRequest.getUsername())) { + OAuthResponse response = OAuthASResponse + .errorResponse(HttpServletResponse.SC_BAD_REQUEST) + .setError(OAuthError.TokenResponse.INVALID_GRANT) + .setErrorDescription("invalid username or password") + .buildJSONMessage(); + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } + } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE) + .equals(GrantType.REFRESH_TOKEN.toString())) { + // refresh token is not supported in this implementation hence the oauth error. + OAuthResponse response = OAuthASResponse + .errorResponse(HttpServletResponse.SC_BAD_REQUEST) + .setError(OAuthError.TokenResponse.INVALID_GRANT) + .setErrorDescription("invalid username or password") + .buildJSONMessage(); + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } + + OAuthResponse response = OAuthASResponse + .tokenResponse(HttpServletResponse.SC_OK) + .setAccessToken(oauthIssuerImpl.accessToken()) + .setExpiresIn("3600") + .buildJSONMessage(); + + return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); + } catch (OAuthProblemException e) { + OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e) + .buildJSONMessage(); + return Response.status(res.getResponseStatus()).entity(res.getBody()).build(); + } + } +} \ No newline at end of file diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/ResourceServlet.java b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/server/ResourceServlet.java similarity index 90% rename from oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/ResourceServlet.java rename to oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/server/ResourceServlet.java index ed0f3581..925faf18 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/ResourceServlet.java +++ b/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/server/ResourceServlet.java @@ -19,7 +19,7 @@ * limitations under the License. */ -package org.apache.amber.oauth2.integration.server; +package org.apache.oltu.oauth2.integration.server; import java.io.IOException; import javax.servlet.ServletConfig; @@ -29,9 +29,9 @@ import javax.servlet.http.HttpServletResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class ResourceServlet extends HttpServlet { diff --git a/oauth-2.0/oauth2-client/src/test/resources/log4j.properties b/oauth-2.0/integration-tests/src/test/resources/log4j.properties similarity index 100% rename from oauth-2.0/oauth2-client/src/test/resources/log4j.properties rename to oauth-2.0/integration-tests/src/test/resources/log4j.properties diff --git a/oauth-2.0/oauth2-integration-tests/src/test/resources/oauth-beans.xml b/oauth-2.0/integration-tests/src/test/resources/oauth-beans.xml similarity index 78% rename from oauth-2.0/oauth2-integration-tests/src/test/resources/oauth-beans.xml rename to oauth-2.0/integration-tests/src/test/resources/oauth-beans.xml index 95d54c32..1b9f2932 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/resources/oauth-beans.xml +++ b/oauth-2.0/integration-tests/src/test/resources/oauth-beans.xml @@ -41,19 +41,20 @@ + class="org.apache.oltu.oauth2.integration.endpoints.RegistrationEndpoint"/> + - - + + + @@ -62,7 +63,7 @@ - + @@ -74,10 +75,10 @@ + class="org.apache.oltu.oauth2.integration.endpoints.ResourceHeaderEndpoint"/> + class="org.apache.oltu.oauth2.integration.endpoints.ResourceBodyEndpoint"/> + class="org.apache.oltu.oauth2.integration.endpoints.ResourceQueryEndpoint"/> \ No newline at end of file diff --git a/oauth-2.0/oauth2-integration-tests/src/test/resources/server/WEB-INF/web.xml b/oauth-2.0/integration-tests/src/test/resources/server/WEB-INF/web.xml similarity index 93% rename from oauth-2.0/oauth2-integration-tests/src/test/resources/server/WEB-INF/web.xml rename to oauth-2.0/integration-tests/src/test/resources/server/WEB-INF/web.xml index 580f84c0..46c3d2d3 100644 --- a/oauth-2.0/oauth2-integration-tests/src/test/resources/server/WEB-INF/web.xml +++ b/oauth-2.0/integration-tests/src/test/resources/server/WEB-INF/web.xml @@ -29,7 +29,7 @@ testServlet - org.apache.amber.oauth2.integration.server.ExampleServlet + org.apache.oltu.oauth2.integration.server.ExampleServlet diff --git a/oauth-2.0/jwt/pom.xml b/oauth-2.0/jwt/pom.xml new file mode 100644 index 00000000..c90a78e2 --- /dev/null +++ b/oauth-2.0/jwt/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.jwt + bundle + 1.0.4-SNAPSHOT + + Apache Oltu - OAuth 2.0 - JWT + OAuth 2.0 library - JWT + + + org.apache.oltu.oauth2.jwt*;version=${project.version} + + + + + org.apache.oltu.commons + org.apache.oltu.commons.encodedtoken + 1.0.0 + + + + org.apache.oltu.commons + org.apache.oltu.commons.json + 1.0.0 + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.authzserver + 1.0.0 + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + 1.0.3-SNAPSHOT + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/ClaimsSet.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/ClaimsSet.java new file mode 100644 index 00000000..12021074 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/ClaimsSet.java @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt; + +import static java.lang.String.format; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.oltu.commons.json.CustomizableEntity; + +/** + * Represents the Claims Set as defined in the 6.1 section of the JWT specification. + * + * @see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06#section-6.1 + */ +public final class ClaimsSet extends CustomizableEntity { + + /** + * The {@code iss} JWT Claims Set parameter. + */ + private final String issuer; + + /** + * The {@code sub} JWT Claims Set parameter. + */ + private final String subject; + + /** + * The {@code aud} JWT Claims Set parameter. + */ + private final List audiences; + + /** + * The {@code exp} JWT Claims Set parameter. + */ + private final long expirationTime; + + /** + * The {@code nbf} JWT Claims Set parameter. + */ + private final String notBefore; + + /** + * The {@code iat} JWT Claims Set parameter. + */ + private final long issuedAt; + + /** + * The {@code jti} JWT Claims Set parameter. + */ + private final String jwdId; + + /** + * The {@code typ} JWT Claims Set parameter. + */ + private final String type; + + ClaimsSet(String issuer, + String subject, + List audiences, + long expirationTime, + String notBefore, + long issuedAt, + String jwdId, + String type, + Map customFields) { + super(customFields); + this.issuer = issuer; + this.subject = subject; + this.audiences = audiences == null ? null : new ArrayList(audiences); + this.expirationTime = expirationTime; + this.notBefore = notBefore; + this.issuedAt = issuedAt; + this.jwdId = jwdId; + this.type = type; + } + + /** + * Returns the {@code iss} JWT Claims Set parameter. + * + * @return the {@code iss} JWT Claims Set parameter. + */ + public String getIssuer() { + return issuer; + } + + /** + * Returns the {@code sub} JWT Claims Set parameter. + * + * @return the {@code sub} JWT Claims Set parameter. + */ + public String getSubject() { + return subject; + } + + /** + * Returns the first audience of the {@code aud} JWT Claims Set + * parameter. + * + *

There may be more than one audience listed.

+ * + * @return the {@code aud} JWT Claims Set parameter. + * @see #getAudiences + */ + public String getAudience() { + return getAudiences().isEmpty() ? null : audiences.get(0); + } + + /** + * Returns the {@code aud} JWT Claims Set parameter. + * + * @return the {@code aud} JWT Claims Set parameter. + */ + public List getAudiences() { + return audiences == null ? new ArrayList() : Collections.unmodifiableList(audiences); + } + + /** + * Returns the {@code exp} JWT Claims Set parameter. + * + * @return the {@code exp} JWT Claims Set parameter. + */ + public long getExpirationTime() { + return expirationTime; + } + + /** + * Returns the {@code nbf} JWT Claims Set parameter. + * + * @return the {@code nbf} JWT Claims Set parameter. + */ + public String getNotBefore() { + return notBefore; + } + + /** + * Returns the {@code iat} JWT Claims Set parameter. + * + * @return the {@code iat} JWT Claims Set parameter. + */ + public long getIssuedAt() { + return issuedAt; + } + + /** + * Returns the {@code jti} JWT Claims Set parameter. + * + * @return the {@code jti} JWT Claims Set parameter. + */ + public String getJwdId() { + return jwdId; + } + + /** + * Returns the {@code typ} JWT Claims Set parameter. + * + * @return the {@code typ} JWT Claims Set parameter. + */ + public String getType() { + return type; + } + + @Override + public String toString() { + return format("{\"iss\": \"%s\", \"sub\": \"%s\", \"aud\": %s, \"exp\": %s, \"nbf\": \"%s\", \"iat\": %s, \"jti\": \"%s\", \"typ\": \"%s\" }", + issuer, subject, formatAudiences(), expirationTime, notBefore, issuedAt, jwdId, type, super.toString()); + } + + private String formatAudiences() { + if (audiences == null || audiences.size() < 1) { + // "null" for no audience at all, "single-audience" otherwise + return "\"" + getAudience() + "\""; + } + StringBuilder sb = new StringBuilder("["); + boolean first = true; + for (String aud : audiences) { + if (!first) { + sb.append(", "); + } + sb.append("\"").append(aud).append("\""); + first = false; + } + return sb.append("]").toString(); + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/Header.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/Header.java new file mode 100644 index 00000000..9343eaf8 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/Header.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt; + +import static java.lang.String.format; + +import java.util.Map; + +import org.apache.oltu.commons.json.CustomizableEntity; + +/** + * Represents the Header as defined in the 6.1 section of the JWT specification. + * + * @see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06#section-6.1 + */ +public final class Header extends CustomizableEntity { + + /** + * The {@code typ} JWT Header parameter. + */ + private final String type; + + /** + * The {@code alg} JWT Header parameter. + */ + private final String algorithm; + + /** + * The {@code cty} JWT Header parameter. + */ + private final String contentType; + + Header(String type, + String algorithm, + String contentType, + Map customFields) { + super(customFields); + this.type = type; + this.algorithm = algorithm; + this.contentType = contentType; + } + + /** + * Returns the {@code typ} JWT Header parameter. + * + * @return the {@code typ} JWT Header parameter. + */ + public String getType() { + return type; + } + + /** + * Returns the {@code alg} JWT Header parameter. + * + * @return the {@code alg} JWT Header parameter. + */ + public String getAlgorithm() { + return algorithm; + } + + /** + * Returns the {@code cty} JWT Header parameter. + * + * @return the {@code cty} JWT Header parameter. + */ + public String getContentType() { + return contentType; + } + + @Override + public String toString() { + return format("{\"typ\": \"%s\", \"alg\": \"%s\", \"cty\": \"%s\" %s}", type, algorithm, contentType, super.toString()); + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/JWT.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/JWT.java new file mode 100644 index 00000000..978d9104 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/JWT.java @@ -0,0 +1,395 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt; + +import static java.lang.String.format; + +import java.util.Arrays; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.oltu.commons.json.CustomizableBuilder; + +/** + * This class contains constants used in the JWT implementation. + * + */ +public class JWT { + + /** + * The JWT Header as defined in the 6.1 section of the JWT specification. + */ + private final Header header; + + /** + * The JWT Claims Set as defined in the 6.1 section of the JWT specification. + */ + private final ClaimsSet claimsSet; + + /** + * The JWT Signature. + */ + private final String signature; + + /** + * The JWT raw string; + */ + private final String rawString; + + JWT(String rawString, Header header, ClaimsSet claimsSet, String signature) { + this.rawString = rawString; + this.header = header; + this.claimsSet = claimsSet; + this.signature = signature; + } + + /** + * Get the JWT Header as defined in the 6.1 section of the JWT specification. + * + * @return the JWT Header. + * @see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06#section-6.1 + */ + public Header getHeader() { + return header; + } + + /** + * Get the JWT Claims Set as defined in the 6.1 section of the JWT specification. + * + * @return the JWT Claims Set + * @see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06#section-6.1 + */ + public ClaimsSet getClaimsSet() { + return claimsSet; + } + + /** + * Get the JWT Signature. + * + * @return the JWT Signature. + */ + public String getSignature() { + return signature; + } + + /** + * Get the JWT raw string. + * + * @return the JWT raw string + */ + public String getRawString() { + return rawString; + } + + @Override + public String toString() { + return format("-- JWT --%nRaw String: %s%nHeader: %s%nClaims Set: %s%nSignature: %s%n---------", + rawString != null ? rawString : "unknown", header, claimsSet, signature); + } + + /** + * A simple {@link JWT} builder. + */ + public static final class Builder extends CustomizableBuilder { + + /** + * The JWT raw string + */ + private final String rawString; + + /** + * The {@code typ} JWT Header parameter. + */ + private String headerType; + + /** + * The {@code alg} JWT Header parameter. + */ + private String headerAlgorithm; + + /** + * The {@code cty} JWT Header parameter. + */ + private String headerContentType; + + /** + * The JWT Header custom fields. + */ + private final Map headerCustomFields = new LinkedHashMap(); + + /** + * The {@code iss} JWT Claims Set parameter. + */ + private String claimsSetIssuer; + + /** + * The {@code sub} JWT Claims Set parameter. + */ + private String claimsSetSubject; + + /** + * The {@code aud} JWT Claims Set parameter. + */ + private List claimsSetAudiences; + + /** + * The {@code exp} JWT Claims Set parameter. + */ + private long claimsSetExpirationTime; + + /** + * The {@code nbf} JWT Claims Set parameter. + */ + private String claimsSetNotBefore; + + /** + * The {@code iat} JWT Claims Set parameter. + */ + private long claimsSetIssuedAt; + + /** + * The {@code jti} JWT Claims Set parameter. + */ + private String claimsSetJwdId; + + /** + * The {@code typ} JWT Claims Set parameter. + */ + private String claimsSetType; + + /** + * The JWT Header custom fields. + */ + private final Map claimsSetCustomFields = new LinkedHashMap(); + + /** + * The JWT Signature. + */ + private String signature; + + public Builder() { + this(null); + } + + public Builder(String rawString) { + this.rawString = rawString; + } + + /** + * Sets the JWT Header {@code typ}. + * + * @param headerType the JWT Header {@code typ}. + * @return this builder instance. + */ + public Builder setHeaderType(String headerType) { + this.headerType = headerType; + return this; + } + + /** + * Sets the JWT Header {@code alg}. + * + * @param headerAlgorithm the JWT Header {@code alg}. + * @return this builder instance. + */ + public Builder setHeaderAlgorithm(String headerAlgorithm) { + this.headerAlgorithm = headerAlgorithm; + return this; + } + + /** + * Sets the JWT Header {@code cty}. + * + * @param headerContentType the JWT Header {@code cty}. + * @return this builder instance. + */ + public Builder setHeaderContentType(String headerContentType) { + this.headerContentType = headerContentType; + return this; + } + + /** + * Set the JWT Header custom field. + * + * @param key the custom field name. + * @param value value the custom field value. + * @return this builder instance. + */ + public Builder setHeaderCustomField(String key, Object value) { + if (key == null) { + throw new IllegalArgumentException("Null key not allowed"); + } + if (value != null) { + headerCustomFields.put(key, value); + } + return this; + } + + /** + * Sets the JWT Claims Set {@code iss}. + * + * @param claimsSetIssuer the JWT Claims Set {@code iss}. + * @return this builder instance. + */ + public Builder setClaimsSetIssuer(String claimsSetIssuer) { + this.claimsSetIssuer = claimsSetIssuer; + return this; + } + + /** + * Sets the JWT Claims Set {@code sub}. + * + * @param claimsSetSubject the JWT Claims Set {@code sub}. + * @return this builder instance. + */ + public Builder setClaimsSetSubject(String claimsSetSubject) { + this.claimsSetSubject = claimsSetSubject; + return this; + } + + /** + * Sets the JWT Claims Set {@code aud} for a single audience. + * + * @param claimsSetAudience the JWT Claims Set {@code aud}. + * @return this builder instance. + */ + public Builder setClaimsSetAudience(String claimsSetAudience) { + this.claimsSetAudiences = claimsSetAudience == null ? null + : Arrays.asList(claimsSetAudience); + return this; + } + + /** + * Sets the JWT Claims Set {@code aud}. + * + * @param claimsSetAudiences the JWT Claims Set {@code aud}. + * @return this builder instance. + */ + public Builder setClaimsSetAudiences(List claimsSetAudiences) { + this.claimsSetAudiences = claimsSetAudiences == null ? null + : new ArrayList(claimsSetAudiences); + return this; + } + + /** + * Sets the JWT Claims Set {@code exp}. + * + * @param claimsSetExpirationTime the JWT Claims Set {@code exp}. + * @return this builder instance. + */ + public Builder setClaimsSetExpirationTime(long claimsSetExpirationTime) { + this.claimsSetExpirationTime = claimsSetExpirationTime; + return this; + } + + /** + * Sets the JWT Claims Set {@code nbf}. + * + * @param claimsSetNotBefore the JWT Claims Set {@code nbf}. + * @return this builder instance. + */ + public Builder setClaimsSetNotBefore(String claimsSetNotBefore) { + this.claimsSetNotBefore = claimsSetNotBefore; + return this; + } + + /** + * Sets the JWT Claims Set {@code issuedAt}. + * + * @param claimsSetIssuedAt the JWT Claims Set {@code issuedAt}. + * @return this builder instance. + */ + public Builder setClaimsSetIssuedAt(long claimsSetIssuedAt) { + this.claimsSetIssuedAt = claimsSetIssuedAt; + return this; + } + + /** + * Sets the JWT Claims Set {@code jti}. + * + * @param claimsSetJwdId the JWT Claims Set {@code jti}. + * @return this builder instance. + */ + public Builder setClaimsSetJwdId(String claimsSetJwdId) { + this.claimsSetJwdId = claimsSetJwdId; + return this; + } + + /** + * Sets the JWT Claims Set {@code typ}. + * + * @param claimsSetType the JWT Claims Set {@code typ}. + * @return this builder instance. + */ + public Builder setClaimsSetType(String claimsSetType) { + this.claimsSetType = claimsSetType; + return this; + } + + /** + * Set the JWT Claims Set custom field. + * + * @param key the custom field name. + * @param value value the custom field value. + * @return this builder instance. + */ + public Builder setClaimsSetCustomField(String key, Object value) { + if (key == null) { + throw new IllegalArgumentException("Null key not allowed"); + } + if (value != null) { + claimsSetCustomFields.put(key, value); + } + return this; + } + + /** + * Sets the JWT signature. + * + * @param signature + * @return this builder instance. + */ + public Builder setSignature(String signature) { + this.signature = signature; + return this; + } + + /** + * Creates a new {@link JWT} instance. + * + * @return a new {@link JWT} instance. + */ + public JWT build() { + return new JWT(rawString, + new Header(headerType, headerAlgorithm, headerContentType, headerCustomFields), + new ClaimsSet(claimsSetIssuer, + claimsSetSubject, + claimsSetAudiences, + claimsSetExpirationTime, + claimsSetNotBefore, + claimsSetIssuedAt, + claimsSetJwdId, + claimsSetType, + claimsSetCustomFields), + signature); + } + + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTClaimsSetParser.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTClaimsSetParser.java new file mode 100644 index 00000000..a7854442 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTClaimsSetParser.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.commons.json.CustomizableEntityReader; +import org.apache.oltu.oauth2.jwt.JWT; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +final class JWTClaimsSetParser extends CustomizableEntityReader implements JWTConstants { + + public JWTClaimsSetParser(JWT.Builder builder) { + super(builder); + } + + @Override + protected boolean handleProperty(String key, T value) { + if (AUDIENCE.equals(key)) { + handleAudience(value); + } else if (EXPIRATION_TIME.equals(key)) { + getBuilder().setClaimsSetExpirationTime(((Number) value).longValue()); + } else if (ISSUED_AT.equals(key)) { + getBuilder().setClaimsSetIssuedAt(((Number) value).longValue()); + } else if (ISSUER.equals(key)) { + getBuilder().setClaimsSetIssuer(String.valueOf(value)); + } else if (JWT_ID.equals(key)) { + getBuilder().setClaimsSetJwdId(String.valueOf(value)); + } else if (NOT_BEFORE.equals(key)) { + getBuilder().setClaimsSetNotBefore(String.valueOf(value)); + } else if (SUBJECT.equals(key)) { + getBuilder().setClaimsSetSubject(String.valueOf(value)); + } else if (TYPE.equals(key)) { + getBuilder().setClaimsSetType(String.valueOf(value)); + } else { + getBuilder().setClaimsSetCustomField(key, value); + } + + return true; + } + + private void handleAudience(T value) { + if (value instanceof Collection) { + getBuilder().setClaimsSetAudiences(collectionToStringList((Collection) value)); + } else if (value instanceof Object[]) { + getBuilder().setClaimsSetAudiences(arrayToStringList((Object[]) value)); + } else { + getBuilder().setClaimsSetAudience(String.valueOf(value)); + } + } + + private List collectionToStringList(Collection values) { + List l = new ArrayList(); + for (Object v : values) { + l.add(String.valueOf(v)); + } + return l; + } + + private List arrayToStringList(Object[] values) { + List l = new ArrayList(); + for (Object v : values) { + l.add(String.valueOf(v)); + } + return l; + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTClaimsSetWriter.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTClaimsSetWriter.java new file mode 100644 index 00000000..7c396c18 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTClaimsSetWriter.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import java.util.List; +import org.apache.oltu.commons.json.CustomizableEntityWriter; +import org.apache.oltu.oauth2.jwt.ClaimsSet; + +public final class JWTClaimsSetWriter extends CustomizableEntityWriter implements JWTConstants { + + @Override + protected void handleProperties(ClaimsSet claimsSet) { + List audiences = claimsSet.getAudiences(); + set(AUDIENCE, audiences.size() > 1 ? audiences : claimsSet.getAudience()); + set(ISSUER, claimsSet.getIssuer()); + set(JWT_ID, claimsSet.getJwdId()); + set(NOT_BEFORE, claimsSet.getNotBefore()); + set(SUBJECT, claimsSet.getSubject()); + set(TYPE, claimsSet.getType()); + set(EXPIRATION_TIME, claimsSet.getExpirationTime()); + set(ISSUED_AT, claimsSet.getIssuedAt()); + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTConstants.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTConstants.java new file mode 100644 index 00000000..6a1a6752 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTConstants.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + + +interface JWTConstants { + + // header defined in the JWT specification + + /** + * The {@code typ} JWT Header key. + */ + public static final String TYPE = "typ"; + + /** + * The {@code alg} JWT Header key. + */ + public static final String ALGORITHM = "alg"; + + /** + * The {@code cty} JWT Header key. + */ + public static final String CONTENT_TYPE = "cty"; + + // reserved claims defined in the JWT specification + + /** + * The {@code iss} JWT Claims Set key. + */ + public static final String ISSUER = "iss"; + + /** + * The {@code sub} JWT Claims Set key. + */ + public static final String SUBJECT = "sub"; + + /** + * The {@code aud} JWT Claims Set key. + */ + public static final String AUDIENCE = "aud"; + + /** + * The {@code exp} JWT Claims Set key. + */ + public static final String EXPIRATION_TIME = "exp"; + + /** + * The {@code nbf} JWT Claims Set key. + */ + public static final String NOT_BEFORE = "nbf"; + + /** + * The {@code iat} JWT Claims Set key. + */ + public static final String ISSUED_AT = "iat"; + + /** + * The {@code jti} JWT Claims Set key. + */ + public static final String JWT_ID = "jti"; + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTHeaderParser.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTHeaderParser.java new file mode 100644 index 00000000..eed0b11b --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTHeaderParser.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.commons.json.CustomizableEntityReader; +import org.apache.oltu.oauth2.jwt.JWT; + +final class JWTHeaderParser extends CustomizableEntityReader implements JWTConstants { + + public JWTHeaderParser(JWT.Builder builder) { + super( builder ); + } + + @Override + protected boolean handleProperty( String key, T value ) { + if (ALGORITHM.equals(key)) { + getBuilder().setHeaderAlgorithm(String.valueOf(value)); + } else if (TYPE.equals(key)) { + getBuilder().setHeaderType(String.valueOf(value)); + } else if (CONTENT_TYPE.equals(key)) { + getBuilder().setHeaderContentType(String.valueOf(value)); + } else { + getBuilder().setHeaderCustomField(key, value); + } + + return true; + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTHeaderWriter.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTHeaderWriter.java new file mode 100644 index 00000000..c86b5d80 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTHeaderWriter.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.commons.json.CustomizableEntityWriter; +import org.apache.oltu.oauth2.jwt.Header; + +public final class JWTHeaderWriter extends CustomizableEntityWriter
implements JWTConstants { + + @Override + protected void handleProperties(Header header) { + set(ALGORITHM, header.getAlgorithm()); + set(CONTENT_TYPE, header.getContentType()); + set(TYPE, header.getType()); + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTReader.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTReader.java new file mode 100644 index 00000000..6d684736 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTReader.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.commons.encodedtoken.TokenReader; +import org.apache.oltu.oauth2.jwt.JWT; + +/** + * A {@link JWT} reader. + */ +public final class JWTReader extends TokenReader { + + @Override + protected JWT build(String rawString, String decodedHeader, String decodedBody, String encodedSignature) { + JWT.Builder jwtBuilder = new JWT.Builder(rawString); + + new JWTHeaderParser(jwtBuilder).read(decodedHeader); + new JWTClaimsSetParser(jwtBuilder).read(decodedBody); + + return jwtBuilder.setSignature(encodedSignature).build(); + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTWriter.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTWriter.java new file mode 100644 index 00000000..575fe8db --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/JWTWriter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.commons.encodedtoken.TokenWriter; +import org.apache.oltu.oauth2.jwt.JWT; + +/** + * A {@link JWT} writer. + */ +public final class JWTWriter extends TokenWriter { + + @Override + protected String writeHeader(JWT token) { + return new JWTHeaderWriter().write(token.getHeader()); + } + + @Override + protected String writeBody(JWT token) { + return new JWTClaimsSetWriter().write(token.getClaimsSet()); + } + + @Override + protected String writeSignature(JWT token) { + return token.getSignature(); + } + +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/package-info.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/package-info.java new file mode 100644 index 00000000..445a119d --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/io/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * JWT I/O manipulators implementation. + */ +package org.apache.oltu.oauth2.jwt.io; diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/package-info.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/package-info.java new file mode 100644 index 00000000..feafe111 --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Basic JSON Web Token implementation. + */ +package org.apache.oltu.oauth2.jwt; diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/JWTBearerValidator.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/JWTBearerValidator.java new file mode 100644 index 00000000..d1d3234b --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/JWTBearerValidator.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.request; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; + +public class JWTBearerValidator extends AbstractValidator { + + public JWTBearerValidator() { + requiredParams.add(OAuth.ASSERTION); + } +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/JWTOAuthRequest.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/JWTOAuthRequest.java new file mode 100644 index 00000000..ad6f955e --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/JWTOAuthRequest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.request; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.as.request.AbstractOAuthTokenRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; + +public class JWTOAuthRequest extends AbstractOAuthTokenRequest { + + /** + * Create a JWT OAuth Token request from a given HttpSerlvetRequest + * + * @param request the httpservletrequest that is validated and transformed into the JWT OAuth Token Request + * @throws OAuthSystemException if an unexpected exception was thrown + * @throws OAuthProblemException if the request was not a valid Token request this exception is thrown. + */ + public JWTOAuthRequest(HttpServletRequest request) throws OAuthSystemException, OAuthProblemException { + super(request); + } + + @Override + protected OAuthValidator initValidator() + throws OAuthProblemException, OAuthSystemException { + validators.put(GrantType.JWT_BEARER.toString(), JWTBearerValidator.class); + return super.initValidator(); + } + + public String getAssertion() { + return getParam(OAuth.ASSERTION); + } +} diff --git a/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/package-info.java b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/package-info.java new file mode 100644 index 00000000..0db8f04a --- /dev/null +++ b/oauth-2.0/jwt/src/main/java/org/apache/oltu/oauth2/jwt/request/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * JWT request manipulators implementation. + */ +package org.apache.oltu.oauth2.jwt.request; diff --git a/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/IOTestCaseConstants.java b/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/IOTestCaseConstants.java new file mode 100644 index 00000000..3e8924d5 --- /dev/null +++ b/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/IOTestCaseConstants.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +interface IOTestCaseConstants { + + public final String JWT = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJlMWRhMGIzNTY3YmQyNjVhMjUwOThmYmNjMmIwOWYyMTM0" + + "NWIzYTIifQ" + + "." + + "eyJhdWQiOiI3ODg3MzIzNzIwNzguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJpc3MiOiJh" + + "Y2NvdW50cy5nb29nbGUuY29tIiwic3ViIjoiMTA2NDIyNDUzMDgyNDc5OTk4NDI5IiwiZXhwIjox" + + "MzY2NzMwMjE3LCJpYXQiOjEzNjY3MjYzMTcsImlkIjoiMTA2NDIyNDUzMDgyNDc5OTk4NDI5Iiwi" + + "dmVyaWZpZWRfZW1haWwiOiJ0cnVlIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwiY2lkIjoiNzg4" + + "NzMyMzcyMDc4LmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiYXpwIjoiNzg4NzMyMzcyMDc4" + + "LmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJhbnRvbmlvLnNhbnNvQGdtYWls" + + "LmNvbSIsInRva2VuX2hhc2giOiJMMkk3N2dpQkxrMFJTczB6UTFTdkNBIiwiYXRfaGFzaCI6Ikwy" + + "STc3Z2lCTGswUlNzMHpRMVN2Q0EifQ" + + "." + + "XWYi5Zj1YWAMGIml_ftoAwmvW1Y7oeybLCpzQrJVuWJpS8L8Vd2TL-RTIOEVG03VA7e0_-_frNuw" + + "7MxUgVEgh8G-Nnbk_baJ6k_3w5c1SKFamFiHHDoKLFhrt1Y8JKSuGwE02V-px4Cn0dRAQAc1IN5C" + + "U6wqCrYK0p-fv_fvy28"; + + public final String JWT_MULTIPLE_AUDIENCES = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJlMWRhMGIzNTY3YmQyNjVhMjUwO" + + "ThmYmNjMmIwOWYyMTM0NWIzYTIifQ" + + "." + + "eyJhdWQiOlsiNzg4NzMyMzcyMDc4LmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZm9vIl0s" + + "ImlzcyI6ImFjY291bnRzLmdvb2dsZS5jb20iLCJzdWIiOiIxMDY0MjI0NTMwODI0Nzk5OTg0Mjki" + + "LCJleHAiOjEzNjY3MzAyMTcsImlhdCI6MTM2NjcyNjMxNywiaWQiOiIxMDY0MjI0NTMwODI0Nzk5" + + "OTg0MjkiLCJ2ZXJpZmllZF9lbWFpbCI6InRydWUiLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJj" + + "aWQiOiI3ODg3MzIzNzIwNzguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhenAiOiI3ODg3" + + "MzIzNzIwNzguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJlbWFpbCI6ImFudG9uaW8uc2Fu" + + "c29AZ21haWwuY29tIiwidG9rZW5faGFzaCI6IkwySTc3Z2lCTGswUlNzMHpRMVN2Q0EiLCJhdF9o" + + "YXNoIjoiTDJJNzdnaUJMazBSU3MwelExU3ZDQSJ9" + + "." + + "XWYi5Zj1YWAMGIml_ftoAwmvW1Y7oeybLCpzQrJVuWJpS8L8Vd2TL-RTIOEVG03VA7e0_-_frNuw" + + "7MxUgVEgh8G-Nnbk_baJ6k_3w5c1SKFamFiHHDoKLFhrt1Y8JKSuGwE02V-px4Cn0dRAQAc1IN5C" + + "U6wqCrYK0p-fv_fvy28"; + +} diff --git a/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/JWTReaderTestCase.java b/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/JWTReaderTestCase.java new file mode 100644 index 00000000..ff2d27f5 --- /dev/null +++ b/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/JWTReaderTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.oauth2.jwt.ClaimsSet; +import org.apache.oltu.oauth2.jwt.Header; +import org.apache.oltu.oauth2.jwt.JWT; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public final class JWTReaderTestCase implements IOTestCaseConstants { + + private JWT jwt; + + private final JWTReader jwtReader = new JWTReader(); + + @Before + public void setUp() throws Exception { + jwt = jwtReader.read(JWT); + } + + @After + public void tearDown() throws Exception { + jwt = null; + } + + @Test + public void testJWT() throws Exception { + assertEquals(JWT, jwt.getRawString()); + } + + @Test + public void testJWTWithMultipleAudiences() throws Exception { + jwt = jwtReader.read(JWT_MULTIPLE_AUDIENCES); + assertEquals(JWT_MULTIPLE_AUDIENCES, jwt.getRawString()); + } + + @Test + public void testHeader() throws Exception { + Header header = jwt.getHeader(); + assertEquals("RS256", header.getAlgorithm()); + } + + @Test + public void testClaimsSet() throws Exception { + ClaimsSet claimsSet = jwt.getClaimsSet(); + assertEquals(Arrays.asList("788732372078.apps.googleusercontent.com"), claimsSet.getAudiences()); + assertEquals("788732372078.apps.googleusercontent.com", claimsSet.getAudience()); + assertEquals("accounts.google.com", claimsSet.getIssuer()); + assertEquals("106422453082479998429", claimsSet.getSubject()); + assertEquals(1366730217L, claimsSet.getExpirationTime()); + assertEquals(1366726317L, claimsSet.getIssuedAt()); + } + + @Test + public void testClaimsSetWithMultipleAudiences() throws Exception { + jwt = jwtReader.read(JWT_MULTIPLE_AUDIENCES); + ClaimsSet claimsSet = jwt.getClaimsSet(); + assertEquals(Arrays.asList("788732372078.apps.googleusercontent.com", "foo"), claimsSet.getAudiences()); + assertEquals("788732372078.apps.googleusercontent.com", claimsSet.getAudience()); + assertEquals("accounts.google.com", claimsSet.getIssuer()); + assertEquals("106422453082479998429", claimsSet.getSubject()); + assertEquals(1366730217L, claimsSet.getExpirationTime()); + assertEquals(1366726317L, claimsSet.getIssuedAt()); + } + +} diff --git a/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/JWTWriterTestCase.java b/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/JWTWriterTestCase.java new file mode 100644 index 00000000..1b3a80ad --- /dev/null +++ b/oauth-2.0/jwt/src/test/java/org/apache/oltu/oauth2/jwt/io/JWTWriterTestCase.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.jwt.io; + +import org.apache.oltu.oauth2.jwt.JWT; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public final class JWTWriterTestCase implements IOTestCaseConstants { + + @Test + public void write() { + JWT jwt = new JWT.Builder() + // header + .setHeaderAlgorithm("RS256") + .setHeaderCustomField("kid", "be1da0b3567bd265a25098fbcc2b09f21345b3a2") + // claimset + .setClaimsSetAudience("788732372078.apps.googleusercontent.com") + .setClaimsSetIssuer("accounts.google.com") + .setClaimsSetSubject("106422453082479998429") + .setClaimsSetExpirationTime(1366730217L) + .setClaimsSetIssuedAt(1366726317L) + .setClaimsSetCustomField("id", "106422453082479998429") + .setClaimsSetCustomField("verified_email", "true") + .setClaimsSetCustomField("email_verified", "true") + .setClaimsSetCustomField("cid", "788732372078.apps.googleusercontent.com") + .setClaimsSetCustomField("azp", "788732372078.apps.googleusercontent.com") + .setClaimsSetCustomField("email", "antonio.sanso@gmail.com") + .setClaimsSetCustomField("token_hash", "L2I77giBLk0RSs0zQ1SvCA") + .setClaimsSetCustomField("at_hash", "L2I77giBLk0RSs0zQ1SvCA") + // signature + .setSignature("XWYi5Zj1YWAMGIml_ftoAwmvW1Y7oeybLCpzQrJVuWJpS8L8Vd2TL-RTIOEVG03VA7e0_-_frNuw7MxUgVEgh8G-Nnbk_baJ6k_3w5c1SKFamFiHHDoKLFhrt1Y8JKSuGwE02V-px4Cn0dRAQAc1IN5CU6wqCrYK0p-fv_fvy28") + .build(); + String encodedJWT = new JWTWriter().write(jwt); + assertEquals(JWT, encodedJWT); + } + + @Test + public void writeSingleAudienceAsList() { + JWT jwt = new JWT.Builder() + // header + .setHeaderAlgorithm("RS256") + .setHeaderCustomField("kid", "be1da0b3567bd265a25098fbcc2b09f21345b3a2") + // claimset + .setClaimsSetAudiences(Arrays.asList("788732372078.apps.googleusercontent.com")) + .setClaimsSetIssuer("accounts.google.com") + .setClaimsSetSubject("106422453082479998429") + .setClaimsSetExpirationTime(1366730217L) + .setClaimsSetIssuedAt(1366726317L) + .setClaimsSetCustomField("id", "106422453082479998429") + .setClaimsSetCustomField("verified_email", "true") + .setClaimsSetCustomField("email_verified", "true") + .setClaimsSetCustomField("cid", "788732372078.apps.googleusercontent.com") + .setClaimsSetCustomField("azp", "788732372078.apps.googleusercontent.com") + .setClaimsSetCustomField("email", "antonio.sanso@gmail.com") + .setClaimsSetCustomField("token_hash", "L2I77giBLk0RSs0zQ1SvCA") + .setClaimsSetCustomField("at_hash", "L2I77giBLk0RSs0zQ1SvCA") + // signature + .setSignature("XWYi5Zj1YWAMGIml_ftoAwmvW1Y7oeybLCpzQrJVuWJpS8L8Vd2TL-RTIOEVG03VA7e0_-_frNuw7MxUgVEgh8G-Nnbk_baJ6k_3w5c1SKFamFiHHDoKLFhrt1Y8JKSuGwE02V-px4Cn0dRAQAc1IN5CU6wqCrYK0p-fv_fvy28") + .build(); + String encodedJWT = new JWTWriter().write(jwt); + assertEquals(JWT, encodedJWT); + } + + @Test + public void writeWithMultipleAudiences() { + JWT jwt = new JWT.Builder() + // header + .setHeaderAlgorithm("RS256") + .setHeaderCustomField("kid", "be1da0b3567bd265a25098fbcc2b09f21345b3a2") + // claimset + .setClaimsSetAudiences(Arrays.asList("788732372078.apps.googleusercontent.com", "foo")) + .setClaimsSetIssuer("accounts.google.com") + .setClaimsSetSubject("106422453082479998429") + .setClaimsSetExpirationTime(1366730217L) + .setClaimsSetIssuedAt(1366726317L) + .setClaimsSetCustomField("id", "106422453082479998429") + .setClaimsSetCustomField("verified_email", "true") + .setClaimsSetCustomField("email_verified", "true") + .setClaimsSetCustomField("cid", "788732372078.apps.googleusercontent.com") + .setClaimsSetCustomField("azp", "788732372078.apps.googleusercontent.com") + .setClaimsSetCustomField("email", "antonio.sanso@gmail.com") + .setClaimsSetCustomField("token_hash", "L2I77giBLk0RSs0zQ1SvCA") + .setClaimsSetCustomField("at_hash", "L2I77giBLk0RSs0zQ1SvCA") + // signature + .setSignature("XWYi5Zj1YWAMGIml_ftoAwmvW1Y7oeybLCpzQrJVuWJpS8L8Vd2TL-RTIOEVG03VA7e0_-_frNuw7MxUgVEgh8G-Nnbk_baJ6k_3w5c1SKFamFiHHDoKLFhrt1Y8JKSuGwE02V-px4Cn0dRAQAc1IN5CU6wqCrYK0p-fv_fvy28") + .build(); + String encodedJWT = new JWTWriter().write(jwt); + assertEquals(JWT_MULTIPLE_AUDIENCES, encodedJWT); + } + +} diff --git a/oauth-2.0/oauth2-authzserver/pom.xml b/oauth-2.0/oauth2-authzserver/pom.xml deleted file mode 100644 index c4f8e22e..00000000 --- a/oauth-2.0/oauth2-authzserver/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - org.apache.amber - amber-oauth2-parent - 0.10-incubating-SNAPSHOT - - - 4.0.0 - oauth2-authzserver - 0.10-incubating-SNAPSHOT - Apache Amber: OAuth 2.0 Implementation - Authorization Server - jar - - - oauth2-authzserver - - - - org.apache.amber - oauth2-common - 0.2-SNAPSHOT - - - - org.codehaus.jettison - jettison - ${jettison.version} - - - stax - stax-api - - - - - - org.apache.cxf - cxf-rt-frontend-jaxrs - ${cxf.version} - test - - - org.apache.cxf - cxf-testutils - ${cxf.version} - test - - - - \ No newline at end of file diff --git a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthTokenRequest.java b/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthTokenRequest.java deleted file mode 100644 index 642b523c..00000000 --- a/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthTokenRequest.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.as.request; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.amber.oauth2.as.validator.AuthorizationCodeValidator; -import org.apache.amber.oauth2.as.validator.AssertionValidator; -import org.apache.amber.oauth2.as.validator.PasswordValidator; -import org.apache.amber.oauth2.as.validator.RefreshTokenValidator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.types.GrantType; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.OAuthValidator; - - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class OAuthTokenRequest extends OAuthRequest { - - - public OAuthTokenRequest(HttpServletRequest request) throws OAuthSystemException, OAuthProblemException { - super(request); - } - - @Override - protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException { - validators.put(GrantType.PASSWORD.toString(), PasswordValidator.class); - validators.put(GrantType.ASSERTION.toString(), AssertionValidator.class); - validators.put(GrantType.AUTHORIZATION_CODE.toString(), AuthorizationCodeValidator.class); - validators.put(GrantType.REFRESH_TOKEN.toString(), RefreshTokenValidator.class); - String requestTypeValue = getParam(OAuth.OAUTH_GRANT_TYPE); - if (OAuthUtils.isEmpty(requestTypeValue)) { - throw OAuthUtils.handleOAuthProblemException("Missing grant_type parameter value"); - } - Class clazz = validators.get(requestTypeValue); - if (clazz == null) { - throw OAuthUtils.handleOAuthProblemException("Invalid grant_type parameter value"); - } - return (OAuthValidator)OAuthUtils.instantiateClass(clazz); - } - - public String getPassword() { - return getParam(OAuth.OAUTH_PASSWORD); - } - - public String getUsername() { - return getParam(OAuth.OAUTH_USERNAME); - } - - public String getAssertion() { - return getParam(OAuth.OAUTH_ASSERTION); - } - - public String getAssertionType() { - return getParam(OAuth.OAUTH_ASSERTION_TYPE); - } - - public String getCode() { - return getParam(OAuth.OAUTH_CODE); - } - - public String getGrantType() { - return getParam(OAuth.OAUTH_GRANT_TYPE); - } - -} diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java b/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java deleted file mode 100644 index e2a916fd..00000000 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java +++ /dev/null @@ -1,824 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.as; - -import java.util.Set; -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.as.request.OAuthAuthzRequest; -import org.apache.amber.oauth2.as.request.OAuthRequest; -import org.apache.amber.oauth2.as.request.OAuthTokenRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.types.GrantType; -import org.apache.amber.oauth2.common.message.types.ResponseType; -import org.junit.Test; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reset; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.fail; - - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class OAuthRequestTest { - - @Test - public void testWrongResponseGetRequestParam() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - expect(request.getParameter("param")).andStubReturn("someparam"); - replay(request); - - try { - new OAuthAuthzRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(null); - expect(request.getParameter("param")).andStubReturn("someparam"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - replay(request); - - try { - new OAuthAuthzRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - @Test - public void testCodeRequestInvalidMethod() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.PUT); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - OAuthRequest req = null; - try { - new OAuthAuthzRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - - @Test - public void testCodeRequestMissingParameter() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - OAuthRequest req = null; - try { - new OAuthAuthzRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn(null); - replay(request); - - try { - new OAuthAuthzRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - } - - @Test - public void testValidCodeRequest() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - OAuthRequest req = null; - try { - new OAuthAuthzRequest(request); - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthAuthzRequest(request); - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - - verify(request); - } - - @Test - public void testTokenWrongGrantType() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - expect(request.getParameter("param")).andStubReturn("someparam"); - replay(request); - - OAuthRequest req = null; - try { - req = new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - expect(request.getParameter("param")).andStubReturn("someparam"); - replay(request); - - try { - req = new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - @Test - public void testTokenRequestInvalidMethod() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.AUTHORIZATION_CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.ASSERTION.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - verify(request); - - reset(request); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.PASSWORD.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.REFRESH_TOKEN.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - verify(request); - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.NONE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - } - - @Test - public void testTokenRequestInvalidContentType() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.AUTHORIZATION_CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - verify(request); - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.ASSERTION.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.PASSWORD.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.REFRESH_TOKEN.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.NONE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - @Test - public void testTokenAuthCodeRequestMissingParameter() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.AUTHORIZATION_CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code"); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.AUTHORIZATION_CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code"); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.AUTHORIZATION_CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - } - - @Test - public void testTokenPasswordRequestMissingParameter() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.PASSWORD.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.PASSWORD.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("test_username"); - expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn(""); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.PASSWORD.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("test_username"); - expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - @Test - public void testTokenAssertionRequestMissingParameter() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.ASSERTION.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn("test_type"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.ASSERTION.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn("test_assertion"); - expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn(null); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.ASSERTION.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn(""); - expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn(""); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - @Test - public void testRefreshTokenRequestMissingParameter() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.REFRESH_TOKEN.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.REFRESH_TOKEN.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(""); - expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token"); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.REFRESH_TOKEN.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red"); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - new OAuthTokenRequest(request); - fail("Exception expected"); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - verify(request); - } - - @Test - public void testValidTokenRequest() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.AUTHORIZATION_CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code"); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("test_secret"); - replay(request); - - OAuthTokenRequest req = null; - try { - req = new OAuthTokenRequest(request); - - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - Assert.assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType()); - Assert.assertEquals("test_client", req.getClientId()); - Assert.assertEquals("http://example.com/callback", req.getRedirectURI()); - Assert.assertEquals("test_code", req.getCode()); - - verify(request); - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.PASSWORD.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("username_test"); - expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password"); - replay(request); - - try { - req = new OAuthTokenRequest(request); - - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - Assert.assertEquals("client_id", req.getClientId()); - Assert.assertEquals("username_test", req.getUsername()); - Assert.assertEquals("test_password", req.getPassword()); - - verify(request); - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.ASSERTION.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn("test_assertion"); - expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn("test_type"); - replay(request); - - try { - req = new OAuthTokenRequest(request); - - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - Assert.assertEquals("test_assertion", req.getAssertion()); - Assert.assertEquals("test_type", req.getAssertionType()); - - verify(request); - reset(request); - - expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)) - .andStubReturn(GrantType.REFRESH_TOKEN.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id"); - expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token"); - expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret"); - replay(request); - - try { - req = new OAuthTokenRequest(request); - - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - Assert.assertEquals("client_id", req.getClientId()); - Assert.assertEquals("refresh_token", req.getRefreshToken()); - Assert.assertEquals("secret", req.getClientSecret()); - - verify(request); - - - } - - @Test - public void testScopes() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - - expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString()); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client"); - expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback"); - expect(request.getParameter(OAuth.OAUTH_SCOPE)).andStubReturn("album photo"); - replay(request); - - OAuthRequest req = null; - try { - req = new OAuthAuthzRequest(request); - } catch (OAuthProblemException e) { - fail("Exception not expected"); - } - - Set scopes = req.getScopes(); - - Assert.assertTrue(findScope(scopes, "album")); - Assert.assertTrue(findScope(scopes, "photo")); - - verify(request); - } - - private boolean findScope(Set scopes, String scope) { - for (String s : scopes) { - if (s.equals(scope)) { - return true; - } - } - return false; - } -} diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java b/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java deleted file mode 100644 index 12ba7afc..00000000 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.as.response; - -import org.apache.amber.oauth2.as.response.OAuthASResponse; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.junit.Assert; -import org.junit.Test; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class OAuthASResponseTest { - - @Test - public void testAuthzResponse() throws Exception { - OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(200) - .location("http://www.example.com") - .setCode("code") - .setAccessToken("access_111") - .setExpiresIn("400") - .setState("ok") - .setParam("testValue", "value2") - .buildQueryMessage(); - - String url = oAuthResponse.getLocationUri(); - - Assert.assertEquals("http://www.example.com?testValue=value2&state=ok&code=code" - + "#expires_in=400&access_token=access_111", url); - Assert.assertEquals(200, oAuthResponse.getResponseStatus()); - - } - - @Test - public void testTokenResponse() throws Exception { - - OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token") - .setExpiresIn("200").setRefreshToken("refresh_token2") - .buildBodyMessage(); - - String body = oAuthResponse.getBody(); - Assert.assertEquals( - "expires_in=200&refresh_token=refresh_token2&access_token=access_token", - body); - - } - - @Test - public void testTokenResponseAdditionalParam() throws Exception { - - OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token") - .setExpiresIn("200").setRefreshToken("refresh_token2").setParam("some_param", "new_param") - .buildBodyMessage(); - - String body = oAuthResponse.getBody(); - Assert.assertEquals( - "some_param=new_param&expires_in=200&refresh_token=refresh_token2&access_token=access_token", - body); - - } - - @Test - public void testErrorResponse() throws Exception { - - OAuthProblemException ex = OAuthProblemException - .error(OAuthError.CodeResponse.ACCESS_DENIED, "Access denied") - .setParameter("testparameter", "testparameter_value") - .scope("album") - .uri("http://www.example.com/error"); - - OAuthResponse oAuthResponse = OAuthResponse.errorResponse(400).error(ex).buildJSONMessage(); - - Assert.assertEquals( - "{\"error_uri\":\"http:\\/\\/www.example.com\\/error\",\"error\":\"access_denied\",\"" - + "error_description\":\"Access denied\"}", - oAuthResponse.getBody()); - - - oAuthResponse = OAuthResponse.errorResponse(500) - .location("http://www.example.com/redirect?param2=true").error(ex).buildQueryMessage(); - Assert.assertEquals( - "http://www.example.com/redirect?param2=true&error_uri=http%3A%2F%2Fwww.example.com%2Ferror" - + "&error=access_denied&error_description=Access+denied", - oAuthResponse.getLocationUri()); - } - - @Test - public void testErrorResponse2() throws Exception { - OAuthProblemException ex = OAuthProblemException - .error(OAuthError.CodeResponse.ACCESS_DENIED, "Access denied") - .setParameter("testparameter", "testparameter_value") - .scope("album") - .uri("http://www.example.com/error"); - - OAuthResponse oAuthResponse = OAuthResponse.errorResponse(500) - .location("http://www.example.com/redirect?param2=true").error(ex).buildQueryMessage(); - Assert.assertEquals( - "http://www.example.com/redirect?param2=true&error_uri=http%3A%2F%2Fwww.example.com%2Ferror" - + "&error=access_denied&error_description=Access+denied", - oAuthResponse.getLocationUri()); - } - - @Test - public void testHeaderResponse() throws Exception { - OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(400).setCode("oauth_code") - .setState("state_ok") - .buildHeaderMessage(); - - String header = oAuthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE); - Assert.assertEquals("OAuth state=\"state_ok\",code=\"oauth_code\"", header); - - header = oAuthResponse.getHeaders().get(OAuth.HeaderType.WWW_AUTHENTICATE); - Assert.assertEquals("OAuth state=\"state_ok\",code=\"oauth_code\"", header); - } - -} diff --git a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java b/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java deleted file mode 100644 index e60d600e..00000000 --- a/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.as.validator; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.amber.oauth2.as.validator.CodeTokenValidator; -import org.apache.amber.oauth2.common.OAuth; -import org.junit.Assert; -import org.junit.Test; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; - -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reset; -import static org.easymock.EasyMock.verify; - - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class CodeTokenValidatorTest { - @Test - public void testValidateMethod() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - - replay(request); - CodeTokenValidator validator = new CodeTokenValidator(); - validator.validateMethod(request); - - verify(request); - - reset(request); - - request = createStrictMock(HttpServletRequest.class); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); - - replay(request); - validator = new CodeTokenValidator(); - validator.validateMethod(request); - - verify(request); - - reset(request); - - request = createStrictMock(HttpServletRequest.class); - expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.DELETE); - - replay(request); - validator = new CodeTokenValidator(); - - try { - validator.validateMethod(request); - Assert.fail("Expected validation exception"); - } catch (OAuthProblemException e) { - //ok, expected - } - - verify(request); - } -} diff --git a/oauth-2.0/oauth2-client-demo/pom.xml b/oauth-2.0/oauth2-client-demo/pom.xml deleted file mode 100644 index 9cf6e41a..00000000 --- a/oauth-2.0/oauth2-client-demo/pom.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - 4.0.0 - oauth2-client-demo - Apache Amber: OAuth 2.0 Implementation - Demo Application - war - - - - - 3.0.3.RELEASE - - - - - oauth2-demo - - - org.mortbay.jetty - maven-jetty-plugin - 6.1.24 - - - / - - - - 8080 - 60000 - - - 10 - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.6 - 1.6 - - - - - - - - - commons-logging - commons-logging - 1.1 - - - org.slf4j - slf4j-jcl - 1.6.0 - - - - - - oauth2-common - org.apache.amber - ${project.version} - - - - - - oauth2-dynamicreg-common - org.apache.amber - ${project.version} - - - - oauth2-dynamicreg-client - org.apache.amber - ${project.version} - - - - - - org.springframework - spring-context - ${org.springframework.version} - - - - commons-logging - commons-logging - - - - - org.springframework - spring-webmvc - ${org.springframework.version} - - - - - - - org.tuckey - urlrewritefilter - 3.1.0 - runtime - - - - - standard - taglibs - 1.1.2 - jar - runtime - - - - - diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java b/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java deleted file mode 100644 index 316e3752..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.client.demo.controller; - -import java.io.IOException; -import javax.servlet.http.HttpServletResponse; - -import org.apache.amber.oauth2.client.demo.Utils; -import org.apache.amber.oauth2.client.demo.model.OAuthRegParams; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -@Controller -@RequestMapping("/") -public class MainController { - - private Logger logger = LoggerFactory.getLogger(MainController.class); - - @RequestMapping("/index") - public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams) - throws OAuthSystemException, IOException { - return new ModelAndView("index"); - } - - @RequestMapping("/main/{app}") - public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, - @ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams, - @PathVariable("app") String app, - HttpServletResponse res) - throws OAuthSystemException, IOException { - - boolean selected = false; - if (Utils.GITHUB.equals(app)) { - selected = true; - oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ); - oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN); - - } else if (Utils.FACEBOOK.equals(app)) { - selected = true; - oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ); - oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN); - } else if (Utils.GOWALLA.equals(app)) { - selected = true; - oauthParams.setAuthzEndpoint(Utils.GOWALLA_AUTHZ); - oauthParams.setTokenEndpoint(Utils.GOWALLA_TOKEN); - } else if (Utils.SMART_GALLERY.equals(app)) { - selected = true; - oauthRegParams.setAuthzEndpoint(Utils.SMART_GALLERY_AUTHZ); - oauthRegParams.setTokenEndpoint(Utils.SMART_GALLERY_TOKEN); - oauthRegParams.setRegistrationEndpoint(Utils.SMART_GALLERY_REGISTER); - oauthRegParams.setApplication(app); - oauthRegParams.setRedirectUri(Utils.REDIRECT_URI); - return new ModelAndView("register"); - } - if (selected) { - oauthParams.setApplication(app); - oauthParams.setRedirectUri(Utils.REDIRECT_URI); - return new ModelAndView("get_authz"); - } - - return new ModelAndView("index"); - } -} diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java b/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java deleted file mode 100644 index d02e1812..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.client.demo.controller; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import javax.servlet.http.HttpServletRequest; - -import org.apache.amber.oauth2.client.demo.Utils; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.OAuth; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -@Controller -@RequestMapping("/get_resource") -public class ResourceController { - - @RequestMapping - public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, - HttpServletRequest req) { - - try { - String tokenName = OAuth.OAUTH_TOKEN_DRAFT_0; - if (Utils.SMART_GALLERY.equals(oauthParams.getApplication())) { - tokenName = OAuth.OAUTH_TOKEN; - } - URL url = new URL( - oauthParams.getResourceUrl() + "?" + tokenName + "=" + oauthParams.getAccessToken()); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - if (conn.getResponseCode() == 200) { - oauthParams.setResource(OAuthUtils.saveStreamAsString(conn.getInputStream())); - } else { - oauthParams.setErrorMessage( - "Could not access resource: " + conn.getResponseCode() + " " + conn.getResponseMessage()); - } - } catch (IOException e) { - oauthParams.setErrorMessage(e.getMessage()); - } - - return new ModelAndView("resource"); - - - } -} diff --git a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java b/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java deleted file mode 100644 index ee984257..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.client.demo.controller; - -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; - -import org.apache.amber.oauth2.client.OAuthClient; -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.demo.Utils; -import org.apache.amber.oauth2.client.demo.exception.ApplicationException; -import org.apache.amber.oauth2.client.demo.model.OAuthParams; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.types.GrantType; -import org.apache.amber.oauth2.client.response.GitHubTokenResponse; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import org.apache.amber.oauth2.client.response.OAuthJSONAccessTokenResponse; - - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -@Controller -@RequestMapping("/get_token") -public class TokenController { - - @RequestMapping - public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, - HttpServletRequest req) throws OAuthSystemException, IOException { - - try { - - Utils.validateTokenParams(oauthParams); - - OAuthClientRequest request = OAuthClientRequest - .tokenLocation(oauthParams.getTokenEndpoint()) - .setClientId(oauthParams.getClientId()) - .setClientSecret(oauthParams.getClientSecret()) - .setRedirectURI(oauthParams.getRedirectUri()) - .setCode(oauthParams.getAuthzCode()) - .setGrantType(GrantType.AUTHORIZATION_CODE) - .buildQueryMessage(); - - OAuthClient client = new OAuthClient(new URLConnectionClient()); - String app = Utils.findCookieValue(req, "app"); - - OAuthAccessTokenResponse oauthResponse = null; - Class cl = OAuthJSONAccessTokenResponse.class; - - if (Utils.FACEBOOK.equals(app)) { - cl = GitHubTokenResponse.class; - } else if (Utils.GITHUB.equals(app)) { - cl = GitHubTokenResponse.class; - } - - oauthResponse = client.accessToken(request, cl); - - oauthParams.setAccessToken(oauthResponse.getAccessToken()); - oauthParams.setExpiresIn(Utils.isIssued(oauthResponse.getExpiresIn())); - oauthParams.setRefreshToken(Utils.isIssued(oauthResponse.getRefreshToken())); - - return new ModelAndView("get_resource"); - - } catch (ApplicationException e) { - oauthParams.setErrorMessage(e.getMessage()); - return new ModelAndView("request_token"); - } catch (OAuthProblemException e) { - StringBuffer sb = new StringBuffer(); - sb.append("
"); - sb.append("Error code: ").append(e.getError()).append("
"); - sb.append("Error description: ").append(e.getDescription()).append("
"); - sb.append("Error uri: ").append(e.getUri()).append("
"); - sb.append("State: ").append(e.getState()).append("
"); - oauthParams.setErrorMessage(sb.toString()); - return new ModelAndView("get_authz"); - } - } -} diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp b/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp deleted file mode 100644 index e6cbc3d6..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp +++ /dev/null @@ -1,84 +0,0 @@ -<%-- - - Copyright 2010 Newcastle University - - http://research.ncl.ac.uk/smart/ - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---%> - -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ page session="false" %> -<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> - - - - OAuth V2.0 Client Application - - - -

Sample OAuth V2.0 Client Application

- -

Web Server Flow

- -

Step 1. Get User's Authorization

- - -

Error: ${oauthParams.errorMessage}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Required OAuth parameters:
Requested Access Scope
End-User Authorization URL:
Token Endpoint:
Client ID:
Client Secret:
Redirect URI:
- - -
-
- - - diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp b/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp deleted file mode 100644 index d3ef2d42..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp +++ /dev/null @@ -1,99 +0,0 @@ -<%-- - - Copyright 2010 Newcastle University - - http://research.ncl.ac.uk/smart/ - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---%> - -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ page session="false" %> -<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> - - - - OAuth V2.0 Client Application - - - -

Sample OAuth V2.0 Client Application

- -

Web Server Flow

- -

Step 3. Get Resource

- - -

${oauthParams.errorMessage}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Required OAuth parameters:
Resource URL:
Access Token:
Expires In:
Refresh Token:
Requested Access Scope
End-User Authorization URL:
Token Endpoint:
Client ID:
Client Secret:
Redirect URI:
- - -
-
- - diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp b/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp deleted file mode 100644 index 6cc3017e..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp +++ /dev/null @@ -1,93 +0,0 @@ -<%-- - - Copyright 2010 Newcastle University - - http://research.ncl.ac.uk/smart/ - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---%> - -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ page session="false" %> -<%--@elvariable id="oauthRegParams" type="org.apache.amber.oauth2.client.demo.model.OAuthRegParams"--%> - - - - OAuth V2.0 Client Application - - - -

Sample OAuth V2.0 Client Application

- -

Dynamic Registration

- -

Step 0. Dynamically Register Application

- - -

${oauthRegParams.errorMessage}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Required OAuth Dynamic Registration parameters:
Registration Type: - - -
Application Name:
Application URL:
Application Description:
Application Redirect URI:
Application Icon URL:
OAuth Registration Endpoint:
- - - - -
-
- - - diff --git a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/request_token.jsp b/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/request_token.jsp deleted file mode 100644 index f91607dd..00000000 --- a/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/request_token.jsp +++ /dev/null @@ -1,83 +0,0 @@ -<%-- - - Copyright 2010 Newcastle University - - http://research.ncl.ac.uk/smart/ - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---%> - -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ page session="false" %> -<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> - - - - OAuth V2.0 Client Application - - - -

Sample OAuth V2.0 Client Application

- -

Web Server Flow

- -

Step 2. Get Access Token

- - -

${oauthParams.errorMessage}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Required OAuth parameters:
Authorization Code:
End-User Authorization URL:
Token Endpoint:
Client ID:
Client Secret:
Redirect URI:
- - -
-
- - diff --git a/oauth-2.0/oauth2-client/pom.xml b/oauth-2.0/oauth2-client/pom.xml deleted file mode 100644 index 2f1ea5b9..00000000 --- a/oauth-2.0/oauth2-client/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - 4.0.0 - oauth2-client - org.apache.amber - Apache Amber: OAuth 2.0 Implementation - Client - jar - 0.10-incubating-SNAPSHOT - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - - oauth2-client - - - org.apache.maven.plugins - maven-surefire-plugin - 2.5 - - - **/utils/* - **/OAuthClientTest.java - - - - - - - - - org.apache.amber - oauth2-common - ${project.version} - - - - org.codehaus.jettison - jettison - ${jettison.version} - - - stax - stax-api - - - - - - - \ No newline at end of file diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/URLConnectionClient.java b/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/URLConnectionClient.java deleted file mode 100644 index 8edbfb71..00000000 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/URLConnectionClient.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.client; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.util.Map; - -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.client.response.OAuthClientResponseFactory; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; - - -/** - * Implementation of the OAuth HttpClient using URL Connection - * - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class URLConnectionClient implements HttpClient { - - public URLConnectionClient() { - } - - public T execute(OAuthClientRequest request, Map headers, - String requestMethod, Class responseClass) - throws OAuthSystemException, OAuthProblemException { - - String responseBody = null; - URLConnection c = null; - int responseCode = 0; - try { - URL url = new URL(request.getLocationUri()); - - c = url.openConnection(); - responseCode = -1; - if (c instanceof HttpURLConnection) { - HttpURLConnection httpURLConnection = (HttpURLConnection)c; - - if (headers != null && !headers.isEmpty()) { - for (Map.Entry header : headers.entrySet()) { - httpURLConnection.addRequestProperty(header.getKey(), header.getValue()); - } - } - - if (!OAuthUtils.isEmpty(requestMethod)) { - httpURLConnection.setRequestMethod(requestMethod); - if (requestMethod.equals(OAuth.HttpMethod.POST)) { - httpURLConnection.setDoOutput(true); - OutputStream ost = httpURLConnection.getOutputStream(); - PrintWriter pw = new PrintWriter(ost); - pw.print(request.getBody()); - pw.flush(); - pw.close(); - } - } else { - httpURLConnection.setRequestMethod(OAuth.HttpMethod.GET); - } - - httpURLConnection.connect(); - - InputStream inputStream; - responseCode = httpURLConnection.getResponseCode(); - if (responseCode == 400) { - inputStream = httpURLConnection.getErrorStream(); - } else { - inputStream = httpURLConnection.getInputStream(); - } - - responseBody = OAuthUtils.saveStreamAsString(inputStream); - } - } catch (IOException e) { - throw new OAuthSystemException(e); - } - - return OAuthClientResponseFactory - .createCustomResponse(responseBody, c.getContentType(), responseCode, responseClass); - } - - @Override - public void shutdown() { - // Nothing to do here - } - -} diff --git a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthClientResponse.java b/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthClientResponse.java deleted file mode 100644 index bce1dd32..00000000 --- a/oauth-2.0/oauth2-client/src/main/java/org/apache/amber/oauth2/client/response/OAuthClientResponse.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.client.response; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.amber.oauth2.client.validator.OAuthClientValidator; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public abstract class OAuthClientResponse { - - protected String body; - protected String contentType; - protected int responseCode; - - protected OAuthClientValidator validator; - protected Map parameters = new HashMap(); - - public abstract String getParam(String param); - - protected abstract void setBody(String body) throws OAuthProblemException; - - protected abstract void setContentType(String contentTypr); - - protected abstract void setResponseCode(int responseCode); - - protected void init(String body, String contentType, int responseCode) throws OAuthProblemException { - this.setBody(body); - this.setContentType(contentType); - this.setResponseCode(responseCode); - this.validate(); - - } - - protected void validate() throws OAuthProblemException { - validator.validate(this); - } -} diff --git a/oauth-2.0/oauth2-common/pom.xml b/oauth-2.0/oauth2-common/pom.xml deleted file mode 100644 index ce528c89..00000000 --- a/oauth-2.0/oauth2-common/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - 4.0.0 - oauth2-common - Apache Amber: OAuth 2.0 Implementation - Common - 0.10-incubating-SNAPSHOT - jar - OAuth 2.0 library - Common - - - oauth2-common - - - org.apache.maven.plugins - maven-surefire-plugin - 2.5 - - - **/TestOAuthClient.java - **/TestOAuthClient.java - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - org/apache/amber/oauth2/common/message/types/**.class - org/apache/amber/oauth2/common/OAuth**.class - - - - - - - - - - org.codehaus.jettison - jettison - ${jettison.version} - - - stax - stax-api - - - - - \ No newline at end of file diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/BasicCredentialsBuilder.java b/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/BasicCredentialsBuilder.java deleted file mode 100644 index a30b4934..00000000 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/BasicCredentialsBuilder.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.amber.oauth2.common.domain.credentials; - -/** - * @author Maciej Machulak - */ -public class BasicCredentialsBuilder { - - protected BasicCredentials credentials; - - private BasicCredentialsBuilder() { - credentials = new BasicCredentials(); - } - - public static BasicCredentialsBuilder credentials() { - return new BasicCredentialsBuilder(); - } - - public BasicCredentials build() { - return credentials; - } - - public BasicCredentialsBuilder setClientId(String value) { - credentials.setClientId(value); - return this; - } - - public BasicCredentialsBuilder setClientSecret(String value) { - credentials.setClientSecret(value); - return this; - } - - public BasicCredentialsBuilder setExpiresIn(Long value) { - credentials.setExpiresIn(value); - return this; - } - - public BasicCredentialsBuilder setIssuedAt(Long value) { - credentials.setIssuedAt(value); - return this; - } -} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/Credentials.java b/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/Credentials.java deleted file mode 100644 index 4d7daddc..00000000 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/domain/credentials/Credentials.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright 2011 Newcastle University. All rights reserved. - * Maciej Machulak, Lukasz Moren, Aad van Moorsel - * - * http://research.ncl.ac.uk/smart/ - */ - -package org.apache.amber.oauth2.common.domain.credentials; - -import java.lang.Long;import java.lang.String; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public interface Credentials { - - String getClientId(); - - String getClientSecret(); - - Long getIssuedAt(); - - Long getExpiresIn(); -} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/error/OAuthError.java b/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/error/OAuthError.java deleted file mode 100644 index 19c95e61..00000000 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/error/OAuthError.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.common.error; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public abstract class OAuthError { - - //error response params - public static final String OAUTH_ERROR = "error"; - public static final String OAUTH_ERROR_DESCRIPTION = "error_description"; - public static final String OAUTH_ERROR_URI = "error_uri"; - - public static final class CodeResponse { - public static final String INVALID_REQUEST = "invalid_request"; - public static final String INVALID_CLIENT = "invalid_client"; - public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; - public static final String REDIRECT_URI_MISMATCH = "redirect_uri_mismatch"; - public static final String ACCESS_DENIED = "access_denied"; - public static final String UNSUPPORTED_RESPONSE_TYPE = "unsupported_response_type"; - public static final String INVALID_SCOPE = "invalid_scope"; - } - - public static final class TokenResponse { - public static final String INVALID_REQUEST = "invalid_request"; - public static final String INVALID_CLIENT = "invalid_client"; - public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; - public static final String INVALID_GRANT = "invalid_grant"; - public static final String UNSUPPORTED_GRANT_TYPE = "unsupported_grant_type"; - public static final String INVALID_SCOPE = "invalid_scope"; - } - - public static final class ResourceResponse { - public static final String INVALID_REQUEST = "invalid_request"; - public static final String EXPIRED_TOKEN = "expired_token"; - public static final String INSUFFICIENT_SCOPE = "insufficient_scope"; - public static final String INVALID_TOKEN = "invalid_token"; - } - -} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/token/BasicOAuthToken.java b/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/token/BasicOAuthToken.java deleted file mode 100644 index 51e9fef3..00000000 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/token/BasicOAuthToken.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apache.amber.oauth2.common.token; - -/** - * @author Lukasz Moren - */ -public class BasicOAuthToken implements OAuthToken { - protected String accessToken; - protected String expiresIn; - protected String refreshToken; - protected String scope; - - public BasicOAuthToken() { - } - - public BasicOAuthToken(String accessToken, String expiresIn, String refreshToken, String scope) { - this.accessToken = accessToken; - this.expiresIn = expiresIn; - this.refreshToken = refreshToken; - this.scope = scope; - } - - public BasicOAuthToken(String accessToken) { - this(accessToken, null, null, null); - } - - public BasicOAuthToken(String accessToken, String expiresIn) { - this(accessToken, expiresIn, null, null); - } - - public BasicOAuthToken(String accessToken, String expiresIn, String scope) { - this(accessToken, expiresIn, null, scope); - } - - public String getAccessToken() { - return accessToken; - } - - public String getExpiresIn() { - return expiresIn; - } - - public String getRefreshToken() { - return refreshToken; - } - - public String getScope() { - return scope; - } -} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/token/OAuthToken.java b/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/token/OAuthToken.java deleted file mode 100644 index 0517761a..00000000 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/token/OAuthToken.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.apache.amber.oauth2.common.token; - -/** - * @author Lukasz Moren - */ -public interface OAuthToken { - - public String getAccessToken(); - - public String getExpiresIn(); - - public String getRefreshToken(); - - public String getScope(); -} diff --git a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/JSONUtils.java b/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/JSONUtils.java deleted file mode 100644 index 9d8022e5..00000000 --- a/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/JSONUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.common.utils; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public final class JSONUtils { - - public static String buildJSON(Map params) throws JSONException { - JSONObject jsonObject = new JSONObject(); - for (Map.Entry param : params.entrySet()) { - if (param.getKey() != null && !"".equals(param.getKey()) && param.getValue() != null && !"" - .equals(param.getValue())) { - jsonObject.put(param.getKey(), param.getValue()); - } - } - - return jsonObject.toString(); - } - - public static Map parseJSON(String jsonBody) throws JSONException { - - Map params = new HashMap(); - JSONObject obj = new JSONObject(jsonBody); - Iterator it = obj.keys(); - while (it.hasNext()) { - Object o = it.next(); - if (o instanceof String) { - String key = (String)o; - params.put(key, obj.getString(key)); - } - } - return params; - } - -} diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java b/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java deleted file mode 100644 index 9ff8c89b..00000000 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.common; - -import java.util.HashMap; -import java.util.Map; -import javax.xml.stream.XMLStreamReader; - -import org.apache.amber.oauth2.common.error.OAuthError; -import org.codehaus.jettison.AbstractXMLStreamReader; -import org.codehaus.jettison.json.JSONObject; -import org.codehaus.jettison.mapped.MappedXMLStreamReader; -import org.junit.Assert; -import org.junit.Test; -import org.apache.amber.oauth2.common.utils.OAuthUtils; - -import org.apache.amber.oauth2.common.utils.JSONUtils; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class OAuthUtilsTest extends Assert { - - @Test - public void testBuildJSON() throws Exception { - Map params = new HashMap(); - params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST); - - String json = JSONUtils.buildJSON(params); - - JSONObject obj = new JSONObject(json); - - AbstractXMLStreamReader reader = new MappedXMLStreamReader(obj); - - assertEquals(XMLStreamReader.START_ELEMENT, reader.next()); - assertEquals(OAuthError.OAUTH_ERROR, reader.getName().getLocalPart()); - - assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, reader.getText()); - assertEquals(XMLStreamReader.CHARACTERS, reader.next()); - assertEquals(XMLStreamReader.END_ELEMENT, reader.next()); - assertEquals(XMLStreamReader.END_DOCUMENT, reader.next()); - - } - - @Test - public void testEncodeOAuthHeader() throws Exception { - - Map entries = new HashMap(); - entries.put("realm", "Some Example Realm"); - entries.put("error", "invalid_token"); - - String header = OAuthUtils.encodeOAuthHeader(entries); - assertEquals("OAuth error=\"invalid_token\",realm=\"Some Example Realm\"", header); - - } -} diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java b/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java deleted file mode 100644 index 9072cd8b..00000000 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.common.utils; - -import java.util.HashMap; -import java.util.Map; -import javax.xml.stream.XMLStreamReader; - -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.utils.JSONUtils; -import org.codehaus.jettison.AbstractXMLStreamReader; -import org.codehaus.jettison.json.JSONObject; -import org.codehaus.jettison.mapped.MappedXMLStreamReader; -import org.junit.Assert; -import org.junit.Test; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class JSONUtilsTest { - - @Test - public void testBuildJSON() throws Exception { - - Map params = new HashMap(); - params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST); - - String json = JSONUtils.buildJSON(params); - - JSONObject obj = new JSONObject(json); - - AbstractXMLStreamReader reader = new MappedXMLStreamReader(obj); - - Assert.assertEquals(XMLStreamReader.START_ELEMENT, reader.next()); - Assert.assertEquals(OAuthError.OAUTH_ERROR, reader.getName().getLocalPart()); - - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, reader.getText()); - Assert.assertEquals(XMLStreamReader.CHARACTERS, reader.next()); - Assert.assertEquals(XMLStreamReader.END_ELEMENT, reader.next()); - Assert.assertEquals(XMLStreamReader.END_DOCUMENT, reader.next()); - - } - - @Test - public void testParseJson() throws Exception { - Map jsonParams = new HashMap(); - jsonParams.put("author", "John B. Smith"); - jsonParams.put("year", "2000"); - - String s = JSONUtils.buildJSON(jsonParams); - Map map = JSONUtils.parseJSON(s); - Assert.assertEquals("John B. Smith", map.get("author")); - Assert.assertEquals("2000", map.get("year")); - - } -} diff --git a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java b/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java deleted file mode 100644 index 4d79191a..00000000 --- a/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.common.utils; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.junit.Assert; -import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; - -import org.apache.amber.oauth2.common.error.OAuthError; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class OAuthUtilsTest { - @Test - public void testFormat() throws Exception { - Map parameters = new HashMap(); - parameters.put("movie", "Kiler"); - parameters.put("director", "Machulski"); - - - String format = OAuthUtils.format(parameters.entrySet(), "UTF-8"); - Assert.assertEquals("movie=Kiler&director=Machulski", format); - } - - @Test - public void testSaveStreamAsString() throws Exception { - String sampleTest = "It is raining again today"; - - InputStream is = new ByteArrayInputStream(sampleTest.getBytes("UTF-8")); - Assert.assertEquals(sampleTest, OAuthUtils.saveStreamAsString(is)); - } - - @Test - public void testHandleOAuthProblemException() throws Exception { - OAuthProblemException exception = OAuthUtils.handleOAuthProblemException("missing parameter"); - - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, exception.getError()); - Assert.assertEquals("missing parameter", exception.getDescription()); - } - - @Test - public void testHandleMissingParameters() throws Exception { - Set missingParameters = new HashSet(); - missingParameters.add(OAuth.OAUTH_CLIENT_ID); - missingParameters.add(OAuth.OAUTH_CLIENT_SECRET); - - OAuthUtils.handleMissingParameters(missingParameters); - } - - @Test - public void testHandleNotAllowedParametersOAuthException() throws Exception { - - } - - @Test - public void testDecodeForm() throws Exception { - - } - - @Test - public void testIsFormEncoded() throws Exception { - - } - - @Test - public void testDecodePercent() throws Exception { - - } - - @Test - public void testPercentEncode() throws Exception { - - } - - @Test - public void testInstantiateClass() throws Exception { - - } - - @Test - public void testInstantiateClassWithParameters() throws Exception { - - } - - @Test - public void testGetAuthHeaderField() throws Exception { - - } - - @Test - public void testDecodeOAuthHeader() throws Exception { - - } - - @Test - public void testEncodeOAuthHeader() throws Exception { - - } - - @Test - public void testIsEmpty() throws Exception { - - } - - @Test - public void testHasEmptyValues() throws Exception { - - } - - @Test - public void testGetAuthzMethod() throws Exception { - - } - - @Test - public void testHandleOAuthError() throws Exception { - - } - - @Test - public void testDecodeScopes() throws Exception { - - } - - @Test - public void testEncodeScopes() throws Exception { - - } - - @Test - public void testIsExpired() throws Exception { - - } - - @Test - public void testGetIssuedTimeInSec() throws Exception { - - } - - @Test - public void testIsMultipart() throws Exception { - - } - - @Test - public void testHasContentType() throws Exception { - - } -} diff --git a/oauth-2.0/oauth2-dynamicreg-client/pom.xml b/oauth-2.0/oauth2-dynamicreg-client/pom.xml deleted file mode 100644 index 655925ab..00000000 --- a/oauth-2.0/oauth2-dynamicreg-client/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - 4.0.0 - oauth2-dynamicreg-client - Apache Amber: OAuth 2.0 Implementation - Dynamic Registration Client - jar - 0.10-incubating-SNAPSHOT - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - - oauth2-dynamicreg-client - - - - - org.apache.amber - oauth2-common - ${project.version} - - - - org.apache.amber - oauth2-client - ${project.version} - - - - org.apache.amber - oauth2-dynamicreg-common - ${project.version} - - - - diff --git a/oauth-2.0/oauth2-dynamicreg-common/pom.xml b/oauth-2.0/oauth2-dynamicreg-common/pom.xml deleted file mode 100644 index 6a6b7f1d..00000000 --- a/oauth-2.0/oauth2-dynamicreg-common/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - 4.0.0 - oauth2-dynamicreg-common - Apache Amber: OAuth 2.0 Implementation - Dynamic Registration Common - jar - 0.10-incubating-SNAPSHOT - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - - oauth2-dynamicreg-common - - - - - org.apache.amber - oauth2-common - ${project.version} - - - diff --git a/oauth-2.0/oauth2-dynamicreg-server/pom.xml b/oauth-2.0/oauth2-dynamicreg-server/pom.xml deleted file mode 100644 index 9e38c255..00000000 --- a/oauth-2.0/oauth2-dynamicreg-server/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - 4.0.0 - oauth2-dynamicreg-server - Apache Amber: OAuth 2.0 Implementation - Dynamic Registration Server - jar - 0.10-incubating-SNAPSHOT - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - - oauth2-dynamicreg-server - - - - - org.apache.amber - oauth2-common - ${project.version} - - - org.apache.amber - oauth2-authzserver - ${project.version} - - - - org.apache.amber - oauth2-dynamicreg-common - ${project.version} - - - - org.codehaus.jettison - jettison - ${jettison.version} - - - stax - stax-api - - - - - - org.apache.amber - oauth2-test-utils - ${project.version} - - - - diff --git a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java b/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java deleted file mode 100644 index 6a866883..00000000 --- a/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Copyright 2011 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.oauth2.ext.dynamicreg.server.request; - -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthRuntimeException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Lukasz Moren - */ -public class JSONHttpServletRequestWrapper extends HttpServletRequestWrapper { - private Logger log = LoggerFactory.getLogger(JSONHttpServletRequestWrapper.class); - private JSONObject body; - private boolean bodyRead = false; - - public JSONHttpServletRequestWrapper(HttpServletRequest request) { - super(request); - } - - public String getParameter(String name) { - final String[] values = getParameterMap().get(name); - if (values == null || values.length == 0) { - return null; - } - return values[0]; - } - - public Map getParameterMap() { - try { - readJsonBody(); - Map parameters = new HashMap(); - - if (body != null) { - final JSONArray attributeNames = body.names(); - for (int i = 0; i < attributeNames.length(); i++) { - final String attributeName = attributeNames.getString(i); - final String attributeValue = body.getString(attributeName); - - parameters.put(attributeName, new String[] {attributeValue}); - } - } - - return Collections.unmodifiableMap(parameters); - } catch (JSONException e) { - log.error("Dynamic client registration error: ", e); - throw new OAuthRuntimeException("OAuth server error"); - } - } - - public Enumeration getParameterNames() { - return Collections.enumeration(getParameterMap().keySet()); - } - - public String[] getParameterValues(String name) { - return getParameterMap().get(name); - } - - /** - * Lazily read JSON from request - * - * @throws OAuthProblemException - */ - private void readJsonBody() { - if (!bodyRead) { - bodyRead = true; - try { - final ServletRequest request = getRequest(); - String contentType = request.getContentType(); - final String expectedContentType = OAuth.ContentType.JSON; - if (!OAuthUtils.hasContentType(contentType, expectedContentType)) { - return; - } - - final ServletInputStream inputStream = request.getInputStream(); - if (inputStream == null) { - return; - } - final String jsonString = OAuthUtils.saveStreamAsString(inputStream); - body = new JSONObject(jsonString); - } catch (JSONException e) { - log.error("Cannot decode request body as a JSON: ", e); - } catch (Exception e) { - log.error("Dynamic client registration error: ", e); - throw new OAuthRuntimeException("OAuth server error"); - } - } - } -} diff --git a/oauth-2.0/oauth2-httpclient4/pom.xml b/oauth-2.0/oauth2-httpclient4/pom.xml deleted file mode 100644 index 3983b85a..00000000 --- a/oauth-2.0/oauth2-httpclient4/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - 4.0.0 - oauth2-httpclient4 - jar - Apache Amber: OAuth 2.0 Implementation - HttpClient - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - - oauth2-httpclient4 - - - 4.1.2 - - - - - org.apache.amber - oauth2-client - ${project.version} - - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - - diff --git a/oauth-2.0/oauth2-integration-tests/pom.xml b/oauth-2.0/oauth2-integration-tests/pom.xml deleted file mode 100644 index 18876dc7..00000000 --- a/oauth-2.0/oauth2-integration-tests/pom.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - 4.0.0 - Apache Amber: OAuth 2.0 Implementation - Integration Tests - oauth2-integration-tests - 0.10-incubating-SNAPSHOT - - - oauth2-integration-tests - - - org.apache.maven.plugins - maven-surefire-plugin - 2.5 - - - **/utils/* - - - - - - - - - org.apache.amber - oauth2-common - ${project.version} - - - org.apache.amber - oauth2-client - ${project.version} - - - org.apache.amber - oauth2-authzserver - ${project.version} - - - - org.apache.amber - oauth2-httpclient4 - ${project.version} - - - - org.apache.amber - oauth2-resourceserver - ${project.version} - - - - org.apache.amber - oauth2-dynamicreg-client - ${project.version} - - - - org.apache.amber - oauth2-dynamicreg-server - ${project.version} - - - - org.apache.cxf - cxf-rt-frontend-jaxrs - ${cxf.version} - test - - - org.eclipse.jetty - jetty-webapp - ${jetty.version} - test - - - org.apache.cxf - cxf-rt-transports-http - ${cxf.version} - test - - - org.apache.cxf - cxf-rt-transports-http-jetty - ${cxf.version} - test - - - org.springframework - spring-context - ${spring.version} - test - - - org.springframework - spring-core - ${spring.version} - test - - - org.springframework - spring-beans - ${spring.version} - test - - - - \ No newline at end of file diff --git a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java b/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java deleted file mode 100644 index 80bd59b3..00000000 --- a/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.integration; - -import org.apache.amber.oauth2.client.OAuthClient; -import org.apache.amber.oauth2.client.URLConnectionClient; -import org.apache.amber.oauth2.client.request.OAuthClientRequest; -import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse; -import org.apache.amber.oauth2.client.response.OAuthClientResponse; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.junit.Test; -import org.apache.amber.oauth2.common.message.types.GrantType; -import org.apache.amber.oauth2.httpclient4.HttpClient4; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class AccessTokenAssertion extends ClientServerOAuthTest { - - @Test - public void testSuccessfullAccesToken() throws Exception { - - OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) - .setGrantType(GrantType.ASSERTION) - .setAssertion(Common.ASSERTION) - .setAssertionType(Common.ASSERTION_TYPE) - .buildBodyMessage(); - - OAuthClient oAuthClient = new OAuthClient(new HttpClient4()); - OAuthAccessTokenResponse response = null; - try { - response = oAuthClient.accessToken(request); - } catch (OAuthProblemException e) { - fail("exception not expected"); - } - assertNotNull(response.getAccessToken()); - assertNotNull(response.getExpiresIn()); - - } - - @Test - public void testInvalidRequest() throws Exception { - - OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) - .setGrantType(GrantType.ASSERTION) - .setAssertionType(Common.ASSERTION_TYPE) - .buildBodyMessage(); - - OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); - - OAuthAccessTokenResponse response = null; - try { - oAuthClient.accessToken(request); - fail("exception expected"); - } catch (OAuthProblemException e) { - assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - - } - - @Test - public void testInvalidRequest2() throws Exception { - - OAuthClientRequest request = OAuthClientRequest - .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT) - .setGrantType(GrantType.ASSERTION) - .buildBodyMessage(); - - OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); - OAuthClientResponse response = null; - try { - oAuthClient.accessToken(request); - fail("exception expected"); - } catch (OAuthProblemException e) { - assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - } - - } -} \ No newline at end of file diff --git a/oauth-2.0/oauth2-resourceserver/pom.xml b/oauth-2.0/oauth2-resourceserver/pom.xml deleted file mode 100644 index 5d610ddf..00000000 --- a/oauth-2.0/oauth2-resourceserver/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - 4.0.0 - oauth2-resourceserver - Apache Amber: OAuth 2.0 Implementation - Resource Server - 0.10-incubating-SNAPSHOT - - - oauth2-resourceserver - - - org.apache.maven.plugins - maven-surefire-plugin - 2.5 - - - **/utils/* - - - - - - - - - oauth2-common - org.apache.amber - ${project.version} - - - - diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/request/OAuthAccessResourceRequest.java b/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/request/OAuthAccessResourceRequest.java deleted file mode 100644 index 7e1dcfdf..00000000 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/request/OAuthAccessResourceRequest.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.rs.request; - - -import java.util.HashMap; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; - -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.OAuthValidator; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.rs.extractor.HeaderTokenExtractor; -import org.apache.amber.oauth2.rs.extractor.QueryTokenExtractor; -import org.apache.amber.oauth2.rs.extractor.TokenExtractor; -import org.apache.amber.oauth2.rs.validator.BodyOAuthValidator; -import org.apache.amber.oauth2.rs.validator.HeaderOAuthValidator; -import org.apache.amber.oauth2.rs.extractor.BodyTokenExtractor; -import org.apache.amber.oauth2.rs.validator.QueryOAuthValidator; - - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class OAuthAccessResourceRequest { - - private HttpServletRequest request; - private ParameterStyle[] parameterStyles = new ParameterStyle[] {OAuth.DEFAULT_PARAMETER_STYLE}; - private ParameterStyle usedParameterStyle; - - private Map extractors = new HashMap(); - private Map validators = new HashMap(); - - private TokenExtractor extractor; - - { - extractors.put(ParameterStyle.HEADER, HeaderTokenExtractor.class); - extractors.put(ParameterStyle.BODY, BodyTokenExtractor.class); - extractors.put(ParameterStyle.QUERY, QueryTokenExtractor.class); - - validators.put(ParameterStyle.HEADER, HeaderOAuthValidator.class); - validators.put(ParameterStyle.BODY, BodyOAuthValidator.class); - validators.put(ParameterStyle.QUERY, QueryOAuthValidator.class); - } - - public OAuthAccessResourceRequest(HttpServletRequest request) - throws OAuthSystemException, OAuthProblemException { - this(request, OAuth.DEFAULT_PARAMETER_STYLE); - } - - public OAuthAccessResourceRequest(HttpServletRequest request, ParameterStyle... parameterStyles) - throws OAuthSystemException, OAuthProblemException { - this.request = request; - this.parameterStyles = parameterStyles; - this.validate(); - } - - public String getAccessToken() throws OAuthSystemException { - return extractor.getAccessToken(request); - } - - private void validate() throws OAuthSystemException, OAuthProblemException { - - int foundValidStyles = 0; - boolean lackAuthInfo = false; - OAuthProblemException ex = null; - String lackAuthReason = "OAuth parameters were not found"; - for (ParameterStyle style : parameterStyles) { - try { - - OAuthValidator validator = instantiateValidator(style); - validator.validateContentType(request); - validator.validateMethod(request); - validator.validateRequiredParameters(request); - - usedParameterStyle = style; - foundValidStyles++; - } catch (OAuthProblemException e) { - //request lacks any authentication information? - if (OAuthUtils.isEmpty(e.getError())) { - lackAuthInfo = true; - lackAuthReason = e.getDescription(); - } else { - ex = OAuthProblemException.error(e.getError(), e.getDescription()); - } - } - } - - if (foundValidStyles > 1) { - throw OAuthProblemException.error(OAuthError.TokenResponse.INVALID_REQUEST, - "Found more than one mechanism for authenticating client"); - } - - if (ex != null) { - throw ex; - } - - if (foundValidStyles == 0 && lackAuthInfo) { - throw OAuthProblemException.error(null, lackAuthReason); - } - - if (foundValidStyles == 0) { - throw OAuthProblemException.error(OAuthError.TokenResponse.INVALID_REQUEST, - "OAuth parameters were not found"); - } - - instantiateExtractor(usedParameterStyle); - } - - private OAuthValidator instantiateValidator(ParameterStyle ps) throws OAuthSystemException { - Class clazz = validators.get(ps); - if (clazz == null) { - throw new OAuthSystemException("Cannot instantiate a message validator."); - } - return (OAuthValidator)OAuthUtils.instantiateClass(clazz); - } - - private void instantiateExtractor(ParameterStyle ps) throws OAuthSystemException { - Class clazz = extractors.get(ps); - if (clazz == null) { - throw new OAuthSystemException("Cannot instantiate a token extractor."); - } - extractor = (TokenExtractor)OAuthUtils.instantiateClass(clazz); - } -} diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java b/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java deleted file mode 100644 index de57853d..00000000 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright 2010 Newcastle University - * - * http://research.ncl.ac.uk/smart/ - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.amber.oauth2.rs.validator; - -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.rs.validator.QueryOAuthValidator; -import org.junit.Test; -import org.apache.amber.oauth2.common.utils.OAuthUtils; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ -public class QueryOAuthValidatorTest { - - - @Test - public void testValidateWrongVersion() throws Exception { - - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn("HMAC-SHA1"); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"access_token"}); - replay(request); - try { - QueryOAuthValidator qov = new QueryOAuthValidator(); - qov.performAllValidations(request); - Assert.fail("Exception not thrown."); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); - } - verify(request); - - } - - @Test - public void testValidateNoQuery() throws Exception { - - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null); - replay(request); - try { - QueryOAuthValidator qov = new QueryOAuthValidator(); - qov.performAllValidations(request); - Assert.fail("Exception not thrown."); - } catch (OAuthProblemException e) { - org.junit.Assert.assertTrue(OAuthUtils.isEmpty(e.getError())); - Assert.assertEquals("Missing OAuth token.", e.getDescription()); - } - verify(request); - - } - - @Test - public void testValidateMultipleTokens() throws Exception { - - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"access_token1", "access_token2"}); - replay(request); - try { - QueryOAuthValidator qov = new QueryOAuthValidator(); - qov.performAllValidations(request); - Assert.fail("Exception not thrown."); - } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Multiple tokens attached.", e.getDescription()); - } - verify(request); - - } - - @Test - public void testValidateToken() throws Exception { - - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"access_token1"}); - replay(request); - QueryOAuthValidator qov = new QueryOAuthValidator(); - qov.performAllValidations(request); - verify(request); - - } - - -} diff --git a/oauth-2.0/oauth2-rs-filter/pom.xml b/oauth-2.0/oauth2-rs-filter/pom.xml deleted file mode 100644 index 3906a016..00000000 --- a/oauth-2.0/oauth2-rs-filter/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - 4.0.0 - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - oauth2-rs-filter - 0.10-incubating-SNAPSHOT - Apache Amber: OAuth 2.0 Implementation - Resource Server Filter - - - oauth2-rs-filter - - - - - oauth2-resourceserver - org.apache.amber - ${project.version} - - - - org.apache.amber - oauth2-common - ${project.version} - - - - diff --git a/oauth-2.0/oauth2-test-utils/pom.xml b/oauth-2.0/oauth2-test-utils/pom.xml deleted file mode 100644 index 7046b34d..00000000 --- a/oauth-2.0/oauth2-test-utils/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - 4.0.0 - oauth2-test-utils - Apache Amber: OAuth 2.0 Implementation - Test Utils - jar - 0.10-incubating-SNAPSHOT - - - amber-oauth2-parent - org.apache.amber - 0.10-incubating-SNAPSHOT - - - - oauth2-test-utils - - - - org.springframework - spring-core - ${spring.version} - - - - diff --git a/oauth-2.0/pom.xml b/oauth-2.0/pom.xml index 08244268..71be11cd 100644 --- a/oauth-2.0/pom.xml +++ b/oauth-2.0/pom.xml @@ -1,252 +1,176 @@ - - - Apache Amber: OAuth 2.0 Implementation - Parent - org.apache.amber - amber-oauth2-parent - 0.10-incubating-SNAPSHOT - 4.0.0 - pom - - - org.apache.amber - amber-parent - 0.10-incubating-SNAPSHOT - - - - oauth2-common - oauth2-client - oauth2-httpclient4 - oauth2-client-demo - oauth2-dynamicreg-client - oauth2-dynamicreg-common - oauth2-authzserver - oauth2-resourceserver - oauth2-rs-filter - oauth2-dynamicreg-server - oauth2-test-utils - oauth2-integration-tests - - - - 1.6 - 2.2.10 - 3.0.2.RELEASE - 2.0.8 - 3.0 - 2.5 - 4.8.1 - 1.2 - 7.1.5.v20100705 - 2.5 - - + + 4.0.0 + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + ../parent + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + pom + + Apache Oltu - OAuth 2.0 + + + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/oauth-2.0 + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/oauth-2.0 + https://svn.apache.org/repos/asf/oltu/trunk/oauth-2.0 + + + + common + client + httpclient4 + dynamicreg-client + dynamicreg-common + authzserver + resourceserver + resourceserver-filter + dynamicreg-server + test-utils + integration-tests + jwt + + + + + apache.website + ${siteUrlDeployment} + + + + Jenkins + https://builds.apache.org/job/Oltu-OAuth-2.0/ + + + mail + true + true + false + false +
dev@oltu.apache.org
+
+
+
+ + + org.apache.oltu.oauth2*;version=${project.version} + 2.2.10 + 3.0.3.RELEASE + 2.0.8 + 3.0 + 2.5 + 7.1.5.v20100705 + 2.5 + + + - - - org.slf4j - slf4j-api - 1.6.1 - - - org.slf4j - slf4j-log4j12 - 1.6.0 - test - - - - junit - junit - ${junit.version} - test - - - - org.springframework - spring-mock - ${spring-mock.version} - test - - - org.easymock - easymock - ${easy-mock.version} - test - - - javax.servlet - servlet-api - ${servlet-api.version} - provided - + + org.apache.geronimo.specs + geronimo-json_1.1_spec + 1.0 + + + + org.apache.johnzon + johnzon-core + 1.1.4 + test + + + + commons-codec + commons-codec + 1.9 + - - - - release - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.2-beta-5 - - - make-assembly - package - - single - - - false - - assembly.xml - - - - - - - - - - - - oauth-parent - install - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.4 - - - org.apache.maven.plugins - maven-release-plugin - 2.0 - - forked-path - false - true - -Psonatype-oss-release - - - - - + + + + + org.slf4j + slf4j-api + 1.7.7 + + + + org.slf4j + slf4j-log4j12 + 1.7.7 + test + + + + org.springframework + spring-mock + ${spring-mock.version} + test + + + + org.easymock + easymock + ${easy-mock.version} + test + + + + javax.servlet + servlet-api + ${servlet-api.version} + provided + + + + + + site + - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - com.mycila.maven-license-plugin - maven-license-plugin - 1.8.0 - - true - ${project.basedir} -
license.txt
- false - true - true - - target/** - **/target/** - **/.hg/** - .clover/** - **/*.class - **/*.iml - **/*.ipr - **/*.iws - - false - - XML_STYLE - XML_STYLE - XML_STYLE - JAVADOC_STYLE - - true - - 2010 - http://research.ncl.ac.uk/smart/ - - UTF-8 -
- - - - format - - - -
- - org.apache.maven.plugins - maven-enforcer-plugin - 1.0-beta-1 - - - enforce-java - - enforce - - - - - - - - [1.6,) - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.1.2 - - - attach-sources - verify - - jar-no-fork - - - - + + org.apache.maven.plugins + maven-site-plugin + + ${project.reporting.outputDirectory}/apidocs + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${scmPubCheckoutDirectory} + scm:svn:https://svn.apache.org/repos/asf/oltu/site/apidocs/oauth2 + Oltu OAuth2 apidocs deployment + ${project.build.directory}/staging + true + +
-
-
\ No newline at end of file + + + + +
diff --git a/oauth-2.0/resourceserver-filter/pom.xml b/oauth-2.0/resourceserver-filter/pom.xml new file mode 100644 index 00000000..a235e3f3 --- /dev/null +++ b/oauth-2.0/resourceserver-filter/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.resourceserver-filter + bundle + + Apache Oltu - OAuth 2.0 - Resource Server Filter + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.resourceserver + ${project.version} + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/resourceserver-filter/src/main/assembly/LICENSE-with-deps b/oauth-2.0/resourceserver-filter/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..c2622deb --- /dev/null +++ b/oauth-2.0/resourceserver-filter/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,234 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/resourceserver-filter/src/main/assembly/NOTICE-with-deps b/oauth-2.0/resourceserver-filter/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/resourceserver-filter/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/resourceserver-filter/src/main/assembly/bin.xml b/oauth-2.0/resourceserver-filter/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/resourceserver-filter/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthClient.java b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthClient.java similarity index 83% rename from oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthClient.java rename to oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthClient.java index eee1151a..d09d7fd2 100644 --- a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthClient.java +++ b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthClient.java @@ -19,12 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rsfilter; +package org.apache.oltu.oauth2.rsfilter; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface OAuthClient { diff --git a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthDecision.java b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthDecision.java similarity index 81% rename from oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthDecision.java rename to oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthDecision.java index 85ee158d..6018097b 100644 --- a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthDecision.java +++ b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthDecision.java @@ -19,19 +19,12 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rsfilter; +package org.apache.oltu.oauth2.rsfilter; import java.security.Principal; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ public interface OAuthDecision { - boolean isAuthorized(); - Principal getPrincipal(); OAuthClient getOAuthClient(); diff --git a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthFilter.java b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthFilter.java similarity index 87% rename from oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthFilter.java rename to oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthFilter.java index cc5b17c2..4cdd1bf3 100644 --- a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthFilter.java +++ b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthFilter.java @@ -19,16 +19,16 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rsfilter; +package org.apache.oltu.oauth2.rsfilter; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.exception.OAuthSystemException; -import org.apache.amber.oauth2.common.message.OAuthResponse; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; -import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest; -import org.apache.amber.oauth2.rs.response.OAuthRSResponse; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest; +import org.apache.oltu.oauth2.rs.response.OAuthRSResponse; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -38,9 +38,9 @@ import java.security.Principal; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthFilter implements Filter { @@ -65,9 +65,9 @@ public class OAuthFilter implements Filter { public void init(FilterConfig filterConfig) throws ServletException { provider = OAuthUtils - .initiateServletContext(filterConfig.getServletContext(), OAUTH_RS_PROVIDER_CLASS, + .initiateServletContext(filterConfig, OAUTH_RS_PROVIDER_CLASS, OAuthRSProvider.class); - realm = filterConfig.getServletContext().getInitParameter(RS_REALM); + realm = filterConfig.getInitParameter(RS_REALM); if (OAuthUtils.isEmpty(realm)) { realm = RS_REALM_DEFAULT; } diff --git a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthRSProvider.java b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthRSProvider.java similarity index 80% rename from oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthRSProvider.java rename to oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthRSProvider.java index a0708a63..bb3eb6a7 100644 --- a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthRSProvider.java +++ b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthRSProvider.java @@ -19,17 +19,17 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rsfilter; +package org.apache.oltu.oauth2.rsfilter; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface OAuthRSProvider { diff --git a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthUtils.java b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthUtils.java similarity index 69% rename from oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthUtils.java rename to oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthUtils.java index d54192d8..55060b02 100644 --- a/oauth-2.0/oauth2-rs-filter/src/main/java/org/apache/amber/oauth2/rsfilter/OAuthUtils.java +++ b/oauth-2.0/resourceserver-filter/src/main/java/org/apache/oltu/oauth2/rsfilter/OAuthUtils.java @@ -19,46 +19,47 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rsfilter; +package org.apache.oltu.oauth2.rsfilter; +import javax.servlet.FilterConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthUtils { - public static T initiateServletContext(ServletContext context, String key, Class expectedClass) + public static T initiateServletContext(FilterConfig config, String key, Class expectedClass) throws ServletException { - T provider = (T)context.getAttribute(key); + T provider = (T) config.getServletContext().getAttribute(key); if (provider != null) { return provider; } - provider = (T)loadObject(context, key, expectedClass); + provider = (T) loadObject(config, key, expectedClass); // set the provider and validator - context.setAttribute(key, provider); + config.getServletContext().setAttribute(key, provider); return provider; } - public static Object loadObject(ServletContext context, String classParamName, Class expectedClass) + public static T loadObject(FilterConfig config, String classParamName, Class expectedClass) throws ServletException { - Object ob = null; + T ob = null; - String providerClassName = context.getInitParameter(classParamName); + String providerClassName = config.getInitParameter(classParamName); if (isEmpty(providerClassName)) { throw new ServletException(classParamName + " context param required"); } try { - Class clazz = Class.forName(providerClassName); + Class clazz = (Class) Class.forName(providerClassName); if (!expectedClass.isAssignableFrom(clazz)) { throw new ServletException(classParamName + " class: " + providerClassName + " must be an instance of: " + expectedClass.getName()); @@ -72,12 +73,11 @@ public static Object loadObject(ServletContext context, String classParamName, C return ob; } - public static Object createObjectFromClassName(Class clazz) - throws IllegalAccessException, InstantiationException { + public static T createObjectFromClassName(Class clazz) throws IllegalAccessException, InstantiationException { return clazz.newInstance(); } public static boolean isEmpty(String value) { - return value == null || "".equals(value); + return value == null || value.isEmpty(); } } diff --git a/oauth-2.0/resourceserver/pom.xml b/oauth-2.0/resourceserver/pom.xml new file mode 100644 index 00000000..1b31ec29 --- /dev/null +++ b/oauth-2.0/resourceserver/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.resourceserver + bundle + + Apache Oltu - OAuth 2.0 - Resource Server + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.common + ${project.version} + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/utils/* + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + release-assembly + package + + single + + + + ${basedir}/src/main/assembly/bin.xml + + + + + + + + + diff --git a/oauth-2.0/resourceserver/src/main/assembly/LICENSE-with-deps b/oauth-2.0/resourceserver/src/main/assembly/LICENSE-with-deps new file mode 100644 index 00000000..c2622deb --- /dev/null +++ b/oauth-2.0/resourceserver/src/main/assembly/LICENSE-with-deps @@ -0,0 +1,234 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +APACHE AMBER OAUTH 2.0 CLIENT DEPENDENCIES: + +The Apache Amber OAuth2.0 client distribution packages include a number of dependencies with +separate copyright notices and license terms. Your use of the binaries for these +dependencies is subject to the terms and conditions of the following licenses. + +For the SLF4J component (http://www.slf4j.org/) +This is licensed under the MIT license +Copyright (c) 2004-2011 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For the Jettison component (http://jettison.codehaus.org/) +This is licensed under the The Apache Software License, Version 2.0, see above diff --git a/oauth-2.0/resourceserver/src/main/assembly/NOTICE-with-deps b/oauth-2.0/resourceserver/src/main/assembly/NOTICE-with-deps new file mode 100644 index 00000000..c64ced11 --- /dev/null +++ b/oauth-2.0/resourceserver/src/main/assembly/NOTICE-with-deps @@ -0,0 +1,5 @@ +Apache Amber +Copyright 2010-2012 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). diff --git a/oauth-2.0/resourceserver/src/main/assembly/bin.xml b/oauth-2.0/resourceserver/src/main/assembly/bin.xml new file mode 100644 index 00000000..b38bf6c1 --- /dev/null +++ b/oauth-2.0/resourceserver/src/main/assembly/bin.xml @@ -0,0 +1,51 @@ + + + + + bin + + tar.gz + zip + + true + ${project.build.finalName} + + + + ${basedir}/src/main/assembly/LICENSE-with-deps + LICENSE + / + 666 + + + ${basedir}/src/main/assembly/NOTICE-with-deps + NOTICE + / + 666 + + + + + + true + /lib + + + + diff --git a/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/BearerResourceServer.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/BearerResourceServer.java new file mode 100644 index 00000000..296a04f4 --- /dev/null +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/BearerResourceServer.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.rs; + +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.rs.extractor.BearerBodyTokenExtractor; +import org.apache.oltu.oauth2.rs.extractor.BearerHeaderTokenExtractor; +import org.apache.oltu.oauth2.rs.extractor.BearerQueryTokenExtractor; +import org.apache.oltu.oauth2.rs.validator.BearerBodyOAuthValidator; +import org.apache.oltu.oauth2.rs.validator.BearerHeaderOAuthValidator; +import org.apache.oltu.oauth2.rs.validator.BearerQueryOAuthValidator; + +public class BearerResourceServer extends ResourceServer { + + public BearerResourceServer() { + extractors.put(ParameterStyle.HEADER, BearerHeaderTokenExtractor.class); + extractors.put(ParameterStyle.BODY, BearerBodyTokenExtractor.class); + extractors.put(ParameterStyle.QUERY, BearerQueryTokenExtractor.class); + + validators.put(ParameterStyle.HEADER, BearerHeaderOAuthValidator.class); + validators.put(ParameterStyle.BODY, BearerBodyOAuthValidator.class); + validators.put(ParameterStyle.QUERY, BearerQueryOAuthValidator.class); + } + +} diff --git a/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/ResourceServer.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/ResourceServer.java new file mode 100644 index 00000000..b21239ae --- /dev/null +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/ResourceServer.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.oauth2.rs; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; +import org.apache.oltu.oauth2.rs.extractor.TokenExtractor; + +public abstract class ResourceServer { + + protected Map extractors = new HashMap(); + protected Map validators = new HashMap(); + + public OAuthValidator instantiateValidator(ParameterStyle ps) throws OAuthSystemException { + Class clazz = validators.get(ps); + if (clazz == null) { + throw new OAuthSystemException("Cannot instantiate a message validator."); + } + return (OAuthValidator)OAuthUtils.instantiateClass(clazz); + } + + public TokenExtractor instantiateExtractor(ParameterStyle ps) throws OAuthSystemException { + Class clazz = extractors.get(ps); + if (clazz == null) { + throw new OAuthSystemException("Cannot instantiate a token extractor."); + } + return (TokenExtractor)OAuthUtils.instantiateClass(clazz); + } + + /** + * A replacement for HttpServletRequest.getParameter() as it will mess up with HTTP POST body + * @param request + * @param name + * @return + */ + public static String[] getQueryParameterValues(HttpServletRequest request, String name) { + String query = request.getQueryString(); + if (query == null) { + return null; + } + List values = new ArrayList(); + String[] params = query.split("&"); + for (String param : params) { + try { + param = URLDecoder.decode(param, "UTF-8"); + } catch (UnsupportedEncodingException e) { + // Ignore + } + int index = param.indexOf('='); + String key = param; + String value = null; + if (index != -1) { + key = param.substring(0, index); + value = param.substring(index + 1); + } + if (key.equals(name)) { + values.add(value); + } + } + return values.toArray(new String[values.size()]); + } + + public static String getQueryParameterValue(HttpServletRequest request, String name) { + String[] values = getQueryParameterValues(request, name); + if (values == null || values.length == 0) { + return null; + } + return values[0]; + } +} diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BodyTokenExtractor.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerBodyTokenExtractor.java similarity index 76% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BodyTokenExtractor.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerBodyTokenExtractor.java index 69dda078..5bd47336 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/BodyTokenExtractor.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerBodyTokenExtractor.java @@ -19,23 +19,27 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class BodyTokenExtractor implements TokenExtractor { +public class BearerBodyTokenExtractor implements TokenExtractor { @Override public String getAccessToken(HttpServletRequest request) { - return request.getParameter(OAuth.OAUTH_TOKEN); + String token = request.getParameter(OAuth.OAUTH_BEARER_TOKEN); + if (token == null) { + token = request.getParameter(OAuth.OAUTH_TOKEN); + } + return token; } @Override diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/HeaderTokenExtractor.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerHeaderTokenExtractor.java similarity index 79% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/HeaderTokenExtractor.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerHeaderTokenExtractor.java index a3ab66d2..27ee4191 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/HeaderTokenExtractor.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerHeaderTokenExtractor.java @@ -19,20 +19,20 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class HeaderTokenExtractor implements TokenExtractor { +public class BearerHeaderTokenExtractor implements TokenExtractor { @Override diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/QueryTokenExtractor.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerQueryTokenExtractor.java similarity index 68% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/QueryTokenExtractor.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerQueryTokenExtractor.java index e07a6838..65f48185 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/QueryTokenExtractor.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/BearerQueryTokenExtractor.java @@ -19,27 +19,33 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; + +import static org.apache.oltu.oauth2.rs.ResourceServer.getQueryParameterValue; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class QueryTokenExtractor implements TokenExtractor { +public class BearerQueryTokenExtractor implements TokenExtractor { @Override public String getAccessToken(HttpServletRequest request) { - return request.getParameter(OAuth.OAUTH_TOKEN); + String token = getQueryParameterValue(request, OAuth.OAUTH_BEARER_TOKEN); + if (token == null) { + token = getQueryParameterValue(request, OAuth.OAUTH_TOKEN); + } + return token; } @Override public String getAccessToken(HttpServletRequest request, String tokenName) { - return request.getParameter(tokenName); + return getQueryParameterValue(request, tokenName); } } diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/TokenExtractor.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/TokenExtractor.java similarity index 84% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/TokenExtractor.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/TokenExtractor.java index ed91b302..dd98b49b 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/extractor/TokenExtractor.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/extractor/TokenExtractor.java @@ -19,14 +19,14 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; import javax.servlet.http.HttpServletRequest; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public interface TokenExtractor { diff --git a/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/request/OAuthAccessResourceRequest.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/request/OAuthAccessResourceRequest.java new file mode 100644 index 00000000..fd1aaa0e --- /dev/null +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/request/OAuthAccessResourceRequest.java @@ -0,0 +1,149 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.rs.request; + + +import java.util.HashMap; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.common.message.types.TokenType; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.OAuthValidator; +import org.apache.oltu.oauth2.rs.BearerResourceServer; +import org.apache.oltu.oauth2.rs.ResourceServer; +import org.apache.oltu.oauth2.rs.extractor.TokenExtractor; + +/** + * + * + * + */ +public class OAuthAccessResourceRequest { + + private HttpServletRequest request; + private ParameterStyle[] parameterStyles=new ParameterStyle[] {OAuth.DEFAULT_PARAMETER_STYLE}; + private TokenType[] tokenTypes=new TokenType []{OAuth.DEFAULT_TOKEN_TYPE}; + private ParameterStyle usedParameterStyle; + private ResourceServer usedResourceServer; + + protected static Map tokens = new HashMap(); + + private TokenExtractor extractor; + + { + tokens.put(TokenType.BEARER, BearerResourceServer.class); + //TODO add MACResourceServer - see AMBER-41 + } + + public OAuthAccessResourceRequest(HttpServletRequest request) + throws OAuthSystemException, OAuthProblemException { + this(request,new TokenType []{OAuth.DEFAULT_TOKEN_TYPE}, new ParameterStyle[] {OAuth.DEFAULT_PARAMETER_STYLE}); + } + + public OAuthAccessResourceRequest(HttpServletRequest request, ParameterStyle... parameterStyles) + throws OAuthSystemException, OAuthProblemException { + this(request, new TokenType[]{OAuth.DEFAULT_TOKEN_TYPE}, parameterStyles); + } + + public OAuthAccessResourceRequest(HttpServletRequest request, TokenType... tokenTypes) + throws OAuthSystemException, OAuthProblemException { + this(request, tokenTypes, new ParameterStyle[]{OAuth.DEFAULT_PARAMETER_STYLE}); + } + + public OAuthAccessResourceRequest(HttpServletRequest request, TokenType[] tokenTypes ,ParameterStyle[] parameterStyles) + throws OAuthSystemException, OAuthProblemException { + this.request = request; + this.tokenTypes = tokenTypes; + this.parameterStyles = parameterStyles; + this.validate(); + } + + public String getAccessToken() throws OAuthSystemException { + return extractor.getAccessToken(request); + } + + private void validate() throws OAuthSystemException, OAuthProblemException { + + int foundValidStyles = 0; + boolean lackAuthInfo = false; + OAuthProblemException ex = null; + String lackAuthReason = "OAuth parameters were not found"; + for (TokenType tokenType : tokenTypes) { + ResourceServer resourceServer = instantiateResourceServer(tokenType); + for (ParameterStyle style : parameterStyles) { + try { + + OAuthValidator validator = resourceServer.instantiateValidator(style); + validator.validateContentType(request); + validator.validateMethod(request); + validator.validateRequiredParameters(request); + + usedParameterStyle = style; + usedResourceServer = resourceServer; + foundValidStyles++; + } catch (OAuthProblemException e) { + //request lacks any authentication information? + if (OAuthUtils.isEmpty(e.getError())) { + lackAuthInfo = true; + lackAuthReason = e.getDescription(); + } else { + ex = OAuthProblemException.error(e.getError(), e.getDescription()); + } + } + } + } + + if (foundValidStyles > 1) { + throw OAuthProblemException.error(OAuthError.TokenResponse.INVALID_REQUEST, + "Found more than one mechanism for authenticating client"); + } + + if (ex != null) { + throw ex; + } + + if (foundValidStyles == 0 && lackAuthInfo) { + throw OAuthProblemException.error(null, lackAuthReason); + } + + if (foundValidStyles == 0) { + throw OAuthProblemException.error(OAuthError.TokenResponse.INVALID_REQUEST, + "OAuth parameters were not found"); + } + + extractor = usedResourceServer.instantiateExtractor(usedParameterStyle); + } + + public static ResourceServer instantiateResourceServer(TokenType tokenType) throws OAuthSystemException { + Class clazz = tokens.get(tokenType); + if (clazz == null) { + throw new OAuthSystemException("Cannot instantiate a resource server."); + } + return (ResourceServer)OAuthUtils.instantiateClass(clazz); + } + +} diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/response/OAuthRSResponse.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/response/OAuthRSResponse.java similarity index 83% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/response/OAuthRSResponse.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/response/OAuthRSResponse.java index 229157fb..c717ccea 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/response/OAuthRSResponse.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/response/OAuthRSResponse.java @@ -19,15 +19,15 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.response; +package org.apache.oltu.oauth2.rs.response; -import org.apache.amber.oauth2.common.message.OAuthResponse; +import org.apache.oltu.oauth2.common.message.OAuthResponse; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ public class OAuthRSResponse extends OAuthResponse { diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidator.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerBodyOAuthValidator.java similarity index 81% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidator.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerBodyOAuthValidator.java index 023b59d3..706c03ab 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidator.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerBodyOAuthValidator.java @@ -19,23 +19,23 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.validator; +package org.apache.oltu.oauth2.rs.validator; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.AbstractValidator; -import org.apache.amber.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class BodyOAuthValidator extends AbstractValidator { +public class BearerBodyOAuthValidator extends AbstractValidator { @Override public void validateMethod(HttpServletRequest request) throws OAuthProblemException { @@ -68,9 +68,12 @@ public void validateRequiredParameters(HttpServletRequest request) throws OAuthP } - String[] tokens = request.getParameterValues(OAuth.OAUTH_TOKEN); + String[] tokens = request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN); if (OAuthUtils.hasEmptyValues(tokens)) { - throw OAuthProblemException.error(null, "Missing OAuth token."); + tokens = request.getParameterValues(OAuth.OAUTH_TOKEN); + if (OAuthUtils.hasEmptyValues(tokens)) { + throw OAuthProblemException.error(null, "Missing OAuth token."); + } } if (tokens.length > 1) { diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/HeaderOAuthValidator.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerHeaderOAuthValidator.java similarity index 82% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/HeaderOAuthValidator.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerHeaderOAuthValidator.java index 941d5083..5be2d1a3 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/HeaderOAuthValidator.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerHeaderOAuthValidator.java @@ -19,24 +19,24 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.validator; +package org.apache.oltu.oauth2.rs.validator; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class HeaderOAuthValidator extends AbstractValidator { +public class BearerHeaderOAuthValidator extends AbstractValidator { @Override public void validateContentType(HttpServletRequest request) throws OAuthProblemException { diff --git a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidator.java b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerQueryOAuthValidator.java similarity index 54% rename from oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidator.java rename to oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerQueryOAuthValidator.java index 38d82833..cb5200ac 100644 --- a/oauth-2.0/oauth2-resourceserver/src/main/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidator.java +++ b/oauth-2.0/resourceserver/src/main/java/org/apache/oltu/oauth2/rs/validator/BearerQueryOAuthValidator.java @@ -19,23 +19,25 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.validator; +package org.apache.oltu.oauth2.rs.validator; -import javax.servlet.http.HttpServletRequest; +import static org.apache.oltu.oauth2.rs.ResourceServer.getQueryParameterValues; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import org.apache.amber.oauth2.common.validators.AbstractValidator; +import javax.servlet.http.HttpServletRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.apache.oltu.oauth2.common.validators.AbstractValidator; +import org.apache.oltu.oauth2.rs.ResourceServer; /** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + * + * + * */ -public class QueryOAuthValidator extends AbstractValidator { +public class BearerQueryOAuthValidator extends AbstractValidator { @Override public void validateContentType(HttpServletRequest request) throws OAuthProblemException { @@ -48,21 +50,22 @@ public void validateMethod(HttpServletRequest request) throws OAuthProblemExcept @Override public void validateRequiredParameters(HttpServletRequest request) throws OAuthProblemException { - - String[] tokens = request.getParameterValues(OAuth.OAUTH_TOKEN); + String[] tokens = getQueryParameterValues(request, OAuth.OAUTH_BEARER_TOKEN); if (OAuthUtils.hasEmptyValues(tokens)) { - throw OAuthProblemException.error("", "Missing OAuth token."); + tokens = getQueryParameterValues(request, OAuth.OAUTH_TOKEN); + if (OAuthUtils.hasEmptyValues(tokens)) { + throw OAuthProblemException.error(null, "Missing OAuth token."); + } } + if (tokens != null && tokens.length > 1) { - throw OAuthProblemException - .error(OAuthError.TokenResponse.INVALID_REQUEST, "Multiple tokens attached."); + throw OAuthProblemException.error(OAuthError.TokenResponse.INVALID_REQUEST, "Multiple tokens attached."); } - String oauthVersionDiff = request.getParameter(OAuth.OAUTH_VERSION_DIFFER); + String oauthVersionDiff = ResourceServer.getQueryParameterValue(request, OAuth.OAUTH_VERSION_DIFFER); if (!OAuthUtils.isEmpty(oauthVersionDiff)) { - throw OAuthProblemException - .error(OAuthError.TokenResponse.INVALID_REQUEST, - "Incorrect OAuth version. Found OAuth V1.0."); + throw OAuthProblemException.error(OAuthError.TokenResponse.INVALID_REQUEST, + "Incorrect OAuth version. Found OAuth V1.0."); } } } diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/OAuthAccessResourceRequestTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/OAuthAccessResourceRequestTest.java similarity index 68% rename from oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/OAuthAccessResourceRequestTest.java rename to oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/OAuthAccessResourceRequestTest.java index 2442437f..5dd4b3df 100644 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/OAuthAccessResourceRequestTest.java +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/OAuthAccessResourceRequestTest.java @@ -19,33 +19,28 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs; +package org.apache.oltu.oauth2.rs; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.fail; import javax.servlet.http.HttpServletRequest; -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.common.message.types.ParameterStyle; -import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.message.types.ParameterStyle; +import org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest; import org.junit.Assert; import org.junit.Test; -import org.apache.amber.oauth2.common.error.OAuthError; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reset; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.fail; - /** - * @author Maciej Machulak - * @author Lukasz Moren + * + * */ public class OAuthAccessResourceRequestTest { - public static final String AUTHORIZATION_HEADER_OAUTH2 = "OAuth sometoken"; + public static final String AUTHORIZATION_HEADER_OAUTH2 = "Bearer sometoken"; @Test public void testCreateNoHeaderRequest() throws Exception { @@ -56,7 +51,6 @@ public void testCreateNoHeaderRequest() throws Exception { expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn(null); replay(request); - OAuthAccessResourceRequest req = null; try { new OAuthAccessResourceRequest(request); @@ -93,16 +87,14 @@ public void testCreateHeaderMissingFieldRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("OAuth "); + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Bearer "); replay(request); try { new OAuthAccessResourceRequest(request); fail("Exception expected"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -114,28 +106,25 @@ public void testCreateHeaderWrongVersionRequest() throws Exception { expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)) - .andStubReturn("OAuth sadfasfd,oauth_signature_method=\"HMAC-SHA1\""); + .andStubReturn("Bearer sadfasfd,oauth_signature_method=\"HMAC-SHA1\""); replay(request); try { new OAuthAccessResourceRequest(request); fail("Exception expected"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } - @Test public void testCreateValidHeaderRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("OAuth token"); + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Bearer token"); replay(request); try { new OAuthAccessResourceRequest(request); @@ -152,7 +141,7 @@ public void testCreateBodyWrongMethod() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); @@ -160,9 +149,7 @@ public void testCreateBodyWrongMethod() throws Exception { new OAuthAccessResourceRequest(request, ParameterStyle.BODY); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -173,16 +160,14 @@ public void testCreateBodyInvalidEncoding() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); try { new OAuthAccessResourceRequest(request, ParameterStyle.BODY); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -193,19 +178,15 @@ public void testCreateBodyWrongOAuthVersion() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn("HMAC-SHA1"); replay(request); try { new OAuthAccessResourceRequest(request, ParameterStyle.BODY); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); - Assert - .assertEquals("Incorrect OAuth version. Found OAuth V1.0.", - e.getDescription()); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); } } @@ -215,19 +196,37 @@ public void testCreateBodyHeaderMixedTokens() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); + expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Bearer sadfasfd"); + replay(request); + + try { + new OAuthAccessResourceRequest(request, ParameterStyle.BODY, ParameterStyle.HEADER); + fail("Exception expected"); + } catch (OAuthProblemException e) { + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + } + verify(request); + } + + @Test + public void testCreateBodyHeaderMixedTokensAndWrongVersion() throws Exception { + + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); + expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)) - .andStubReturn("OAuth sadfasfd,oauth_signature_method=\"HMAC-SHA1\""); + .andStubReturn("Bearer sadfasfd,oauth_signature_method=\"HMAC-SHA1\""); replay(request); try { new OAuthAccessResourceRequest(request, ParameterStyle.BODY, ParameterStyle.HEADER); fail("Exception expected"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -238,6 +237,7 @@ public void testCreateBodyNoToken() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); @@ -257,8 +257,8 @@ public void testCreateBodyMultipleTokens() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"sometoken", "othertoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken", + "othertoken"}); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); @@ -266,9 +266,7 @@ public void testCreateBodyMultipleTokens() throws Exception { new OAuthAccessResourceRequest(request, ParameterStyle.BODY); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -279,7 +277,7 @@ public void testCreateBodyValidRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); @@ -297,8 +295,10 @@ public void testCreateQueryNoToken() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + expect(request.getQueryString()).andStubReturn(null); + // expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); + // expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null); + // expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); try { @@ -316,17 +316,18 @@ public void testCreateQueryWrongVersion() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn("HMAC-SHA1"); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_VERSION_DIFFER + "=HMAC-SHA1&" + + OAuth.OAUTH_BEARER_TOKEN + + "=sometoken"); + // expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); + // expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn("HMAC-SHA1"); replay(request); try { new OAuthAccessResourceRequest(request, ParameterStyle.QUERY); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -336,18 +337,19 @@ public void testCreateQueryMultipleTokens() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"sometoken", "othertoken"}); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_BEARER_TOKEN + "=sometoken&" + + OAuth.OAUTH_BEARER_TOKEN + + "=othertoken"); + // expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)) + // .andStubReturn(new String[] {"sometoken", "othertoken"}); + // expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); try { new OAuthAccessResourceRequest(request, ParameterStyle.QUERY); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } verify(request); } @@ -357,8 +359,9 @@ public void testCreateQueryValidRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"sometoken"}); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_BEARER_TOKEN + "=sometoken"); + // expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); + // expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); replay(request); try { @@ -373,10 +376,12 @@ public void testCreateQueryValidRequest() throws Exception { @Test public void testGetAccessTokenWrongQueryRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn(null); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {null}); + expect(request.getQueryString()).andStubReturn(null); + // expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); + // expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null); + // expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + // expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)) + // .andStubReturn(new String[] {null}); replay(request); @@ -392,11 +397,10 @@ public void testGetAccessTokenWrongQueryRequest() throws Exception { @Test public void testGetAccessTokenWrongHeaderRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn(null); + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getHeader("Authorization")).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {null}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {null}); replay(request); @@ -412,13 +416,12 @@ public void testGetAccessTokenWrongHeaderRequest() throws Exception { @Test public void testGetAccessTokenWrongBodyRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn(null); + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {null}); - + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {null}); + expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {null}); replay(request); try { @@ -435,12 +438,11 @@ public void testGetAccessCorrectRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); //test body - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn("sometoken"); + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken"); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); replay(request); OAuthAccessResourceRequest req = null; @@ -455,11 +457,10 @@ public void testGetAccessCorrectRequest() throws Exception { reset(request); //test header - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn("sometoken"); + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken"); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getHeader("Authorization")).andStubReturn(AUTHORIZATION_HEADER_OAUTH2); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); replay(request); try { @@ -473,10 +474,11 @@ public void testGetAccessCorrectRequest() throws Exception { reset(request); //test uri query - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn("sometoken"); - expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"sometoken"}); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_BEARER_TOKEN + "=sometoken"); + + // expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken"); + // expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + // expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); replay(request); req = new OAuthAccessResourceRequest(request, ParameterStyle.QUERY); @@ -488,19 +490,20 @@ public void testGetAccessCorrectRequest() throws Exception { @Test public void testMultipleStylesValidRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn(null); + expect(request.getQueryString()).andStubReturn(null); + + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {null}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {null}); + expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {null}); expect(request.getHeader("Authorization")).andStubReturn(AUTHORIZATION_HEADER_OAUTH2); replay(request); try { - new OAuthAccessResourceRequest(request, ParameterStyle.QUERY, ParameterStyle.BODY, - ParameterStyle.HEADER); + new OAuthAccessResourceRequest(request, ParameterStyle.QUERY, ParameterStyle.BODY, ParameterStyle.HEADER); } catch (OAuthProblemException e) { fail("Exception not expected"); } @@ -510,28 +513,25 @@ public void testMultipleStylesValidRequest() throws Exception { @Test public void testMultipleStylesInvalidRequest() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn("sometoken"); + expect(request.getQueryString()).andStubReturn(null); + + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken"); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) - .andStubReturn(new String[] {"sometoken"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"}); expect(request.getHeader("Authorization")).andStubReturn(AUTHORIZATION_HEADER_OAUTH2); replay(request); OAuthAccessResourceRequest req = null; try { - new OAuthAccessResourceRequest(request, ParameterStyle.BODY, - ParameterStyle.QUERY, ParameterStyle.HEADER); + new OAuthAccessResourceRequest(request, ParameterStyle.BODY, ParameterStyle.QUERY, ParameterStyle.HEADER); fail("Exception expeted"); } catch (OAuthProblemException e) { - Assert - .assertTrue( - OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); + Assert.assertTrue(OAuthError.TokenResponse.INVALID_REQUEST.equals(e.getError())); } - verify(request); } } diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/BodyTokenExtractorTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/BodyTokenExtractorTest.java similarity index 63% rename from oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/BodyTokenExtractorTest.java rename to oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/BodyTokenExtractorTest.java index a2b762dc..213b7721 100644 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/BodyTokenExtractorTest.java +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/BodyTokenExtractorTest.java @@ -19,48 +19,37 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.rs.extractor.BodyTokenExtractor; +import org.apache.oltu.oauth2.common.OAuth; import org.junit.Test; -import org.apache.amber.oauth2.common.OAuth; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import javax.servlet.http.HttpServletRequest; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ public class BodyTokenExtractorTest { @Test public void testGetAccessToken() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn("sometoken"); + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken"); replay(request); - BodyTokenExtractor bte = new BodyTokenExtractor(); - Assert.assertEquals("sometoken", bte.getAccessToken(request)); + BearerBodyTokenExtractor bte = new BearerBodyTokenExtractor(); + assertEquals("sometoken", bte.getAccessToken(request)); verify(request); } @Test public void testGetAccessTokenNull() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); + expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn(null); replay(request); - BodyTokenExtractor bte = new BodyTokenExtractor(); - Assert.assertNull(bte.getAccessToken(request)); + BearerBodyTokenExtractor bte = new BearerBodyTokenExtractor(); + assertNull(bte.getAccessToken(request)); verify(request); } } diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/HeaderTokenExtractorTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/HeaderTokenExtractorTest.java similarity index 65% rename from oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/HeaderTokenExtractorTest.java rename to oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/HeaderTokenExtractorTest.java index 49763fb6..045b617b 100644 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/HeaderTokenExtractorTest.java +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/HeaderTokenExtractorTest.java @@ -19,48 +19,36 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.rs.extractor.HeaderTokenExtractor; +import org.apache.oltu.oauth2.common.OAuth; import org.junit.Test; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import javax.servlet.http.HttpServletRequest; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ public class HeaderTokenExtractorTest { @Test public void testGetAccessToken() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); - expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("OAuth sometoken"); + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Bearer sometoken"); replay(request); - HeaderTokenExtractor hte = new HeaderTokenExtractor(); - Assert.assertEquals("sometoken", hte.getAccessToken(request)); + BearerHeaderTokenExtractor hte = new BearerHeaderTokenExtractor(); + assertEquals("sometoken", hte.getAccessToken(request)); verify(request); } @Test public void testGetAccessTokenNull() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn(null); replay(request); - HeaderTokenExtractor hte = new HeaderTokenExtractor(); - Assert.assertNull(hte.getAccessToken(request)); + BearerHeaderTokenExtractor hte = new BearerHeaderTokenExtractor(); + assertNull(hte.getAccessToken(request)); verify(request); } } diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/QueryTokenExtractorTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/QueryTokenExtractorTest.java similarity index 60% rename from oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/QueryTokenExtractorTest.java rename to oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/QueryTokenExtractorTest.java index 608b30c8..efdf1134 100644 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/extractor/QueryTokenExtractorTest.java +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/extractor/QueryTokenExtractorTest.java @@ -19,51 +19,36 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.extractor; +package org.apache.oltu.oauth2.rs.extractor; -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.rs.extractor.QueryTokenExtractor; import org.junit.Test; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import javax.servlet.http.HttpServletRequest; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ public class QueryTokenExtractorTest { @Test public void testGetAccessToken() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn("sometoken"); + expect(request.getQueryString()).andStubReturn("access_token=sometoken"); replay(request); - QueryTokenExtractor qte = new QueryTokenExtractor(); - Assert.assertEquals("sometoken", qte.getAccessToken(request)); + BearerQueryTokenExtractor qte = new BearerQueryTokenExtractor(); + assertEquals("sometoken", qte.getAccessToken(request)); verify(request); - } @Test public void testGetAccessTokenNull() throws Exception { - HttpServletRequest request = createStrictMock(HttpServletRequest.class); - expect(request.getParameter(OAuth.OAUTH_TOKEN)).andStubReturn(null); + expect(request.getQueryString()).andStubReturn(null); replay(request); - QueryTokenExtractor qte = new QueryTokenExtractor(); - Assert.assertNull(qte.getAccessToken(request)); + BearerQueryTokenExtractor qte = new BearerQueryTokenExtractor(); + assertNull(qte.getAccessToken(request)); verify(request); - } } diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/BodyOAuthValidatorTest.java similarity index 63% rename from oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java rename to oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/BodyOAuthValidatorTest.java index c6ba8f4f..d4bcf9ab 100644 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/BodyOAuthValidatorTest.java @@ -19,44 +19,34 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.validator; +package org.apache.oltu.oauth2.rs.validator; -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.rs.validator.BodyOAuthValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.junit.Test; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import javax.servlet.http.HttpServletRequest; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ public class BodyOAuthValidatorTest { @Test public void testValidateInvalidMethod() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getMethod()).andStubReturn("GET"); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); replay(request); try { - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Incorrect method. POST, PUT, DELETE are supported.", e.getDescription()); + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Incorrect method. POST, PUT, DELETE are supported.", e.getDescription()); } verify(request); } @@ -68,12 +58,12 @@ public void tesValidateMultipartMessage() throws Exception { expect(request.getContentType()).andStubReturn("multipart/form-data"); replay(request); try { - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.CodeResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Request is not single part.", e.getDescription()); + assertEquals(OAuthError.CodeResponse.INVALID_REQUEST, e.getError()); + assertEquals("Request is not single part.", e.getDescription()); } verify(request); } @@ -85,12 +75,12 @@ public void tesValidateInvalidEncoding() throws Exception { expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON); replay(request); try { - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Bad request content type. Expecting: application/x-www-form-urlencoded", e.getDescription()); + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Bad request content type. Expecting: application/x-www-form-urlencoded", e.getDescription()); } verify(request); } @@ -101,15 +91,15 @@ public void tesValidateInvalidOAuthVersion() throws Exception { expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn("HMAC-SHA1"); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"access_token"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"access_token"}); replay(request); try { - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); } verify(request); } @@ -120,15 +110,16 @@ public void tesValidateTokenMissing() throws Exception { expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(null); expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null); replay(request); try { - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(null, e.getError()); - Assert.assertEquals("Missing OAuth token.", e.getDescription()); + assertEquals(null, e.getError()); + assertEquals("Missing OAuth token.", e.getDescription()); } verify(request); } @@ -139,16 +130,16 @@ public void tesValidateMultipleTokens() throws Exception { expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)) + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)) .andStubReturn(new String[] {"access_token1", "access_token2"}); replay(request); try { - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Multiple tokens attached.", e.getDescription()); + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Multiple tokens attached.", e.getDescription()); } verify(request); } @@ -159,9 +150,9 @@ public void tesValidateValidMessage() throws Exception { expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST); expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED); expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null); - expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[] {"access_token"}); + expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"access_token"}); replay(request); - BodyOAuthValidator bov = new BodyOAuthValidator(); + BearerBodyOAuthValidator bov = new BearerBodyOAuthValidator(); bov.performAllValidations(request); verify(request); } diff --git a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/HeaderOAuthValidatorTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/HeaderOAuthValidatorTest.java similarity index 58% rename from oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/HeaderOAuthValidatorTest.java rename to oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/HeaderOAuthValidatorTest.java index 7c0de8cd..0e9f8b2d 100644 --- a/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/HeaderOAuthValidatorTest.java +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/HeaderOAuthValidatorTest.java @@ -19,113 +19,95 @@ * limitations under the License. */ -package org.apache.amber.oauth2.rs.validator; +package org.apache.oltu.oauth2.rs.validator; -import javax.servlet.http.HttpServletRequest; - -import junit.framework.Assert; - -import org.apache.amber.oauth2.common.OAuth; -import org.apache.amber.oauth2.common.error.OAuthError; -import org.apache.amber.oauth2.common.exception.OAuthProblemException; -import org.apache.amber.oauth2.rs.validator.HeaderOAuthValidator; +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; import org.junit.Test; -import org.apache.amber.oauth2.common.utils.OAuthUtils; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import javax.servlet.http.HttpServletRequest; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; -/** - * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) - * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) - * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) - */ public class HeaderOAuthValidatorTest { @Test public void testValidateNoHeader() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn(null); replay(request); try { - HeaderOAuthValidator bov = new HeaderOAuthValidator(); + BearerHeaderOAuthValidator bov = new BearerHeaderOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - org.junit.Assert.assertTrue(OAuthUtils.isEmpty(e.getError())); - Assert.assertEquals("Missing authorization header.", e.getDescription()); + assertTrue(OAuthUtils.isEmpty(e.getError())); + assertEquals("Missing authorization header.", e.getDescription()); } verify(request); - } @Test public void testValidateInvalidHeader() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Basic arawersadf"); replay(request); try { - HeaderOAuthValidator bov = new HeaderOAuthValidator(); + BearerHeaderOAuthValidator bov = new BearerHeaderOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - org.junit.Assert.assertTrue(OAuthUtils.isEmpty(e.getError())); - Assert.assertEquals("Incorrect authorization method.", e.getDescription()); + assertTrue(OAuthUtils.isEmpty(e.getError())); + assertEquals("Incorrect authorization method.", e.getDescription()); } verify(request); - } @Test public void testValidateValidHeaderMissingField() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("OAuth "); + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Bearer "); replay(request); try { - HeaderOAuthValidator bov = new HeaderOAuthValidator(); + BearerHeaderOAuthValidator bov = new BearerHeaderOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Missing required parameter.", e.getDescription()); + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Missing required parameter.", e.getDescription()); } verify(request); - } @Test public void testValidateValidHeaderWrongVersion() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)) - .andStubReturn("OAuth sdfsadfsadf,oauth_signature_method=\"HMAC-SHA1\""); + .andStubReturn("Bearer sdfsadfsadf,oauth_signature_method=\"HMAC-SHA1\""); replay(request); try { - HeaderOAuthValidator bov = new HeaderOAuthValidator(); + BearerHeaderOAuthValidator bov = new BearerHeaderOAuthValidator(); bov.performAllValidations(request); - Assert.fail("Exception not thrown."); + fail("Exception not thrown."); } catch (OAuthProblemException e) { - Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); - Assert.assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); } verify(request); } @Test public void testValidateValidHeader() throws Exception { - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("OAuth sdfsadfsadf"); + expect(request.getHeader(OAuth.HeaderType.AUTHORIZATION)).andStubReturn("Bearer sdfsadfsadf"); replay(request); - HeaderOAuthValidator bov = new HeaderOAuthValidator(); + BearerHeaderOAuthValidator bov = new BearerHeaderOAuthValidator(); bov.performAllValidations(request); verify(request); diff --git a/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/QueryOAuthValidatorTest.java b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/QueryOAuthValidatorTest.java new file mode 100644 index 00000000..4432c5d1 --- /dev/null +++ b/oauth-2.0/resourceserver/src/test/java/org/apache/oltu/oauth2/rs/validator/QueryOAuthValidatorTest.java @@ -0,0 +1,100 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oltu.oauth2.rs.validator; + +import org.apache.oltu.oauth2.common.OAuth; +import org.apache.oltu.oauth2.common.error.OAuthError; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.utils.OAuthUtils; +import org.junit.Test; + +import javax.servlet.http.HttpServletRequest; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; + +public class QueryOAuthValidatorTest { + + @Test + public void testValidateWrongVersion() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_VERSION_DIFFER + "=HMAC-SHA1&" + + OAuth.OAUTH_BEARER_TOKEN + + "=access_token"); + replay(request); + try { + BearerQueryOAuthValidator qov = new BearerQueryOAuthValidator(); + qov.performAllValidations(request); + fail("Exception not thrown."); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription()); + } + verify(request); + } + + @Test + public void testValidateNoQuery() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getQueryString()).andStubReturn(null); + replay(request); + try { + BearerQueryOAuthValidator qov = new BearerQueryOAuthValidator(); + qov.performAllValidations(request); + fail("Exception not thrown."); + } catch (OAuthProblemException e) { + assertTrue(OAuthUtils.isEmpty(e.getError())); + assertEquals("Missing OAuth token.", e.getDescription()); + } + verify(request); + } + + @Test + public void testValidateMultipleTokens() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_BEARER_TOKEN + "=access_token1&" + + OAuth.OAUTH_BEARER_TOKEN + + "=access_token2"); + + replay(request); + try { + BearerQueryOAuthValidator qov = new BearerQueryOAuthValidator(); + qov.performAllValidations(request); + fail("Exception not thrown."); + } catch (OAuthProblemException e) { + assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError()); + assertEquals("Multiple tokens attached.", e.getDescription()); + } + verify(request); + } + + @Test + public void testValidateToken() throws Exception { + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_BEARER_TOKEN + "=access_token1"); + + replay(request); + BearerQueryOAuthValidator qov = new BearerQueryOAuthValidator(); + qov.performAllValidations(request); + verify(request); + } +} diff --git a/oauth-2.0/test-utils/pom.xml b/oauth-2.0/test-utils/pom.xml new file mode 100644 index 00000000..888a7b80 --- /dev/null +++ b/oauth-2.0/test-utils/pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.parent + 1.0.3-SNAPSHOT + + + org.apache.oltu.oauth2.test-utils + + Apache Oltu - OAuth 2.0 - Test Utils + + + + org.springframework + spring-core + ${org.springframework.version} + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + diff --git a/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java b/oauth-2.0/test-utils/src/main/java/org/apache/oltu/oauth2/utils/test/FileUtils.java similarity index 93% rename from oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java rename to oauth-2.0/test-utils/src/main/java/org/apache/oltu/oauth2/utils/test/FileUtils.java index 22728337..643a4952 100644 --- a/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java +++ b/oauth-2.0/test-utils/src/main/java/org/apache/oltu/oauth2/utils/test/FileUtils.java @@ -18,7 +18,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.oauth2.utils.test; +package org.apache.oltu.oauth2.utils.test; import java.io.BufferedReader; import java.io.IOException; @@ -26,7 +26,7 @@ import java.net.URL; /** - * @author Lukasz Moren + * */ public class FileUtils { private FileUtils() { diff --git a/openid-connect/client/pom.xml b/openid-connect/client/pom.xml new file mode 100644 index 00000000..3bd53570 --- /dev/null +++ b/openid-connect/client/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + + org.apache.oltu.openidconnect + org.apache.oltu.openidconnect.parent + 1-SNAPSHOT + + + org.apache.oltu.openidconnect.client + 0.0.1-SNAPSHOT + bundle + + Apache Oltu - OpenId Connect - Client + OpenId Connect library - Client + + + 1.0.3-SNAPSHOT + 1.0.4-SNAPSHOT + + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${oltu.oauth2.version} + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.jwt + ${oltu.oauth2.jwt.version} + + + junit-addons + junit-addons + 1.4 + test + + + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + diff --git a/server/src/main/java/org/apache/amber/server/TokenCredentialsGenerator.java b/openid-connect/client/src/main/java/org/apache/oltu/openidconnect/OpenIdConnect.java similarity index 75% rename from server/src/main/java/org/apache/amber/server/TokenCredentialsGenerator.java rename to openid-connect/client/src/main/java/org/apache/oltu/openidconnect/OpenIdConnect.java index 30d9bb2b..2fec5d82 100644 --- a/server/src/main/java/org/apache/amber/server/TokenCredentialsGenerator.java +++ b/openid-connect/client/src/main/java/org/apache/oltu/openidconnect/OpenIdConnect.java @@ -14,20 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.amber.server; +package org.apache.oltu.openidconnect; /** - * Token credentials generator. - * - * @version $Id$ + * Class containing all the basic constants of the OpenId + * connect specification */ -public interface TokenCredentialsGenerator { +public class OpenIdConnect { - /** - * Generates a new token credentials. - * - * @return a new token credentials. - */ - String generate(); + public static final String ID_TOKEN= "id_token"; } diff --git a/openid-connect/client/src/main/java/org/apache/oltu/openidconnect/client/response/OpenIdConnectResponse.java b/openid-connect/client/src/main/java/org/apache/oltu/openidconnect/client/response/OpenIdConnectResponse.java new file mode 100644 index 00000000..93749f6d --- /dev/null +++ b/openid-connect/client/src/main/java/org/apache/oltu/openidconnect/client/response/OpenIdConnectResponse.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.openidconnect.client.response; + +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.jwt.JWT; +import org.apache.oltu.oauth2.jwt.io.JWTReader; +import org.apache.oltu.openidconnect.OpenIdConnect; + +/** + * + * + */ +public class OpenIdConnectResponse extends OAuthJSONAccessTokenResponse { + + private JWT idToken; + + @Override + protected void init(String body, String contentType, int responseCode) + throws OAuthProblemException { + super.init(body, contentType, responseCode); + try { + idToken = new JWTReader().read(getParam(OpenIdConnect.ID_TOKEN)); + } catch (IllegalArgumentException ie) { + //is not open id connect compliant + //nothing to do. + } + + } + + public final JWT getIdToken() { + return idToken; + } + + /** + * ID Token Validation as per OpenID Connect + * Basic Client Profile 1.0 draft 22 Section 2.4 + * + * @param issuer + * @param audience + * @return + */ + public boolean checkId(String issuer, String audience) { + if (idToken.getClaimsSet().getIssuer().equals(issuer) + && idToken.getClaimsSet().getAudience().equals(audience) + && idToken.getClaimsSet().getExpirationTime() < System + .currentTimeMillis()) { + return true; + } + return false; + } + +} diff --git a/openid-connect/client/src/test/java/org/apache/oltu/openidconnect/client/response/OpenIdConnectResponseTest.java b/openid-connect/client/src/test/java/org/apache/oltu/openidconnect/client/response/OpenIdConnectResponseTest.java new file mode 100644 index 00000000..fdc7054d --- /dev/null +++ b/openid-connect/client/src/test/java/org/apache/oltu/openidconnect/client/response/OpenIdConnectResponseTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.oltu.openidconnect.client.response; + +import junitx.util.PrivateAccessor; + +import org.apache.oltu.oauth2.jwt.JWT; +import org.apache.oltu.oauth2.jwt.io.JWTReader; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class OpenIdConnectResponseTest { + + private final String JWT = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJlMWRhMGIzNTY3YmQyNjVhMjUwOThmYmNjMmIwOWYyMTM0NWIzYTIifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiaWQiOiIxMDY0MjI0NTMwODI0Nzk5OTg0MjkiLCJzdWIiOiIxMDY0MjI0NTMwODI0Nzk5OTg0MjkiLCJ2ZXJpZmllZF9lbWFpbCI6InRydWUiLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJhdWQiOiI3ODg3MzIzNzIwNzguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJjaWQiOiI3ODg3MzIzNzIwNzguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhenAiOiI3ODg3MzIzNzIwNzguYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJlbWFpbCI6ImFudG9uaW8uc2Fuc29AZ21haWwuY29tIiwidG9rZW5faGFzaCI6IkwySTc3Z2lCTGswUlNzMHpRMVN2Q0EiLCJhdF9oYXNoIjoiTDJJNzdnaUJMazBSU3MwelExU3ZDQSIsImlhdCI6MTM2NjcyNjMxNywiZXhwIjoxMzY2NzMwMjE3fQ.XWYi5Zj1YWAMGIml_ftoAwmvW1Y7oeybLCpzQrJVuWJpS8L8Vd2TL-RTIOEVG03VA7e0_-_frNuw7MxUgVEgh8G-Nnbk_baJ6k_3w5c1SKFamFiHHDoKLFhrt1Y8JKSuGwE02V-px4Cn0dRAQAc1IN5CU6wqCrYK0p-fv_fvy28"; + + @Test + public void testCheckId() throws NoSuchFieldException{ + JWT idToken = new JWTReader().read(JWT); + OpenIdConnectResponse openIdConnectResponse= new OpenIdConnectResponse(); + PrivateAccessor.setField(openIdConnectResponse, "idToken", idToken); + + assertTrue(openIdConnectResponse.checkId("accounts.google.com", "788732372078.apps.googleusercontent.com")); + assertFalse(openIdConnectResponse.checkId("wrongaccounts.google.com", "788732372078.apps.googleusercontent.com")); + assertFalse(openIdConnectResponse.checkId("wrongaccounts.google.com", "notexists788732372078.apps.googleusercontent.com")); + } + +} diff --git a/openid-connect/common/pom.xml b/openid-connect/common/pom.xml new file mode 100644 index 00000000..5c959d07 --- /dev/null +++ b/openid-connect/common/pom.xml @@ -0,0 +1,47 @@ + + + + 4.0.0 + + + org.apache.oltu.openidconnect + org.apache.oltu.openidconnect.parent + 1-SNAPSHOT + + + org.apache.oltu.openidconnect.common + 0.0.1-SNAPSHOT + bundle + + Apache Oltu - OpenId Connect - Common + OpenId Connect library - Common + + + + + ${basedir}../../ + META-INF + + LICENSE + NOTICE + + + + + + diff --git a/openid-connect/deploySite.sh b/openid-connect/deploySite.sh new file mode 100755 index 00000000..7328d417 --- /dev/null +++ b/openid-connect/deploySite.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +mvn clean site site:stage -P site +mvn scm-publish:publish-scm -Dusername=$1 -Dpassword=$2 -P site diff --git a/openid-connect/pom.xml b/openid-connect/pom.xml new file mode 100644 index 00000000..15a3c992 --- /dev/null +++ b/openid-connect/pom.xml @@ -0,0 +1,100 @@ + + + + 4.0.0 + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + ../parent + + + org.apache.oltu.openidconnect + org.apache.oltu.openidconnect.parent + 1-SNAPSHOT + pom + + Apache Oltu - OpenId Connect + + + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/openid-connect + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/openid-connect + https://svn.apache.org/repos/asf/oltu/trunk/openid-connect + + + + + apache.website + ${siteUrlDeployment} + + + + Jenkins + https://builds.apache.org/job/Oltu-OpenID-Conect/ + + + mail + true + true + false + false +
dev@oltu.apache.org
+
+
+
+ + + org.apache.oltu.openidconnect.*;version=${project.version} + + + + common + client + + + + + site + + + + org.apache.maven.plugins + maven-site-plugin + + ${project.reporting.outputDirectory}/apidocs + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${scmPubCheckoutDirectory} + scm:svn:https://svn.apache.org/repos/asf/oltu/site/apidocs/openid-connect + Oltu OpenID Connect apidocs deployment + ${project.build.directory}/staging + true + + + + + + + +
diff --git a/parent/pom.xml b/parent/pom.xml new file mode 100644 index 00000000..f3f8f224 --- /dev/null +++ b/parent/pom.xml @@ -0,0 +1,980 @@ + + + + 4.0.0 + + + org.apache + apache + 17 + + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + pom + + Apache Oltu - Parent + Apache Oltu is an OAuth protocol implementation in Java. + https://oltu.apache.org/ + 2010 + + + + asanso + Antonio Sanso + asanso@apache.org + Adobe + http://www.day.com + + Chair + PMC Member + Committer + + +1 + + + + jasha + Jasha Joachimsthal + jasha@apache.org + Onegini + https://www.onegini.com + + PMC Member + Committer + + +1 + + + + lmoren + Lukasz Moren + lmoren@apache.org + + PMC Member + Committer + + 0 + + + + mmachulak + Maciej Machulak + mmachulak@apache.org + + PMC Member + Committer + + 0 + + + + pidster + Stuart "Pid" Williams + pidster@apache.org + + PMC Member + Committer + + +1 + + + + rfeng + Raymond Zhaohui Feng + rfeng@apache.org + + PMC Member + Committer + + + + + simonetripodi + Simone Tripodi + simonetripodi@apache.org + Adobe + + PMC Member + Committer + + +1 + + + + stein + Stein Welberg + stein@apache.org + Onegini + https://www.onegini.com + + PMC Member + Committer + + +1 + + + + + + tommaso + Tommaso Teofili + tommaso@apache.org + Adobe + + Emeritus + + +1 + + + + brianm + Brian McCallister + brianm@apache.org + + Mentor + PMC Member + Committer + Emeritus + + + + + djencks + David Jencks + djencks@apache.org + + Mentor + PMC Member + Committer + Emeritus + + + + + gianugo + Gianugo Rabellino + gianugo@apache.org + + Mentor + PMC Member + Committer + Emeritus + + + + + henning + Henning Schmiedehausen + henning@apache.org + + Mentor + PMC Member + Committer + Emeritus + + + + + jfclere + Jean-Frederic Clere + jfclere@apache.org + + Mentor + PMC Member + Committer + Emeritus + + + + + lindner + Paul Lindner + lindner@apache.org + + PMC Member + Committer + Emeritus + + +1 + + + + pablo + Pablo Fernandez + pablo@apache.org + + PMC Member + Committer + Emeritus + + +1 + + + + recordond + David Recordon + recordond@apache.org + + PMC Member + Committer + Emeritus + + +1 + + + + simoneg + Simone Gianni + simoneg@apache.org + Semeru S.r.l. + http://www.semeru.it/ + + PMC Member + Committer + Emeritus + + +1 + + + + + + Markus Sabadello + + + + + + + + + + + Ben Noordhuis + + + + + + + + + + + Alexis Tessier + http://banzoner.com/ + + Apache Oltu logos designer + + +1 + + + + + + Dev Mailing List + dev@oltu.apache.org + dev-subscribe@oltu.apache.org + dev-unsubscribe@oltu.apache.org + https://mail-archives.apache.org/mod_mbox/oltu-dev/ + + https://mail-archives.apache.org/mod_mbox/incubator-amber-dev/ + + + + + User Mailing List + user@oltu.apache.org + user-subscribe@oltu.apache.org + user-unsubscribe@oltu.apache.org + https://mail-archives.apache.org/mod_mbox/oltu-user/ + + https://mail-archives.apache.org/mod_mbox/incubator-amber-user/ + + + + + Commits Mailing List + commits@oltu.apache.org + commits-subscribe@oltu.apache.org + commits-unsubscribe@oltu.apache.org + https://mail-archives.apache.org/mod_mbox/oltu-commits/ + + https://mail-archives.apache.org/mod_mbox/incubator-amber-commits/ + + + + + + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/parent + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/parent + https://svn.apache.org/repos/asf/oltu/trunk/parent + + + JIRA + https://issues.apache.org/jira/browse/OLTU + + + Jenkins + https://builds.apache.org/job/Oltu/ + + + mail + true + true + false + false +
dev@oltu.apache.org
+
+
+
+ + https://oltu.apache.org/download.html + + + + UTF-8 + UTF-8 + UTF-8 + 1.8 + 1.8 + yyyy-MM-dd HH:mm:ssZ + ${scmBranch}@r${buildNumber} + + 2.9.1 + + ${project.artifactId};version=${project.version} + * + + + + + + + + + commons-logging + commons-logging + 1.1.3 + compile + + + + log4j + log4j + 1.2.17 + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + javax.jms + jms + + + javax.mail + mail + + + junit + junit + + + oro + oro + + + + + + + + + junit + junit + 4.11 + test + + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + + + org.apache.maven.plugins + maven-clean-plugin + 2.5 + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.1 + + + + org.apache.maven.plugins + maven-install-plugin + 2.5.1 + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.6 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4 + + + org.codehaus.plexus + plexus-utils + 3.0.8 + + + + true + gnu + + + + + org.apache.maven.plugins + maven-release-plugin + 2.4.2 + + forked-path + false + clean install + false + -Prelease,apache + https://svn.apache.org/repos/asf/oltu/tags + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0 + + true + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.3.1 + + + enforce-java + validate + + enforce + + + + + [1.8,) + [ERROR] The currently supported version of Java is 1.8 or higher + + + [2.2.0,) + [ERROR] The currently supported version of Maven is 2.2.0 or higher + + + Best Practice is to always define plugin versions! + true + true + true + [ERROR] clean,deploy,site + + + + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.2 + + + validate + + create + + + + + false + false + + true + + ?????? + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${javac.src.version} + ${javac.target.version} + true + true + true + + + + + org.apache.felix + maven-bundle-plugin + true + + + + <_removeheaders>Include-Resource,JAVA_1_3_HOME,JAVA_1_4_HOME,JAVA_1_5_HOME,JAVA_1_6_HOME,JAVA_1_7_HOME,JAVA_1_8_HOME + ${project.name} + ${project.artifactId} + ${project.description} + ${osgi.export} + ${osgi.private} + ${osgi.import} + ${osgi.dynamicImport} + ${project.url} + + ${osgi.activator} + ${implementation.build} + ${maven.build.timestamp} + ${javac.src.version} + ${javac.target.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + org.apache.maven.plugins + maven-doap-plugin + 1.1 + + + site + site + + generate + + + + + doap.rdf + + ${project.inceptionYear}-05-09 + + + ${project.description} + Antonio Sanso + + + + + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.4 + + + + org.codehaus.mojo + jdepend-maven-plugin + 2.0-beta-2 + + + + org.codehaus.mojo + findbugs-maven-plugin + 2.5.3 + + true + target/findbugs-reports + target/findbugs-reports + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.16 + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.0.1 + + true + 100 + 1.8 + + + + + + + + release + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + org.apache.apache.resources + apache-source-release-assembly-descriptor + 1.0.4 + + + + + source-release-assembly + package + + single + + + true + + ${sourceReleaseAssemblyDescriptor} + + + + + + + + org.apache.rat + apache-rat-plugin + 0.10 + + + rat-verify + test + + check + + + + CHANGES + DISCLAIMER + **/NOTICE* + .idea/** + .classpath + .project + .settings + maven-eclipse.xml + .externalToolBuilders/** + **/*.json + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + true + true + + + ${implementation.build} + ${maven.build.timestamp} + ${javac.src.version} + ${javac.target.version} + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.version} + + + attach-javadocs + + jar + + + true + + + true + true + + + ${implementation.build} + ${maven.build.timestamp} + ${javac.src.version} + ${javac.target.version} + + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.4 + + + sign-artifacts + verify + + sign + + + + + + + + + + site + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.version} + + true + ${sun.boot.class.path} + com.google.doclava.Doclava + false + -J-Xmx1024m + + com.google.doclava + doclava + 1.0.5 + + + -quiet + -federate JDK http://download.oracle.com/javase/6/docs/api/index.html? + -federationxml JDK http://doclava.googlecode.com/svn/static/api/openjdk-6.xml + -hdf project.name "${project.name}" + -apiversion "${project.version}" + -d ${project.reporting.outputDirectory}/apidocs + + + + + aggregate + site + + aggregate + + + + + + + org.apache.maven.plugins + maven-site-plugin + + en + + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + false + false + + + + + index + mailing-list + project-team + scm + cim + issue-tracking + license + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.version} + + + default + + javadoc + + + + aggregate + + aggregate + + + + + + + + + + toolchain + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 1.1 + + + + 1.8 + oracle + + + + + + + toolchain + + + + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + + + + + + +
diff --git a/parent/src/site/site.xml b/parent/src/site/site.xml new file mode 100644 index 00000000..0c2e30e4 --- /dev/null +++ b/parent/src/site/site.xml @@ -0,0 +1,57 @@ + + + + + + Apache Oltu OAuth reference implementation + images/oltu_head.png + ${project.url}/index.html + + + + The Apache Software Foundation + https://www.apache.org/img/asf_logo.png + https://www.apache.org/ + + + + org.apache.maven.skins + maven-fluido-skin + 1.3.0 + + + + + + + + + + + + + +
+
Apache Oltu, Apache, the Apache feather logo, and the Apache Oltu project logos are trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners.
+
+ + +
diff --git a/pom.xml b/pom.xml index 56d4173e..1bc70ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,558 +1,56 @@ - - - - org.apache - apache - 7 - - - 4.0.0 - org.apache.amber - amber-parent - pom - 0.10-incubating-SNAPSHOT - Apache Amber - https://cwiki.apache.org/confluence/display/AMBER - - - scm:svn:https://svn.apache.org/repos/asf/incubator/amber/trunk/ - scm:svn:https://svn.apache.org/repos/asf/incubator/amber/trunk/ - https://svn.apache.org/repos/asf/incubator/amber/trunk/ - - - - JIRA - https://issues.apache.org/jira/browse/AMBER - - - - - Dev Mailing List - amber-dev[at]incubator[dot]apache[dot]org - amber-dev-subscribe[at]incubator[dot]apache[dot]org - amber-dev-unsubscribe[at]incubator[dot]apache[dot]org - - - - User Mailing List - amber-user[at]incubator[dot]apache[dot]org - amber-user-subscribe[at]incubator[dot]apache[dot]org - amber-user-unsubscribe[at]incubator[dot]apache[dot]org - - - - Commits Mailing List - amber-commits[at]incubator[dot]apache[dot]org - amber-commits-subscribe[at]incubator[dot]apache[dot]org - amber-commits-unsubscribe[at]incubator[dot]apache[dot]org - - - - - - brianm - Brian McCallister - brianm[at]apache[dot]org - - Mentor - PMC Member - Committer - - - - - henning - Henning Schmiedehausen - henning[at]apache[dot]org - - Mentor - PMC Member - Committer - - - - - jfclere - Jean-Frederic Clere - jfclere[at]apache[dot]org - - Mentor - PMC Member - Committer - - - - - gianugo - Gianugo Rabellino - gianugo[at]apache[dot]org - - Mentor - PMC Member - Committer - - - - - djencks - David Jencks - djencks[at]apache[dot]org - - Mentor - PMC Member - Committer - - - - - lmoren - Lukasz Moren - lmoren[at]apache[dot]org - - Committer - - 0 - - - - mmachulak - Maciej Machulak - mmachulak[at]apache[dot]org - - Committer - - 0 - - - - simoneg - Simone Gianni - simoneg[at]apache[dot]org - Semeru S.r.l. - http://www.semeru.it/ - - PMC Member - Committer - - +1 - - - - simonetripodi - Simone Tripodi - simonetripodi[at]apache[dot]org - Sourcesense S.r.l. - http://www.sourcesense.com/ - - PMC Member - Committer - - +1 - - - - pidster - Stuart "Pid" Williams - - PMC Member - Committer - - +1 - - - - recordond - David Recordon - recordond[at]apache[dot]org - - PMC Member - Committer - - +1 - - - - tommaso - Tommaso Teofili - tommaso[at]apache[dot]org - Sourcesense S.r.l. - http://www.sourcesense.com/ - - PMC Member - Committer - - +1 - - - - lindner - Paul Lindner - lindner[at]apache[dot]org - - PMC Member - Committer - - +1 - - - - TBD - Pablo Fernandez - - PMC Member - Committer - - +1 - - - - - UTF-8 - 1.6 - 1.6 - yyyy-MM-dd HH:mm:ssZ - - - - - - commons-logging - commons-logging - 1.1.1 - compile - - - - log4j - log4j - 1.2.15 - - - com.sun.jdmk - jmxtools - - - com.sun.jmx - jmxri - - - javax.jms - jms - - - javax.mail - mail - - - junit - junit - - - oro - oro - - - - - - - - - junit - junit - 4.7 - test - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.7 - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.2 - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.2 - - - - org.codehaus.mojo - jdepend-maven-plugin - 2.0-beta-2 - - - - org.codehaus.mojo - findbugs-maven-plugin - 2.3.1 - - true - target/findbugs-reports - target/findbugs-reports - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.6 - - - - org.apache.maven.plugins - maven-changes-plugin - 2.3 - - - - jira-report - - - - - - - org.apache.maven.plugins - maven-pmd-plugin - 2.5 - - true - 100 - 1.5 - - - - - - - - - maven-clean-plugin - 2.4.1 - - - - maven-deploy-plugin - 2.5 - - - - maven-install-plugin - 2.3.1 - - - - maven-resources-plugin - 2.4.3 - - ${project.build.sourceEncoding} - - - - - maven-jar-plugin - 2.3.1 - - - - true - true - - - r${buildNumber} - ${maven.build.timestamp} - ${javac.src.version} - ${javac.target.version} - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 1.0-beta-1 - - - enforce-java - validate - - enforce - - - - - [1.6,) - - - [2.2.0,) - - - Best Practice is to always define plugin versions! - true - true - true - clean,deploy,site - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - ${javac.src.version} - ${javac.target.version} - ${project.build.sourceEncoding} - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.7 - - true - - - - attach-javadocs - package - - jar - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.1.2 - - - attach-sources - package - - jar - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.5 - - - - org.apache.maven.plugins - maven-site-plugin - 3.0 - - ${project.reporting.outputEncoding} - - - - - - - - src/main/resources - - - - ${basedir} - META-INF - - LICENSE - NOTICE - DISCLAIMER - - - - - - - - release - - - - org.apache.maven.plugins - maven-release-plugin - 2.1 - - clean install - true - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.1 - - - sign-artifacts - verify - - sign - - - - - - - - - - - spec-api - signature-api - server - oauth-1.0 - oauth-2.0 - - - - - website - scp://people.apache.org/www/incubator.apache.org/amber/ - - + + 4.0.0 + + + org.apache + apache + 17 + + + org.apache.oltu + org.apache.oltu.reactor + 1-SNAPSHOT + pom + + Apache Oltu - Reactor + + + parent + commons + oauth-2.0 + openid-connect + jose + demos + + + + + + org.apache.maven.plugins + maven-deploy-plugin + false + + true + + + + diff --git a/server/pom.xml b/server/pom.xml deleted file mode 100644 index 068afe4c..00000000 --- a/server/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - org.apache.amber - amber-parent - 0.10-incubating-SNAPSHOT - - - 4.0.0 - org.apache.amber - amber-server - jar - Apache Amber: Server - - - - org.apache.amber - amber-signature-api - ${project.version} - compile - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.2 - - - - dependencies - dependency-convergence - index - summary - - - - - - - - diff --git a/server/src/main/java/org/apache/amber/server/Access.java b/server/src/main/java/org/apache/amber/server/Access.java deleted file mode 100644 index a066957d..00000000 --- a/server/src/main/java/org/apache/amber/server/Access.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * Association of nonce(s) and timestamp. - * - * @version $Id$ - */ -public final class Access implements Comparable { - - /** - * The nonces associated to the timestamp. - */ - private final Set nonces = new HashSet(); - - /** - * The timestamp reference. - */ - private final long timestamp; - - /** - * Creates a new access using the received timestamp and nonce. - * - * @param timestamp the received timestamp - * @param nonce the received nonce - */ - public Access(final long timestamp, final String nonce) { - this.timestamp = timestamp; - this.addNonce(nonce); - } - - /** - * Returns the timestamp access. - * - * @return the timestamp access - */ - public long getTimestamp() { - return this.timestamp; - } - - /** - * Add a nonce to an access. - * - * @param nonce the nonce has o be added. - * @return true, if the nonce has not used yet, false otherwise. - */ - public boolean addNonce(String nonce) { - return this.nonces.add(nonce); - } - - /** - * Checks if the access already contains a nonce. - * - * @param nonce the nonce has to be checked. - * @return true if the nonce is contained, false otherwise. - */ - public boolean containsNonce(String nonce) { - return this.nonces.contains(nonce); - } - - /** - * Returns the whole list of nonces associated to the timestamp. - * - * @return the whole list of nonces associated to the timestamp. - */ - protected Set getNonces() { - return Collections.unmodifiableSet(this.nonces); - } - - /** - * {@inheritDoc} - */ - public int compareTo(Long timestamp) { - if (this.timestamp > timestamp) { - return 1; - } else if (this.timestamp < timestamp) { - return -1; - } else { - return 0; - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - boolean equals = false; - if (obj instanceof Access) { - Access other = (Access) obj; - if (other.timestamp == this.timestamp && other.nonces.equals(this.nonces)) { - equals = true; - } - } - return equals; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((nonces == null) ? 0 : nonces.hashCode()); - result = prime * result + (int) (timestamp ^ (timestamp >>> 32)); - return result; - } - -} diff --git a/server/src/main/java/org/apache/amber/server/AccessStorage.java b/server/src/main/java/org/apache/amber/server/AccessStorage.java deleted file mode 100644 index f37e597e..00000000 --- a/server/src/main/java/org/apache/amber/server/AccessStorage.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -/** - * Nonce/timestamp storage definition. - * - * @version $Id$ - */ -public interface AccessStorage { - - /** - * Stores a new nonce / timestamp pair associated with a consumer key. - * - * @param clientCredentials the consumer to be associated with the access. - * @param timestamp the timestamp of the request. - * @param nonce the nonce associated with the timestamp. - * @throws StorageException if a backend error occurs. - */ - void add(String clientCredentials, long timestamp, String nonce) throws StorageException; - - /** - * Get the last access (by timestamp) of a consumer. - * - * @param clientCredentials the consumer whose access needs to be read. - * @return the access object. - * @throws StorageException if a backend error occurs. - */ - Access getLastAccess(String clientCredentials) throws StorageException; - - /** - * Remove a consumer access. - * - * @param clientCredentials the consumer key. - * @param timestamp the timestamp. - * @throws StorageException if a backend error occurs. - */ - void remove(String clientCredentials, long timestamp) throws StorageException; - -} diff --git a/server/src/test/java/org/apache/amber/server/AccessTest.java b/server/src/test/java/org/apache/amber/server/AccessTest.java deleted file mode 100644 index 348b837d..00000000 --- a/server/src/test/java/org/apache/amber/server/AccessTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * @version $Id$ - */ -public class AccessTest { - - @Test - public void matchingEqualsHashTest() { - Access access1 = new Access(123456, "313121"); - Access access2 = new Access(123456, "313121"); - assertTrue(!access1.equals(null)); - assertTrue(access1.equals(access2) && access1.hashCode() == access2.hashCode()); - } - - @Test - public void notMatchingEqualsHashTest() { - Access access1 = new Access(123456, "313121"); - Access access2 = new Access(123446, "313121"); - Access access3 = new Access(123456, "313122"); - Access access4 = new Access(123456, "313121"); - access4.addNonce("313122"); - assertTrue(!access1.equals(access2) && access1.hashCode() != access2.hashCode()); - assertTrue(!access1.equals(access3) && access1.hashCode() != access3.hashCode()); - assertTrue(!access1.equals(access4) && access1.hashCode() != access4.hashCode()); - } - -} diff --git a/signature-api/pom.xml b/signature-api/pom.xml deleted file mode 100644 index c7cee15b..00000000 --- a/signature-api/pom.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - org.apache.amber - amber-parent - 0.10-incubating-SNAPSHOT - - - 4.0.0 - org.apache.amber - amber-signature-api - jar - Apache Amber: Signature API - - - - org.apache.amber - amber-spec-api - ${project.parent.version} - compile - - - - commons-codec - commons-codec - 1.4 - compile - - - - commons-logging - commons-logging - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.2 - - - - dependencies - dependency-convergence - index - summary - - - - - - - - - - - org.codehaus.mojo - javacc-maven-plugin - 2.5 - - - javacc - - javacc - - - 2 - false - - - - - - - - diff --git a/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java b/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java deleted file mode 100644 index 00b78c6b..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature; - -import java.net.URI; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.BitSet; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.Map.Entry; - -import org.apache.amber.OAuthMessageParameter; -import org.apache.amber.OAuthRequest; -import org.apache.amber.OAuthRequestParameter; -import org.apache.amber.OAuthToken; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.net.URLCodec; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Abstract implementation of OAuth signature method algorithm. - * - * @version $Id$ - */ -public abstract class AbstractMethod implements SignatureMethod { - - /** - * HTTP protocol name. - */ - private static final String HTTP_PROTOCOL = "http"; - - /** - * HTTPS protocol name. - */ - private static final String HTTPS_PROTOCOL = "https"; - - /** - * URL path separator. - */ - private static final String PATH_SEPARATOR = "/"; - - /** - * URL scheme separator. - */ - private static final String SCHEME_SEPARATOR = "://"; - - /** - * The default HTTP port ({@code 80}) constant. - */ - private static final int DEFAULT_HTTP_PORT = 80; - - /** - * The default HTTPS port ({@code 443}) constant. - */ - private static final int DEFAULT_HTTPS_PORT = 443; - - /** - * The empty string constant. - */ - private static final String EMPTY = ""; - - /** - * The default {@code UTF-8} character encoding. - */ - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - /** - * The {@code RFC3986} unreserved chars. - */ - private static final BitSet UNRESERVED_CHARS = new BitSet(256); - - /** - * Static unreserved chars bit set initialization. - */ - static { - for (byte b = 'A'; b <= 'Z'; b++) { - UNRESERVED_CHARS.set(b); - } - for (byte b = 'a'; b <= 'z'; b++) { - UNRESERVED_CHARS.set(b); - } - for (byte b = '0'; b <= '9'; b++) { - UNRESERVED_CHARS.set(b); - } - - // special URL encoding chars - UNRESERVED_CHARS.set('-'); - UNRESERVED_CHARS.set('.'); - UNRESERVED_CHARS.set('_'); - UNRESERVED_CHARS.set('~'); - } - - /** - * This class log. - */ - private final Log log = LogFactory.getLog(this.getClass()); - - /** - * Return this class log. - * - * @return this class log. - */ - protected Log getLog() { - return this.log; - } - - /** - * {@inheritDoc} - */ - public final String calculate(SigningKey signingKey, - OAuthToken token, - OAuthRequest request) throws SignatureException { - if (signingKey == null) { - throw new SignatureException("parameter 'signingKey' must not be null"); - } - if (request == null) { - throw new SignatureException("parameter 'request' must not be null"); - } - this.checkKey(signingKey); - - String baseString = this.createBaseString(request); - String tokenSecret = extractTokenSecret(token); - return this.calculate(signingKey, tokenSecret, baseString); - } - - /** - * Calculates the signature applying the method algorithm. - * - * @param signingKey the key has to be used to sign the request. - * @param tokenSecret the temporary/token credential. - * @param baseString the OAuth base string. - * @return the calculated signature. - * @throws SignatureException if any error occurs. - */ - protected abstract String calculate(SigningKey signingKey, String tokenSecret, String baseString) throws SignatureException; - - /** - * {@inheritDoc} - */ - public final boolean verify(String signature, - VerifyingKey verifyingKey, - OAuthToken token, - OAuthRequest request) throws SignatureException { - if (signature == null) { - throw new SignatureException("parameter 'signature' must not be null"); - } - if (verifyingKey == null) { - throw new SignatureException("parameter 'verifyingKey' must not be null"); - } - if (request == null) { - throw new SignatureException("parameter 'request' must not be null"); - } - this.checkKey(verifyingKey); - - String baseString = this.createBaseString(request); - String tokenSecret = extractTokenSecret(token); - return this.verify(signature, verifyingKey, tokenSecret, baseString); - } - - /** - * Verifies the signature applying the method algorithm. - * - * @param signature the OAuth signature has to be verified. - * @param verifyingKey the key has to be used to verify the request. - * @param tokenSecret the temporary/token credential. - * @param baseString the OAuth base string. - * @return true if the signature is verified, false otherwise. - * @throws SignatureException if any error occurs. - */ - protected abstract boolean verify(String signature, VerifyingKey verifyingKey, String tokenSecret, String baseString) throws SignatureException; - - /** - * - * - * @param key - * @throws SignatureException - */ - private void checkKey(Key key) throws SignatureException { - for (String method : key.getAlgorithmMethods()) { - if (this.getAlgorithm().equals(method)) { - return; - } - } - throw new SignatureException("Required '" - + this.getAlgorithm() - + "', key of type '" - + key.getClass().getName() - + "' only supports " - + Arrays.toString(key.getAlgorithmMethods()) - + " methods"); - } - - /** - * Calculates the OAuth base string. - * - * @param request - * @return the calculated OAuth base string. - * @throws SignatureException if any error occurs. - */ - private String createBaseString(OAuthRequest request) throws SignatureException { - // the HTTP method - String method = request.getHTTPMethod().name(); - - // the normalized request URL - URI url = request.getRequestURL(); - String scheme = url.getScheme().toLowerCase(); - String authority = url.getAuthority().toLowerCase(); - - int port = url.getPort(); - if ((HTTP_PROTOCOL.equals(scheme) && DEFAULT_HTTP_PORT == port) - || (HTTPS_PROTOCOL.equals(scheme) && DEFAULT_HTTPS_PORT == port)) { - int index = authority.lastIndexOf(':'); - if (index >= 0) { - authority = authority.substring(0, index); - } - } - - String path = url.getPath(); - if (path == null || path.length() <= 0) { - path = PATH_SEPARATOR; // conforms to RFC 2616 section 3.2.2 - } - - String requestUrl = new StringBuilder(scheme) - .append(SCHEME_SEPARATOR) - .append(authority) - .append(path) - .toString(); - - // parameters normalization - SortedSet> normalizedParameters = new TreeSet>(); - - for (OAuthMessageParameter parameter : request.getOAuthMessageParameters()) { - if (parameter.getKey().isIncludeInSignature()) { - encodeAndAddParameter(parameter.getKey().getLabel(), parameter.getValue(), normalizedParameters); - } - } - - for (OAuthRequestParameter parameter : request.getOAuthRequestParameters()) { - if (request.getOAuthMessageParameters().contains(parameter)) { - throw new SignatureException("Request parameter " - + parameter - + " can't override an OAuth message one"); - } - encodeAndAddParameter(parameter.getKey(), parameter.getValue(), normalizedParameters); - } - - // now serialize the normalized parameters - StringBuilder normalizedParametersBuffer = new StringBuilder(); - int counter = 0; - for (Entry parameter : normalizedParameters) { - if (counter > 0) { - normalizedParametersBuffer.append('&'); - } - - normalizedParametersBuffer.append(parameter.getKey()); - normalizedParametersBuffer.append('='); - normalizedParametersBuffer.append(parameter.getValue()); - counter++; - } - - return new StringBuilder(method) - .append('&') - .append(percentEncode(requestUrl)) - .append('&') - .append(percentEncode(normalizedParametersBuffer.toString())) - .toString(); - } - - private static final String extractTokenSecret(OAuthToken token) { - if (token == null) { - return EMPTY; - } - return token.getTokenSecret(); - } - - /** - * Applies the percent encoding algorithm to the input text. - * - * @param text the text has to be encoded. - * @return the encoded string. - */ - protected static String percentEncode(String text) { - return new String(URLCodec.encodeUrl(UNRESERVED_CHARS, toUTF8Bytes(text)), UTF_8); - } - - /** - * Converts the input text in a sequence of UTF-8 bytes. - * - * @param text the text has to be converted. - * @return the UTF-8 bytes sequence. - */ - protected static byte[] toUTF8Bytes(String text) { - return text.getBytes(UTF_8); - } - - /** - * Encodes a bytes sequence applying the Base64 algorithm without chuncking - * the output string. - * - * @param sequence the bytes sequence has to be encoded. - * @return the Base64 encoded string. - */ - protected static String encodeBase64(byte[] sequence) { - return new String(Base64.encodeBase64(sequence, false)); - } - - /** - * Decodes an input text to a bytes sequence applying the Base64 algorithm. - * - * @param text the text has to be encoded. - * @return the decoded bytes sequence; - */ - protected static byte[] decodeBase64(String text) { - return Base64.decodeBase64(text); - } - - /** - * Add the input parameter in the list, encoding the parameter name/value - * first, then putting it in the list in the right position - * - * @param parameter the input parameter. - * @param parametersList the list where add the parameter. - */ - private static void encodeAndAddParameter(String name, String value, SortedSet> normalizedParameters) { - normalizedParameters.add(new OAuthRequestParameter(percentEncode(name), percentEncode(value))); - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/BasicKey.java b/signature-api/src/main/java/org/apache/amber/signature/BasicKey.java deleted file mode 100644 index d1201400..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/BasicKey.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature; - -/** - * - * - * @version $Id$ - */ -public final class BasicKey implements SigningKey, VerifyingKey { - - private static final String[] METHODS = { "PLAINTEXT", "HMAC-SHA1" }; - - private final String value; - - public BasicKey(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } - - public String[] getAlgorithmMethods() { - return METHODS; - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java b/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java deleted file mode 100644 index 457ef570..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.hmac; - -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import org.apache.amber.signature.AbstractMethod; -import org.apache.amber.signature.SignatureException; -import org.apache.amber.signature.SigningKey; -import org.apache.amber.signature.VerifyingKey; - -/** - * HMAC-SHA1 Method implementation. - * - * @version $Id$ - */ -public final class HmacSha1Method extends AbstractMethod { - - private static final String HMAC_SHA1 = "HMAC-SHA1"; - - private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1"; - - /** - * {@inheritDoc} - */ - @Override - protected String calculate(SigningKey signingKey, - String tokenSecret, - String baseString) throws SignatureException { - String key = new StringBuilder(percentEncode(signingKey.getValue())) - .append('&') - .append(percentEncode(tokenSecret)) - .toString(); - - SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM); - - Mac mac = null; - try { - mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); - } catch (NoSuchAlgorithmException e) { - throw new SignatureException("HMAC-SHA1 Algorithm not supported", e); - } - - try { - mac.init(secretKeySpec); - } catch (InvalidKeyException e) { - throw new SignatureException(new StringBuilder("Signing key '") - .append(key) - .append("' caused HMAC-SHA1 error") - .toString(), e); - } - - byte[] rawHmac = mac.doFinal(baseString.getBytes()); - - return encodeBase64(rawHmac); - } - - /** - * {@inheritDoc} - */ - @Override - protected boolean verify(String signature, - VerifyingKey verifyingKey, - String tokenSecret, - String baseString) throws SignatureException { - String expectedSignature = this.calculate((SigningKey) verifyingKey, tokenSecret, baseString); - - if (this.getLog().isDebugEnabled()) { - this.getLog().debug(new StringBuilder("Received signature {") - .append(signature) - .append("} expected signature {") - .append(expectedSignature) - .append('}') - .toString()); - } - - return expectedSignature.equals(signature); - } - - /** - * {@inheritDoc} - */ - public String getAlgorithm() { - return HMAC_SHA1; - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java b/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java deleted file mode 100644 index a7891e48..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.plaintext; - -import org.apache.amber.signature.AbstractMethod; -import org.apache.amber.signature.SignatureException; -import org.apache.amber.signature.SigningKey; -import org.apache.amber.signature.VerifyingKey; - -/** - * PLAINTEXT Method implementation. - * - * @version $Id$ - */ -public final class PlaintextMethod extends AbstractMethod { - - private static final String PLAINTEXT = "PLAINTEXT"; - - /** - * {@inheritDoc} - */ - @Override - protected String calculate(SigningKey signingKey, - String tokenSecret, - String baseString) throws SignatureException { - return new StringBuilder(signingKey.getValue()) - .append('&') - .append(tokenSecret) - .toString(); - } - - /** - * {@inheritDoc} - */ - @Override - protected boolean verify(String signature, - VerifyingKey verifyingKey, - String tokenSecret, - String baseString) throws SignatureException { - String expectedSignature = this.calculate((SigningKey) verifyingKey, tokenSecret, baseString); - - if (this.getLog().isDebugEnabled()) { - this.getLog().debug(new StringBuilder("Received signature {") - .append(signature) - .append("} expected signature {") - .append(expectedSignature) - .append('}') - .toString()); - } - - return expectedSignature.equals(signature); - } - - /** - * {@inheritDoc} - */ - public String getAlgorithm() { - return PLAINTEXT; - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java b/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java deleted file mode 100644 index 2608ede4..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/rsa/AbstractRsaSha1Key.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.rsa; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; - -import org.apache.amber.signature.SignatureException; - -/** - * Abstract implementation of RSA-SHA1 key. - * - * @version $Id$ - */ -abstract class AbstractRsaSha1Key implements org.apache.amber.signature.Key { - - private static final String[] METHODS = { "RSA-SHA1" }; - - private final T rsaKey; - - /** - * Loads a key from a certificate located in the classpath. - * - * @param certificateClasspathLocation - * @throws SignatureException - */ - public AbstractRsaSha1Key(String certificateClasspathLocation) throws SignatureException { - if (certificateClasspathLocation == null) { - throw new SignatureException("parameter 'certificateClasspathLocation' must not be null"); - } - if ('/' == certificateClasspathLocation.charAt(0)) { - certificateClasspathLocation = certificateClasspathLocation.substring(1); - } - - URL certificateURL = this.getClass().getClassLoader().getResource(certificateClasspathLocation); - if (certificateURL == null) { - certificateURL = Thread.currentThread().getContextClassLoader().getResource(certificateClasspathLocation); - } - - if (certificateURL == null) { - throw new SignatureException("Classpath resource '" - + certificateClasspathLocation - + "' not found, please make sure it exists in the classpath"); - } - - this.rsaKey = this.readCertificate(certificateURL); - } - - /** - * Loads a key from a certificate located in a file. - * - * @param certificateFileLocation - * @throws SignatureException - */ - public AbstractRsaSha1Key(File certificateFileLocation) throws SignatureException { - if (certificateFileLocation == null) { - throw new SignatureException("parameter 'certificateFileLocation' must not be null"); - } - if (certificateFileLocation.exists() || certificateFileLocation.isDirectory()) { - throw new SignatureException("Impossible to load the certificate, '" - + certificateFileLocation - + "' doesn't exist or is a directory"); - } - - try { - this.rsaKey = this.readCertificate(certificateFileLocation.toURI().toURL()); - } catch (MalformedURLException e) { - throw new SignatureException("Impossible to read the certificate from '" - + certificateFileLocation - + "' file", e); - } - } - - /** - * Loads a key from a certificate located in an URL. - * - * @param certificateURL - * @throws SignatureException - */ - public AbstractRsaSha1Key(URL certificateURL) throws SignatureException { - if (certificateURL == null) { - throw new SignatureException("parameter 'certificateURL' must not be null"); - } - - this.rsaKey = this.readCertificate(certificateURL); - } - - private T readCertificate(URL certificateURL) throws SignatureException { - URLConnection urlConnection = null; - InputStream input = null; - - try { - urlConnection = certificateURL.openConnection(); - input = urlConnection.getInputStream(); - - return this.readCertificate(input); - } catch (Exception e) { - throw new SignatureException("Impossible to read the certificate from '" - + certificateURL - + "' URL", e); - } finally { - if (urlConnection != null && urlConnection instanceof HttpURLConnection) { - ((HttpURLConnection) urlConnection).disconnect(); - } - - if (input != null) { - try { - input.close(); - } catch (IOException e) { - // close quietly - } - } - } - } - - public final T getRsaKey() { - return this.rsaKey; - } - - @Override - public final String getValue() { - return String.valueOf(this.rsaKey); - } - - protected abstract T readCertificate(InputStream input) throws Exception; - - /** - * {@inheritDoc} - */ - public final String[] getAlgorithmMethods() { - return METHODS; - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java b/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java deleted file mode 100644 index a2136ca6..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1SigningKey.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.rsa; - -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.security.interfaces.RSAPrivateKey; - -import org.apache.amber.signature.SignatureException; -import org.apache.amber.signature.SigningKey; - -/** - * - * - * @version $Id$ - */ -public final class PemRsaSha1SigningKey - extends AbstractRsaSha1Key - implements SigningKey { - - public PemRsaSha1SigningKey(File certificateFileLocation) - throws SignatureException { - super(certificateFileLocation); - } - - public PemRsaSha1SigningKey(String certificateClasspathLocation) - throws SignatureException { - super(certificateClasspathLocation); - } - - public PemRsaSha1SigningKey(URL certificateURL) throws SignatureException { - super(certificateURL); - } - - /** - * {@inheritDoc} - */ - @Override - protected RSAPrivateKey readCertificate(InputStream input) throws Exception { - PemCertificateParser pemCertificateParser = new PemCertificateParser(input); - return pemCertificateParser.parsePrivateKey(); - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java b/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java deleted file mode 100644 index e180aca3..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/rsa/PemRsaSha1VerifyingKey.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.rsa; - -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.security.interfaces.RSAPublicKey; - -import org.apache.amber.signature.SignatureException; -import org.apache.amber.signature.VerifyingKey; - -/** - * - * - * @version $Id$ - */ -public final class PemRsaSha1VerifyingKey - extends AbstractRsaSha1Key - implements VerifyingKey { - - public PemRsaSha1VerifyingKey(File certificateFileLocation) - throws SignatureException { - super(certificateFileLocation); - } - - public PemRsaSha1VerifyingKey(String certificateClasspathLocation) - throws SignatureException { - super(certificateClasspathLocation); - } - - public PemRsaSha1VerifyingKey(URL certificateURL) throws SignatureException { - super(certificateURL); - } - - /** - * {@inheritDoc} - */ - @Override - protected RSAPublicKey readCertificate(InputStream input) throws Exception { - PemCertificateParser pemCertificateParser = new PemCertificateParser(input); - return pemCertificateParser.parsePublicCertificate(); - } - -} diff --git a/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java b/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java deleted file mode 100644 index a6fd679d..00000000 --- a/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.rsa; - -import java.security.Signature; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - -import org.apache.amber.signature.AbstractMethod; -import org.apache.amber.signature.SignatureException; -import org.apache.amber.signature.SigningKey; -import org.apache.amber.signature.VerifyingKey; - -/** - * RSA-SHA1 Method implementation. - * - * @version $Id$ - */ -public final class RsaSha1Method extends AbstractMethod { - - /** - * RSA+SHA1 algorithm name. - */ - private static final String RSA_SHA1_ALGORITHM = "SHA1withRSA"; - - /** - * This method name. - */ - private final static String RSA_SHA1 = "RSA-SHA1"; - - /** - * {@inheritDoc} - */ - @Override - public String getAlgorithm() { - return RSA_SHA1; - } - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("unchecked") - protected String calculate(SigningKey signingKey, - String tokenSecret, - String baseString) throws SignatureException { - try { - Signature signer = Signature.getInstance(RSA_SHA1_ALGORITHM); - signer.initSign(((AbstractRsaSha1Key) signingKey).getRsaKey()); - signer.update(toUTF8Bytes(baseString)); - byte[] signature = signer.sign(); - - return encodeBase64(signature); - } catch (Exception e) { - // TODO add a meaningful message - throw new SignatureException(e); - } - } - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("unchecked") - protected boolean verify(String signature, - VerifyingKey verifyingKey, - String tokenSecret, - String baseString) throws SignatureException { - try { - Signature verifier = Signature.getInstance(RSA_SHA1_ALGORITHM); - verifier.initVerify(((AbstractRsaSha1Key) verifyingKey).getRsaKey()); - verifier.update(toUTF8Bytes(baseString)); - - return verifier.verify(decodeBase64(signature)); - } catch (Exception e) { - // TODO add a meaningful message - throw new SignatureException(e); - } - } - -} diff --git a/signature-api/src/main/javacc/PemCertificateParser.jj b/signature-api/src/main/javacc/PemCertificateParser.jj deleted file mode 100644 index a0072eae..00000000 --- a/signature-api/src/main/javacc/PemCertificateParser.jj +++ /dev/null @@ -1,122 +0,0 @@ -PARSER_BEGIN(PemCertificateParser) -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.rsa; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.security.KeyFactory; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; - -import org.apache.commons.codec.binary.Base64OutputStream; - -/** - * PEM private/public certificates parser. - * - * @version $Id$ - */ -final class PemCertificateParser { - - private static final String RSA_NAME = "RSA"; - - private static KeyFactory getRsaKeyFactory() { - try { - return KeyFactory.getInstance(RSA_NAME); - } catch (Exception e) { - throw new RuntimeException("Impossible to instantiate the RSA KeyFactory", e); - } - } - - private final KeyFactory keyFactory = getRsaKeyFactory(); - - private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - private final Base64OutputStream output = new Base64OutputStream(baos, false); - -} - -PARSER_END(PemCertificateParser) - -SKIP : { - <[" ","\t","\n","\r"]> -} - -TOKEN : { - - | - | - | - | messageParameters = new TreeSet(); - - private final SortedSet requestParameters = new TreeSet(); - - public void addOAuthMessageParameter(OAuthMessageParameter parameter) { - this.messageParameters.add(parameter); - } - - public void addOAuthRequestParameter(OAuthRequestParameter parameter) { - this.requestParameters.add(parameter); - } - - public HTTPMethod getHTTPMethod() { - return this.httpMethod; - } - - public void setHTTPMethod(HTTPMethod httpMethod) { - this.httpMethod = httpMethod; - } - - public OAuthParameterLocation getParameterLocation() { - return this.parameterLocation; - } - - public void setParameterLocation(OAuthParameterLocation parameterLocation) { - this.parameterLocation = parameterLocation; - } - - public Collection getOAuthMessageParameters() { - return this.messageParameters; - } - - public Collection getOAuthRequestParameters() { - return this.requestParameters; - } - - public URI getRequestURL() { - return this.requestURL; - } - - public void setRequestURL(URI requestURL) { - this.requestURL = requestURL; - } - - public String getOAuthMessageParameter(OAuthParameter parameter) { - for (OAuthMessageParameter omp : this.messageParameters) { - if (omp.getKey().equals(parameter)) { - return omp.getValue(); - } - } - return null; // not ideal, but it's only a test - } - - public String getOAuthRequestParameter(String name) { - for (OAuthRequestParameter orp : this.requestParameters) { - if (orp.getKey().equals(name)) { - return orp.getValue(); - } - } - return null; // not ideal, but it's only a test - } - -} diff --git a/signature-api/src/test/java/org/apache/amber/signature/FakeToken.java b/signature-api/src/test/java/org/apache/amber/signature/FakeToken.java deleted file mode 100644 index 874e26cd..00000000 --- a/signature-api/src/test/java/org/apache/amber/signature/FakeToken.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.apache.amber.signature; - -import java.util.Set; -import java.util.Map.Entry; - -import org.apache.amber.OAuthToken; - -final class FakeToken implements OAuthToken { - - /** - * - */ - private static final long serialVersionUID = -4501539974041422272L; - - private String tokenSecret; - - public void addAdditionalParameters(String name, String value) { - // unneded for test purposes - } - - public Set> additionalParametersEntrySet() { - // unneded for test purposes - return null; - } - - public String getToken() { - // unneded for test purposes - return null; - } - - public String getTokenSecret() { - // unneded for test purposes - return this.tokenSecret; - } - - public boolean isCallbackConfirmed() { - // unneded for test purposes - return false; - } - - public void setCallbackConfirmed(boolean callbackConfirmed) { - // unneded for test purposes - } - - public void setToken(String token) { - // unneded for test purposes - } - - public void setTokenSecret(String tokenSecret) { - this.tokenSecret = tokenSecret; - } - -} diff --git a/signature-api/src/test/java/org/apache/amber/signature/hmac/HmacSha1MethodTestCase.java b/signature-api/src/test/java/org/apache/amber/signature/hmac/HmacSha1MethodTestCase.java deleted file mode 100644 index abfd2d0e..00000000 --- a/signature-api/src/test/java/org/apache/amber/signature/hmac/HmacSha1MethodTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.hmac; - -import org.apache.amber.signature.AbstractMethodTestCase; -import org.apache.amber.signature.BasicKey; -import org.junit.Test; - -/** - * HMAC-SHA1 Method test case implementation. - * - * @version $Id$ - */ -public class HmacSha1MethodTestCase extends AbstractMethodTestCase { - - @Test - public void verifyHmacSha1MethodAlgorithm() throws Exception { - this.verifySignature(new BasicKey("kd94hf93k423kf44"), - new HmacSha1Method(), - "tR3+Ty81lMeYAr/Fid0kMTYa/WM="); - } - -} diff --git a/signature-api/src/test/java/org/apache/amber/signature/plaintext/PlaintextMethodTestCase.java b/signature-api/src/test/java/org/apache/amber/signature/plaintext/PlaintextMethodTestCase.java deleted file mode 100644 index 9b7050b9..00000000 --- a/signature-api/src/test/java/org/apache/amber/signature/plaintext/PlaintextMethodTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature.plaintext; - -import org.apache.amber.signature.AbstractMethodTestCase; -import org.apache.amber.signature.BasicKey; -import org.junit.Test; - -/** - * HMAC-SHA1 Method test case implementation. - * - * @version $Id$ - */ -public class PlaintextMethodTestCase extends AbstractMethodTestCase { - - @Test - public void verifyHmacSha1MethodAlgorithm() throws Exception { - this.verifySignature(new BasicKey("kd94hf93k423kf44"), - new PlaintextMethod(), - "kd94hf93k423kf44&pfkkdhi9sl3r4s00"); - } - -} diff --git a/signature-api/src/test/resources/org/apache/amber/signature/rsa/private.pem b/signature-api/src/test/resources/org/apache/amber/signature/rsa/private.pem deleted file mode 100644 index 53e20286..00000000 --- a/signature-api/src/test/resources/org/apache/amber/signature/rsa/private.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQDEvO0izOt4zfdK5Z+BDRd0wXuiPvXzgD5ZdFI1QpS/eqZffZue -lzY6cm7MA1xTtw/jX7tHaALw5MvGh6T7SShrrKQcSxsSQWN+4RclLYfVe0xKin+7 -IOV3fXo1EPAIGrJNITffTsPgLuygsFRYBY7+3Q90PfETKIizkddBxcUL1QIDAQAB -AoGAPg/jNrEyLv+6XRQmxw0cMya+G6aE6/WutYVuUYLZbbYBOepj5xmIb9OdhBoj -S/1Zs76FU7dKBjgG2G/96Y9ggljkqbM28hCRg+M5+rsOQZGHO8+S+cUTkpR6pqT9 -GJ+tkC+ca08mtZkSBF9GOM2b18kbxNIBs+N781+JeLlwr1kCQQD1JpZkn6G2CrFC -vqzeHQyPlkZtbyf3yrAMwl2pYuq4Zhm+4l7E3KhaLped1Yu8R76CRdsUR4N8N8eq -mHDPyRdfAkEAzXHZ5/XKJs32co/e5oX+il9+cdO1qHsx7lAif2dNhLHKQ+PK8HTd -73G3Id4FH/yEUuronOoAigSb0X2q6PCtSwJAbH1uMwu+GfzzY3FUuVsrsuOzOTzm -+C8X6B2gK5UeAQsWO7accAyi6H4UFQJrO6CYe7iEcp4PX0qkLygVTK9WiwJBAMZz -dbRVfsJhLfCX/Q7c3HY5rGCzysRGzIKRseEznnPRcbqGrh/8I+4KAIaceoLdX8zg -0XXRrFemAAYqyA9ffWUCQE/euQGTP1lTxkpjFBmf5SM2Z2Ytc07WNkVaefyFrY2x -R8UhvCkS8Q5PQCfmf/Ffe5OSiRb40zxl+KZR90LsiCw= ------END RSA PRIVATE KEY----- diff --git a/signature-api/src/test/resources/org/apache/amber/signature/rsa/public.pem b/signature-api/src/test/resources/org/apache/amber/signature/rsa/public.pem deleted file mode 100644 index 3916836c..00000000 --- a/signature-api/src/test/resources/org/apache/amber/signature/rsa/public.pem +++ /dev/null @@ -1,6 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEvO0izOt4zfdK5Z+BDRd0wXui -PvXzgD5ZdFI1QpS/eqZffZuelzY6cm7MA1xTtw/jX7tHaALw5MvGh6T7SShrrKQc -SxsSQWN+4RclLYfVe0xKin+7IOV3fXo1EPAIGrJNITffTsPgLuygsFRYBY7+3Q90 -PfETKIizkddBxcUL1QIDAQAB ------END PUBLIC KEY----- diff --git a/site/apidocs/allclasses-frame.html b/site/apidocs/allclasses-frame.html deleted file mode 100644 index 621a419c..00000000 --- a/site/apidocs/allclasses-frame.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - -All Classes (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - -All Classes -
- - - - - -
AbstractMethod -
-Access -
-AccessStorage -
-BasicKey -
-ConsumerStorage -
-HmacSha1Method -
-HttpConnector -
-HTTPMethod -
-Key -
-NonceGenerator -
-OAuth -
-OAuthClient -
-OAuthConsumer -
-OAuthException -
-OAuthFactory -
-OAuthMessageParameter -
-OAuthnServer -
-OAuthParameter -
-OAuthParameterLocation -
-OAuthProvider -
-OAuthProviders -
-OAuthRequest -
-OAuthRequestParameter -
-OAuthResponse -
-OAuthResponseParser -
-OAuthRuntimeException -
-OAuthServer -
-OAuthServerConfiguration -
-OAuthToken -
-OAuthzServer -
-ParseException -
-PemCertificateParserConstants -
-PemCertificateParserTokenManager -
-PemRsaSha1SigningKey -
-PemRsaSha1VerifyingKey -
-PlaintextMethod -
-RsaSha1Method -
-SignatureException -
-SignatureMethod -
-SigningKey -
-SimpleCharStream -
-StorageException -
-TemporaryCredentialsGenerator -
-Token -
-TokenCredentialsGenerator -
-TokenMgrError -
-TokenStorage -
-VerifyingKey -
-Version -
-
- - - diff --git a/site/apidocs/allclasses-noframe.html b/site/apidocs/allclasses-noframe.html deleted file mode 100644 index 68c27bc8..00000000 --- a/site/apidocs/allclasses-noframe.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - -All Classes (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - -All Classes -
- - - - - -
AbstractMethod -
-Access -
-AccessStorage -
-BasicKey -
-ConsumerStorage -
-HmacSha1Method -
-HttpConnector -
-HTTPMethod -
-Key -
-NonceGenerator -
-OAuth -
-OAuthClient -
-OAuthConsumer -
-OAuthException -
-OAuthFactory -
-OAuthMessageParameter -
-OAuthnServer -
-OAuthParameter -
-OAuthParameterLocation -
-OAuthProvider -
-OAuthProviders -
-OAuthRequest -
-OAuthRequestParameter -
-OAuthResponse -
-OAuthResponseParser -
-OAuthRuntimeException -
-OAuthServer -
-OAuthServerConfiguration -
-OAuthToken -
-OAuthzServer -
-ParseException -
-PemCertificateParserConstants -
-PemCertificateParserTokenManager -
-PemRsaSha1SigningKey -
-PemRsaSha1VerifyingKey -
-PlaintextMethod -
-RsaSha1Method -
-SignatureException -
-SignatureMethod -
-SigningKey -
-SimpleCharStream -
-StorageException -
-TemporaryCredentialsGenerator -
-Token -
-TokenCredentialsGenerator -
-TokenMgrError -
-TokenStorage -
-VerifyingKey -
-Version -
-
- - - diff --git a/site/apidocs/constant-values.html b/site/apidocs/constant-values.html deleted file mode 100644 index d6c6215d..00000000 --- a/site/apidocs/constant-values.html +++ /dev/null @@ -1,301 +0,0 @@ - - - - - - - -Constant Field Values (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Constant Field Values

-
-
-Contents - - - - - - -
-org.apache.*
- -

- - - - - - - - - - - - - - - - - -
org.apache.amber.OAuth
-public static final StringJAXB_PACKAGE"org.apache.amber.jaxb.package"
-public static final StringOUT_OF_BAND"oob"
- -

- -

- - - - - - - - - - - - - - - - - -
org.apache.amber.OAuthMessageParameter
-protected static final intINITIAL_ODD_NUMBER1
-protected static final intMULTIPLIER_ODD_NUMBER31
- -

- -

- - - - - - - - - - - - - - - - - -
org.apache.amber.OAuthRequestParameter
-protected static final intINITIAL_ODD_NUMBER1
-protected static final intMULTIPLIER_ODD_NUMBER31
- -

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
org.apache.amber.signature.rsa.PemCertificateParserConstants
-public static final intBEGIN_CERTIFICATE4
-public static final intBEGIN_PRIVATE_KEY2
-public static final intCERTIFICATE_CONTENT6
-public static final intDEFAULT0
-public static final intEND_CERTIFICATE5
-public static final intEND_PRIVATE_KEY3
-public static final intEOF0
- -

- -

- - - - - - - - - - - - -
org.apache.amber.signature.rsa.SimpleCharStream
-public static final booleanstaticFlagfalse
- -

- -

-


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/deprecated-list.html b/site/apidocs/deprecated-list.html deleted file mode 100644 index 3e044a8d..00000000 --- a/site/apidocs/deprecated-list.html +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - - -Deprecated List (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Deprecated API

-
-
-Contents - - - - - - - - - - - - -
-Deprecated Methods
org.apache.amber.signature.rsa.SimpleCharStream.getColumn() -
-            
org.apache.amber.signature.rsa.SimpleCharStream.getLine() -
-            
-  -

-


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/help-doc.html b/site/apidocs/help-doc.html deleted file mode 100644 index 228b0c4f..00000000 --- a/site/apidocs/help-doc.html +++ /dev/null @@ -1,224 +0,0 @@ - - - - - - - -API Help (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Overview

-
- -

-The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

-

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    -
  • Interfaces (italic)
  • Classes
  • Enums
  • Exceptions
  • Errors
  • Annotation Types
-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    -
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description -

    -

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary -

    -

  • Field Detail
  • Constructor Detail
  • Method Detail
-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

    -
  • Annotation Type declaration
  • Annotation Type description
  • Required Element Summary
  • Optional Element Summary
  • Element Detail
-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

    -
  • Enum declaration
  • Enum description
  • Enum Constant Summary
  • Enum Constant Detail
-
-

-Use

-
-Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    -
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
-
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/index-all.html b/site/apidocs/index-all.html deleted file mode 100644 index ef59383f..00000000 --- a/site/apidocs/index-all.html +++ /dev/null @@ -1,1134 +0,0 @@ - - - - - - - -Index (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -A B C D E F G H I J K L M N O P R S T U V
-

-A

-
-
AbstractMethod - Class in org.apache.amber.signature
Abstract implementation of OAuth signature method algorithm.
AbstractMethod() - -Constructor for class org.apache.amber.signature.AbstractMethod -
  -
Access - Interface in org.apache.amber.server
Association of nonce(s) and timestamp.
AccessStorage - Interface in org.apache.amber.server
Nonce/timestamp storage definition.
accessToken(OAuthRequest) - -Method in interface org.apache.amber.server.OAuthnServer -
Generates a new access token. -
add(String, long, String) - -Method in interface org.apache.amber.server.AccessStorage -
Stores a new nonce / timestamp pair associated with a consumer key. -
add(OAuthConsumer) - -Method in interface org.apache.amber.server.ConsumerStorage -
Stores consumer data. -
add(String, OAuthToken) - -Method in interface org.apache.amber.server.TokenStorage -
Stores a new token. -
add_escapes(String) - -Method in exception org.apache.amber.signature.rsa.ParseException -
Used to convert raw characters to their escaped version - when these raw version cannot be used as part of an ASCII - string literal. -
addAdditionalParameters(String, String) - -Method in interface org.apache.amber.OAuthToken -
Associates the specified value with the specified name in this additional - parameters map. -
addEscapes(String) - -Static method in error org.apache.amber.signature.rsa.TokenMgrError -
Replaces unprintable characters by their escaped (or unicode escaped) - equivalents in the given string -
additionalParametersEntrySet() - -Method in interface org.apache.amber.OAuthToken -
  -
addNonce(String) - -Method in interface org.apache.amber.server.Access -
Add a nonce to an access. -
addOAuthMessageParameter(OAuthMessageParameter) - -Method in interface org.apache.amber.OAuthRequest -
  -
addOAuthRequestParameter(OAuthRequestParameter) - -Method in interface org.apache.amber.OAuthRequest -
  -
adjustBeginLineColumn(int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Method to adjust line and column numbers for the start of a token. -
authorizeToken(String) - -Method in interface org.apache.amber.server.OAuthnServer -
Authorize a request token. -
-
-

-B

-
-
backup(int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Backup a number of characters. -
BasicKey - Class in org.apache.amber.signature
 
BasicKey(String) - -Constructor for class org.apache.amber.signature.BasicKey -
  -
BEGIN_CERTIFICATE - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
RegularExpression Id. -
BEGIN_PRIVATE_KEY - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
RegularExpression Id. -
beginColumn - -Variable in class org.apache.amber.signature.rsa.Token -
The column number of the first character of this Token. -
beginLine - -Variable in class org.apache.amber.signature.rsa.Token -
The line number of the first character of this Token. -
BeginToken() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Start. -
bufcolumn - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
buffer - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
bufline - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
bufpos - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
Position in buffer. -
-
-

-C

-
-
calculate(SigningKey, OAuthToken, OAuthRequest) - -Method in class org.apache.amber.signature.AbstractMethod -
Calculates the OAuth request message signature. -
calculate(SigningKey, String, String) - -Method in class org.apache.amber.signature.AbstractMethod -
Calculates the signature applying the method algorithm. -
calculate(SigningKey, String, String) - -Method in class org.apache.amber.signature.hmac.HmacSha1Method -
Calculates the signature applying the method algorithm. -
calculate(SigningKey, String, String) - -Method in class org.apache.amber.signature.plaintext.PlaintextMethod -
Calculates the signature applying the method algorithm. -
calculate(SigningKey, String, String) - -Method in class org.apache.amber.signature.rsa.RsaSha1Method -
Calculates the signature applying the method algorithm. -
calculate(SigningKey, OAuthToken, OAuthRequest) - -Method in interface org.apache.amber.signature.SignatureMethod -
Calculates the OAuth request message signature. -
CERTIFICATE_CONTENT - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
RegularExpression Id. -
column - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
ConsumerStorage - Interface in org.apache.amber.server
OAuthConsumer consumer storage interface.
containsNonce(String) - -Method in interface org.apache.amber.server.Access -
Checks if the access already contains a nonce. -
createFactory() - -Static method in class org.apache.amber.OAuth -
Perform initialisation of a factory -
createFactory(Properties) - -Static method in class org.apache.amber.OAuth -
Perform initialisation of a factory -
createFactory(Version) - -Static method in class org.apache.amber.OAuth -
Perform initialisation of a factory -
createFactory(Version, Properties) - -Static method in class org.apache.amber.OAuth -
Perform initialisation of a factory -
createServer(String) - -Method in interface org.apache.amber.OAuthFactory -
  -
curChar - -Variable in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
  -
currentToken - -Variable in exception org.apache.amber.signature.rsa.ParseException -
This is the last token that has been consumed successfully. -
-
-

-D

-
-
debugStream - -Variable in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Debug output. -
decodeBase64(String) - -Static method in class org.apache.amber.signature.AbstractMethod -
Decodes an input text to a bytes sequence applying the Base64 algorithm. -
DEFAULT - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
Lexical state. -
delete(String) - -Method in interface org.apache.amber.server.ConsumerStorage -
Removes a token from the store. -
delete(String) - -Method in interface org.apache.amber.server.TokenStorage -
Removes a token from the store. -
Done() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reset buffer when finished. -
-
-

-E

-
-
encodeBase64(byte[]) - -Static method in class org.apache.amber.signature.AbstractMethod -
Encodes a bytes sequence applying the Base64 algorithm without chuncking - the output string. -
END_CERTIFICATE - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
RegularExpression Id. -
END_PRIVATE_KEY - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
RegularExpression Id. -
endColumn - -Variable in class org.apache.amber.signature.rsa.Token -
The column number of the last character of this Token. -
endLine - -Variable in class org.apache.amber.signature.rsa.Token -
The line number of the last character of this Token. -
EOF - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
End of File. -
eol - -Variable in exception org.apache.amber.signature.rsa.ParseException -
The end of line string for this machine. -
equals(Object) - -Method in class org.apache.amber.OAuthMessageParameter -
-
equals(Object) - -Method in class org.apache.amber.OAuthRequestParameter -
-
execute(OAuthRequest, String) - -Method in interface org.apache.amber.client.HttpConnector -
The execute method does the work of processing a request and returning a - response from the Provider. -
ExpandBuff(boolean) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
expectedTokenSequences - -Variable in exception org.apache.amber.signature.rsa.ParseException -
Each entry in this array is an array of integers. -
-
-

-F

-
-
FillBuff() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
-
-

-G

-
-
generate() - -Method in interface org.apache.amber.client.NonceGenerator -
Generate a nonce string value. -
generate() - -Method in interface org.apache.amber.server.TemporaryCredentialsGenerator -
Generates a new temporary credentials. -
generate() - -Method in interface org.apache.amber.server.TokenCredentialsGenerator -
Generates a new token credentials. -
getAccessStorage() - -Method in interface org.apache.amber.server.OAuthServerConfiguration -
  -
getAccessToken(OAuthToken, String) - -Method in interface org.apache.amber.client.OAuthClient -
Convert the authorised token to an access token, using the supplied - verification code. -
getAccessToken(OAuthConsumer, OAuthToken, String) - -Method in interface org.apache.amber.client.OAuthClient -
Convert the authorised token to an access token, using the supplied - consumer and verification code. -
getAccessTokenPath() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getAlgorithm() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getAlgorithm() - -Method in class org.apache.amber.signature.hmac.HmacSha1Method -
Returns the signing algorithm method. -
getAlgorithm() - -Method in class org.apache.amber.signature.plaintext.PlaintextMethod -
Returns the signing algorithm method. -
getAlgorithm() - -Method in class org.apache.amber.signature.rsa.RsaSha1Method -
Returns the signing algorithm method. -
getAlgorithm() - -Method in interface org.apache.amber.signature.SignatureMethod -
Returns the signing algorithm method. -
getAlgorithmMethods() - -Method in class org.apache.amber.signature.BasicKey -
  -
getAlgorithmMethods() - -Method in interface org.apache.amber.signature.Key -
Returns the signing algorithm methods. -
getAuthenticatePath() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getAuthenticateURL(OAuthToken) - -Method in interface org.apache.amber.client.OAuthClient -
Get the authentication URL for the configured provider, using the - specified token. -
getAuthenticateURL(OAuthToken, String) - -Method in interface org.apache.amber.client.OAuthClient -
Get the authentication URL for the configured provider, using the - specified token and callback. -
getAuthorizePath() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getAuthorizeURL(OAuthToken) - -Method in interface org.apache.amber.client.OAuthClient -
Get the authorisation URL for the configured provider, using the - specified token. -
getAuthorizeURL(OAuthToken, String) - -Method in interface org.apache.amber.client.OAuthClient -
Get the authorisation URL for the configured provider, using the - specified token. -
getBeginColumn() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Get token beginning column number. -
getBeginLine() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Get token beginning line number. -
getCallback() - -Method in interface org.apache.amber.client.OAuthConsumer -
The callback field contains the HTTP URL that the Provider will redirect - the User to during the authentication / authorisation process. -
getColumn() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Deprecated.   -
getConfiguration() - -Method in class org.apache.amber.server.OAuthServer -
  -
getConnector() - -Method in interface org.apache.amber.client.OAuthClient -
Get the current connector. -
getConsumers() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getConsumerStorage() - -Method in interface org.apache.amber.server.OAuthServerConfiguration -
  -
getEndColumn() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Get token end column number. -
getEndLine() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Get token end line number. -
getHTTPMethod() - -Method in interface org.apache.amber.OAuthRequest -
  -
GetImage() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Get token literal value. -
getKey() - -Method in interface org.apache.amber.client.OAuthConsumer -
The key field contains the key string assigned to the Consumer by the - Provider, during registration. -
getLabel() - -Method in enum org.apache.amber.OAuthParameter -
  -
getLastAccess(String) - -Method in interface org.apache.amber.server.AccessStorage -
Get the last access (by timestamp) of a consumer. -
getLine() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Deprecated.   -
getLocation() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getLog() - -Method in class org.apache.amber.signature.AbstractMethod -
Return this class log. -
getMessage() - -Method in exception org.apache.amber.signature.rsa.ParseException -
This method has the standard behavior when this object has been - created using the standard constructors. -
getMessage() - -Method in error org.apache.amber.signature.rsa.TokenMgrError -
You can also modify the body of this method to customize your error messages. -
getName() - -Method in interface org.apache.amber.client.OAuthConsumer -
The name field is a convenient reference to the Consumer and SHOULD match - the string used during the Provider registration process -
getNextToken() - -Method in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Get the next Token. -
getNonceGenerator() - -Method in interface org.apache.amber.client.OAuthClient -
Returns the current nonce generator to be used. -
getNonces() - -Method in interface org.apache.amber.server.Access -
Returns the whole list of nonces associated to the timestamp. -
getOAuthMessageParameter(OAuthParameter) - -Method in interface org.apache.amber.OAuthRequest -
  -
getOAuthMessageParameters() - -Method in interface org.apache.amber.OAuthRequest -
Returns the OAuth parameters will be included in the OAuth message. -
getOAuthRequestParameter(String) - -Method in interface org.apache.amber.OAuthRequest -
  -
getOAuthRequestParameters() - -Method in interface org.apache.amber.OAuthRequest -
Returns the aux parameters client will included in the request. -
getParameterLocation() - -Method in interface org.apache.amber.OAuthRequest -
  -
getProperties() - -Method in interface org.apache.amber.OAuthFactory -
  -
getProvider() - -Method in interface org.apache.amber.server.OAuthProviders -
  -
getProviders() - -Method in interface org.apache.amber.OAuthFactory -
  -
getRealm() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getRequestToken() - -Method in interface org.apache.amber.client.OAuthClient -
Get a request token using the default consumer and token. -
getRequestToken(OAuthConsumer) - -Method in interface org.apache.amber.client.OAuthClient -
Get a request token using the specified consumer. -
getRequestToken(Class<? extends OAuthToken>) - -Method in interface org.apache.amber.client.OAuthClient -
Get a request token, instantiated from the provided class, using the - default consumer. -
getRequestToken(Class<? extends OAuthToken>, OAuthConsumer) - -Method in interface org.apache.amber.client.OAuthClient -
Get a request token, instantiated from the provided class, using the - specified consumer. -
getRequestTokenPath() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getRequestURL() - -Method in interface org.apache.amber.OAuthRequest -
  -
getResponseParser() - -Method in interface org.apache.amber.server.OAuthProvider -
  -
getSecret() - -Method in interface org.apache.amber.client.OAuthConsumer -
  -
GetSuffix(int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Get the suffix. -
getTabSize(int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
getTimestamp() - -Method in interface org.apache.amber.server.Access -
Returns the timestamp access. -
getToken() - -Method in interface org.apache.amber.OAuthToken -
  -
getTokenSecret() - -Method in interface org.apache.amber.OAuthToken -
  -
getTokenStorage() - -Method in interface org.apache.amber.server.OAuthServerConfiguration -
  -
getValue() - -Method in class org.apache.amber.signature.BasicKey -
  -
getValue() - -Method in interface org.apache.amber.signature.Key -
Returns the key string representation. -
getValue() - -Method in class org.apache.amber.signature.rsa.Token -
An optional attribute value of the Token. -
getVersion() - -Method in interface org.apache.amber.OAuthFactory -
  -
-
-

-H

-
-
hashCode() - -Method in class org.apache.amber.OAuthMessageParameter -
-
hashCode() - -Method in class org.apache.amber.OAuthRequestParameter -
-
HmacSha1Method - Class in org.apache.amber.signature.hmac
HMAC-SHA1 Method implementation.
HmacSha1Method() - -Constructor for class org.apache.amber.signature.hmac.HmacSha1Method -
  -
HttpConnector - Interface in org.apache.amber.client
The HttpConnector does the work converting executing an - OAuthRequest and returning an - OAuthResponse.
HTTPMethod - Enum in org.apache.amber
Enumeration of available HTTP methods.
-
-

-I

-
-
image - -Variable in class org.apache.amber.signature.rsa.Token -
The string image of the token. -
inBuf - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
input_stream - -Variable in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
  -
inputStream - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
isAuthorized(OAuthRequest) - -Method in interface org.apache.amber.server.OAuthzServer -
Evaluates if a specific request contains authorization token to - access to a protected resource. -
isCallbackConfirmed() - -Method in interface org.apache.amber.OAuthToken -
  -
isIncludeInSignature() - -Method in enum org.apache.amber.OAuthParameter -
  -
isOptional() - -Method in enum org.apache.amber.OAuthParameter -
  -
-
-

-J

-
-
JAXB_PACKAGE - -Static variable in class org.apache.amber.OAuth -
  -
jjFillToken() - -Method in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
  -
jjstrLiteralImages - -Static variable in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Token literal values. -
-
-

-K

-
-
Key - Interface in org.apache.amber.signature
Client Credential representation.
kind - -Variable in class org.apache.amber.signature.rsa.Token -
An integer that describes the kind of this token. -
-
-

-L

-
-
LexicalError(boolean, int, int, int, String, char) - -Static method in error org.apache.amber.signature.rsa.TokenMgrError -
Returns a detailed message for the Error when it is thrown by the - token manager to indicate a lexical error. -
lexStateNames - -Static variable in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Lexer state names. -
line - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
-
-

-M

-
-
maxNextCharInd - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
-
-

-N

-
-
newToken(int, String) - -Static method in class org.apache.amber.signature.rsa.Token -
Returns a new Token object, by default. -
newToken(int) - -Static method in class org.apache.amber.signature.rsa.Token -
  -
next - -Variable in class org.apache.amber.signature.rsa.Token -
A reference to the next regular (non-special) token from the input - stream. -
NonceGenerator - Interface in org.apache.amber.client
Generator of nonce values.
-
-

-O

-
-
OAuth - Class in org.apache.amber
The OAuth object provides access to the OAuthFactory.
OAuth() - -Constructor for class org.apache.amber.OAuth -
  -
OAuthClient - Interface in org.apache.amber.client
- An OAuth Service is an abstract representation of the standard remote API - offered by an OAuthProvider, providing a simple mechanism - for performing OAuth authentication and authorisation - tasks.
OAuthConsumer - Interface in org.apache.amber.client
The OAuth Consumer is defined in the OAuth Specification as - the client in one of the legs during an authorisation or authentication.
OAuthException - Exception in org.apache.amber
- Check exception, wraps exceptions thrown by implementation that can be - recovered from.
OAuthException(String, Throwable) - -Constructor for exception org.apache.amber.OAuthException -
  -
OAuthException(String) - -Constructor for exception org.apache.amber.OAuthException -
  -
OAuthException(Throwable) - -Constructor for exception org.apache.amber.OAuthException -
  -
OAuthFactory - Interface in org.apache.amber
TODO Write extensive documentation
OAuthMessageParameter - Class in org.apache.amber
Identifier for the OAuth Authorization message parameter.
OAuthMessageParameter(OAuthParameter, String) - -Constructor for class org.apache.amber.OAuthMessageParameter -
  -
OAuthnServer - Interface in org.apache.amber.server
 
OAuthParameter - Enum in org.apache.amber
The OAuth specification defines individual parameters required by a provider - at different stages of the authentication and authorisation process.
OAuthParameterLocation - Enum in org.apache.amber
Defines the possible locations for the OAuth parameters during each request.
OAuthProvider - Interface in org.apache.amber.server
- The minimum configurable values required to specify the different behaviour - of a Provider (an entity defined by the OAuth specification).
OAuthProviders - Interface in org.apache.amber.server
- A convenience object which contains multiple possible OAuth Service - Providers, in order of preference.
OAuthRequest - Interface in org.apache.amber
A convenient object representing the properties of an OAuth request to a - OAuthProvider.
OAuthRequestParameter - Class in org.apache.amber
Identifier for the auxiliar OAuth server required parameter.
OAuthRequestParameter(String, String) - -Constructor for class org.apache.amber.OAuthRequestParameter -
  -
OAuthResponse - Interface in org.apache.amber
An object representing the response returned from an - OAuthClient or OAuthServer.
OAuthResponseParser - Interface in org.apache.amber
- It's possible that a OAuthProvider will return OAuth - information in a custom response format.
OAuthRuntimeException - Exception in org.apache.amber
- Unchecked exception wrapper, thrown when there is a configuration or other - unchecked exception that prevents the implementation from operating.
OAuthRuntimeException(String, Throwable) - -Constructor for exception org.apache.amber.OAuthRuntimeException -
  -
OAuthRuntimeException(String) - -Constructor for exception org.apache.amber.OAuthRuntimeException -
  -
OAuthRuntimeException(Throwable) - -Constructor for exception org.apache.amber.OAuthRuntimeException -
  -
OAuthServer - Class in org.apache.amber.server
An OAuth Server provides the functionality required to deliver OAuth Provider - functionality.
OAuthServer(OAuthServerConfiguration) - -Constructor for class org.apache.amber.server.OAuthServer -
  -
OAuthServerConfiguration - Interface in org.apache.amber.server
 
OAuthToken - Interface in org.apache.amber
- An OAuthToken is the wrapper for the pair of key values returned by the - OAuthClient during the authentication or authorisation - process.
OAuthzServer - Interface in org.apache.amber.server
 
org.apache.amber - package org.apache.amber
An OAuth Java Specification - - Provides the interfaces for an implementation of the OAuth specification.
org.apache.amber.client - package org.apache.amber.client
 
org.apache.amber.server - package org.apache.amber.server
 
org.apache.amber.signature - package org.apache.amber.signature
 
org.apache.amber.signature.hmac - package org.apache.amber.signature.hmac
 
org.apache.amber.signature.plaintext - package org.apache.amber.signature.plaintext
 
org.apache.amber.signature.rsa - package org.apache.amber.signature.rsa
 
OUT_OF_BAND - -Static variable in class org.apache.amber.OAuth -
default callback value -
-
-

-P

-
-
ParseException - Exception in org.apache.amber.signature.rsa
This exception is thrown when parse errors are encountered.
ParseException(Token, int[][], String[]) - -Constructor for exception org.apache.amber.signature.rsa.ParseException -
This constructor is used by the method "generateParseException" - in the generated parser. -
ParseException() - -Constructor for exception org.apache.amber.signature.rsa.ParseException -
The following constructors are for use by you for whatever - purpose you can think of. -
ParseException(String) - -Constructor for exception org.apache.amber.signature.rsa.ParseException -
Constructor with message. -
parseResponse(OAuthToken, OAuthResponse) - -Method in interface org.apache.amber.OAuthResponseParser -
Update the provided token, to include the details from the response -
PemCertificateParserConstants - Interface in org.apache.amber.signature.rsa
Token literal values and constants.
PemCertificateParserTokenManager - Class in org.apache.amber.signature.rsa
Token Manager.
PemCertificateParserTokenManager(SimpleCharStream) - -Constructor for class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Constructor. -
PemCertificateParserTokenManager(SimpleCharStream, int) - -Constructor for class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Constructor. -
PemRsaSha1SigningKey - Class in org.apache.amber.signature.rsa
 
PemRsaSha1SigningKey(File) - -Constructor for class org.apache.amber.signature.rsa.PemRsaSha1SigningKey -
  -
PemRsaSha1SigningKey(String) - -Constructor for class org.apache.amber.signature.rsa.PemRsaSha1SigningKey -
  -
PemRsaSha1SigningKey(URL) - -Constructor for class org.apache.amber.signature.rsa.PemRsaSha1SigningKey -
  -
PemRsaSha1VerifyingKey - Class in org.apache.amber.signature.rsa
 
PemRsaSha1VerifyingKey(File) - -Constructor for class org.apache.amber.signature.rsa.PemRsaSha1VerifyingKey -
  -
PemRsaSha1VerifyingKey(String) - -Constructor for class org.apache.amber.signature.rsa.PemRsaSha1VerifyingKey -
  -
PemRsaSha1VerifyingKey(URL) - -Constructor for class org.apache.amber.signature.rsa.PemRsaSha1VerifyingKey -
  -
percentEncode(String) - -Static method in class org.apache.amber.signature.AbstractMethod -
Applies the percent encoding algorithm to the input text. -
PlaintextMethod - Class in org.apache.amber.signature.plaintext
PLAINTEXT Method implementation.
PlaintextMethod() - -Constructor for class org.apache.amber.signature.plaintext.PlaintextMethod -
  -
prevCharIsCR - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
prevCharIsLF - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
-
-

-R

-
-
read(String) - -Method in interface org.apache.amber.server.ConsumerStorage -
Searches for an existing consumer. -
read(String, String) - -Method in interface org.apache.amber.server.TokenStorage -
Searches for an existing token. -
read(String) - -Method in interface org.apache.amber.server.TokenStorage -
Searches for an existing token. -
readCertificate(InputStream) - -Method in class org.apache.amber.signature.rsa.PemRsaSha1SigningKey -
-
readCertificate(InputStream) - -Method in class org.apache.amber.signature.rsa.PemRsaSha1VerifyingKey -
-
readChar() - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Read a character. -
register(OAuthProvider) - -Method in interface org.apache.amber.OAuthFactory -
  -
ReInit(SimpleCharStream) - -Method in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Reinitialise parser. -
ReInit(SimpleCharStream, int) - -Method in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Reinitialise parser. -
ReInit(Reader, int, int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(Reader, int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(Reader) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(InputStream, String, int, int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(InputStream, int, int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(InputStream, String) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(InputStream) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(InputStream, String, int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
ReInit(InputStream, int, int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
Reinitialise. -
remove(String, long) - -Method in interface org.apache.amber.server.AccessStorage -
Remove a consumer access. -
requestToken(OAuthRequest) - -Method in interface org.apache.amber.server.OAuthnServer -
Generates a new request token. -
RsaSha1Method - Class in org.apache.amber.signature.rsa
RSA-SHA1 Method implementation.
RsaSha1Method() - -Constructor for class org.apache.amber.signature.rsa.RsaSha1Method -
  -
-
-

-S

-
-
setAccessTokenPath(String) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setAlgorithm(String) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setAuthenticatePath(String) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setAuthorizePath(String) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setCallback(String) - -Method in interface org.apache.amber.client.OAuthConsumer -
  -
setCallbackConfirmed(boolean) - -Method in interface org.apache.amber.OAuthToken -
  -
setConnector(HttpConnector) - -Method in interface org.apache.amber.client.OAuthClient -
Set the connector to be used. -
setConsumers(List<OAuthConsumer>) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setDebugStream(PrintStream) - -Method in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Set debug output. -
setHTTPMethod(HTTPMethod) - -Method in interface org.apache.amber.OAuthRequest -
  -
setKey(String) - -Method in interface org.apache.amber.client.OAuthConsumer -
  -
setLocation(OAuthParameterLocation) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setName(String) - -Method in interface org.apache.amber.client.OAuthConsumer -
  -
setNonceGenerator(NonceGenerator) - -Method in interface org.apache.amber.client.OAuthClient -
Sets the nonce generator to be used. -
setParameterLocation(OAuthParameterLocation) - -Method in interface org.apache.amber.OAuthRequest -
  -
setProperties(Properties) - -Method in interface org.apache.amber.OAuthFactory -
  -
setProvider(List<OAuthProvider>) - -Method in interface org.apache.amber.server.OAuthProviders -
  -
setRealm(String) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setRequestTokenPath(String) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setRequestURL(URI) - -Method in interface org.apache.amber.OAuthRequest -
  -
setResponseParser(OAuthResponseParser) - -Method in interface org.apache.amber.server.OAuthProvider -
  -
setSecret(String) - -Method in interface org.apache.amber.client.OAuthConsumer -
The secret field contains the unique secret string generated by the - Provider, during registration. -
setTabSize(int) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
setToken(String) - -Method in interface org.apache.amber.OAuthToken -
  -
setTokenSecret(String) - -Method in interface org.apache.amber.OAuthToken -
  -
SignatureException - Exception in org.apache.amber.signature
Encapsulate a general OAuth signature error or warning.
SignatureException(String) - -Constructor for exception org.apache.amber.signature.SignatureException -
Constructs a new signature exception with the specified detail message. -
SignatureException(Throwable) - -Constructor for exception org.apache.amber.signature.SignatureException -
Constructs a new signature exception with the specified cause. -
SignatureException(String, Throwable) - -Constructor for exception org.apache.amber.signature.SignatureException -
Constructs a new signature exception with the specified detail message - and cause. -
SignatureMethod - Interface in org.apache.amber.signature
Common definition of OAuth signature method algorithm.
SigningKey - Interface in org.apache.amber.signature
Identifies that the key has to be used to sign requests.
SimpleCharStream - Class in org.apache.amber.signature.rsa
An implementation of interface CharStream, where the stream is assumed to - contain only ASCII characters (without unicode processing).
SimpleCharStream(Reader, int, int, int) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(Reader, int, int) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(Reader) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(InputStream, String, int, int, int) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(InputStream, int, int, int) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(InputStream, String, int, int) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(InputStream, int, int) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(InputStream, String) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
SimpleCharStream(InputStream) - -Constructor for class org.apache.amber.signature.rsa.SimpleCharStream -
Constructor. -
specialConstructor - -Variable in exception org.apache.amber.signature.rsa.ParseException -
This variable determines which constructor was used to create - this object and thereby affects the semantics of the - "getMessage" method (see below). -
specialToken - -Variable in class org.apache.amber.signature.rsa.Token -
This field is used to access special tokens that occur prior to this - token, but after the immediately preceding regular (non-special) token. -
staticFlag - -Static variable in class org.apache.amber.signature.rsa.SimpleCharStream -
Whether parser is static. -
StorageException - Exception in org.apache.amber.server
Exception thrown when an error occurs when accessing to the Access Storage.
StorageException(String) - -Constructor for exception org.apache.amber.server.StorageException -
  -
StorageException(Throwable) - -Constructor for exception org.apache.amber.server.StorageException -
  -
StorageException(String, Throwable) - -Constructor for exception org.apache.amber.server.StorageException -
  -
SwitchTo(int) - -Method in class org.apache.amber.signature.rsa.PemCertificateParserTokenManager -
Switch to specified lex state. -
-
-

-T

-
-
tabSize - -Variable in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
TemporaryCredentialsGenerator - Interface in org.apache.amber.server
Temporary credentials generator.
toHandle() - -Method in enum org.apache.amber.Version -
  -
Token - Class in org.apache.amber.signature.rsa
Describes the input token stream.
Token() - -Constructor for class org.apache.amber.signature.rsa.Token -
No-argument constructor -
Token(int) - -Constructor for class org.apache.amber.signature.rsa.Token -
Constructs a new token for the specified Image. -
Token(int, String) - -Constructor for class org.apache.amber.signature.rsa.Token -
Constructs a new token for the specified Image and Kind. -
TokenCredentialsGenerator - Interface in org.apache.amber.server
Token credentials generator.
tokenImage - -Variable in exception org.apache.amber.signature.rsa.ParseException -
This is a reference to the "tokenImage" array of the generated - parser within which the parse error occurred. -
tokenImage - -Static variable in interface org.apache.amber.signature.rsa.PemCertificateParserConstants -
Literal token values. -
TokenMgrError - Error in org.apache.amber.signature.rsa
Token Manager Error.
TokenMgrError() - -Constructor for error org.apache.amber.signature.rsa.TokenMgrError -
No arg constructor. -
TokenMgrError(String, int) - -Constructor for error org.apache.amber.signature.rsa.TokenMgrError -
Constructor with message and reason. -
TokenMgrError(boolean, int, int, int, String, char, int) - -Constructor for error org.apache.amber.signature.rsa.TokenMgrError -
Full Constructor. -
TokenStorage - Interface in org.apache.amber.server
 
toString() - -Method in enum org.apache.amber.OAuthParameter -
  -
toString() - -Method in class org.apache.amber.signature.rsa.Token -
Returns the image. -
toString() - -Method in enum org.apache.amber.Version -
  -
toUTF8Bytes(String) - -Static method in class org.apache.amber.signature.AbstractMethod -
Converts the input text in a sequence of UTF-8 bytes. -
-
-

-U

-
-
update(OAuthConsumer) - -Method in interface org.apache.amber.server.ConsumerStorage -
Modifies a consumer data. -
update(OAuthToken) - -Method in interface org.apache.amber.server.TokenStorage -
Modifies an existing token. -
UpdateLineColumn(char) - -Method in class org.apache.amber.signature.rsa.SimpleCharStream -
  -
useService(String) - -Method in interface org.apache.amber.OAuthFactory -
  -
-
-

-V

-
-
valueOf(String) - -Static method in enum org.apache.amber.HTTPMethod -
Returns the enum constant of this type with the specified name. -
valueOf(String) - -Static method in enum org.apache.amber.OAuthParameter -
Returns the enum constant of this type with the specified name. -
valueOf(String) - -Static method in enum org.apache.amber.OAuthParameterLocation -
Returns the enum constant of this type with the specified name. -
valueOf(String) - -Static method in enum org.apache.amber.Version -
Returns the enum constant of this type with the specified name. -
values() - -Static method in enum org.apache.amber.HTTPMethod -
Returns an array containing the constants of this enum type, in -the order they are declared. -
values() - -Static method in enum org.apache.amber.OAuthParameter -
Returns an array containing the constants of this enum type, in -the order they are declared. -
values() - -Static method in enum org.apache.amber.OAuthParameterLocation -
Returns an array containing the constants of this enum type, in -the order they are declared. -
values() - -Static method in enum org.apache.amber.Version -
Returns an array containing the constants of this enum type, in -the order they are declared. -
verify(String, VerifyingKey, OAuthToken, OAuthRequest) - -Method in class org.apache.amber.signature.AbstractMethod -
Verifies the OAuth request message signature. -
verify(String, VerifyingKey, String, String) - -Method in class org.apache.amber.signature.AbstractMethod -
Verifies the signature applying the method algorithm. -
verify(String, VerifyingKey, String, String) - -Method in class org.apache.amber.signature.hmac.HmacSha1Method -
Verifies the signature applying the method algorithm. -
verify(String, VerifyingKey, String, String) - -Method in class org.apache.amber.signature.plaintext.PlaintextMethod -
Verifies the signature applying the method algorithm. -
verify(String, VerifyingKey, String, String) - -Method in class org.apache.amber.signature.rsa.RsaSha1Method -
Verifies the signature applying the method algorithm. -
verify(String, VerifyingKey, OAuthToken, OAuthRequest) - -Method in interface org.apache.amber.signature.SignatureMethod -
Verifies the OAuth request message signature. -
VerifyingKey - Interface in org.apache.amber.signature
Identifies that the key has to be used to verify requests.
Version - Enum in org.apache.amber
 
-
-A B C D E F G H I J K L M N O P R S T U V - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/index.html b/site/apidocs/index.html deleted file mode 100644 index 91c91a6b..00000000 --- a/site/apidocs/index.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - -Apache Amber 1.0-SNAPSHOT API - - - - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="overview-summary.html">Non-frame version.</A> - - - diff --git a/site/apidocs/overview-frame.html b/site/apidocs/overview-frame.html deleted file mode 100644 index 9662f2cd..00000000 --- a/site/apidocs/overview-frame.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - -Overview List (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - - - - -
-
- - - - - -
All Classes -

- -Packages -
-org.apache.amber -
-org.apache.amber.client -
-org.apache.amber.server -
-org.apache.amber.signature -
-org.apache.amber.signature.hmac -
-org.apache.amber.signature.plaintext -
-org.apache.amber.signature.rsa -
-

- -

-  - - diff --git a/site/apidocs/overview-summary.html b/site/apidocs/overview-summary.html deleted file mode 100644 index 9817da1c..00000000 --- a/site/apidocs/overview-summary.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - -Overview (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -


- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Apache Amber 1.0-SNAPSHOT API -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Packages
org.apache.amberAn OAuth Java Specification - - Provides the interfaces for an implementation of the OAuth specification.
org.apache.amber.client 
org.apache.amber.server 
org.apache.amber.signature 
org.apache.amber.signature.hmac 
org.apache.amber.signature.plaintext 
org.apache.amber.signature.rsa 
- -


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/overview-tree.html b/site/apidocs/overview-tree.html deleted file mode 100644 index 76bf6330..00000000 --- a/site/apidocs/overview-tree.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - - - -Class Hierarchy (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
org.apache.amber, org.apache.amber.client, org.apache.amber.server, org.apache.amber.signature, org.apache.amber.signature.hmac, org.apache.amber.signature.plaintext, org.apache.amber.signature.rsa
-
-

-Class Hierarchy -

- -

-Interface Hierarchy -

- -

-Enum Hierarchy -

- -
- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/package-list b/site/apidocs/package-list deleted file mode 100644 index a85b3453..00000000 --- a/site/apidocs/package-list +++ /dev/null @@ -1,7 +0,0 @@ -org.apache.amber -org.apache.amber.client -org.apache.amber.server -org.apache.amber.signature -org.apache.amber.signature.hmac -org.apache.amber.signature.plaintext -org.apache.amber.signature.rsa diff --git a/site/apidocs/serialized-form.html b/site/apidocs/serialized-form.html deleted file mode 100644 index 0f50773f..00000000 --- a/site/apidocs/serialized-form.html +++ /dev/null @@ -1,352 +0,0 @@ - - - - - - - -Serialized Form (Apache Amber 1.0-SNAPSHOT API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Serialized Form

-
-
- - - - - -
-Package org.apache.amber
- -

- - - - - -
-Class org.apache.amber.OAuthException extends Exception implements Serializable
- -

-serialVersionUID: 1L - -

- -

- - - - - -
-Class org.apache.amber.OAuthRuntimeException extends RuntimeException implements Serializable
- -

-serialVersionUID: 1L - -

-


- - - - - -
-Package org.apache.amber.client
-
- - - - - -
-Package org.apache.amber.server
- -

- - - - - -
-Class org.apache.amber.server.StorageException extends Exception implements Serializable
- -

-serialVersionUID: 1L - -

-


- - - - - -
-Package org.apache.amber.signature
- -

- - - - - -
-Class org.apache.amber.signature.SignatureException extends OAuthException implements Serializable
- -

-serialVersionUID: 1L - -

-


- - - - - -
-Package org.apache.amber.signature.rsa
- -

- - - - - -
-Class org.apache.amber.signature.rsa.ParseException extends Exception implements Serializable
- -

- - - - - -
-Serialized Fields
- -

-specialConstructor

-
-boolean specialConstructor
-
-
This variable determines which constructor was used to create - this object and thereby affects the semantics of the - "getMessage" method (see below). -

-

-
-
-
-

-currentToken

-
-Token currentToken
-
-
This is the last token that has been consumed successfully. If - this object has been created due to a parse error, the token - followng this token will (therefore) be the first error token. -

-

-
-
-
-

-expectedTokenSequences

-
-int[][] expectedTokenSequences
-
-
Each entry in this array is an array of integers. Each array - of integers represents a sequence of tokens (by their ordinal - values) that is expected at this point of the parse. -

-

-
-
-
-

-tokenImage

-
-String[] tokenImage
-
-
This is a reference to the "tokenImage" array of the generated - parser within which the parse error occurred. This array is - defined in the generated ...Constants interface. -

-

-
-
-
-

-eol

-
-String eol
-
-
The end of line string for this machine. -

-

-
-
- -

- - - - - -
-Class org.apache.amber.signature.rsa.TokenMgrError extends Error implements Serializable
- -

- - - - - -
-Serialized Fields
- -

-errorCode

-
-int errorCode
-
-
Indicates the reason why the exception is thrown. It will have - one of the above 4 values. -

-

-
-
- -

-


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/apidocs/stylesheet.css b/site/apidocs/stylesheet.css deleted file mode 100644 index 6ea9e516..00000000 --- a/site/apidocs/stylesheet.css +++ /dev/null @@ -1,29 +0,0 @@ -/* Javadoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF; color:#000000 } - -/* Headings */ -h1 { font-size: 145% } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */ -.TableRowColor { background: #FFFFFF; color:#000000 } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */ -.NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} - diff --git a/site/css/maven-base.css b/site/css/maven-base.css deleted file mode 100644 index 17e10bb4..00000000 --- a/site/css/maven-base.css +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2009 Simone Tripodi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -body { - background-color: #f2f2f2; -} - -body, td, select, input, li { - font-family: "Trebuchet MS", "Geneva", "Arial", "Helvetica", "SunSans-Regular", sans-serif; - color: #555555; -} - -h2, h3, h4 { - color: #265fc2; - background: none; - border: none; -} - -a, a.externalLink, a:active, a:hover { - color: #265fc2; -} - -a:hover { - text-decoration: underline; -} - -#wrapper { - width: 80%; - margin: 1em auto 1em; - background-color: #ffffff; - padding: 1em; -} - -img { - border: none; -} - -table { - padding: 0px; - width: 100%; - margin-left: -2px; - margin-right: -2px; -} - -acronym { - cursor: help; - border-bottom: 1px dotted #feb; -} - -table.bodyTable th,table.bodyTable td { - padding: 2px 4px 2px 4px; - vertical-align: top; -} - -div.clear { - clear: both; - visibility: hidden; -} - -div.clear hr { - display: none; -} - -#bannerLeft,#bannerRight { - font-size: xx-large; - font-weight: bold; -} - -#bannerLeft img,#bannerRight img { - margin: 8px; -} - -.xleft,#bannerLeft img { - float: left; - text-shadow: #7CFC00; -} - -.xright,#bannerRight img { - float: right; - text-shadow: #7CFC00; -} - -#banner { - border-bottom: 1px solid #fff; -} - -#banner img { - border: none; -} - -#footer,#breadcrumbs { - padding: 3px 10px 3px 10px; -} - -#leftColumn { - width: 18%; - float: left; - background-color: #EAEAEA; - margin: 1.5em 0.5em; -} - -#bodyColumn { - margin-left: 20%; -} - -#legend { - padding: 8px 0 8px 0; -} - -#navcolumn { - padding: 1em; - margin: 0; - line-height: 150%; - border: 0; - background-color: #EAEAEA; -} - -#navcolumn h5,#navcolumn ul { - margin: 0; - padding: 0; - font-size: small; -} - -#navcolumn li { - background: transparent; - list-style-type: none; - padding-left: 0.7em; - list-style-position: ouside; - font-size: smaller; -} - -#navcolumn li.expanded { - background: url("../images/collapsed.png") no-repeat left top; -} - -#navcolumn li.collapsed { - background: url("../images/expanded.png") no-repeat left top; -} - -#poweredBy { - text-align: center; -} - -#navcolumn img { - margin-top: 10px; - margin-bottom: 3px; -} - -#poweredBy img { - display: block; - margin: 20px 0 20px 17px; - border: 1px solid black; - width: 90px; - height: 30px; -} - -#search img { - margin: 0px; - display: block; -} - -#search #q,#search #btnG { - border: 1px solid #999; - margin-bottom: 10px; -} - -#search form { - margin: 0px; -} - -#lastPublished { - font-size: x-small; -} - -.navSection { - margin-bottom: 2px; - padding: 8px; -} - -.navSectionHead { - font-weight: bold; - font-size: x-small; -} - -.section { - padding: 4px; -} - -#footer { - font-size: x-small; -} - -#breadcrumbs { - background-color: #EAEAEA; - font-size: x-small; - margin: 0pt; - border: none; -} - -.source { - padding: 12px; - margin: 1em 7px 1em 7px; -} - -.source pre { - margin: 0px; - padding: 0px; -} diff --git a/site/css/maven-theme.css b/site/css/maven-theme.css deleted file mode 100644 index 0bab5293..00000000 --- a/site/css/maven-theme.css +++ /dev/null @@ -1,165 +0,0 @@ -body { - padding: 0px 0px 10px 0px; -} - -body,td,select,input,li { - font-size: 13px; -} - -code { - font-family: Courier, monospace; - font-size: 13px; -} - -a { - text-decoration: none; -} - -a:link { - color: #36a; -} - -a:visited { - color: #47a; -} - -a:active,a:hover { - color: #69c; -} - -#legend li.externalLink { - background: url(../images/window-new.png) left top no-repeat; - padding-left: 18px; -} - -a.externalLink,a.externalLink:link,a.externalLink:visited,a.externalLink:active,a.externalLink:hover - { - background: url(../images/window-new.png) right center no-repeat; - padding-right: 18px; -} - -#legend li.newWindow { - background: url(../images/window-new.png) left top no-repeat; - padding-left: 18px; -} - -a.newWindow,a.newWindow:link,a.newWindow:visited,a.newWindow:active,a.newWindow:hover - { - background: url(../images/window-new.png) right center no-repeat; - padding-right: 18px; -} - -h2 { - padding: 4px 4px 4px 6px; - border: 1px solid #999; - color: #900; - background-color: #ddd; - font-weight: 900; - font-size: x-large; -} - -h3 { - padding: 4px 4px 4px 6px; - border: 1px solid #aaa; - color: #900; - background-color: #eee; - font-weight: normal; - font-size: large; -} - -h4 { - padding: 4px 4px 4px 6px; - border: 1px solid #bbb; - color: #900; - background-color: #fff; - font-weight: normal; - font-size: large; -} - -h5 { - padding: 4px 4px 4px 6px; - color: #900; - font-size: normal; -} - - -p { - line-height: 1.3em; - font-size: small; -} - -#breadcrumbs { - border-top: 1px solid #aaa; - border-bottom: 1px solid #aaa; - background-color: #ccc; -} - -#leftColumn { - margin: 10px 0 0 5px; - border: 1px solid #999; - background-color: #eee; -} - -#navcolumn h5 { - font-size: smaller; - border-bottom: 1px solid #aaaaaa; - padding-top: 2px; - color: #000; -} - -table.bodyTable th { - color: white; - background-color: #bbb; - text-align: left; - font-weight: bold; -} - -table.bodyTable th,table.bodyTable td { - font-size: 1em; -} - -table.bodyTable tr.a { - background-color: #ddd; -} - -table.bodyTable tr.b { - background-color: #eee; -} - -.source { - border: 1px solid #999; -} - -dl { - padding: 4px 4px 4px 6px; - border: 1px solid #aaa; - background-color: #ffc; -} - -dt { - color: #900; -} - -#organizationLogo img,#projectLogo img,#projectLogo span { - margin: 8px; -} - -#banner { - border-bottom: 1px solid #fff; -} - -.errormark,.warningmark,.donemark,.infomark { - background: url(../images/dialog-error.png) no-repeat; -} - -.warningmark { - background-image: url(../images/dialog-warning.png); -} - -.donemark { - background-image: url(../images/dialog-apply.png); -} - -.infomark { - background-image: url(../images/dialog-information.png); -} diff --git a/site/css/niftyCorners.css b/site/css/niftyCorners.css deleted file mode 100644 index 6570f60e..00000000 --- a/site/css/niftyCorners.css +++ /dev/null @@ -1,35 +0,0 @@ -/*Nifty Corners Cube CSS by Alessandro Fulciniti -The following classes are added dinamically by javascript, -and their use should be avoided in the markup */ - -b.niftycorners,b.niftyfill{display:block} -b.niftycorners *{display:block;height: 1px;line-height:1px;font-size: 1px; - overflow:hidden;border-style:solid;border-width: 0 1px} -/*normal*/ -b.r1{margin: 0 3px;border-width: 0 2px} -b.r2{margin: 0 2px} -b.r3{margin: 0 1px} -b.r4{height: 2px} -b.rb1{margin: 0 8px;border-width:0 2px} -b.rb2{margin: 0 6px;border-width:0 2px} -b.rb3{margin: 0 5px} -b.rb4{margin: 0 4px} -b.rb5{margin: 0 3px} -b.rb6{margin: 0 2px} -b.rb7{margin: 0 1px;height:2px} -b.rb8{margin: 0;height:2px} -b.rs1{margin: 0 1px} -/*transparent inside*/ -b.t1{border-width: 0 5px} -b.t2{border-width: 0 3px} -b.t3{border-width: 0 2px} -b.t4{height: 2px} -b.tb1{border-width: 0 10px} -b.tb2{border-width: 0 8px} -b.tb3{border-width: 0 6px} -b.tb4{border-width: 0 5px} -b.tb5{border-width: 0 4px} -b.tb6{border-width: 0 3px} -b.tb7{border-width: 0 2px;height:2px} -b.tb8{border-width: 0 1px;height:2px} -b.ts1{border-width: 0 2px} \ No newline at end of file diff --git a/site/css/prettify.css b/site/css/prettify.css deleted file mode 100644 index 43a62534..00000000 --- a/site/css/prettify.css +++ /dev/null @@ -1,92 +0,0 @@ -.str { - color: #080 -} - -.kwd { - color: #008 -} - -.com { - color: #800 -} - -.typ { - color: #606 -} - -.lit { - color: #066 -} - -.pun { - color: #660 -} - -.pln { - color: #000 -} - -.tag { - color: #008 -} - -.atn { - color: #606 -} - -.atv { - color: #080 -} - -.dec { - color: #606 -} - -.source { - background-color: #EAEAEA; - border: none; - margin: 0.5em; -} - -.source pre { - font-family: "Monaco",Courier,monospace; - font-size: 0.9em; - margin-bottom: 0; -} - -@media print { - .str { - color: #060 - } - .kwd { - color: #006; - font-weight: bold - } - .com { - color: #600; - font-style: italic - } - .typ { - color: #404; - font-weight: bold - } - .lit { - color: #044 - } - .pun { - color: #440 - } - .pln { - color: #000 - } - .tag { - color: #006; - font-weight: bold - } - .atn { - color: #404 - } - .atv { - color: #060 - } -} \ No newline at end of file diff --git a/site/css/site.css b/site/css/site.css deleted file mode 100644 index 055e7e28..00000000 --- a/site/css/site.css +++ /dev/null @@ -1 +0,0 @@ -/* You can override this file with your own styles */ \ No newline at end of file diff --git a/site/dependencies.html b/site/dependencies.html deleted file mode 100644 index d4fc95d3..00000000 --- a/site/dependencies.html +++ /dev/null @@ -1,273 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Project Dependencies - - - - - - - - - -
- - -
- -
-
-
-

Project Dependencies

test

The following is a list of test dependencies for this project. These dependencies are only required to compile and run unit tests for the application:

GroupIdArtifactIdVersionType
junitjunit4.7jar

Project Transitive Dependencies

No transitive dependencies are required for this project.

Project Dependency Graph

-

Dependency Tree

  • org.apache.amber:amber-parent:pom:1.0-SNAPSHOT Information
    • junit:junit:jar:4.7 (test) Information

Licenses

Common Public License Version 1.0: JUnit

The Apache Software License, Version 2.0: Apache Amber

Dependency File Details

FilenameSizeEntriesClassesPackagesJDK RevDebug
junit-4.7.jar226.91 kB261225291.5debug
TotalSizeEntriesClassesPackagesJDK RevDebug
1226.91 kB261225291.51
test: 1test: 226.91 kBtest: 261test: 225test: 29-test: 1

Dependency Repository Locations

Repo IDURLReleaseSnapshot
apache.snapshotshttp://repository.apache.org/snapshots-Yes
centralhttp://repo1.maven.org/maven2Yes-

Repository locations for each of the Dependencies.

Artifactapache.snapshotscentral
junit:junit:jar:4.7-Found at http://repo1.maven.org/maven2
Totalapache.snapshotscentral
1 (test: 1)01
-
-
-
-
-
- -
- - diff --git a/site/dependency-convergence.html b/site/dependency-convergence.html deleted file mode 100644 index 4ea49ef3..00000000 --- a/site/dependency-convergence.html +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Reactor Dependency Convergence - - - - - - - - - -
- - -
- -
-
-
-

Reactor Dependency Convergence

- Legend: -
successAll projects share one version of the dependency.
errorAt least one project has a differing version of the dependency.

- Statistics: -
Number of sub-projects:5
Number of dependencies (NOD):5
Number of unique artifacts (NOA):5
Number of SNAPSHOT artifacts (NOS):0
Convergence (NOD/NOA):success 100%
Ready for Release (100% Convergence and no SNAPSHOTS):success Success
-
-
-
-
-
- -
- - diff --git a/site/dependency-management.html b/site/dependency-management.html deleted file mode 100644 index bca14f6b..00000000 --- a/site/dependency-management.html +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Project Dependency Management - - - - - - - - - -
- - -
- -
-
-
-

Project Dependency Management

compile

The following is a list of compile dependencies in the DependencyManagement of this project. These dependencies can be included in the submodules to compile and run the submodule:

GroupIdArtifactIdVersionType
commons-loggingcommons-logging1.1.1jar
log4jlog4j1.2.15jar
-
-
-
-
-
- -
- - diff --git a/site/deploySite.sh b/site/deploySite.sh new file mode 100755 index 00000000..90ae8870 --- /dev/null +++ b/site/deploySite.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +mvn clean site-deploy -P site -Dusername=$1 -Dpassword=$2 diff --git a/site/images/amber_head.png b/site/images/amber_head.png deleted file mode 100644 index 587e0119..00000000 Binary files a/site/images/amber_head.png and /dev/null differ diff --git a/site/images/close.gif b/site/images/close.gif deleted file mode 100644 index 1c26bbc5..00000000 Binary files a/site/images/close.gif and /dev/null differ diff --git a/site/images/collapsed.png b/site/images/collapsed.png deleted file mode 100644 index 233e83ea..00000000 Binary files a/site/images/collapsed.png and /dev/null differ diff --git a/site/images/dialog-apply.png b/site/images/dialog-apply.png deleted file mode 100644 index dd5fd4f2..00000000 Binary files a/site/images/dialog-apply.png and /dev/null differ diff --git a/site/images/dialog-error.png b/site/images/dialog-error.png deleted file mode 100644 index afbe6547..00000000 Binary files a/site/images/dialog-error.png and /dev/null differ diff --git a/site/images/dialog-information.png b/site/images/dialog-information.png deleted file mode 100644 index 3eae22b4..00000000 Binary files a/site/images/dialog-information.png and /dev/null differ diff --git a/site/images/dialog-warning.png b/site/images/dialog-warning.png deleted file mode 100644 index 3c392a1d..00000000 Binary files a/site/images/dialog-warning.png and /dev/null differ diff --git a/site/images/expanded.png b/site/images/expanded.png deleted file mode 100644 index 0b994320..00000000 Binary files a/site/images/expanded.png and /dev/null differ diff --git a/site/images/icon_error_sml.gif b/site/images/icon_error_sml.gif deleted file mode 100644 index ebacbe29..00000000 Binary files a/site/images/icon_error_sml.gif and /dev/null differ diff --git a/site/images/icon_help_sml.gif b/site/images/icon_help_sml.gif deleted file mode 100644 index 1ba58657..00000000 Binary files a/site/images/icon_help_sml.gif and /dev/null differ diff --git a/site/images/icon_info_sml.gif b/site/images/icon_info_sml.gif deleted file mode 100644 index e789925f..00000000 Binary files a/site/images/icon_info_sml.gif and /dev/null differ diff --git a/site/images/icon_success_sml.gif b/site/images/icon_success_sml.gif deleted file mode 100644 index 1866b0a9..00000000 Binary files a/site/images/icon_success_sml.gif and /dev/null differ diff --git a/site/images/icon_warning_sml.gif b/site/images/icon_warning_sml.gif deleted file mode 100644 index 1ce360b6..00000000 Binary files a/site/images/icon_warning_sml.gif and /dev/null differ diff --git a/site/images/window-new.png b/site/images/window-new.png deleted file mode 100644 index 7901bc82..00000000 Binary files a/site/images/window-new.png and /dev/null differ diff --git a/site/index.html b/site/index.html deleted file mode 100644 index f044b85d..00000000 --- a/site/index.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - About - - - - - - - - - - -
- - -
- -
-
-
-

About Apache Amber

The Apache Software Foundation provides support for the Apache community of open-source software projects. - The Apache projects are characterized by a collaborative, consensus based development process, an open and - pragmatic software license, and a desire to create high quality software that leads the way in its field. - We consider ourselves not simply a group of projects sharing a server, but rather a community of developers - and users.

-
-
-
-
-
- -
- - diff --git a/site/integration.html b/site/integration.html deleted file mode 100644 index 99dddec1..00000000 --- a/site/integration.html +++ /dev/null @@ -1,253 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Continuous Integration - - - - - - - - - - -
- - -
- -
-
-
-

Continuous Integration

No continuous integration management system is defined. Please check back at a later date.

-
-
-
-
-
- -
- - diff --git a/site/issue-tracking.html b/site/issue-tracking.html deleted file mode 100644 index 62f42bca..00000000 --- a/site/issue-tracking.html +++ /dev/null @@ -1,253 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Issue Tracking - - - - - - - - - - -
- - -
- -
-
-
-

Overview

This project uses JIRA a J2EE-based, issue tracking and project management application.

Issue Tracking

Issues, bugs, and feature requests should be submitted to the following issue tracking system for this project.

-
-
-
-
-
- -
- - diff --git a/site/jira-report.html b/site/jira-report.html deleted file mode 100644 index a5b4cd55..00000000 --- a/site/jira-report.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - JIRA Report - - - - - - - - - - -
- - -
- -
-
-
-

JIRA Report

KeySummaryStatusResolutionBy
AMBER-4[server] Missing equals and hashCode methods in Access classClosedFixedTommaso Teofili
-
-
-
-
-
- -
- - diff --git a/site/js/niftycube.js b/site/js/niftycube.js deleted file mode 100644 index e69de29b..00000000 diff --git a/site/js/prettify.js b/site/js/prettify.js deleted file mode 100644 index bce1e23d..00000000 --- a/site/js/prettify.js +++ /dev/null @@ -1,623 +0,0 @@ -function H() { - var x = navigator && navigator.userAgent - && /\bMSIE 6\./.test(navigator.userAgent); - H = function() { - return x - }; - return x -} -(function() { - function x(b) { - b = b.split(/ /g); - var a = {}; - for ( var c = b.length; --c >= 0;) { - var d = b[c]; - if (d) - a[d] = null - } - return a - } - var y = "break continue do else for if return while ", U = y - + "auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile ", D = U - + "catch class delete false import new operator private protected public this throw true try ", I = D - + "alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename typeof using virtual wchar_t where ", J = D - + "boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient ", V = J - + "as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var ", K = D - + "debugger eval export function get null set undefined var with Infinity NaN ", L = "caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END ", M = y - + "and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None ", N = y - + "alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END ", O = y - + "case done elif esac eval fi function in local set then until ", W = I - + V + K + L + M + N + O; - function X(b) { - return b >= "a" && b <= "z" || b >= "A" && b <= "Z" - } - function u(b, a, c, d) { - b.unshift(c, d || 0); - try { - a.splice.apply(a, b) - } finally { - b.splice(0, 2) - } - } - var Y = (function() { - var b = [ "!", "!=", "!==", "#", "%", "%=", "&", "&&", "&&=", "&=", - "(", "*", "*=", "+=", ",", "-=", "->", "/", "/=", ":", "::", - ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>", - ">>=", ">>>", ">>>=", "?", "@", "[", "^", "^=", "^^", "^^=", - "{", "|", "|=", "||", "||=", "~", "break", "case", "continue", - "delete", "do", "else", "finally", "instanceof", "return", - "throw", "try", "typeof" ], a = "(?:(?:(?:^|[^0-9.])\\.{1,3})|(?:(?:^|[^\\+])\\+)|(?:(?:^|[^\\-])-)"; - for ( var c = 0; c < b.length; ++c) { - var d = b[c]; - a += X(d.charAt(0)) ? "|\\b" + d : "|" - + d.replace(/([^=<>:&])/g, "\\$1") - } - a += "|^)\\s*$"; - return new RegExp(a) - })(), P = /&/g, Q = //g, Z = /\"/g; - function $(b) { - return b.replace(P, "&").replace(Q, "<").replace(R, ">") - .replace(Z, """) - } - function E(b) { - return b.replace(P, "&").replace(Q, "<").replace(R, ">") - } - var aa = /</g, ba = />/g, ca = /'/g, da = /"/g, ea = /&/g, fa = / /g; - function ga(b) { - var a = b.indexOf("&"); - if (a < 0) - return b; - for (--a; (a = b.indexOf("&#", a + 1)) >= 0;) { - var c = b.indexOf(";", a); - if (c >= 0) { - var d = b.substring(a + 3, c), g = 10; - if (d && d.charAt(0) === "x") { - d = d.substring(1); - g = 16 - } - var e = parseInt(d, g); - if (!isNaN(e)) - b = b.substring(0, a) + String.fromCharCode(e) - + b.substring(c + 1) - } - } - return b.replace(aa, "<").replace(ba, ">").replace(ca, "'").replace(da, - '"').replace(ea, "&").replace(fa, " ") - } - function S(b) { - return "XMP" === b.tagName - } - function z(b, a) { - switch (b.nodeType) { - case 1: - var c = b.tagName.toLowerCase(); - a.push("<", c); - for ( var d = 0; d < b.attributes.length; ++d) { - var g = b.attributes[d]; - if (!g.specified) - continue; - a.push(" "); - z(g, a) - } - a.push(">"); - for ( var e = b.firstChild; e; e = e.nextSibling) - z(e, a); - if (b.firstChild || !/^(?:br|link|img)$/.test(c)) - a.push(""); - break; - case 2: - a.push(b.name.toLowerCase(), '="', $(b.value), '"'); - break; - case 3: - case 4: - a.push(E(b.nodeValue)); - break - } - } - var F = null; - function ha(b) { - if (null === F) { - var a = document.createElement("pre"); - a - .appendChild(document - .createTextNode('\n')); - F = !/= 0; i -= " ".length) - d.push(" ".substring(0, i)); - g = e + 1; - break; - case "\n": - a = 0; - break; - default: - ++a - } - } - if (!d) - return c; - d.push(c.substring(g)); - return d.join("") - } - } - var ja = /(?:[^<]+| + + + 4.0.0 + + + org.apache.oltu + org.apache.oltu.parent + 5-SNAPSHOT + ../parent + + + org.apache.oltu.site + 1-SNAPSHOT + pom + + Apache Oltu + https://oltu.apache.org/ + + + https://svn.apache.org/viewvc/oltu/trunk/site + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/site + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/site + + + + https://svn.apache.org/repos/asf/oltu/site/ + site-publish + + + + + apache.website.svnpub + scm:svn:${svnUrl} + + + + + + apache.snapshots + Apache Snapshot Repository + https://repository.apache.org/snapshots + + false + + + + + + + + org.apache.maven.plugins + maven-doap-plugin + + + ${project.parent.groupId} + ${project.parent.artifactId} + ${project.parent.version} + + + + + + org.apache.maven.plugins + maven-site-plugin + + en + true + + + + attach-descriptor + + attach-descriptor + + + + stage-for-scm-publish + post-site + + stage + + + false + + + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + false + + Oltu main site deployment + + apidocs** + amber-sources** + amber-oauth2-parent** + + ${checkoutDirectory} + + + + scm-publish + site-deploy + + publish-scm + + + + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + org.apache.oltu + https://svn.apache.org/viewvc/oltu/trunk/ + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/ + scm:svn:https://svn.apache.org/repos/asf/oltu/trunk/ + + + + + + + + setup-checkout + + + site-publish + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-checkout + pre-site + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/site/project-info.html b/site/project-info.html deleted file mode 100644 index cf615dc5..00000000 --- a/site/project-info.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Project Information - - - - - - - - - - -
- - -
- -
-
-
-

Project Information

This document provides an overview of the various documents and links that are part of this project's general information. All of this content is automatically generated by Maven on behalf of the project.

Overview

DocumentDescription
AboutThe Apache Software Foundation provides support for the Apache community of open-source software projects. - The Apache projects are characterized by a collaborative, consensus based development process, an open and - pragmatic software license, and a desire to create high quality software that leads the way in its field. - We consider ourselves not simply a group of projects sharing a server, but rather a community of developers - and users.
Continuous IntegrationThis is a link to the definitions of all continuous integration processes that builds and tests code on a frequent, regular basis.
DependenciesThis document lists the project's dependencies and provides information on each dependency.
Dependency ConvergenceThis document presents the convergence of dependency versions across the entire project, and its sub modules.
Dependency ManagementThis document lists the dependencies that are defined through dependencyManagement.
Issue TrackingThis is a link to the issue management system for this project. Issues (bugs, features, change requests) can be created and queried using this link.
Mailing ListsThis document provides subscription and archive information for this project's mailing lists.
Plugin ManagementThis document lists the plugins that are defined through pluginManagement.
Project LicenseThis is a link to the definitions of project licenses.
Project ModulesThis document lists the modules (sub-projects) of this project.
Project PluginsThis document lists the build plugins and the report plugins used by this project.
Project SummaryThis document lists other related information of this project
Project TeamThis document provides information on the members of this project. These are the individuals who have contributed to the project in one form or another.
Source RepositoryThis is a link to the online source repository that can be viewed via a web browser.
-
-
-
-
-
- -
- - diff --git a/site/project-reports.html b/site/project-reports.html deleted file mode 100644 index 80cfa4c1..00000000 --- a/site/project-reports.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Generated Reports - - - - - - - - - - -
- - -
- -
-
-
-

Generated Reports

This document provides an overview of the various reports that are automatically generated by Maven . Each report is briefly described below.

Overview

DocumentDescription
JavaDocsJavaDoc API documentation.
JIRA ReportReport on Issues from the JIRA Issue Tracking System.
Surefire ReportReport on the test results of the project.
Test JavaDocsTest JavaDoc API documentation.
-
-
-
-
-
- -
- - diff --git a/site/project-summary.html b/site/project-summary.html deleted file mode 100644 index c6039ebe..00000000 --- a/site/project-summary.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Project Summary - - - - - - - - - - -
- - -
- -
-
-
-

Project Summary

Project Information

FieldValue
NameApache Amber
DescriptionThe Apache Software Foundation provides support for the Apache community of open-source software projects. - The Apache projects are characterized by a collaborative, consensus based development process, an open and - pragmatic software license, and a desire to create high quality software that leads the way in its field. - We consider ourselves not simply a group of projects sharing a server, but rather a community of developers - and users.
Homepage../../../../people.apache.org/www/incubator.apache.org/amber/

Project Organization

FieldValue
NameThe Apache Software Foundation
URLhttp://www.apache.org/

Build Information

FieldValue
GroupIdorg.apache.amber
ArtifactIdamber-parent
Version1.0-SNAPSHOT
Typepom
-
-
-
-
-
- -
- - diff --git a/site/source-repository.html b/site/source-repository.html deleted file mode 100644 index 8beaa8d2..00000000 --- a/site/source-repository.html +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Source Repository - - - - - - - - - - -
- - -
- -
-
-
-

Overview

This project uses Subversion to manage its source code. Instructions on Subversion use can be found at http://svnbook.red-bean.com/.

Web Access

The following is a link to the online source repository.

Anonymous access

The source can be checked out anonymously from SVN with this command:

$ svn checkout https://svn.apache.org/repos/asf/incubator/amber/trunk/ amber-parent

Developer access

Everyone can access the Subversion repository via HTTP, but Committers must checkout the Subversion repository via HTTPS.

$ svn checkout https://svn.apache.org/repos/asf/incubator/amber/trunk/ amber-parent

To commit changes to the repository, execute the following command to commit your changes (svn will prompt you for your password)

$ svn commit --username your-username -m "A message"

Access from behind a firewall

For those users who are stuck behind a corporate firewall which is blocking HTTP access to the Subversion repository, you can try to access it via the developer connection:

$ svn checkout https://svn.apache.org/repos/asf/incubator/amber/trunk/ amber-parent

Access through a proxy

The Subversion client can go through a proxy, if you configure it to do so. First, edit your "servers" configuration file to indicate which proxy to use. The file's location depends on your operating system. On Linux or Unix it is located in the directory "~/.subversion". On Windows it is in "%APPDATA%\Subversion". (Try "echo %APPDATA%", note this is a hidden directory.)

There are comments in the file explaining what to do. If you don't have that file, get the latest Subversion client and run any command; this will cause the configuration directory and template files to be created.

Example: Edit the 'servers' file and add something like:

[global]
-http-proxy-host = your.proxy.name
-http-proxy-port = 3128
-
-
-
-
-
-
- -
- - diff --git a/site/src/site/resources/images/asf_logo_url.png b/site/src/site/resources/images/asf_logo_url.png new file mode 100644 index 00000000..cc448759 Binary files /dev/null and b/site/src/site/resources/images/asf_logo_url.png differ diff --git a/site/src/site/resources/images/oltu_head.png b/site/src/site/resources/images/oltu_head.png new file mode 100644 index 00000000..7c4cef52 Binary files /dev/null and b/site/src/site/resources/images/oltu_head.png differ diff --git a/site/src/site/site.xml b/site/src/site/site.xml new file mode 100644 index 00000000..324fc6c1 --- /dev/null +++ b/site/src/site/site.xml @@ -0,0 +1,81 @@ + + + + + + Apache Oltu OAuth reference implementation + images/oltu_head.png + ${project.url}/index.html + + + + The Apache Software Foundation + images/asf_logo_url.png + https://www.apache.org/ + + + + org.apache.maven.skins + maven-fluido-skin + 1.3.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Apache Oltu, Apache, the Apache feather logo, and the Apache Oltu project logos are trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners.
+
+ + + diff --git a/site/src/site/xdoc/books.xml b/site/src/site/xdoc/books.xml new file mode 100644 index 00000000..c866f1c8 --- /dev/null +++ b/site/src/site/xdoc/books.xml @@ -0,0 +1,47 @@ + + + + + + Books + Apache Oltu Documentation Team + + + +
+

This page lists the known books about OAuth 2. If you happen to know a book which is not listed then please contact us,.

+

The Apache Oltu PMC does not endorse or recommend any of the books on this page. We love all our supporters equally.

+ + +

OAuth 2 in Action by Justin Richer and Antonio Sanso published by Manning

+

OAuth 2 in Action

+

OAuth 2 in Action teaches you practical use and deployment of this protocol from the perspective of a client, authorization server, and resource server

+
+ + +

The Apache Oltu PMC does not and cannot endorse or recommend any books.

+

All submitted information must be factual and informational in nature and not be a marketing statement. + Statements that promote your products and services over other offerings on the page will not be tolerated and will be removed. + Such marketing statements can be added to your own pages on your own site.

+

When in doubt, email the Apache Oltu PMC list (see Mailing Lists) and ask. We are be happy to help.

+
+
+ + +
diff --git a/site/src/site/xdoc/commercial-support.xml b/site/src/site/xdoc/commercial-support.xml new file mode 100644 index 00000000..22d79988 --- /dev/null +++ b/site/src/site/xdoc/commercial-support.xml @@ -0,0 +1,45 @@ + + + + + + Commercial Support + Apache Oltu Documentation Team + + + +
+

This page is dedicated to companies offering products and services around or including Apache Oltu.

+

The Apache Oltu PMC does not endorse or recommend any of the products or services on this page. We love all our supporters equally.

+ + +

To be listed in the Commercial Support page send a mail to the Apache Oltu PMC with a description of your offerings and the text you would like to have added.

+
+ + +

The Apache Oltu PMC does not and cannot endorse or recommend any products or services.

+

All submitted information must be factual and informational in nature and not be a marketing statement. + Statements that promote your products and services over other offerings on the page will not be tolerated and will be removed. + Such marketing statements can be added to your own pages on your own site.

+

When in doubt, email the Apache Oltu PMC list (see Mailing Lists) and ask. We are be happy to help.

+
+
+ + +
diff --git a/site/src/site/xdoc/download.xml b/site/src/site/xdoc/download.xml new file mode 100644 index 00000000..842acb1e --- /dev/null +++ b/site/src/site/xdoc/download.xml @@ -0,0 +1,198 @@ + + + + + + Apache Oltu - Download + Apache Oltu Team + + + +
+

Apache Oltu is distributed in several formats for your convenience. Use a + source archive + if you intend to build + Apache Oltu yourself. Otherwise, simply pick a ready-made binary distribution and follow the installation + instructions given inside the archives.

+ + https://www.apache.org/dyn/closer.cgi/oltu/ + +

You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 + hours to reach all mirrors.

+ +

In order to guard against corrupted downloads/installations, it is highly recommended to + verify the signature + of the release bundles against the public KEYS used by the Apache Oltu + developers.

+ +

As there are many artifacts for Oltu, users are encouraged to include Oltu as a Maven dependency. + A list of Oltu Maven artifacts can be found in The Central Repository.

+ +

Apache Oltu is distributed under the Apache License, version 2.0.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ArtifactVersionLinkChecksumSignature
Apache Oltu Commons1 + + org.apache.oltu.commons.parent-1-source-release.zip + + + + + + PGP + +
Apache Oltu JOSE1 + + org.apache.oltu.jose.parent-1-source-release.zip + + + + + + PGP + +
Apache Oltu OAuth21.0.2 + + org.apache.oltu.oauth2.parent-1.0.2-source-release.zip + + + + + + PGP + +
Apache Oltu Parent4 + + org.apache.oltu.parent-4-source-release.zip + + + + + PGP +
+
+ + +

It is strongly recommended to use the latest release version of Apache Oltu to take advantage of newest + features and bug fixes. +

+

If you still want to use an old version you can download files from the + archives. +

+
+ +
+ +
diff --git a/site/src/site/xdoc/index.xml b/site/src/site/xdoc/index.xml new file mode 100644 index 00000000..4bc8e9db --- /dev/null +++ b/site/src/site/xdoc/index.xml @@ -0,0 +1,48 @@ + + + + + + Home + Apache Oltu Documentation Team + + + +
+

Apache Oltu is an OAuth protocol implementation in Java. It also covers others "OAuth family" related implementations such as JWT, JWS and OpenID Connect

+
+ +
+

Looking for documentation? The best place where finding the latest up-to-date documentation is the + Wiki.

+

You might also find some useful information about OAuth in one of the referenced books

+

Please help us on keeping the documentation updated! Every contribution is more than welcome!

+

Have a look also to APIs documentation.

+
+ +
+

Looking for distribution packages? Have a look at the latest published release!

+
+ +
+

Looking for Apache Maven artifacts? Just query the Search service!

+
+ + +
\ No newline at end of file diff --git a/site/src/site/xdoc/release-howto.xml b/site/src/site/xdoc/release-howto.xml new file mode 100644 index 00000000..51a881b7 --- /dev/null +++ b/site/src/site/xdoc/release-howto.xml @@ -0,0 +1,414 @@ + + + + + + Apache Oltu - Release HowTo + Apache Oltu Team + + + +
+

This short guide is for volunteers that intend to cover the role of Release Manager

+
+ +
+
    +
  • Install/Configure GPG - The artifacts that are deployed to the ASF central repository need to + be signed. To do this you will need to have a public and private keypair. There is a very good + guide that will + walk you though this.
  • + +
  • Install Apache Maven 2.2.1 or higher. 2.2.0 has a bug that will produce invalid checksums; we strongly + encourage our committers to install Apache Maven 3.0.4.
  • +
+
+ +
+ +

As of Maven 2.1.0 you can now encrypt your servers passwords. We highly recommend that you follow this + guide to set your master password and + use it to encrypt your ASF password in the next section.

+
+ + +

Using the instructions from the previous step encrypt your Sonatype password and add the following servers to + your ~/.m2/settings.xml file. You may already have other servers in this file. If not just create + the file.

+ + + + ... + + + apache.snapshots.https + simonetripodi + {put your encrypted password here} + + + apache.releases.https + simonetripodi + {put your encrypted password here} + + + ... + + + apache + + false + + + forked-path + 19FEA27D\ + + your-gpg-passphrase + + + + ... +]]> + +

You can find a settings.xml + template in our SVN committers space

+
+
+ +
+ +
    +
  1. Clean up JIRA so the Fix Version in issues resolved since the last release includes this release + version correctly. Also, transition any Resolved issues to the Closed state. +
  2. +
  3. Update the text files in a working copy of the project root: +
      +
    1. Update the CHANGES based on the Text release reports from JIRA.
    2. +
    3. Review and update README if needed.
    4. +
    5. Commit any changes back to svn:
      svn commit -m "updating files for release"
      .
    6. +
    +
  4. +
  5. Perform a full build and deploy the SNAPSHOT artifacts:
    mvn clean deploy
  6. +
+
+ + +
    +
  1. Only for new major releases (like 1.0.0 to 1.1.0): +
    + Create a sub-branch from which to make the release. +
    + Releasing from a branch will allow any cosmetic changes that need to be made for the release to be + approved to be done without preventing other more disruptive advances in the trunk from potentially + causing problems with the release. It also provides a future maintenance branch (like 1.0.x.) +
    + A branch can be made by running: +
    mvn release:branch -DbranchName=1.0.x
  2. +
  3. Checkout a clean copy of the trunk/branch to release using command line svn: +
    svn checkout https://svn.apache.org/repos/asf/oltu/trunk/ release
  4. +
+
+ + +
    +
  1. Do a dry run of the release:prepare step. +
    mvn release:prepare -DdryRun=true
    + + The dry run will not commit any changes back to SVN and gives you the opportunity to verify that the + release process will complete as expected. + +

    If you cancel a release:prepare before it updates the pom.xml versions, then use the + release:clean goal to just remove the extra files that were created.

  2. + +
  3. Verify that the release process completed as expected: +
      +
    1. The release plugin will create pom.xml.tag files which contain the changes that would + have been committed to SVN. The only differences between pom.xml.tag and its corresponding + pom.xml file should be the version + number.
    2. + +
    3. If other formatting changes have been made you should review the changes and then commit them: +
      svn commit -m "fixing formatting for release"
    4. + +
    5. Assuming the .tag files look OK you may proceed and do any other validation you feel + necessary. The following list may be helpful: +
        +
      1. Check release.properties and make sure that the scm properties have the right version. + Sometimes the scm location can be the previous version not the next version.
      2. + +
      3. Verify signatures: On Un*x platforms the following command can be executed: +for file in `find . -type f -iname '*.asc'` +do + gpg --verify ${file} +done + + You'll need to look at the output to ensure it contains only good signatures: +gpg: Good signature from ... +gpg: Signature made ... +
      4. +
      +
    6. + +
    7. Once any failures or required updates have been committed to svn, rollback the release prepare files: + mvn release:rollback
    8. +
    +
  4. + +
  5. Run the release:prepare step for real this time. You'll be prompted for the same version + information and optionally your GPG passphrase again.
    mvn release:prepare
    +
  6. +
+
+ + +
    +
  1. + From the directory where you have launched release:prepare execute (this step will create a maven staging repository): + mvn release:perform [-Duser.name=<your_apache_uid>] + +

    + If your local OS userid doesn't match your Apache userid, then you'll have to also override the value + provided by the OS to Maven for the site-deploy step to work. This is known to work for Linux, + but not for Mac and unknown for Windows. + +

    + +
      +
    1. Verify the staged artifacts in the Nexus repository: +
        +
      1. https://repository.apache.org/
      2. +
      3. Enterprise --> Staging
      4. +
      5. Staging tab --> Name column --> org.apache.oltu
      6. +
      7. Navigate through the artifact tree and make sure that all binary, + javadoc, + sources, and + tests jars, as well as + poms, ... have + .asc (GPG signature) and checksum files (see + Repository FAQ and + Detached Signatures). + The oltu-sources-dist-X.Y.tar.gz and + oltu-sources-dist-X.Y.zip files shall likewise have signature and checksum files. +
      8. +
      +
    2. + +
    3. Close the Nexus staging repo: +
        +
      1. https://repository.apache.org/
      2. +
      3. Enterprise --> Staging
      4. +
      5. Staging tab --> Name column --> org.apache.oltu
      6. +
      7. Right click on the open org.apache.oltu-XXX staging repo and select + Close.
      8. +
      +
    4. + +
    5. Add the distribution artifacts to the build area (the grab-binaries.sh + script is versioned under the committer space of Oltu SVN). + ssh asf-id@people.apache.org +cd /x1/builds/oltu + +bash grab-binaries.sh REPO_ID VERSION +
    6. +
    +
  2. + +
  3. + This step will create the staging site: From the directory where you have launched release:perform execute: + cd target/checkout +svn checkout https://svn.apache.org/repos/asf/oltu/site/ staging-site +mvn -P site site-deploy -Dsite.deploymentBaseUrl=file:///<absolute path to/<staging-site/version>> +cd staging-site +svn add <version> +svn commit -m "staging site for release" +
  4. +
+
+ + +
    +
  1. Create a VOTE email thread on dev@oltu + to record votes as replies, e.g.: +
    
    +Subject: [VOTE] Release Apache Oltu X.Y
    +
    +Hi,
    +
    +We solved N issues:
    +https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12311100&styleName=Html&version=X.Y
    +
    +There are still a couple of issues left in JIRA:
    +https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12311100&status=1
    +
    +SVN source tag (r9999999):
    +https://svn.apache.org/repos/asf/oltu/tags/X.Y/
    +
    +Staging repo:
    +https://repository.apache.org/content/repositories/orgapacheoltu-[YOUR REPOSITORY ID]/
    +
    +Staging binaries:
    +http://people.apache.org/builds/oltu/
    +
    +Staging site:
    +http://incubator.apache.org/oltu/X.Y/
    +
    +PGP release keys (signed using ABCDEFG):
    +http://www.apache.org/dist/oltu/KEYS
    +
    +Vote will be open for 72 hours.
    +
    +[ ] +1, let's get it ruuuumbleeeeee!!!
    +[ ] +/-0, fine, but consider to fix few issues before...
    +[ ] -1, nope, because... (and please explain why)]]>
    +
  2. + +
  3. Create a DISCUSS email thread on dev@oltu for any vote questions, e.g.: +
    
    +Subject: [DISCUSS] Apache Oltu X.Y
    +
    +Discussion thread for vote on <version> release candidate, with SVN source tag (r9999999).
    +
    +For more information on the release process, check out http://www.apache.org/dev/release.html
    +
    +Some of the things to check before voting are:
    + - does "mvn rat:check" pass on the source
    + - can you build the contents of source-release.zip and svn tag
    + - do all of the staged jars/zips contain the required LICENSE and NOTICE files
    + - are all of the staged jars signed and the signature verifiable
    + - is the signing key in the project's KEYS file and on a public server (i.e. http://www.apache.org/dist/oltu/)]]>
    +            
    +
  4. + +
  5. Perform a review of the release and cast your vote. For more details on Apache releases see + https://www.apache.org/dev/release.html.
  6. + +
  7. A -1 vote does not necessarily mean that the vote must be redone, however it is usually a + good idea to rollback the release if a -1 vote is received + (see "Recovering from a vetoed release" below).
  8. + +
  9. After the vote has been open for at least 72 hours, has at least three +1 PMC votes and no -1 votes, then + post the results to the vote thread, replying to the initial email prepending [RESULT] to the + original subject and include a list of every binding +1, 0 and -1 vote. +
    
    +CC: "Apache Oltu PMC List" 
    +Subject: [RESULT] [VOTE] Release Apache Oltu X.Y
    +
    +Hi,
    +The vote has passed with the following result :
    +
    ++1 (binding):
    +
    +    Antonio Sanso
    +    Tommaso Teofili
    +    Stuart "Pid" Williams
    +    Simone Tripodi
    +
    ++1 (non binding):
    +
    +    Mario Rossi
    +    John Doe
    +
    +I will promote the artifacts to the central repo.]]>
    +
  10. +
+
+ + +
    +
  1. Promote the staged nexus artifacts: +
      +
    1. https://repository.apache.org/
    2. +
    3. Enterprise --> Staging
    4. +
    5. Staging tab --> Name column --> org.apache.oltu
    6. +
    7. Right click on the closed org.apache.oltu-XXX staging repo and select Release. +
    8. +
    +
  2. + +
  3. Add the distribution artifacts to the distribution area + ssh asf-id@people.apache.org +cd /x1/www/www.apache.org/dist/oltu/ + +mv /x1/builds/oltu/sources/* sources/ +mv /x1/builds/oltu/binaries/* binaries/ +
  4. + +
  5. Update the + JIRA versions + page to mark the version as Released, and set the date to the date that + the release was approved. You may also need to make a new release entry for the next release.
  6. +
+
+ + +

Make an announcement about the release on the + user@oltu, + dev@oltu, and + announce@apache.org lists as per + the Apache Announcement Mailing Lists page +

+ +
, "Apache Oltu Users List" 
+CC: "Apache Oltu Developers List" 
+Subject: [ANNOUNCE] Apache Oltu X.Y
+
+The Apache Oltu Team is pleased to announce the release of Apache Oltu X.Y.
+
+The Oltu project will deliver a Java development framework mainly aimed to build OAuth-aware applications.
+
+Release Notes:
+
+(put JIRA release notes here)
+
+Have Fun,
+(committer name), on behalf of the Apache Oltu PMC]]>
+
+
+ +
+
    +
  1. Reply to the initial vote email prepending [CANCELED] to the original subject.
  2. +
  3. Rollback the version upgrades in trunk by either: +
      +
    1. Restore the 0.1-rc1.tar.gz and run mvn release:rollback or + manually revert the versions in trunk to the prior version and commit
    2. +
    +
  4. + +
  5. Delete the svn tag created by the release:perform step: +
    svn rm https://svn.apache.org/repos/asf/oltu/tags/X.Y -m "deleting tag from rolled back release"
  6. + +
  7. Drop the Nexus staging repo: +
      +
    1. https://repository.apache.org/
    2. +
    3. Enterprise --> Staging
    4. +
    5. Staging tab --> Name column --> org.apache.oltu
    6. +
    7. Right click on the closed org.apache.oltu-XXX staging repo and select Drop. +
    8. +
    +
  8. + +
  9. Make the required updates that caused the vote to be canceled.
  10. + +
  11. Spin another release attempt!
  12. +
+
+ + +
diff --git a/src/site/xdoc/stats.xml b/site/src/site/xdoc/stats.xml similarity index 73% rename from src/site/xdoc/stats.xml rename to site/src/site/xdoc/stats.xml index eaeecf17..cf9921e0 100644 --- a/src/site/xdoc/stats.xml +++ b/site/src/site/xdoc/stats.xml @@ -27,19 +27,19 @@
- + - + - + - +
diff --git a/site/stats.html b/site/stats.html deleted file mode 100644 index 792dbd76..00000000 --- a/site/stats.html +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - - Apache Amber project stats - - - - - - - - - - -
- - -
- -
-
-
- - -

Project Stats

-

Basic stats

- -
- -

Cocomo

- -
- -

Factoids

- -
- -

Languages

- -
-
- - -
-
-
-
-
- -
- - diff --git a/site/surefire-report.html b/site/surefire-report.html deleted file mode 100644 index 75275696..00000000 --- a/site/surefire-report.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Surefire Report - - - - - - - - - - -
- - -
- -
-
-
-

Surefire Report

Summary


TestsErrors FailuresSkippedSuccess RateTime
00000%0

Note: failures are anticipated and checked for with assertions while errors are unanticipated.


-
-
-
-
-
- -
- - diff --git a/site/team-list.html b/site/team-list.html deleted file mode 100644 index 6c3e0988..00000000 --- a/site/team-list.html +++ /dev/null @@ -1,275 +0,0 @@ - - - - - - - - - - - - - - - Apache Amber - Team list - - - - - - - - - - -
- - -
- -
-
-
-

The Team

A successful project requires many people to play many roles. Some members write code or documentation, while others are valuable as testers, submitting patches and suggestions.

The team is comprised of Members and Contributors. Members have direct access to the source of a project and actively evolve the code-base. Contributors improve the project through submission of patches and suggestions to the Members. The number of Contributors to the project is unbounded. Get involved today. All contributions to the project are greatly appreciated.

Members

The following is a list of developers with commit privileges that have directly contributed to the project in one way or another.

IdNameEmailOrganizationOrganization URLRolesTime ZoneActual Time (GMT)
brianmBrian McCallisterbrianm[at]apache[dot]org--Mentor, PMC Member, Committer--
henningHenning Schmiedehausenhenning[at]apache[dot]org--Mentor, PMC Member, Committer--
jfclereJean-Frederic Clerejfclere[at]apache[dot]org--Mentor, PMC Member, Committer--
gianugoGianugo Rabellinogianugo[at]apache[dot]org--Mentor, PMC Member, Committer--
djencksDavid Jencksdjencks[at]apache[dot]org--Mentor, PMC Member, Committer--
simonegSimone Giannisimoneg[at]apache[dot]orgSemeru S.r.l.http://www.semeru.it/PMC Member, Committer+1+1
simonetripodiSimone Tripodisimonetripodi[at]apache[dot]orgSourcesense S.r.l.http://www.sourcesense.com/PMC Member, Committer+1+1
pidsterStuart "Pid" Williams---PMC Member, Committer+1+1
recordondDavid Recordonrecordond[at]apache[dot]org--PMC Member, Committer+1+1
tommasoTommaso Teofilitommaso[at]apache[dot]orgSourcesense S.r.l.http://www.sourcesense.com/PMC Member, Committer+1+1
lindnerPaul Lindnerlindner[at]apache[dot]org--PMC Member, Committer+1+1
TBDPablo Fernandez---PMC Member, Committer+1+1

Contributors

There are no contributors listed for this project. Please check back again later.

-
-
-
-
-
- -
- - diff --git a/site/testapidocs/allclasses-frame.html b/site/testapidocs/allclasses-frame.html deleted file mode 100644 index 3576d87f..00000000 --- a/site/testapidocs/allclasses-frame.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - -All Classes (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - -All Classes -
- - - - - -
AbstractMethodTestCase -
-AccessTest -
-HmacSha1MethodTestCase -
-PlaintextMethodTestCase -
-RsaSha1MethodTestCase -
-
- - - diff --git a/site/testapidocs/allclasses-noframe.html b/site/testapidocs/allclasses-noframe.html deleted file mode 100644 index 29120e05..00000000 --- a/site/testapidocs/allclasses-noframe.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - -All Classes (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - -All Classes -
- - - - - -
AbstractMethodTestCase -
-AccessTest -
-HmacSha1MethodTestCase -
-PlaintextMethodTestCase -
-RsaSha1MethodTestCase -
-
- - - diff --git a/site/testapidocs/constant-values.html b/site/testapidocs/constant-values.html deleted file mode 100644 index ecd4ba53..00000000 --- a/site/testapidocs/constant-values.html +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - -Constant Field Values (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Constant Field Values

-
-
-Contents
    -
- -
- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/testapidocs/deprecated-list.html b/site/testapidocs/deprecated-list.html deleted file mode 100644 index a160fa5d..00000000 --- a/site/testapidocs/deprecated-list.html +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - -Deprecated List (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Deprecated API

-
-
-Contents
    -
- -
- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/testapidocs/help-doc.html b/site/testapidocs/help-doc.html deleted file mode 100644 index 1ddcd057..00000000 --- a/site/testapidocs/help-doc.html +++ /dev/null @@ -1,224 +0,0 @@ - - - - - - - -API Help (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Overview

-
- -

-The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

-

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    -
  • Interfaces (italic)
  • Classes
  • Enums
  • Exceptions
  • Errors
  • Annotation Types
-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    -
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description -

    -

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary -

    -

  • Field Detail
  • Constructor Detail
  • Method Detail
-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

    -
  • Annotation Type declaration
  • Annotation Type description
  • Required Element Summary
  • Optional Element Summary
  • Element Detail
-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

    -
  • Enum declaration
  • Enum description
  • Enum Constant Summary
  • Enum Constant Detail
-
-

-Use

-
-Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    -
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
-
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/testapidocs/index-all.html b/site/testapidocs/index-all.html deleted file mode 100644 index 42d29c3b..00000000 --- a/site/testapidocs/index-all.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - -Index (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -A D H M N O P R V
-

-A

-
-
AbstractMethodTestCase - Class in org.apache.amber.signature
Abstract implementation of OAuth signature method algorithm test case.
AbstractMethodTestCase() - -Constructor for class org.apache.amber.signature.AbstractMethodTestCase -
  -
AccessTest - Class in org.apache.amber.server
 
AccessTest() - -Constructor for class org.apache.amber.server.AccessTest -
  -
-
-

-D

-
-
doNothing() - -Method in class org.apache.amber.signature.rsa.RsaSha1MethodTestCase -
  -
-
-

-H

-
-
HmacSha1MethodTestCase - Class in org.apache.amber.signature.hmac
HMAC-SHA1 Method test case implementation.
HmacSha1MethodTestCase() - -Constructor for class org.apache.amber.signature.hmac.HmacSha1MethodTestCase -
  -
-
-

-M

-
-
matchingEqualsHashTest() - -Method in class org.apache.amber.server.AccessTest -
  -
-
-

-N

-
-
notMatchingEqualsHashTest() - -Method in class org.apache.amber.server.AccessTest -
  -
-
-

-O

-
-
org.apache.amber.server - package org.apache.amber.server
 
org.apache.amber.signature - package org.apache.amber.signature
 
org.apache.amber.signature.hmac - package org.apache.amber.signature.hmac
 
org.apache.amber.signature.plaintext - package org.apache.amber.signature.plaintext
 
org.apache.amber.signature.rsa - package org.apache.amber.signature.rsa
 
-
-

-P

-
-
PlaintextMethodTestCase - Class in org.apache.amber.signature.plaintext
HMAC-SHA1 Method test case implementation.
PlaintextMethodTestCase() - -Constructor for class org.apache.amber.signature.plaintext.PlaintextMethodTestCase -
  -
-
-

-R

-
-
RsaSha1MethodTestCase - Class in org.apache.amber.signature.rsa
 
RsaSha1MethodTestCase() - -Constructor for class org.apache.amber.signature.rsa.RsaSha1MethodTestCase -
  -
-
-

-V

-
-
verifyHmacSha1MethodAlgorithm() - -Method in class org.apache.amber.signature.hmac.HmacSha1MethodTestCase -
  -
verifyHmacSha1MethodAlgorithm() - -Method in class org.apache.amber.signature.plaintext.PlaintextMethodTestCase -
  -
verifyRsaSha1MethodAlgorithm() - -Method in class org.apache.amber.signature.rsa.RsaSha1MethodTestCase -
  -
verifySignature(VerifyingKey, SignatureMethod, String) - -Method in class org.apache.amber.signature.AbstractMethodTestCase -
  -
-
-A D H M N O P R V - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/testapidocs/index.html b/site/testapidocs/index.html deleted file mode 100644 index 15197cb3..00000000 --- a/site/testapidocs/index.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - -Apache Amber 1.0-SNAPSHOT Test API - - - - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="overview-summary.html">Non-frame version.</A> - - - diff --git a/site/testapidocs/overview-frame.html b/site/testapidocs/overview-frame.html deleted file mode 100644 index 989f895c..00000000 --- a/site/testapidocs/overview-frame.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - -Overview List (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - - - - -
-
- - - - - -
All Classes -

- -Packages -
-org.apache.amber.server -
-org.apache.amber.signature -
-org.apache.amber.signature.hmac -
-org.apache.amber.signature.plaintext -
-org.apache.amber.signature.rsa -
-

- -

-  - - diff --git a/site/testapidocs/overview-summary.html b/site/testapidocs/overview-summary.html deleted file mode 100644 index 6fabb740..00000000 --- a/site/testapidocs/overview-summary.html +++ /dev/null @@ -1,173 +0,0 @@ - - - - - - - -Overview (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - -


- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Apache Amber 1.0-SNAPSHOT Test API -

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
-Packages
org.apache.amber.server 
org.apache.amber.signature 
org.apache.amber.signature.hmac 
org.apache.amber.signature.plaintext 
org.apache.amber.signature.rsa 
- -


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/testapidocs/overview-tree.html b/site/testapidocs/overview-tree.html deleted file mode 100644 index 2ae9142c..00000000 --- a/site/testapidocs/overview-tree.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - -Class Hierarchy (Apache Amber 1.0-SNAPSHOT Test API) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
org.apache.amber.server, org.apache.amber.signature, org.apache.amber.signature.hmac, org.apache.amber.signature.plaintext, org.apache.amber.signature.rsa
-
-

-Class Hierarchy -

- -
- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010 The Apache Software Foundation. All Rights Reserved. - - diff --git a/site/testapidocs/package-list b/site/testapidocs/package-list deleted file mode 100644 index 8812ff27..00000000 --- a/site/testapidocs/package-list +++ /dev/null @@ -1,5 +0,0 @@ -org.apache.amber.server -org.apache.amber.signature -org.apache.amber.signature.hmac -org.apache.amber.signature.plaintext -org.apache.amber.signature.rsa diff --git a/site/testapidocs/stylesheet.css b/site/testapidocs/stylesheet.css deleted file mode 100644 index 6ea9e516..00000000 --- a/site/testapidocs/stylesheet.css +++ /dev/null @@ -1,29 +0,0 @@ -/* Javadoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF; color:#000000 } - -/* Headings */ -h1 { font-size: 145% } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */ -.TableRowColor { background: #FFFFFF; color:#000000 } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */ -.NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} - diff --git a/spec-api/pom.xml b/spec-api/pom.xml deleted file mode 100644 index f1ca94eb..00000000 --- a/spec-api/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - org.apache.amber - amber-parent - 0.10-incubating-SNAPSHOT - - - 4.0.0 - org.apache.amber - amber-spec-api - jar - Apache Amber: Specification API - - diff --git a/spec-api/src/main/java/org/apache/amber/AbstractParameter.java b/spec-api/src/main/java/org/apache/amber/AbstractParameter.java deleted file mode 100644 index 0dd6314f..00000000 --- a/spec-api/src/main/java/org/apache/amber/AbstractParameter.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -import java.util.Map.Entry; - -/** - * - * - * @version $Id$ - * @param - */ -abstract class AbstractParameter - implements Entry, Comparable> { - - /** - * A non-zero, odd number used as the initial value. - */ - protected static final int INITIAL_ODD_NUMBER = 1; - - /** - * A non-zero, odd number used as the multiplier. - */ - protected static final int MULTIPLIER_ODD_NUMBER = 31; - - /** - * The parameter key. - */ - private final N key; - - /** - * The parameter value. - */ - private final String value; - - /** - * Creates a new parameter by his key and value. - * - * @param key the parameter key. - * @param value the parameter value. - */ - public AbstractParameter(N key, String value) { - if (key == null) { - throw new IllegalArgumentException("Paramater 'key' must not be null"); - } - if (value == null) { - throw new IllegalArgumentException("Paramater 'value' must not be null"); - } - this.key = key; - this.value = value; - } - - /** - * {@inheritDoc} - */ - public final int compareTo(AbstractParameter parameter) { - if (parameter == null) { - return 1; - } - - int nameComparison = String.valueOf(this.key).compareTo(String.valueOf(parameter.getKey())); - if (0 == nameComparison) { - return this.value.compareTo(parameter.getValue()); - } - return nameComparison; - } - - /** - * {@inheritDoc} - */ - public final N getKey() { - return this.key; - } - - /** - * {@inheritDoc} - */ - public final String getValue() { - return this.value; - } - - /** - * {@inheritDoc} - */ - public final String setValue(String value) { - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return new StringBuilder("Parameter { key=") - .append(this.key) - .append(", value=") - .append(this.value) - .append(" }") - .toString(); - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuth.java b/spec-api/src/main/java/org/apache/amber/OAuth.java deleted file mode 100644 index b02f3f7d..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuth.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -import org.apache.amber.server.OAuthProvider; -import org.apache.amber.server.OAuthProviders; -import org.xml.sax.SAXException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.Properties; -import java.util.ServiceLoader; - -import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; - -/** - * The OAuth object provides access to the {@link org.apache.amber.OAuthFactory}. - * - * @version $Id$ - */ -public final class OAuth { - - /** - * - */ - public static final String JAXB_PACKAGE = "org.apache.amber.jaxb.package"; - - /** - * default callback value - */ - public static final String OUT_OF_BAND = "oob"; - - /** - * oauth-providers.xsd schema - */ - private static final String PROVIDER_XSD = "/META-INF/oauth-providers.xsd"; - - /** - * oauth-providers.xml filename - */ - private static final String PROVIDER_XML = "META-INF/oauth-providers.xml"; - - /** - * oauth-properties.xml - */ - private static final String PROPERTIES_XML = "META-INF/oauth-properties.xml"; - - /** - * Perform initialisation of a factory - * - * @return An instantiated factory - * @throws OAuthRuntimeException - */ - public static final OAuthFactory createFactory() throws OAuthRuntimeException { - return createFactory(Version.v1_0a); - } - - /** - * Perform initialisation of a factory - * - * @param properties - * - * @return An instantiated factory - * @throws OAuthRuntimeException - */ - public static final OAuthFactory createFactory(Properties properties) throws OAuthRuntimeException { - return createFactory(Version.v1_0a, properties); - } - - /** - * Perform initialisation of a factory - * - * @param version - * - * @return An instantiated factory - * @throws OAuthRuntimeException - */ - public static final OAuthFactory createFactory(Version version) throws OAuthRuntimeException { - Properties properties = new Properties(); - - // The getContextClassLoader() method is called inside the other - // load method anyway, so we might as well expose it here - // TODO avoid classloader memory leaks? - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - - InputStream inputStream = null; - try { - Enumeration resources = loader.getResources(PROPERTIES_XML); - while (resources.hasMoreElements()) { - // TODO specify classloader search order manually? - // Load the first resource - URL resource = resources.nextElement(); - inputStream = resource.openStream(); - properties.loadFromXML(inputStream); - } - } catch (IOException e) { - throw new OAuthRuntimeException(e); - } finally { - closeQuietly(inputStream); - } - - return createFactory(version, properties); - } - - /** - * Perform initialisation of a factory - * - * @param version - * @param properties - * - * @return An instantiated factory - * @throws OAuthRuntimeException - */ - public static final OAuthFactory createFactory(Version version, Properties properties) throws OAuthRuntimeException { - - // TODO Can we avoid classloader leaks and related trauma, by: - // ClassLoader loader = OAuth.class.getClassLoader(); - - ServiceLoader factories = ServiceLoader.load(OAuthFactory.class); - - for (OAuthFactory factory : factories) { - - if (!factory.getVersion().equals(version)) { - continue; - } - - factory.setProperties(properties); - - // ------------------------------------------------------------------------ - // Load any installed OAuthProvider classes using the ServiceLoader - // mechanism - try { - ServiceLoader providers = ServiceLoader.load(OAuthProvider.class); - - for (OAuthProvider provider : providers) { - factory.register(provider); - } - - // clean up forcibly - providers = null; - } - catch (Exception e) { - throw new OAuthRuntimeException(e); - } - - // ------------------------------------------------------------------------ - // Check for JAXB support in this implementation, and register any - // OAuthProvider's found - if (factory.getProperties().containsKey(JAXB_PACKAGE)) { - - // ------------------------------------------------------------------------ - // Load any installed OAuthProviders using the JAXB XML - // mechanism - try { - - // load schema from API resources - URL schemaURL = OAuth.class.getResource(PROVIDER_XSD); - SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); - Schema schema = schemaFactory.newSchema(schemaURL); - - // Use factory implementation class to determine package - // String packageName = - // factory.getClass().getPackage().getName(); - - String packageName = factory.getProperties().getProperty(JAXB_PACKAGE); - - // Create unMarshaller for multiple usages - JAXBContext context = JAXBContext.newInstance(packageName); - Unmarshaller unMarshaller = context.createUnmarshaller(); - unMarshaller.setSchema(schema); - - // find multiple instances of the XML configuration file - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - Enumeration providerXMLs = loader.getResources(PROVIDER_XML); - - while (providerXMLs.hasMoreElements()) { - URL resourceURL = providerXMLs.nextElement(); - InputStream inputStream = resourceURL.openStream(); - Source source = new StreamSource(inputStream); - - try { - // Parse the XML file, then loop and register the - // providers - JAXBElement element = unMarshaller.unmarshal(source, factory.getProviders().getClass()); - - for (OAuthProvider provider : element.getValue().getProvider()) { - factory.register(provider); - } - } catch (JAXBException e) { - // TODO warn of error here, in log? - e.printStackTrace(); - } finally { - closeQuietly(inputStream); - } - } - } catch (IOException e) { - throw new OAuthRuntimeException(e); - } catch (SAXException e) { - throw new OAuthRuntimeException(e); - } catch (JAXBException e) { - throw new OAuthRuntimeException(e); - } - } - - // ------------------------------------------------------------------------ - // return the completed OAuthFactory - - return factory; - } - - // clean up services forcibly, who knows what GC will do otherwise. - factories = null; - - throw new OAuthRuntimeException(OAuthFactory.class.getName() + " implementation not found."); - } - - private static void closeQuietly(Closeable closeable) { - if (closeable != null) { - try { - closeable.close(); - } catch (Exception e) { - // close quietly - } - } - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthException.java b/spec-api/src/main/java/org/apache/amber/OAuthException.java deleted file mode 100644 index 98247091..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - * - *

- * Check exception, wraps exceptions thrown by implementation that can be - * recovered from. - *

- * - * @version $Revision$ $Date$ - * - */ -public class OAuthException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * @param message - * @param cause - */ - public OAuthException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * @param message - */ - public OAuthException(final String message) { - super(message); - } - - /** - * @param cause - */ - public OAuthException(final Throwable cause) { - super(cause); - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthFactory.java b/spec-api/src/main/java/org/apache/amber/OAuthFactory.java deleted file mode 100644 index 774d28d4..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -import org.apache.amber.client.OAuthClient; -import org.apache.amber.server.OAuthProvider; -import org.apache.amber.server.OAuthProviders; -import org.apache.amber.server.OAuthServer; - -import java.io.Serializable; -import java.util.Properties; - -/** - * TODO Write extensive documentation - * - * @version $Id $HeadURL $Revision $Date $Author - */ -public interface OAuthFactory extends Serializable { - - /** - * @return version - */ - Version getVersion(); - - /** - * @param properties - */ - void setProperties(Properties properties); - - /** - * @return properties - */ - Properties getProperties(); - - /** - * @return providers - */ - OAuthProviders getProviders(); - - /** - * @param provider - * @throws OAuthRuntimeException - */ - void register(OAuthProvider provider) throws OAuthRuntimeException; - - /** - * @param realm - * @return service - * @throws OAuthException - */ - OAuthClient useService(String realm) throws OAuthException; - - /** - * @param realm - * @return service - * @throws OAuthException - */ - T createServer(String realm) throws OAuthException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthMessageParameter.java b/spec-api/src/main/java/org/apache/amber/OAuthMessageParameter.java deleted file mode 100644 index f3b235e6..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthMessageParameter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - * Identifier for the OAuth Authorization message parameter. - * - * @version $Id$ - */ -public final class OAuthMessageParameter extends AbstractParameter { - - /** - * @param key - * @param value - */ - public OAuthMessageParameter(OAuthParameter key, String value) { - super(key, value); - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - int result = INITIAL_ODD_NUMBER; - result = MULTIPLIER_ODD_NUMBER * result + ((this.getKey() == null) ? 0 : this.getKey().hashCode()); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null) { - return false; - } - - if (this.getClass() != obj.getClass()) { - return false; - } - - AbstractParameter other = (AbstractParameter) obj; - - if (this.getKey() == null) { - if (other.getKey() != null) { - return false; - } - } else if (!String.valueOf(this.getKey()).equals(String.valueOf(other.getKey()))) { - return false; - } - - return true; - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthParameter.java b/spec-api/src/main/java/org/apache/amber/OAuthParameter.java deleted file mode 100644 index fa5d9e9c..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthParameter.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - * The OAuth specification defines individual parameters required by a provider - * at different stages of the authentication and authorisation process. - * - * @version $Id$ - */ -public enum OAuthParameter { - - /** - * The callback parameter name. - * - * Value: {@code oauth_callback}. - */ - CALLBACK("oauth_callback"), - - /** - * The Consumer key parameter name. - * - * Value: {@code oauth_consumer_key}. - */ - CONSUMER_KEY("oauth_consumer_key"), - - /** - * The nonce parameter name. - * - * Value: {@code oauth_nonce}. - */ - NONCE("oauth_nonce"), - - /** - * The realm parameter name. - * - * Value: {@code realm}. - */ - REALM("realm", false, false), - - /** - * The signature parameter name. - * - * Value: {@code oauth_signature}. - */ - SIGNATURE("oauth_signature"), - - /** - * The signature method parameter name. - * - * Value: {@code oauth_signature_method}. - */ - SIGNATURE_METHOD("oauth_signature_method"), - - /** - * The timestamp parameter name. - * - * Value: {@code oauth_timestamp}. - */ - TIMESTAMP("oauth_timestamp", true, true), - - /** - * The token parameter name. - * - * Value: {@code oauth_token}. - * - * @see org.apache.amber.OAuthToken - */ - TOKEN("oauth_token"), - - /** - * The token secret parameter name. - * - * Value: {@code oauth_token_secret}. - * - * @see org.apache.amber.OAuthToken - */ - TOKEN_SECRET("oauth_token_secret", false, false), - - /** - * The verifier parameter name. - * - * Value: {@code oauth_verifier}. - */ - VERIFIER("oauth_verifier", false, false), - - /** - * The version parameter name. - * - * Value: {@code oauth_version}. - * - * @see org.apache.amber.Version - */ - VERSION("oauth_version", false, true); - - private final String label; - - private final boolean optional; - - private final boolean includeInSignature; - - private OAuthParameter(String label) { - this(label, false, true); - } - - private OAuthParameter(String label, boolean optional, boolean includeInSignature) { - this.label = label; - this.optional = optional; - this.includeInSignature = includeInSignature; - } - - public String getLabel() { - return this.label; - } - - public boolean isOptional() { - return this.optional; - } - - public boolean isIncludeInSignature() { - return this.includeInSignature; - } - - @Override - public String toString() { - return this.label; - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthParameterLocation.java b/spec-api/src/main/java/org/apache/amber/OAuthParameterLocation.java deleted file mode 100644 index e59b82a8..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthParameterLocation.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - * Defines the possible locations for the OAuth parameters during each request. - * - * N.B. Each Provider is likely to have a preferred location. - * - * @version $Id$ - */ -public enum OAuthParameterLocation { - - /** - * OAuth parameters should be included in the appropriate header. - */ - Header, - - /** - * OAuth parameters are included in the query string. - * - * N.B. size/length limits may impact on the request. - */ - Query, - - /** - * OAuth parameters are included in the body of the request. - */ - Body, - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthRequest.java b/spec-api/src/main/java/org/apache/amber/OAuthRequest.java deleted file mode 100644 index bf014e42..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthRequest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -import java.net.URI; -import java.util.Collection; - -/** - * A convenient object representing the properties of an OAuth request to a - * {@link org.apache.amber.server.OAuthProvider}. - * - * @version $Id$ - */ -public interface OAuthRequest { - - URI getRequestURL(); - - void setRequestURL(URI requestURL); - - HTTPMethod getHTTPMethod(); - - void setHTTPMethod(HTTPMethod httpMethod); - - OAuthParameterLocation getParameterLocation(); - - void setParameterLocation(OAuthParameterLocation parameterLocation); - - /** - * @param parameter - */ - void addOAuthMessageParameter(OAuthMessageParameter parameter); - - /** - * Returns the OAuth parameters will be included in the OAuth message. - * - * @return the OAuth parameters will be included in the OAuth message. - */ - Collection getOAuthMessageParameters(); - - /** - * @param parameter - */ - void addOAuthRequestParameter(OAuthRequestParameter parameter); - - /** - * @param signatureMethod - * @return - */ - String getOAuthMessageParameter(OAuthParameter parameter); - - /** - * Returns the aux parameters client will included in the request. - * - * @return the aux parameters client will included in the request. - */ - Collection getOAuthRequestParameters(); - - /** - * @param signatureMethod - * @return - */ - String getOAuthRequestParameter(String name); - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthRequestParameter.java b/spec-api/src/main/java/org/apache/amber/OAuthRequestParameter.java deleted file mode 100644 index 9ea667ff..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthRequestParameter.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - * Identifier for the auxiliar OAuth server required parameter. - * - * @version $Id$ - */ -public class OAuthRequestParameter extends AbstractParameter { - - /** - * @param key - * @param value - */ - public OAuthRequestParameter(String key, String value) { - super(key, value); - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - int result = INITIAL_ODD_NUMBER; - result = MULTIPLIER_ODD_NUMBER * result + ((this.getKey() == null) ? 0 : this.getKey().hashCode()); - result = MULTIPLIER_ODD_NUMBER * result + ((this.getValue() == null) ? 0 : this.getValue().hashCode()); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null) { - return false; - } - - if (this.getClass() != obj.getClass()) { - return false; - } - - AbstractParameter other = (AbstractParameter) obj; - - if (this.getKey() == null) { - if (other.getKey() != null) { - return false; - } - } else if (!String.valueOf(this.getKey()).equals(String.valueOf(other.getKey()))) { - return false; - } - - if (this.getValue() == null) { - if (other.getValue() != null) { - return false; - } - } else if (!this.getValue().equals(other.getValue())) { - return false; - } - - return true; - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthResponse.java b/spec-api/src/main/java/org/apache/amber/OAuthResponse.java deleted file mode 100644 index 9020b40d..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -import java.util.Map; - -/** - * An object representing the response returned from an - * {@link org.apache.amber.client.OAuthClient} or {@link org.apache.amber.server.OAuthServer}. - * - * @version $Id$ - * @see org.apache.amber.client.OAuthClient - */ -public interface OAuthResponse { - - public String getLocationUri(); - - public String getBody(); - - public String getHeader(String name); - - public Map getHeaders(); - - public int getResponseStatus(); - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthResponseParser.java b/spec-api/src/main/java/org/apache/amber/OAuthResponseParser.java deleted file mode 100644 index 6031c0cb..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthResponseParser.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - *

- * It's possible that a {@link org.apache.amber.server.OAuthProvider} will return OAuth - * information in a custom response format. The response parser interface allows - * a {@link org.apache.amber.server.OAuthProvider} to specific a concrete implementation. - *

- * - *

- * An OAuth API implementation MUST provide a response parser that assumes the - * returned parameters are name/value pairs, separated by ampersand characters. - *

- * - * @version $Revision$ $Date$ - * - */ -public interface OAuthResponseParser { - - /** - * Update the provided token, to include the details from the response - * - * @param token - * @param response - * @return token - */ - OAuthToken parseResponse(OAuthToken token, OAuthResponse response); - -} \ No newline at end of file diff --git a/spec-api/src/main/java/org/apache/amber/OAuthRuntimeException.java b/spec-api/src/main/java/org/apache/amber/OAuthRuntimeException.java deleted file mode 100644 index c488b0d8..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthRuntimeException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - *

- * Unchecked exception wrapper, thrown when there is a configuration or other - * unchecked exception that prevents the implementation from operating. - *

- * - * @version $Id$ - */ -public class OAuthRuntimeException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - /** - * @param message - * @param cause - */ - public OAuthRuntimeException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * @param message - */ - public OAuthRuntimeException(final String message) { - super(message); - } - - /** - * @param cause - */ - public OAuthRuntimeException(final Throwable cause) { - super(cause); - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/OAuthToken.java b/spec-api/src/main/java/org/apache/amber/OAuthToken.java deleted file mode 100644 index 7ab41306..00000000 --- a/spec-api/src/main/java/org/apache/amber/OAuthToken.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -import java.io.Serializable; -import java.util.Map.Entry; -import java.util.Set; - -/** - *

- * An OAuthToken is the wrapper for the pair of key values returned by the - * {@link org.apache.amber.client.OAuthClient} during the authentication or authorisation - * process. - *

- * - *

- * The implementation MUST also support validation of the returned access token - * values to determine whether the token is authorised or unauthorised. - *

- * - *

- * A Map contains additional response parameters, sent by the provider. - *

- * - * @version $Id$ - */ -public interface OAuthToken extends Serializable { - - /** - * @return the the {@code oauth_token} parameter. - */ - String getToken(); - - /** - * @param token the {@code oauth_token} parameter. - */ - void setToken(String token); - - /** - * @return the {@code oauth_token_secret} parameter. - */ - String getTokenSecret(); - - /** - * @param tokenSecret the {@code oauth_token_secret} parameter. - */ - void setTokenSecret(String tokenSecret); - - /** - * @return the {@code oauth_callback_confirmed} parameter. - */ - boolean isCallbackConfirmed(); - - /** - * @param callbackConfirmed the {@code oauth_callback_confirmed} parameter. - */ - void setCallbackConfirmed(boolean callbackConfirmed); - - /** - * Associates the specified value with the specified name in this additional - * parameters map. - * - * @param name name with which the specified value is to be associated. - * @param value value to be associated with the specified name. - */ - void addAdditionalParameters(String name, String value); - - /** - * @return a {@link Set} view of the mappings contained in this additional - * parameters map - */ - Set> additionalParametersEntrySet(); - -} diff --git a/spec-api/src/main/java/org/apache/amber/Version.java b/spec-api/src/main/java/org/apache/amber/Version.java deleted file mode 100644 index ae762e66..00000000 --- a/spec-api/src/main/java/org/apache/amber/Version.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber; - -/** - * @version $Revision$ $Date$ - * - */ -public enum Version { - - /** - * 1.0 - * - * @since 1.0 - */ - v1_0(1, 0), - - /** - * 1.0a - * - * @since 1.0a - */ - v1_0a(1, 0, 'a') - - ; // End of enum type definitions - - private static final char EMPTY_VARIANT = ' '; - - private static final char UNDERSCORE_SEPARATOR = '_'; - - private static final char DOT_SEPARATOR = '.'; - - private final int major; - - private final int minor; - - private final char variant; - - /** - * - */ - Version(int major, int minor) { - this(major, minor, EMPTY_VARIANT); - } - - /** - * - */ - Version(int major, int minor, char variant) { - this.major = major; - this.minor = minor; - this.variant = variant; - } - - /** - * @return handle - */ - public String toHandle() { - StringBuilder s = new StringBuilder(this.getClass().getSimpleName()) - .append(UNDERSCORE_SEPARATOR) - .append(this.major) - .append(UNDERSCORE_SEPARATOR) - .append(this.minor); - if (this.variant != ' ') { - s.append(UNDERSCORE_SEPARATOR); - s.append(this.variant); - } - - return s.toString(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Enum#toString() - */ - @Override - public String toString() { - StringBuilder s = new StringBuilder(); - - s.append(this.major) - .append(DOT_SEPARATOR) - .append(this.minor); - if (EMPTY_VARIANT != this.variant) { - s.append(this.variant); - } - - return s.toString(); - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/client/HttpConnector.java b/spec-api/src/main/java/org/apache/amber/client/HttpConnector.java deleted file mode 100644 index 31f6e70f..00000000 --- a/spec-api/src/main/java/org/apache/amber/client/HttpConnector.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.client; - -import org.apache.amber.OAuthRequest; -import org.apache.amber.OAuthResponse; - -import java.io.IOException; - -/** - * The HttpConnector does the work converting executing an - * {@link org.apache.amber.OAuthRequest} and returning an - * {@link org.apache.amber.OAuthResponse}. This is configurable to allow some choice - * with regard to libraries, code etc. - * - * An implementation MUST provide a default connector. - * - * @version $Id$ - */ -public interface HttpConnector { - - /** - * The execute method does the work of processing a request and returning a - * response from the Provider. - * - * @param request - * @param authorization - * @return response - * @throws IOException - * if something untoward happened, propagate the exception - */ - OAuthResponse execute(OAuthRequest request, String authorization) throws IOException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/client/NonceGenerator.java b/spec-api/src/main/java/org/apache/amber/client/NonceGenerator.java deleted file mode 100644 index d9212e63..00000000 --- a/spec-api/src/main/java/org/apache/amber/client/NonceGenerator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.client; - -/** - * Generator of {@code nonce} values. - * - * @version $Id$ - */ -public interface NonceGenerator { - - /** - * Generate a {@code nonce} string value. - * - * @return a {@code nonce} string value. - */ - String generate(); - -} diff --git a/spec-api/src/main/java/org/apache/amber/client/OAuthClient.java b/spec-api/src/main/java/org/apache/amber/client/OAuthClient.java deleted file mode 100644 index 5f8201eb..00000000 --- a/spec-api/src/main/java/org/apache/amber/client/OAuthClient.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.client; - -import org.apache.amber.OAuthException; -import org.apache.amber.OAuthToken; - -import java.io.Serializable; - -/** - *

- * An OAuth Service is an abstract representation of the standard remote API - * offered by an {@link org.apache.amber.server.OAuthProvider}, providing a simple mechanism - * for performing {@link org.apache.amber.OAuth} authentication and authorisation - * tasks. - *

- * - *

Using an OAuthClient

- * - *

- * By far the easiest way to use an OAuthClient is by configuring an - * {@link org.apache.amber.server.OAuthProvider} in an XML file (called - * "oauth-providers.xml") and placing it in the META-INF directory on - * the applications classpath. - *

- * - *
- * <?xml version="1.0" encoding="UTF-8"?>
- *  <providers>
- *      <provider
- *          realm="http://example.com"
- *          algorithm="HmacSHA1"
- *          requestTokenPath="/oauth/request_token"
- *          authorizePath="/oauth/authorize"
- *          accessTokenPath="/oauth/access_token">
- *          <consumer
- *              name="mysite.com"
- *              callback="http://www.mysite.com/oauth/response"
- *              key="mykey"
- *              secret="mysecret"/>
- *      </provider>
- *  </providers>
- * 
- * - *

- * The OAuthClient is called by using it's realm name as a reference. The - * example below assumes the API is used in a Servlet environment, and simply - * redirects the user to the {@link org.apache.amber.server.OAuthProvider} to authorize the - * token. - *

- * - *

- * The {@link org.apache.amber.server.OAuthProvider} uses the default - * {@link OAuthConsumer} configured in the XML file. - *

- * - *
- * HttpSession session = request.getSession();
- *
- * OAuthClient service = OAuth.useService("http://example.com");
- * OAuthToken requestToken = service.getRequestToken(); // This method also takes an OAuthToken implementation class 
- *
- * session.setAttribute("requestToken", requestToken);
- *
- * String authorizePath = service.getAuthorizeURL(requestToken);
- * response.sendRedirect(authorizePath);
- * 
- * - *

- * If you supply your own implementation of the {@link org.apache.amber.OAuthToken} - * interface when you call the requestToken method, you could store the - * OAuthToken in a database. - *

- * - *

- * The token is stored in the user session, as we can re-use it when the - * response comes back. We initialise the service and retrieve the token from - * the session, before resubmitting the token and the verifier to the - * {@link org.apache.amber.server.OAuthProvider}, who converts the authorised Request Token - * into an Access Token. - *

- * - *

- * After checking that the token is authorised, we remove the old request token - * from the session and add the access token, so it can be used to sign future - * requests for services at the {@link org.apache.amber.server.OAuthProvider}. - *

- * - *
- * HttpSession session = req.getSession();
- *
- * OAuthClient service = OAuth.useService("http://oauth.apache.site/");
- * OAuthToken requestToken = OAuthToken.class.cast(session
- *         .getAttribute("requestToken"));
- *
- * String oauth_token = req.getParameter("oauth_token"); // you could check this matches the one in the session
- * String oauth_verifier = req.getParameter("oauth_verifier"); // supplied with the response
- * OAuthToken accessToken = service.getAccessToken(requestToken, oauth_verifier);
- *
- * if (accessToken.isAuthorized()) {
- *     session.removeAttribute("requestToken");
- *     session.setAttribute("accessToken", accessToken);
- * }
- * 
- * - *

- * The OAuthClient could be initialised in an HttpServlet.init() method and - * stored in an instance field. Implementations must be thread-safe. - *

- * - * @version $Id$ - */ -public interface OAuthClient extends Serializable { - - /** - * Get a request token using the default consumer and token. - * - * @return token - * @throws org.apache.amber.OAuthException - */ - OAuthToken getRequestToken() throws OAuthException; - - /** - * Get a request token using the specified consumer. - * - * @param consumer - * @return token - * @throws OAuthException - */ - OAuthToken getRequestToken(OAuthConsumer consumer) throws OAuthException; - - /** - * Get a request token, instantiated from the provided class, using the - * default consumer. - * - * @param tokenClass - * @return token - * @throws OAuthException - */ - OAuthToken getRequestToken(Class tokenClass) throws OAuthException; - - /** - * Get a request token, instantiated from the provided class, using the - * specified consumer. - * - * @param tokenClass - * @param consumer - * @return token - * @throws OAuthException - */ - OAuthToken getRequestToken(Class tokenClass, OAuthConsumer consumer) throws OAuthException; - - /** - * Get the authentication URL for the configured provider, using the - * specified token. - * - * @param token - * The token to be authenticated - * @return path The path to which the user should be directed for - * authentication - */ - String getAuthenticateURL(OAuthToken token); - - /** - * Get the authentication URL for the configured provider, using the - * specified token and callback. - * - * @param token - * @param callback - * The URL to which the user should be redirected after - * authentication - * @return path The path to which the user should be directed for - * authentication - */ - String getAuthenticateURL(OAuthToken token, String callback); - - /** - * Get the authorisation URL for the configured provider, using the - * specified token. - * - * @param token - * The token to be authorised - * @return path The path to which the user should be directed for - * authentication - */ - String getAuthorizeURL(OAuthToken token); - - /** - * Get the authorisation URL for the configured provider, using the - * specified token. - * - * @param token - * @param callback - * The URL to which the user should be redirected after - * authorisation - * @return path The path to which the user should be directed for - * authorisation - */ - String getAuthorizeURL(OAuthToken token, String callback); - - /** - * Convert the authorised token to an access token, using the supplied - * verification code. - * - * @param token - * @param verifier - * @return authorised token - * @throws OAuthException - */ - OAuthToken getAccessToken(OAuthToken token, String verifier) throws OAuthException; - - /** - * Convert the authorised token to an access token, using the supplied - * consumer and verification code. - * - * @param consumer - * @param token - * @param verifier - * @return authorised token - * @throws OAuthException - */ - OAuthToken getAccessToken(OAuthConsumer consumer, OAuthToken token, String verifier) throws OAuthException; - - /** - * Get the current connector. - * - * @return connector - */ - HttpConnector getConnector(); - - /** - * Set the connector to be used. - * - * @param httpConnector - */ - void setConnector(HttpConnector httpConnector); - - /** - * Returns the current nonce generator to be used. - * - * @return the current nonce generator to be used. - */ - NonceGenerator getNonceGenerator(); - - /** - * Sets the nonce generator to be used. - * - * @param nonceGenerator the nonce generator to be used. - */ - void setNonceGenerator(NonceGenerator nonceGenerator); - -} diff --git a/spec-api/src/main/java/org/apache/amber/client/OAuthConsumer.java b/spec-api/src/main/java/org/apache/amber/client/OAuthConsumer.java deleted file mode 100644 index 79e34b7f..00000000 --- a/spec-api/src/main/java/org/apache/amber/client/OAuthConsumer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.client; - -import java.io.Serializable; - -/** - * The OAuth Consumer is defined in the {@link org.apache.amber.OAuth} Specification as - * the client in one of the legs during an authorisation or authentication. - * - * @version $Id$ - */ -public interface OAuthConsumer extends Serializable { - - /** - * The name field is a convenient reference to the Consumer and SHOULD match - * the string used during the Provider registration process - * - * @return name - */ - String getName(); - - /** - * @param name the name to set - */ - void setName(String name); - - /** - * The key field contains the key string assigned to the Consumer by the - * Provider, during registration. - * - * @return the key - */ - String getKey(); - - /** - * @param key the key to set - */ - void setKey(String key); - - /** - * @return the secret - */ - String getSecret(); - - /** - * The secret field contains the unique secret string generated by the - * Provider, during registration. - * - * @param secret the secret to set - */ - void setSecret(String secret); - - /** - * The callback field contains the HTTP URL that the Provider will redirect - * the User to during the authentication / authorisation process. - * - * It MUST be set to the "OUT OF BAND" value "oob" if - * the response can't be sent via an HTTP redirect. - * - * @return the callback - */ - String getCallback(); - - /** - * @param callback the callback to set - */ - void setCallback(String callback); - -} diff --git a/spec-api/src/main/java/org/apache/amber/package-info.java b/spec-api/src/main/java/org/apache/amber/package-info.java deleted file mode 100644 index a4399256..00000000 --- a/spec-api/src/main/java/org/apache/amber/package-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - *

An OAuth Java Specification

- * - *

Provides the interfaces for an implementation of the OAuth specification.

- * - *

The implementation MUST permit entirely programmatical configuration, configuration - * by the presence of an XML file called "oauth-providers.xml" located in a META-INF - * directory on the classpath and by detecting classes configured using the ServiceLoader - * mechanism.

- * - * @version $Revision$ $Date$ - * @see org.apache.amber.OAuth - * - */ -package org.apache.amber; - diff --git a/spec-api/src/main/java/org/apache/amber/server/Access.java b/spec-api/src/main/java/org/apache/amber/server/Access.java deleted file mode 100644 index 3c18c5de..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/Access.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import java.util.Collection; - -/** - * Association of nonce(s) and timestamp. - * - * @version $Id$ - */ -public interface Access extends Comparable { - - /** - * Returns the timestamp access. - * - * @return the timestamp access - */ - long getTimestamp(); - - /** - * Add a nonce to an access. - * - * @param nonce the nonce has o be added. - * @return true, if the nonce has not used yet, false otherwise. - */ - boolean addNonce(String nonce); - - /** - * Checks if the access already contains a nonce. - * - * @param nonce the nonce has to be checked. - * @return true if the nonce is contained, false otherwise. - */ - boolean containsNonce(String nonce); - - /** - * Returns the whole list of nonces associated to the timestamp. - * - * @return the whole list of nonces associated to the timestamp. - */ - Collection getNonces(); - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/AccessStorage.java b/spec-api/src/main/java/org/apache/amber/server/AccessStorage.java deleted file mode 100644 index f37e597e..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/AccessStorage.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -/** - * Nonce/timestamp storage definition. - * - * @version $Id$ - */ -public interface AccessStorage { - - /** - * Stores a new nonce / timestamp pair associated with a consumer key. - * - * @param clientCredentials the consumer to be associated with the access. - * @param timestamp the timestamp of the request. - * @param nonce the nonce associated with the timestamp. - * @throws StorageException if a backend error occurs. - */ - void add(String clientCredentials, long timestamp, String nonce) throws StorageException; - - /** - * Get the last access (by timestamp) of a consumer. - * - * @param clientCredentials the consumer whose access needs to be read. - * @return the access object. - * @throws StorageException if a backend error occurs. - */ - Access getLastAccess(String clientCredentials) throws StorageException; - - /** - * Remove a consumer access. - * - * @param clientCredentials the consumer key. - * @param timestamp the timestamp. - * @throws StorageException if a backend error occurs. - */ - void remove(String clientCredentials, long timestamp) throws StorageException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/ConsumerStorage.java b/spec-api/src/main/java/org/apache/amber/server/ConsumerStorage.java deleted file mode 100644 index 2cc5eec2..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/ConsumerStorage.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import org.apache.amber.client.OAuthConsumer; - -/** - * OAuthConsumer consumer storage interface. - * - * @version $Id$ - */ -public interface ConsumerStorage { - - /** - * Stores consumer data. - * - * @param consumer the consumer has to be stored. - * @throws StorageException if a backend error occurs. - */ - void add(OAuthConsumer consumer) throws StorageException; - - /** - * Modifies a consumer data. - * - * @param consumer the consumer has to be stored. - * @throws StorageException if a backend error occurs. - */ - void update(OAuthConsumer consumer) throws StorageException; - - /** - * Searches for an existing consumer. - * - * @param consumerKey the consumer key. - * @return the consumer data if any, null otherwise. - * @throws StorageException if a backend error occurs. - */ - OAuthConsumer read(String consumerKey) throws StorageException; - - /** - * Removes a token from the store. - * - * @param consumerKey the consumer key. - * @throws StorageException if a backend error occurs. - */ - void delete(String consumerKey) throws StorageException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/OAuthProvider.java b/spec-api/src/main/java/org/apache/amber/server/OAuthProvider.java deleted file mode 100644 index 6cb75871..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/OAuthProvider.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import org.apache.amber.OAuthParameterLocation; -import org.apache.amber.OAuthResponseParser; -import org.apache.amber.client.OAuthConsumer; - -import java.io.Serializable; -import java.util.List; - -/** - *

- * The minimum configurable values required to specify the different behaviour - * of a Provider (an entity defined by the OAuth specification). - *

- * - * @version $Revision$ $Date$ - * - */ -public interface OAuthProvider extends Serializable { - - /** - * @return consumer - */ - List getConsumers(); - - /** - * @param consumers - */ - void setConsumers(List consumers); - - /** - * @return the algorithm - */ - String getAlgorithm(); - - /** - * @param algorithm - * the algorithm to set - */ - void setAlgorithm(String algorithm); - - /** - * @return the location - */ - OAuthParameterLocation getLocation(); - - /** - * @param location - * the location to set - */ - void setLocation(OAuthParameterLocation location); - - /** - * @return the realm - */ - String getRealm(); - - /** - * @param realm - * the realm to set - */ - void setRealm(String realm); - - /** - * @return the requestTokenPath - */ - String getRequestTokenPath(); - - /** - * @param requestTokenPath - * the requestTokenPath to set - */ - void setRequestTokenPath(String requestTokenPath); - - /** - * @return the accessTokenPath - */ - String getAccessTokenPath(); - - /** - * @param accessTokenPath - * the accessTokenPath to set - */ - void setAccessTokenPath(String accessTokenPath); - - /** - * @return the authorizePath - */ - String getAuthorizePath(); - - /** - * @param authorizePath - * the authorizePath to set - */ - void setAuthorizePath(String authorizePath); - - /** - * @return the authenticatePath - */ - String getAuthenticatePath(); - - /** - * @param authenticatePath - * the authenticatePath to set - */ - void setAuthenticatePath(String authenticatePath); - - /** - * @return the responseParser - */ - OAuthResponseParser getResponseParser(); - - /** - * @param responseParser - * the responseParser to set - */ - void setResponseParser(OAuthResponseParser responseParser); - -} \ No newline at end of file diff --git a/spec-api/src/main/java/org/apache/amber/server/OAuthProviders.java b/spec-api/src/main/java/org/apache/amber/server/OAuthProviders.java deleted file mode 100644 index 232ac1d5..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/OAuthProviders.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import java.util.List; - -/** - *

- * A convenience object which contains multiple possible OAuth Service - * Providers, in order of preference. - *

- * - *

- * The first Provider will be considered to be the default one, where - * applicable. - *

- * - * @version $Revision$ $Date$ - * - */ -public interface OAuthProviders { - - /** - * @return the provider - */ - List getProvider(); - - /** - * @param provider - * the provider to set - */ - void setProvider(List provider); - -} \ No newline at end of file diff --git a/spec-api/src/main/java/org/apache/amber/server/OAuthServer.java b/spec-api/src/main/java/org/apache/amber/server/OAuthServer.java deleted file mode 100644 index 80057a4c..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/OAuthServer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -/** - * An OAuth Server provides the functionality required to deliver OAuth Provider - * functionality. It can be exposed by wrapping it in an HTTP layer, e.g. that - * provided by the Servlet Spec or perhaps directly exposed by a custom HTTP - * server. - * - * @version $Id$ - */ -public abstract class OAuthServer implements OAuthnServer, OAuthzServer { - - private OAuthServerConfiguration configuration; - - /** - * @param configuration - */ - protected OAuthServer(OAuthServerConfiguration configuration) { - this.configuration = configuration; - } - - /** - * @return configuration - */ - protected OAuthServerConfiguration getConfiguration() { - return configuration; - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/OAuthServerConfiguration.java b/spec-api/src/main/java/org/apache/amber/server/OAuthServerConfiguration.java deleted file mode 100644 index d40a567c..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/OAuthServerConfiguration.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -/** - * - * - * @version $Id$ - */ -public interface OAuthServerConfiguration { - - /** - * @return access storage - */ - AccessStorage getAccessStorage(); - - /** - * @return consumer storage - */ - ConsumerStorage getConsumerStorage(); - - /** - * @return token storage - */ - TokenStorage getTokenStorage(); - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/OAuthnServer.java b/spec-api/src/main/java/org/apache/amber/server/OAuthnServer.java deleted file mode 100644 index 12831e7b..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/OAuthnServer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import org.apache.amber.OAuthException; -import org.apache.amber.OAuthRequest; -import org.apache.amber.OAuthToken; - -/** - * - * - * @version $Id$ - */ -public interface OAuthnServer { - - /** - * Generates a new request token. - * - * @param request - * @return - * @throws OAuthException - */ - OAuthToken requestToken(OAuthRequest request) throws OAuthException; - - /** - * Authorize a request token. - * - * @param oauthToken - * @return - * @throws OAuthException - */ - OAuthToken authorizeToken(String oauthToken) throws OAuthException; - - /** - * Generates a new access token. - * - * @param request - * @return - * @throws OAuthException - */ - OAuthToken accessToken(OAuthRequest request) throws OAuthException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/OAuthzServer.java b/spec-api/src/main/java/org/apache/amber/server/OAuthzServer.java deleted file mode 100644 index 980953f1..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/OAuthzServer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import org.apache.amber.OAuthException; -import org.apache.amber.OAuthRequest; - -/** - * - * - * @version $Id$ - */ -public interface OAuthzServer { - - /** - * Evaluates if a specific request contains authorization token to - * access to a protected resource. - * - * @param request - * @return - * @throws OAuthException - */ - boolean isAuthorized(OAuthRequest request) throws OAuthException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/server/TokenStorage.java b/spec-api/src/main/java/org/apache/amber/server/TokenStorage.java deleted file mode 100644 index b0e25f83..00000000 --- a/spec-api/src/main/java/org/apache/amber/server/TokenStorage.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.server; - -import org.apache.amber.OAuthToken; - -/** - * - * - * @version $Id$ - */ -public interface TokenStorage { - - /** - * Stores a new token. - * - * @param consumerKey Consumer key associated to the token to be stored - * @param token The token to be stored - * @throws StorageException if a backend error occurs. - */ - void add(String consumerKey, OAuthToken token) throws StorageException; - - /** - * Modifies an existing token. - * - * @param token The token to be modified - * @throws StorageException if a backend error occurs. - */ - void update(OAuthToken token) throws StorageException; - - /** - * Searches for an existing token. - * - * @param consumerKey The consumer key associated with the Token - * @param token The token string to be searched - * @return the relative token associated to the consumerKey - * @throws StorageException if a backend error occurs. - */ - OAuthToken read(String consumerKey, String token) throws StorageException; - - /** - * Searches for an existing token. - * - * @param token The token string to be searched - * @return the relative token - * @throws StorageException if a backend error occurs. - */ - OAuthToken read(String token) throws StorageException; - - /** - * Removes a token from the store. - * - * @param token The token to be removed - * @throws StorageException if a backend error occurs. - */ - void delete(String token) throws StorageException; - -} diff --git a/spec-api/src/main/java/org/apache/amber/signature/Key.java b/spec-api/src/main/java/org/apache/amber/signature/Key.java deleted file mode 100644 index ac83ee9c..00000000 --- a/spec-api/src/main/java/org/apache/amber/signature/Key.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature; - -/** - * Client Credential representation. - * - * @version $Id$ - */ -public interface Key { - - /** - * Returns the signing algorithm methods. - * - * @return the signing algorithm methods. - */ - String[] getAlgorithmMethods(); - - /** - * Returns the key string representation. - * - * @return the key string representation. - */ - String getValue(); - -} diff --git a/spec-api/src/main/java/org/apache/amber/signature/SignatureException.java b/spec-api/src/main/java/org/apache/amber/signature/SignatureException.java deleted file mode 100644 index cef0e7c4..00000000 --- a/spec-api/src/main/java/org/apache/amber/signature/SignatureException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature; - -import org.apache.amber.OAuthException; - -/** - * Encapsulate a general OAuth signature error or warning. - * - * @version $Id$ - */ -public final class SignatureException extends OAuthException { - - /** - * The serial version UID. - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs a new signature exception with the specified detail message. - * - * @param message the specified detail message. - */ - public SignatureException(String message) { - super(message); - } - - /** - * Constructs a new signature exception with the specified cause. - * - * @param cause the specified cause. - */ - public SignatureException(Throwable cause) { - super(cause); - } - - /** - * Constructs a new signature exception with the specified detail message - * and cause. - * - * @param message the specified detail message. - * @param cause the specified cause. - */ - public SignatureException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java b/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java deleted file mode 100644 index 1b9bc9e0..00000000 --- a/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.amber.signature; - -import org.apache.amber.OAuthRequest; -import org.apache.amber.OAuthToken; - -/** - * Common definition of OAuth signature method algorithm. - * - * @version $Id$ - */ -public interface SignatureMethod { - - /** - * Returns the signing algorithm method. - * - * @return the signing algorithm method. - */ - String getAlgorithm(); - - /** - * Calculates the OAuth request message signature. - * - * @param signingKey the key has to be used to sign the request. - * @param token the received OAuth token, can be {@code null} if clients - * are requesting for the authorization token. - * @param request the OAuth request message has to be signed. - * @return the calculated signature. - * @throws SignatureException if any error occurs. - */ - String calculate(SigningKey signingKey, - OAuthToken token, - OAuthRequest request) throws SignatureException; - - /** - * Verifies the OAuth request message signature. - * - * @param signature the OAuth signature has to be verified. - * @param verifyingKey the key has to be used to verify the request. - * @param token the received OAuth token, can be {@code null} if clients - * are requesting for the authorization token. - * @param request the signed OAuth request message. - * @return true if the signature is correct, false otherwise. - * @throws SignatureException if any error occurs. - */ - boolean verify(String signature, - VerifyingKey verifyingKey, - OAuthToken token, - OAuthRequest request) throws SignatureException; - -} diff --git a/spec-api/src/main/resources/META-INF/oauth-providers.xsd b/spec-api/src/main/resources/META-INF/oauth-providers.xsd deleted file mode 100644 index 02fe667e..00000000 --- a/spec-api/src/main/resources/META-INF/oauth-providers.xsd +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/site/resources/images/amber_head.png b/src/site/resources/images/amber_head.png deleted file mode 100644 index 587e0119..00000000 Binary files a/src/site/resources/images/amber_head.png and /dev/null differ diff --git a/src/site/site.xml b/src/site/site.xml deleted file mode 100644 index c881dd28..00000000 --- a/src/site/site.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - Apache Amber OAuth reference implementation - images/amber_head.png - ${project.url}/index.html - - - - - - - - - - - - - - - - - - - - com.googlecode.fluido-skin - fluido-skin - 1.3 - -