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;
}
}
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:
}
}
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);
}
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.");
}
}
Aggregations