userconsole.jsp revision e8721886dbfd32e88cc7077cbee4b6bb1b44b443
109faf633e12ab0bbdd602c7addc795cce59e8addreid DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
dec8fb7a4d03d8f0f485af9556bbd2b3f385696ejerenkrantz The contents of this file are subject to the terms
8721697e2aece27b0e738519329f7976c72b27bfjerenkrantz of the Common Development and Distribution License
4a257be29f8aeab984fe5622fa69e0b2aab204d7jerenkrantz (the License). You may not use this file except in
91cacb801f6c0215b38322f6d2fc58cbfedfecfbjerenkrantz compliance with the License.
df14f0d3a5191cdd7c4bb5b03acd135d43a6f51brbb You can obtain a copy of the License at
571760de5e60c0b459cb11be45507b923cd023eejwoolley See the License for the specific language governing
571760de5e60c0b459cb11be45507b923cd023eejwoolley permission and limitations under the License.
bcb6e1be6041dfeb549c8ea8d37f97ad4e90a0c3rbb When distributing Covered Code, include this CDDL
9bd71e35f5d26d26d23fe3a677401828e842ed72wrowe Header Notice in each file and include the License file
a548c09e6a8ca1b059d0e93b5256c6ccb2b3c3cdrbb If applicable, add the following below the CDDL Header,
a548c09e6a8ca1b059d0e93b5256c6ccb2b3c3cdrbb with the fields enclosed by brackets [] replaced by
a548c09e6a8ca1b059d0e93b5256c6ccb2b3c3cdrbb your own identifying information:
b876b7bcf0ce3d232da723246d709e8dbbfe8762rbb "Portions Copyrighted [year] [name of copyright owner]"
35330e0d79ceb8027223bbb8330a381b1f989d6etrawick $Id: userconsole.jsp,v 1.3 2010/01/20 17:51:38 huacui Exp $
2deb319e6b3de239f45c16a3e9e836d44f1f7108rbb Portions Copyrighted 2012 ForgeRock AS
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj<%@page contentType="text/html"%>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page pageEncoding="UTF-8"%>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page import="com.sun.identity.oauth.service.OAuthServiceException" %>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page import="com.sun.identity.oauth.service.PathDefs" %>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page import="com.sun.identity.oauth.service.util.OAuthProperties" %>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page import="com.sun.identity.oauth.service.util.OAuthServiceUtils" %>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page import="java.net.URLEncoder" %>
af4c982a7cf4515f124935f99a329744035fc699slive<%@page import="javax.servlet.http.Cookie" %>
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj<%@page import="javax.servlet.http.HttpServletRequest" %>
531c23ff01a2489646f0a2029097013b328d935agstein<%@page import="javax.servlet.http.HttpServletResponse" %>
c00273b9c51c617ede471e9cb95c22420f1227fbbrianpThe taglib directive below imports the JSTL library. If you uncomment it,
c00273b9c51c617ede471e9cb95c22420f1227fbbrianpyou must also add the JSTL library to the project. The Add Library... action
54e1babd5a5a56c576eeeace54110150769cc916coaron Libraries node in Projects view can be used to add the JSTL 1.1 library.
54e1babd5a5a56c576eeeace54110150769cc916coar<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
7fe18c15b669db9d191859695901dc4fcf3829dawrowe static String openssoCookieName = OAuthProperties.get(
7fe18c15b669db9d191859695901dc4fcf3829dawrowe String getUid(String cookieValue)
976501adbc040220270f7d1d77c4b8373033be69wrowe throws OAuthServiceException {
976501adbc040220270f7d1d77c4b8373033be69wrowe String uuid = null;
976501adbc040220270f7d1d77c4b8373033be69wrowe uuid = OAuthServiceUtils.getUUIDByTokenId(cookieValue);
976501adbc040220270f7d1d77c4b8373033be69wrowe } catch (OAuthServiceException oe) {
bf9acc131271d18db51d30ace549d3c3b6a2b9fbrbb return uuid;
bf9acc131271d18db51d30ace549d3c3b6a2b9fbrbb<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
b84f66c93f820824b1d5455181f55598b766319cwrowe <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
a601d863bd772fefc4dc82a883589d8be6a44811wrowe <title>Authentication</title>
79d5106a9b65b956d646f5daae4b94bc79e315b8trawick <script type="text/javascript">
dc96a5e6f9af3c514df4c61ab9468fcf97f9846fwrowe function makeithappen(oauthtk, id) {
dc96a5e6f9af3c514df4c61ab9468fcf97f9846fwrowe var strs = path.split("/");
976501adbc040220270f7d1d77c4b8373033be69wrowe var contextRoot = strs[1];
dc96a5e6f9af3c514df4c61ab9468fcf97f9846fwrowe redir += "//" + window.location.host;
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz redir += "/" + contextRoot;
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz redir += "/resources/1/oauth/AuthorizationFactory";
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz redir += "?oauth_token=" + oauthtk.toString();
924c8dd40352ca7775704a31a7a77ab86dc951b4ianh redir += "&id=" + id.toString();
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz function revoke(oauthtk) {
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz var redir = "./deletetoken.jsp?oauth_token=";
39cf872a6df49bd5affe2ca6eaf683918184fbb4trawick <h1 align="center">OAuth User Authorization Page</h1><hr>
39cf872a6df49bd5affe2ca6eaf683918184fbb4trawick String otk = request.getParameter("oauth_token");
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz if (otk == null) {
1b3f48fd6b1ccb8745f908e40156c5a85ca3c347jerenkrantz out.println("<h1>Error</h1><h2>OAuth token is missing.</h2>");
33f5961d34a8b5390cebad0543b3ebe67830e5d7jerenkrantz String uid = null;
33f5961d34a8b5390cebad0543b3ebe67830e5d7jerenkrantz HttpServletRequest httpRequest = (HttpServletRequest)request;
33f5961d34a8b5390cebad0543b3ebe67830e5d7jerenkrantz HttpServletResponse httpResponse = (HttpServletResponse)response;
33f5961d34a8b5390cebad0543b3ebe67830e5d7jerenkrantz Cookie[] cookies = httpRequest.getCookies();
54e1babd5a5a56c576eeeace54110150769cc916coar if (cookies != null && cookies.length > 0) {
54e1babd5a5a56c576eeeace54110150769cc916coar for (int i=0; i < cookies.length; i++) {
54e1babd5a5a56c576eeeace54110150769cc916coar Cookie nextCookie = cookies[i];
54e1babd5a5a56c576eeeace54110150769cc916coar String name = nextCookie.getName();
54e1babd5a5a56c576eeeace54110150769cc916coar String value = nextCookie.getValue();
54e1babd5a5a56c576eeeace54110150769cc916coar if (name.equals(openssoCookieName)) {
54e1babd5a5a56c576eeeace54110150769cc916coar // get the UUID of the user based on the OpenAM session cookie
54e1babd5a5a56c576eeeace54110150769cc916coar uid = getUid(value);
54e1babd5a5a56c576eeeace54110150769cc916coar } catch (OAuthServiceException oe) {
54e1babd5a5a56c576eeeace54110150769cc916coar uid = null;
949aa7bba7f804faa8e6b08cad42a98fc0255d85jerenkrantz //throw new ServletException(oe.getMessage());
07021d9f405849228b859d9fb4b877f20e4fbba3jerenkrantz if (uid == null) {
07021d9f405849228b859d9fb4b877f20e4fbba3jerenkrantz // session is not valid so redirect the user to OpenAM login page
07021d9f405849228b859d9fb4b877f20e4fbba3jerenkrantz String loginURL =
07021d9f405849228b859d9fb4b877f20e4fbba3jerenkrantz OAuthProperties.get(PathDefs.OPENSSO_SERVER_URL) +
07021d9f405849228b859d9fb4b877f20e4fbba3jerenkrantz OAuthProperties.get(PathDefs.OPENSSO_SERVER_LOGIN_URI);
07021d9f405849228b859d9fb4b877f20e4fbba3jerenkrantz StringBuffer requestURL = httpRequest.getRequestURL();
f126ee03179eb54308118f1ec3de5a7b461685d8aaron if (query != null) {
f126ee03179eb54308118f1ec3de5a7b461685d8aaron requestURL.append("?").append(query);
f126ee03179eb54308118f1ec3de5a7b461685d8aaron StringBuffer redirectURL = new StringBuffer();
f126ee03179eb54308118f1ec3de5a7b461685d8aaron if (loginURL.indexOf("?") > 0) {
f126ee03179eb54308118f1ec3de5a7b461685d8aaron redirectURL.append(URLEncoder.encode(requestURL.toString()));
f126ee03179eb54308118f1ec3de5a7b461685d8aaron out.println("User ID: " + uid + "<br>");
109faf633e12ab0bbdd602c7addc795cce59e8addreid <h2>Do you authorize the Service Consumer to access your resource?</h2>
109faf633e12ab0bbdd602c7addc795cce59e8addreid <form name="AuthoriseToken" >
109faf633e12ab0bbdd602c7addc795cce59e8addreid <input type="button" onclick="revoke('<%= otk%>')" value="Revoke" name="Revoke">
109faf633e12ab0bbdd602c7addc795cce59e8addreid <input type="button" onclick="makeithappen('<%= otk%>', '<%= uid%>')" value="Authorize" name="Authorize">