Search in sources :

Example 1 with OA4MPResponse

use of edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse in project OA4MP by ncsa.

the class OA2TestCommands method geturi.

/**
 * Constructs the URI
 *
 * @param inputLine
 * @throws Exception
 */
public void geturi(InputLine inputLine) throws Exception {
    if (showHelp(inputLine)) {
        getURIHelp();
        return;
    }
    Identifier id = AssetStoreUtil.createID();
    OA4MPResponse resp = getService().requestCert(id);
    dummyAsset = (OA2Asset) getCe().getAssetStore().get(id.toString());
    say(resp.getRedirect().toString());
}
Also used : Identifier(edu.uiuc.ncsa.security.core.Identifier) OA4MPResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)

Example 2 with OA4MPResponse

use of edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse in project OA4MP by ncsa.

the class OA2StartRequest method doIt.

@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    info("1.a. Starting transaction");
    OA4MPResponse gtwResp = null;
    // Drumroll please: here is the work for this call.
    Identifier id = AssetStoreUtil.createID();
    gtwResp = getOA4MPService().requestCert(id);
    // if there is a store, store something in it.
    Cookie cookie = new Cookie(OA4MP_CLIENT_REQUEST_ID, id.getUri().toString());
    // 15 minutes
    cookie.setMaxAge(15 * 60);
    cookie.setSecure(true);
    debug("id = " + id.getUri());
    response.addCookie(cookie);
    info("1.b. Got response. Creating page with redirect for " + gtwResp.getRedirect().getHost());
    if (getCE().isShowRedirectPage()) {
        request.setAttribute(REDIR, REDIR);
        request.setAttribute("redirectUrl", gtwResp.getRedirect().toString());
        request.setAttribute(ACTION_KEY, ACTION_KEY);
        request.setAttribute("action", ACTION_REDIRECT_VALUE);
        // Normally, we'd just do a redirect, but we will put up a page and show the redirect to the user.
        // The client response contains the generated private key as well
        // In a real application, the private key would be stored. This, however, exceeds the scope of this
        // sample application -- all we need to do to complete the process is send along the redirect url.
        info("1.b. Showing redirect page.");
        JSPUtil.fwd(request, response, getCE().getRedirectPagePath());
        return;
    }
    response.sendRedirect(gtwResp.getRedirect().toString());
}
Also used : Cookie(javax.servlet.http.Cookie) Identifier(edu.uiuc.ncsa.security.core.Identifier) OA4MPResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)

Example 3 with OA4MPResponse

use of edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse in project OA4MP by ncsa.

the class SimpleStartRequest method doIt.

@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    info("1.a. Starting transaction");
    OA4MPResponse gtwResp = null;
    // Drumroll please: here is the work for this call.
    Identifier id = AssetStoreUtil.createID();
    gtwResp = getOA4MPService().requestCert(id);
    // if there is a store, store something in it.
    Cookie cookie = new Cookie(OA4MP_CLIENT_REQUEST_ID, id.getUri().toString());
    // 15 minutes
    cookie.setMaxAge(15 * 60);
    cookie.setSecure(true);
    debug("id = " + id.getUri());
    response.addCookie(cookie);
    info("1.b. Got response. Creating page with redirect for " + gtwResp.getRedirect().getHost());
    if (getCE().isShowRedirectPage()) {
        request.setAttribute(REDIR, REDIR);
        request.setAttribute("redirectUrl", gtwResp.getRedirect().toString());
        request.setAttribute("privateKey", KeyUtil.toPKCS8PEM(gtwResp.getPrivateKey()));
        request.setAttribute(ACTION_KEY, ACTION_KEY);
        request.setAttribute("action", ACTION_REDIRECT_VALUE);
        // Normally, we'd just do a redirect, but we will put up a page and show the redirect to the user.
        // The client response contains the generated private key as well. It is a very bad idea to show the
        // private key anywhere.
        // This is a sample application -- all we need to do to complete the process is send along the redirect url.
        info("1.b. Showing redirect page.");
        JSPUtil.fwd(request, response, getCE().getRedirectPagePath());
        return;
    }
    response.sendRedirect(gtwResp.getRedirect().toString());
}
Also used : Cookie(javax.servlet.http.Cookie) Identifier(edu.uiuc.ncsa.security.core.Identifier) OA4MPResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)

Example 4 with OA4MPResponse

use of edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse in project airavata by apache.

the class CredentialStoreStartServlet method doIt.

@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    String gatewayName = request.getParameter(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER);
    String portalUserName = request.getParameter(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER);
    String contactEmail = request.getParameter(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER);
    String associatedToken = TokenGenerator.generateToken(gatewayName, portalUserName);
    if (gatewayName == null) {
        JSPUtil.handleException(new RuntimeException("Please specify a gateway name."), request, response, configurationReader.getErrorUrl());
        return;
    }
    if (portalUserName == null) {
        JSPUtil.handleException(new RuntimeException("Please specify a portal user name."), request, response, configurationReader.getErrorUrl());
        return;
    }
    if (contactEmail == null) {
        JSPUtil.handleException(new RuntimeException("Please specify a contact email address for community" + " user account."), request, response, configurationReader.getErrorUrl());
        return;
    }
    log.info("1.a. Starting transaction");
    OA4MPResponse gtwResp;
    Map<String, String> queryParameters = new HashMap<String, String>();
    queryParameters.put(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER, gatewayName);
    queryParameters.put(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER, portalUserName);
    queryParameters.put(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER, contactEmail);
    queryParameters.put(CredentialStoreConstants.PORTAL_TOKEN_ID_ASSIGNED, associatedToken);
    Map<String, String> additionalParameters = new HashMap<String, String>();
    if (getOA4MPService() == null) {
        loadEnvironment();
    }
    String modifiedCallbackUri = decorateURI(getOA4MPService().getEnvironment().getCallback(), queryParameters);
    info("The modified callback URI - " + modifiedCallbackUri);
    additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), modifiedCallbackUri);
    try {
        gtwResp = getOA4MPService().requestCert(additionalParameters);
        // Private key in store
        PrivateKeyStore privateKeyStore = PrivateKeyStore.getPrivateKeyStore();
        privateKeyStore.addKey(associatedToken, gtwResp.getPrivateKey());
    } catch (Throwable t) {
        JSPUtil.handleException(t, request, response, configurationReader.getErrorUrl());
        return;
    }
    log.info("1.b. Got response. Creating page with redirect for " + gtwResp.getRedirect().getHost());
    // Normally, we'd just do a redirect, but we will put up a page and show the redirect to the user.
    // The client response contains the generated private key as well
    // In a real application, the private key would be stored. This, however, exceeds the scope of this
    // sample application -- all we need to do to complete the process is send along the redirect url.
    request.setAttribute(REDIR, REDIR);
    request.setAttribute("redirectUrl", gtwResp.getRedirect().toString());
    request.setAttribute(ACTION_KEY, ACTION_KEY);
    request.setAttribute("action", ACTION_REDIRECT_VALUE);
    log.info("1.b. Showing redirect page.");
    JSPUtil.fwd(request, response, configurationReader.getPortalRedirectUrl());
}
Also used : HashMap(java.util.HashMap) PrivateKeyStore(org.apache.airavata.credential.store.util.PrivateKeyStore) OA4MPResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)

Aggregations

OA4MPResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse)4 Identifier (edu.uiuc.ncsa.security.core.Identifier)3 Cookie (javax.servlet.http.Cookie)2 HashMap (java.util.HashMap)1 PrivateKeyStore (org.apache.airavata.credential.store.util.PrivateKeyStore)1