Search in sources :

Example 46 with GeneralException

use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.

the class TransactionConverter method fromMap.

@Override
public V fromMap(ConversionMap<String, Object> map, V v) {
    V t = super.fromMap(map, v);
    String CertReqString = map.getString(getDSTK().certReq());
    if (CertReqString != null && 0 < CertReqString.length())
        t.setCertReq(CertUtil.fromStringToCertReq(CertReqString));
    String y = map.getString(getDSTK().cert());
    if (y != null && 0 < y.length()) {
        try {
            ByteArrayInputStream baos = new ByteArrayInputStream(y.getBytes("UTF-8"));
            MyX509Certificates myCert = new MyX509Certificates(fromPEM(baos));
            t.setProtectedAsset(myCert);
        } catch (CertificateException e) {
            throw new GeneralException("Error decoding certificate", e);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    Identifier clientKey = BasicIdentifier.newID(map.getString(getDSTK().clientKey()));
    if (clientKey != null) {
        t.setClient(clientStore.get(clientKey));
    }
    String uName = map.getString(getDSTK().username());
    if (uName != null) {
        t.setUsername(uName);
    }
    String myproxyUsername = map.getString(getDSTK().myproxyUsername());
    if (myproxyUsername != null) {
        t.setMyproxyUsername(myproxyUsername);
    }
    return t;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CertificateException(java.security.cert.CertificateException) MyX509Certificates(edu.uiuc.ncsa.security.delegation.token.MyX509Certificates)

Example 47 with GeneralException

use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.

the class SQLPermissionStore method getAdmins.

@Override
public List<Identifier> getAdmins(Identifier clientID) {
    ArrayList<Identifier> admins = new ArrayList<>();
    if (clientID == null)
        return admins;
    Connection c = getConnection();
    PermissionKeys permissionKeys = new PermissionKeys();
    try {
        PreparedStatement stmt = c.prepareStatement("select " + permissionKeys.adminID() + "  from " + getTable().getFQTablename() + " where " + permissionKeys.clientID() + "=?");
        stmt.setString(1, clientID.toString());
        // just execute() since executeQuery(x) would throw an exception regardless of content per JDBC spec.
        stmt.execute();
        ResultSet rs = stmt.getResultSet();
        while (rs.next()) {
            String adminID = rs.getString(permissionKeys.adminID());
            admins.add(BasicIdentifier.newID(adminID));
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error: could not get database object", e);
    } finally {
        releaseConnection(c);
    }
    return admins;
}
Also used : BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Identifier(edu.uiuc.ncsa.security.core.Identifier) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 48 with GeneralException

use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.

the class OA2MPService method getCert.

public AssetResponse getCert(OA2Asset a, ATResponse2 atResponse2) {
    KeyPair keyPair = getNextKeyPair();
    MyPKCS10CertRequest certReq = null;
    try {
        certReq = CertUtil.createCertRequest(keyPair, a.getUsername());
    } catch (Throwable e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new GeneralException("Could no create cert request", e);
    }
    a.setPrivateKey(keyPair.getPrivate());
    a.setCertReq(certReq);
    Map<String, String> m1 = getAssetParameters(a);
    preGetCert(a, m1);
    if (MANUAL_TEST) {
        return manualTest(a, m1);
    }
    DelegatedAssetResponse daResp = getEnvironment().getDelegationService().getCert(atResponse2, getEnvironment().getClient(), m1);
    AssetResponse par = new AssetResponse();
    MyX509Certificates myX509Certificate = (MyX509Certificates) daResp.getProtectedAsset();
    par.setX509Certificates(myX509Certificate.getX509Certificates());
    postGetCert(a, par);
    a.setCertificates(par.getX509Certificates());
    getEnvironment().getAssetStore().save(a);
    return par;
}
Also used : KeyPair(java.security.KeyPair) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) AssetResponse(edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse) MyX509Certificates(edu.uiuc.ncsa.security.delegation.token.MyX509Certificates) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Example 49 with GeneralException

use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.

the class OA2ClientExceptionHandler method parseContent.

/**
 * This will parse the standard error reponse from an OIDC server.
 *
 * @param content
 * @param request
 * @return
 */
protected void parseContent(String content, HttpServletRequest request) {
    // This will take the payload and parse it as follows. The assumption is that it is of the form
    // X0=Y0
    // X1=Y1
    // X2=Y2
    // etc. where X's are standard OIDB error indicators (e.g. error_description, state) and Y's are the value
    // These are set in the response as attributes, so there is no limit on them.
    boolean hasValidContent = false;
    StringTokenizer st = new StringTokenizer(content, "\n");
    while (st.hasMoreElements()) {
        String currentLine = st.nextToken();
        StringTokenizer clST = new StringTokenizer(currentLine, "=");
        if (!clST.hasMoreTokens() || clST.countTokens() != 2) {
            continue;
        }
        try {
            request.setAttribute(clST.nextToken(), URLDecoder.decode(clST.nextToken(), "UTF-8"));
        } catch (UnsupportedEncodingException xx) {
            // ok, try it without decoding it. (This case should never really happen)
            request.setAttribute(clST.nextToken(), clST.nextToken());
        }
        hasValidContent = true;
    }
    if (!hasValidContent) {
        getLogger().warn("Body or error was not parseable");
        throw new GeneralException();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 50 with GeneralException

use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.

the class OA4MPService method preRequestCert.

@Override
public void preRequestCert(Asset asset, Map additionalParameters) {
    KeyPair keyPair = getNextKeyPair();
    MyPKCS10CertRequest certReq = null;
    try {
        certReq = CertUtil.createCertRequest(keyPair);
    } catch (Throwable e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new GeneralException("Could not create cert request", e);
    }
    asset.setPrivateKey(keyPair.getPrivate());
    asset.setCertReq(certReq);
    additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, Base64.encodeBase64String(asset.getCertReq().getEncoded()));
    // additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, "Mairzy doates and does eat stoats.");
    if (!additionalParameters.containsKey(getEnvironment().getConstants().get(CALLBACK_URI_KEY))) {
        additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), getEnvironment().getCallback().toString());
    }
    if (0 <= getEnvironment().getCertLifetime()) {
        additionalParameters.put(ClientEnvironment.CERT_LIFETIME_KEY, getEnvironment().getCertLifetime());
    }
}
Also used : KeyPair(java.security.KeyPair) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)

Aggregations

GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)53 ServiceTransaction (edu.uiuc.ncsa.security.delegation.server.ServiceTransaction)9 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 Identifier (edu.uiuc.ncsa.security.core.Identifier)5 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)5 MyPKCS10CertRequest (edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)5 X509Certificate (java.security.cert.X509Certificate)5 AssetResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse)4 TransactionState (edu.uiuc.ncsa.security.delegation.servlet.TransactionState)4 AccessToken (edu.uiuc.ncsa.security.delegation.token.AccessToken)4 AuthorizationGrant (edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)4 OA2SE (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE)3 OA2ServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction)3 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)3 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3