Search in sources :

Example 11 with ColumnMap

use of edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap in project OA4MP by ncsa.

the class ClientServerTest method testCreate.

public void testCreate(CMTestStoreProvider tp2) throws Exception {
    // only needs an admin client and map.
    CC cc = setupClients(tp2);
    OA2ClientConverter converter = getClientConverter(tp2);
    ColumnMap values = new ColumnMap();
    converter.toMap(cc.client, values);
    tp2.getClientStore().remove(cc.client.getIdentifier());
    assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
    // remove the identifier and create it
    OA2ClientKeys clientKeys = getClientKeys(tp2);
    values.remove(clientKeys.identifier());
    values.remove(clientKeys.creationTS());
    JSONObject json = new JSONObject();
    json.putAll(values);
    CreateRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionCreate(), null, json);
    ClientServer server = new ClientServer(tp2.getCOSE());
    CreateResponse resp = (CreateResponse) server.process(req);
    OA2Client newClient = resp.getClient();
    assert tp2.getClientStore().containsKey(newClient.getIdentifier());
    // quick and dirty check
    OA2Client oldClient = (OA2Client) cc.client;
    oldClient.setIdentifier(newClient.getIdentifier());
    oldClient.setSecret(newClient.getSecret());
    assert oldClient.equals(newClient);
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) JSONObject(net.sf.json.JSONObject) OA2ClientKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys) TypeClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)

Example 12 with ColumnMap

use of edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap in project OA4MP by ncsa.

the class SQLAssetStore method getByToken.

@Override
public Asset getByToken(Identifier token) {
    if (token == null) {
        return null;
    }
    Connection c = getConnection();
    Asset t = null;
    try {
        PreparedStatement stmt = c.prepareStatement(getAST().getByTokenStatement());
        stmt.setString(1, token.toString());
        stmt.executeQuery();
        ResultSet rs = stmt.getResultSet();
        // Now we have to pull in all the values.
        if (!rs.next()) {
            rs.close();
            stmt.close();
            // returning a null fulfills contract for this being a map.
            return null;
        }
        ColumnMap map = rsToMap(rs);
        rs.close();
        stmt.close();
        t = create();
        populate(map, t);
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error getting object with identifier \"" + token + "\"", e);
    } finally {
        releaseConnection(c);
    }
    return t;
}
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) Asset(edu.uiuc.ncsa.myproxy.oa4mp.client.Asset) PreparedStatement(java.sql.PreparedStatement)

Aggregations

ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)12 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)6 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)4 AdminClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)3 OA2ClientConverter (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 TypeClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)2 OA2ClientKeys (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientKeys)2 JSONObject (net.sf.json.JSONObject)2 Asset (edu.uiuc.ncsa.myproxy.oa4mp.client.Asset)1 PermissionServer (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.permissions.PermissionServer)1 ActionAdd (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionAdd)1 TypePermission (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission)1 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)1 ClientKeys (edu.uiuc.ncsa.security.delegation.storage.ClientKeys)1