Search in sources :

Example 6 with GeneralException

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

the class CRServlet method getX509Certificates.

/**
 * Loops through the facade looking for the active connection and calls it.
 *
 * @param transaction
 * @param localCertRequest
 * @param statusString
 * @return
 * @throws GeneralSecurityException
 */
protected LinkedList<X509Certificate> getX509Certificates(ServiceTransaction transaction, MyPKCS10CertRequest localCertRequest, String statusString) throws GeneralSecurityException {
    MyProxyConnectable mpc = getMPConnection(transaction);
    mpc.setLifetime(transaction.getLifetime());
    LinkedList<X509Certificate> certs = mpc.getCerts(localCertRequest);
    if (certs.isEmpty()) {
        info(statusString + "Error: MyProxy service returned no certs.");
        throw new GeneralException("Error: MyProxy service returned no certs.");
    }
    info(statusString + "Got cert from MyProxy, issuing a limited proxy & storing it.");
    return certs;
}
Also used : MyProxyConnectable(edu.uiuc.ncsa.myproxy.MyProxyConnectable) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) X509Certificate(java.security.cert.X509Certificate)

Example 7 with GeneralException

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

the class SQLPermissionStore method get.

@Override
public PermissionList get(Identifier adminID, Identifier clientID) {
    PermissionList allOfThem = new PermissionList();
    Connection c = getConnection();
    PermissionKeys permissionKeys = new PermissionKeys();
    try {
        PreparedStatement stmt = c.prepareStatement("select * from " + getTable().getFQTablename() + " where " + permissionKeys.clientID() + "=? AND " + permissionKeys.adminID() + "=?");
        stmt.setString(1, clientID.toString());
        stmt.setString(2, adminID.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()) {
            V newOne = create();
            ColumnMap map = rsToMap(rs);
            populate(map, newOne);
            allOfThem.add(newOne);
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error: could not get database object", e);
    } finally {
        releaseConnection(c);
    }
    return allOfThem;
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 8 with GeneralException

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

the class SQLPermissionStore method getClients.

@Override
public List<Identifier> getClients(Identifier adminID) {
    ArrayList<Identifier> clients = new ArrayList<>();
    if (adminID == null)
        return clients;
    Connection c = getConnection();
    PermissionKeys permissionKeys = new PermissionKeys();
    try {
        PreparedStatement stmt = c.prepareStatement("select " + permissionKeys.clientID() + "  from " + getTable().getFQTablename() + " where " + permissionKeys.adminID() + "=?");
        stmt.setString(1, adminID.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 clientID = rs.getString(permissionKeys.clientID());
            clients.add(BasicIdentifier.newID(clientID));
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error: could not get database object", e);
    } finally {
        releaseConnection(c);
    }
    return clients;
}
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 9 with GeneralException

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

the class SQLClientApprovalStore method getPendingCount.

@Override
public int getPendingCount() {
    int count = 0;
    String query = "Select " + getTable().getPrimaryKeyColumnName() + " from " + getTable().getFQTablename() + " where " + getCAT().ca().approved() + "=false ";
    Connection c = getConnection();
    try {
        PreparedStatement stmt = c.prepareStatement(query);
        stmt.execute();
        ResultSet rs = stmt.getResultSet();
        while (rs.next()) {
            count++;
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error getting the user ids", e);
    } finally {
        releaseConnection(c);
    }
    return count;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 10 with GeneralException

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

the class SQLClientApprovalStore method getUnapprovedCount.

@Override
public int getUnapprovedCount() {
    int count = 0;
    String query = "Select " + getTable().getPrimaryKeyColumnName() + " from " + getTable().getFQTablename() + " where " + getCAT().ca().approved() + "=false ";
    Connection c = getConnection();
    try {
        PreparedStatement stmt = c.prepareStatement(query);
        stmt.execute();
        ResultSet rs = stmt.getResultSet();
        while (rs.next()) {
            count++;
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error getting the user ids", e);
    } finally {
        releaseConnection(c);
    }
    return count;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

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