Search in sources :

Example 1 with Client

use of edu.uiuc.ncsa.security.delegation.storage.Client 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 2 with Client

use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.

the class AbstractRegistrationServlet method doIt.

@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    if (!request.isSecure()) {
        // Tomcat docs say to explicitly check here for the right protocol if it is truly required.
        throw new ServletException("Unsupported protocol");
    }
    int state = getState(request);
    // Addresses
    if (state == INITIAL_STATE) {
        if (getServiceEnvironment().getMaxAllowedNewClientRequests() <= getServiceEnvironment().getClientApprovalStore().getPendingCount()) {
            // throw new TooManyRequestsException("Error: Max number of new client requests reached. Request rejected.");
            log("Too many client approvals pending. Max allowed unapproved count is " + getServiceEnvironment().getMaxAllowedNewClientRequests());
            // Fixes CIL-414, CIL-426 (send email notification), CIL-427
            getServiceEnvironment().getMailUtil().sendMessage("Too many pending approvals", request.getServerName() + " has too many pending client approval requests outstanding. " + "The server is configured for a limit of " + getServiceEnvironment().getMaxAllowedNewClientRequests() + " and" + " there are " + getServiceEnvironment().getClientApprovalStore().getPendingCount() + " pending approvals in the store.", null);
            JSPUtil.fwd(request, response, "/tooManyClientRequests.jsp");
            // Fixes OAUTH-90 bug.
            return;
        }
    }
    PresentationState pState = new PresentationState(state, request, response);
    try {
        prepare(pState);
        if (state == REQUEST_STATE) {
            Client client = addNewClient(request, response);
            // Fix for OAUTH-157 bug. Always save any updates to the client
            getServiceEnvironment().getClientStore().save(client);
            pState = new ClientState(state, request, response, client);
        }
        present(pState);
    } catch (ClientRegistrationRetryException r) {
        getServiceEnvironment().getClientStore().remove(r.getClient().getIdentifier());
        setRetryParameters(request, r);
        if ((request.getAttribute(getValueTag(CLIENT_PROXY_LIMITED)) != null) && request.getAttribute(getValueTag(CLIENT_PROXY_LIMITED)).equals("on")) {
            // so this is checked
            request.setAttribute(getValueTag(CLIENT_PROXY_LIMITED), "checked");
        } else {
            // so this is unchecked
            request.removeAttribute(getValueTag(CLIENT_PROXY_LIMITED));
        }
        request.setAttribute(CLIENT_NAME, CLIENT_NAME);
        // Nest commands reset the state on the form so the contents are processed.
        request.setAttribute(CLIENT_ACTION_KEY, CLIENT_ACTION_KEY);
        request.setAttribute(CLIENT_ACTION_REQUEST_VALUE, CLIENT_ACTION_REQUEST_VALUE);
        request.setAttribute("actionToTake", request.getContextPath() + "/register");
        request.setAttribute("retryMessage", r.getMessage());
        JSPUtil.fwd(request, response, INIT_PAGE);
    } catch (Throwable t) {
        if (ServletDebugUtil.isEnabled()) {
            t.printStackTrace();
        }
        warn("Error registering a new client:" + t.getMessage());
        handleError(pState, t);
    }
}
Also used : ServletException(javax.servlet.ServletException) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 3 with Client

use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.

the class ClientStoreCommands method extraUpdates.

@Override
public void extraUpdates(Identifiable identifiable) {
    Client client = (Client) identifiable;
    client.setErrorUri(getInput("enter error uri", client.getErrorUri()));
    client.setHomeUri(getInput("enter home uri", client.getHomeUri()));
    client.setProxyLimited(isOk(getInput("does this client require limited proxies?", client.isProxyLimited() ? "y" : "n")));
    getPublicKeyFile((Client) identifiable);
}
Also used : Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 4 with Client

use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.

the class ClientStoreCommands method update.

@Override
public boolean update(Identifiable identifiable) {
    Client client = (Client) identifiable;
    String newIdentifier = null;
    info("Starting client update for id = " + client.getIdentifierString());
    say("Update the values. A return accepts the existing or default value in []'s");
    newIdentifier = getInput("enter the identifier", client.getIdentifierString());
    boolean removeCurrentClient = false;
    Identifier oldID = client.getIdentifier();
    // no clean way to do this.
    client.setName(getInput("enter the name", client.getName()));
    client.setEmail(getInput("enter email", client.getEmail()));
    client.setErrorUri(getInput("enter error uri", client.getErrorUri()));
    client.setHomeUri(getInput("enter home uri", client.getHomeUri()));
    client.setProxyLimited(isOk(getInput("does this client require limited proxies?", client.isProxyLimited() ? "y" : "n")));
    // set file not found message.
    extraUpdates(client);
    sayi("here is the complete client:");
    longFormat(client);
    if (!newIdentifier.equals(client.getIdentifierString())) {
        sayi2(" remove client with id=\"" + client.getIdentifier() + "\" [y/n]? ");
        removeCurrentClient = isOk(readline());
        client.setIdentifier(BasicIdentifier.newID(newIdentifier));
    }
    sayi2("save [y/n]?");
    if (isOk(readline())) {
        // getStore().save(client);
        if (removeCurrentClient) {
            info("removing client with id = " + oldID);
            getStore().remove(client.getIdentifier());
            sayi("client with id " + oldID + " removed. Be sure to save any changes.");
        }
        sayi("client updated.");
        info("Client with id " + client.getIdentifierString() + " saving...");
        return true;
    }
    sayi("client not updated, losing changes...");
    info("User terminated updates for client with id " + client.getIdentifierString());
    return false;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 5 with Client

use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.

the class ClientLoader method createInstance.

@Override
public T createInstance() {
    Provider<TokenForge> tokenForgeProvider = new Provider<TokenForge>() {

        @Override
        public TokenForge get() {
            return new OAuthTokenForge(getId());
        }
    };
    Provider<Client> clientProvider = new Provider<Client>() {

        @Override
        public Client get() {
            OAClient c = new OAClient(BasicIdentifier.newID(getId()));
            c.setSignatureMethod(OAuthConstants.RSA_SHA1);
            c.setCreationTS(new Date());
            return c;
        }
    };
    // sets constants specific to this protocol.
    HashMap<String, String> constants = new HashMap<String, String>();
    constants.put(CALLBACK_URI_KEY, OAuthConstants.OAUTH_CALLBACK);
    constants.put(ClientEnvironment.FORM_ENCODING, "UTF-8");
    constants.put(ClientEnvironment.TOKEN, OAuth.OAUTH_TOKEN);
    constants.put(ClientEnvironment.VERIFIER, OAuth.OAUTH_VERIFIER);
    return createInstance(tokenForgeProvider, clientProvider, constants);
}
Also used : OAuthTokenForge(edu.uiuc.ncsa.security.oauth_1_0a.OAuthTokenForge) TokenForge(edu.uiuc.ncsa.security.delegation.token.TokenForge) OAClient(edu.uiuc.ncsa.security.oauth_1_0a.client.OAClient) HashMap(java.util.HashMap) Client(edu.uiuc.ncsa.security.delegation.storage.Client) OAClient(edu.uiuc.ncsa.security.oauth_1_0a.client.OAClient) OAuthTokenForge(edu.uiuc.ncsa.security.oauth_1_0a.OAuthTokenForge) Date(java.util.Date) Provider(javax.inject.Provider) AssetProvider(edu.uiuc.ncsa.myproxy.oa4mp.client.storage.AssetProvider) DelegationServiceImplProvider(edu.uiuc.ncsa.security.oauth_1_0a.client.DelegationServiceImplProvider) OA4MPServiceProvider(edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPServiceProvider)

Aggregations

Client (edu.uiuc.ncsa.security.delegation.storage.Client)26 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)8 Test (org.junit.Test)7 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)6 Date (java.util.Date)6 Identifier (edu.uiuc.ncsa.security.core.Identifier)5 OA4MPIdentifierProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider)3 OA2ClientMemoryStore (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.OA2ClientMemoryStore)2 OA4MPServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction)2 UnknownClientException (edu.uiuc.ncsa.security.core.exceptions.UnknownClientException)2 ClientProvider (edu.uiuc.ncsa.security.delegation.storage.ClientProvider)2 ClientConverter (edu.uiuc.ncsa.security.delegation.storage.impl.ClientConverter)2 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)2 OA2ClientConverter (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)2 OA2ClientProvider (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider)2 JSONObject (net.sf.json.JSONObject)2 OA4MPServiceProvider (edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPServiceProvider)1 AssetProvider (edu.uiuc.ncsa.myproxy.oa4mp.client.storage.AssetProvider)1 AdminClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)1 MultiDSClientStoreProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.MultiDSClientStoreProvider)1