Search in sources :

Example 1 with DelegationResponse

use of edu.uiuc.ncsa.security.delegation.client.request.DelegationResponse in project OA4MP by ncsa.

the class AbstractOA4MPService method requestCert.

protected OA4MPResponse requestCert(Asset asset, Map additionalParameters) {
    if (additionalParameters == null) {
        additionalParameters = new HashMap();
    }
    try {
        preRequestCert(asset, additionalParameters);
        OA4MPResponse mpdsResponse = new OA4MPResponse();
        mpdsResponse.setPrivateKey(asset.getPrivateKey());
        DelegationRequest daReq = new DelegationRequest();
        daReq.setParameters(additionalParameters);
        daReq.setClient(getEnvironment().getClient());
        daReq.setBaseUri(getEnvironment().getAuthorizationUri());
        DelegationResponse daResp = (DelegationResponse) getEnvironment().getDelegationService().process(daReq);
        if (daResp.getAuthorizationGrant() != null) {
            asset.setToken(BasicIdentifier.newID(daResp.getAuthorizationGrant().getToken()));
            if (asset.getIdentifier() == null) {
                asset.setIdentifier(makeb64Uri(daResp.getAuthorizationGrant().getToken().toString()));
            }
        }
        String skin = getEnvironment().getSkin();
        String r = daResp.getRedirectUri().toString();
        if (skin != null) {
            r = r + "&" + SKIN_PARAMETER + "=" + skin;
        }
        // FIXME!! For OAuth 2, how do we introduce the skin parameter if there is no rewriting of the url before
        // getting forwarded to an Authz module? Might have to send it across in the initial call.
        mpdsResponse.setRedirect(URI.create(r));
        getAssetStore().save(asset);
        postRequestCert(asset, mpdsResponse);
        return mpdsResponse;
    } catch (Throwable e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new GeneralException("Error generating request", e);
    }
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) HashMap(java.util.HashMap) DelegationResponse(edu.uiuc.ncsa.security.delegation.client.request.DelegationResponse) Base64String(edu.uiuc.ncsa.security.util.pkcs.Base64String) DelegationRequest(edu.uiuc.ncsa.security.delegation.client.request.DelegationRequest)

Aggregations

GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 DelegationRequest (edu.uiuc.ncsa.security.delegation.client.request.DelegationRequest)1 DelegationResponse (edu.uiuc.ncsa.security.delegation.client.request.DelegationResponse)1 Base64String (edu.uiuc.ncsa.security.util.pkcs.Base64String)1 HashMap (java.util.HashMap)1