Search in sources :

Example 6 with TransactionState

use of edu.uiuc.ncsa.security.delegation.servlet.TransactionState in project OA4MP by ncsa.

the class AbstractInitServlet method doDelegation.

/**
 * Actual work call. This parses and returns the passed in parameters.
 *
 * @param req
 * @param resp
 * @return
 * @throws java.io.IOException
 * @throws javax.servlet.ServletException
 */
protected void doDelegation(HttpServletRequest req, HttpServletResponse resp) throws Throwable {
    Client client = getClient(req);
    try {
        String cid = "client=" + client.getIdentifier();
        info("2.a. Starting a new cert request: " + cid);
        checkClientApproval(client);
        AGResponse agResponse = (AGResponse) getAGI().process(new AGRequest(req, client));
        agResponse.setClient(client);
        ServiceTransaction transaction = verifyAndGet(agResponse);
        transaction.setClient(client);
        getTransactionStore().save(transaction);
        info("Saved new transaction with id=" + transaction.getIdentifierString());
        Map<String, String> params = agResponse.getParameters();
        preprocess(new TransactionState(req, resp, params, transaction));
        debug("saved transaction for " + cid + ", trans id=" + transaction.getIdentifierString());
        agResponse.write(resp);
        info("2.b finished initial request for token =\"" + transaction.getIdentifierString() + "\".");
        postprocess(new IssuerTransactionState(req, resp, params, transaction, agResponse));
    } catch (Throwable t) {
        if (t instanceof UnapprovedClientException) {
            warn("Unapproved client: " + client.getIdentifierString());
        }
        throw t;
    }
}
Also used : TransactionState(edu.uiuc.ncsa.security.delegation.servlet.TransactionState) AGRequest(edu.uiuc.ncsa.security.delegation.server.request.AGRequest) ServiceTransaction(edu.uiuc.ncsa.security.delegation.server.ServiceTransaction) AGResponse(edu.uiuc.ncsa.security.delegation.server.request.AGResponse) UnapprovedClientException(edu.uiuc.ncsa.security.delegation.server.UnapprovedClientException) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 7 with TransactionState

use of edu.uiuc.ncsa.security.delegation.servlet.TransactionState in project OA4MP by ncsa.

the class AbstractRegistrationServlet method present.

public void present(PresentableState state) throws Throwable {
    postprocess(new TransactionState(state.getRequest(), state.getResponse(), null, null));
    switch(state.getState()) {
        case INITIAL_STATE:
            JSPUtil.fwd(state.getRequest(), state.getResponse(), INIT_PAGE);
            break;
        case REQUEST_STATE:
            if (state instanceof ClientState) {
                ClientState cState = (ClientState) state;
                state.getRequest().setAttribute("client", cState.getClient());
                JSPUtil.fwd(state.getRequest(), state.getResponse(), OK_PAGE);
            } else {
                throw new IllegalStateException("Error: An instance of ClientState was expected, but got an instance of \"" + state.getClass().getName() + "\"");
            }
            break;
        case ERROR_STATE:
        default:
    }
}
Also used : TransactionState(edu.uiuc.ncsa.security.delegation.servlet.TransactionState)

Example 8 with TransactionState

use of edu.uiuc.ncsa.security.delegation.servlet.TransactionState in project OA4MP by ncsa.

the class AbstractAuthorizationServlet method doIt.

@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    info("*** STARTING request");
    // String ag = request.getParameter(CONST(TOKEN_KEY));
    String ag = getParam(request, CONST(TOKEN_KEY));
    ServiceTransaction trans = null;
    if (ag == null) {
        throw new GeneralException("Error: Invalid request -- no token. Request rejected.");
    }
    trans = getAndCheckTransaction(ag);
    AuthorizedState pState = new AuthorizedState(getState(request), request, response, trans);
    prepare(pState);
    preprocess(new TransactionState(request, response, null, trans));
    switch(pState.getState()) {
        case AUTHORIZATION_ACTION_OK:
            // As per the spec, if the code gets to here then authentication worked.
            trans.setAuthGrantValid(true);
            getTransactionStore().save(trans);
            // get the cert and store it. Then forward user.
            try {
                createRedirect(request, response, trans);
                // at this point.
                return;
            } catch (ConnectionException ce) {
                ce.printStackTrace();
                request.setAttribute(RETRY_MESSAGE, getServiceEnvironment().getMessages().get(RETRY_MESSAGE));
                pState.setState(AUTHORIZATION_ACTION_START);
                prepare(pState);
            } catch (GeneralSecurityException | NoUsableMyProxyServerFoundException t) {
                // CIL-173 fix: process NoUsableMPSFound.
                info("Prompting user to retry");
                request.setAttribute(RETRY_MESSAGE, getServiceEnvironment().getMessages().get(RETRY_MESSAGE));
                pState.setState(AUTHORIZATION_ACTION_START);
                prepare(pState);
            }
            break;
        case AUTHORIZATION_ACTION_START:
            // no processing needed for initial request.
            break;
        default:
    }
    present(pState);
}
Also used : TransactionState(edu.uiuc.ncsa.security.delegation.servlet.TransactionState) NoUsableMyProxyServerFoundException(edu.uiuc.ncsa.myproxy.NoUsableMyProxyServerFoundException) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ServiceTransaction(edu.uiuc.ncsa.security.delegation.server.ServiceTransaction) GeneralSecurityException(java.security.GeneralSecurityException) ConnectionException(edu.uiuc.ncsa.security.core.exceptions.ConnectionException)

Example 9 with TransactionState

use of edu.uiuc.ncsa.security.delegation.servlet.TransactionState in project OA4MP by ncsa.

the class AbstractRegistrationServlet method prepare.

public void prepare(PresentableState state) throws Throwable {
    preprocess(new TransactionState(state.getRequest(), state.getResponse(), null, null));
    switch(state.getState()) {
        case INITIAL_STATE:
            HttpServletRequest request = state.getRequest();
            info("Processing new client registration request.");
            request.setAttribute(CLIENT_NAME, CLIENT_NAME);
            request.setAttribute(CLIENT_PUBLIC_KEY, CLIENT_PUBLIC_KEY);
            request.setAttribute(CLIENT_HOME_URL, CLIENT_HOME_URL);
            request.setAttribute(CLIENT_ERROR_URL, CLIENT_ERROR_URL);
            request.setAttribute(CLIENT_EMAIL, CLIENT_EMAIL);
            request.setAttribute(CLIENT_PROXY_LIMITED, CLIENT_PROXY_LIMITED);
            request.setAttribute(CLIENT_ACTION_KEY, CLIENT_ACTION_KEY);
            request.setAttribute(CLIENT_ACTION_REQUEST_VALUE, CLIENT_ACTION_REQUEST_VALUE);
            request.setAttribute("actionToTake", request.getContextPath() + "/register");
            break;
        case REQUEST_STATE:
            // nothing to do.
            return;
        case ERROR_STATE:
        default:
            warn("Error: unknown action request.");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TransactionState(edu.uiuc.ncsa.security.delegation.servlet.TransactionState)

Aggregations

TransactionState (edu.uiuc.ncsa.security.delegation.servlet.TransactionState)9 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)5 ServiceTransaction (edu.uiuc.ncsa.security.delegation.server.ServiceTransaction)5 PARequest (edu.uiuc.ncsa.security.delegation.server.request.PARequest)2 PAResponse (edu.uiuc.ncsa.security.delegation.server.request.PAResponse)2 HashMap (java.util.HashMap)2 NoUsableMyProxyServerFoundException (edu.uiuc.ncsa.myproxy.NoUsableMyProxyServerFoundException)1 ConnectionException (edu.uiuc.ncsa.security.core.exceptions.ConnectionException)1 UnapprovedClientException (edu.uiuc.ncsa.security.delegation.server.UnapprovedClientException)1 AGRequest (edu.uiuc.ncsa.security.delegation.server.request.AGRequest)1 AGResponse (edu.uiuc.ncsa.security.delegation.server.request.AGResponse)1 ATRequest (edu.uiuc.ncsa.security.delegation.server.request.ATRequest)1 ATResponse (edu.uiuc.ncsa.security.delegation.server.request.ATResponse)1 Client (edu.uiuc.ncsa.security.delegation.storage.Client)1 AccessToken (edu.uiuc.ncsa.security.delegation.token.AccessToken)1 AuthorizationGrant (edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)1 Verifier (edu.uiuc.ncsa.security.delegation.token.Verifier)1 MyPKCS10CertRequest (edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Enumeration (java.util.Enumeration)1