Search in sources :

Example 6 with ColumnMap

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

the class AttributeServer method setClientAttribute.

protected AttributeClientResponse setClientAttribute(AttributeSetClientRequest request) {
    canWrite(request);
    OA2Client client = (OA2Client) getClientStore().get(request.getClient().getIdentifier());
    OA2ClientConverter clientConverter = (OA2ClientConverter) getClientConverter();
    ColumnMap map = new ColumnMap();
    clientConverter.toMap(client, map);
    for (String key : request.getAttributes().keySet()) {
        // don't let anyone change the identifier.
        if (!key.equals(getClientConverter().getKeys().identifier())) {
            map.put(key, request.getAttributes().get(key));
        }
        if (key.equalsIgnoreCase(clientConverter.getCK2().secret())) {
            // they are changing the secret and we want a hash of this.
            String secret = DigestUtils.sha1Hex(String.valueOf(request.getAttributes().get(key)));
            map.put(key, secret);
        }
    }
    OA2Client updatedClient = getClientConverter().fromMap(map, null);
    getClientStore().save(updatedClient);
    AttributeClientResponse attributeClientResponse = new AttributeClientResponse(updatedClient);
    return attributeClientResponse;
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)

Example 7 with ColumnMap

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

the class ClientServer method create.

public CreateResponse create(CreateRequest request) {
    if (request.getAdminClient() != null && (request.getAdminClient().getIdentifier() == null || request.getAdminClient().getIdentifierString().length() == 0)) {
        throw new GeneralException("Error: An admin client was specified, but no identifier for this client was given. Request rejected.");
    }
    // canCreate(request);
    // requires and admin client and hashmap
    ColumnMap values = new ColumnMap();
    values.putAll(request.getAttributes());
    // values.putAll(); // add all the values passed in
    ClientKeys keys = (ClientKeys) getClientStore().getACConverter().getKeys();
    OA2Client client = (OA2Client) getClientStore().create();
    values.put(keys.identifier(), client.getIdentifier());
    values.put(keys.creationTS(), client.getCreationTS());
    String secret = null;
    if (values.containsKey(keys.secret())) {
        // if the secret is supplied, just store its hash
        secret = (String) values.get(keys.secret());
    } else {
        // no secret means to create one.
        byte[] bytes = new byte[cose.getClientSecretLength()];
        random.nextBytes(bytes);
        secret = Base64.encodeBase64URLSafeString(bytes);
    }
    String hash = DigestUtils.sha1Hex(secret);
    values.put(keys.secret(), hash);
    getClientStore().getACConverter().fromMap(values, client);
    getClientStore().save(client);
    // set the permissions for this.
    if (request.getAdminClient() != null) {
        // if there is no admin client, then do not set permissions for it. It is possible for a client to simply
        // be created and manage itself.
        PermissionServer permissionServer = new PermissionServer(cose);
        permissionServer.process(RequestFactory.createRequest(request.getAdminClient(), new TypePermission(), new ActionAdd(), client, null));
    }
    // CIL-414 Make sure an approval record is created here so we can accurately track how many approvals are pending
    ClientApproval approval = (ClientApproval) getClientApprovalStore().create();
    approval.setApproved(false);
    approval.setIdentifier(client.getIdentifier());
    getClientApprovalStore().save(approval);
    return new CreateResponse(client, secret);
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) PermissionServer(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.permissions.PermissionServer) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) TypePermission(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypePermission) ActionAdd(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.actions.ActionAdd) ClientKeys(edu.uiuc.ncsa.security.delegation.storage.ClientKeys)

Example 8 with ColumnMap

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

the class AttributeServer method setAdminClientAttribute.

protected AttributeAdminClientResponse setAdminClientAttribute(AttributeSetClientRequest request) {
    AdminClient client = getAdminClientStore().get(request.getAdminClient().getIdentifier());
    ColumnMap map = new ColumnMap();
    getACConverter().toMap(client, map);
    for (String key : request.getAttributes().keySet()) {
        // don't let anyone change the identifier.
        if (!key.equals(getACConverter().getKeys().identifier())) {
            map.put(key, request.getAttributes().get(key));
        }
    }
    AdminClient updatedClient = getACConverter().fromMap(map, null);
    getAdminClientStore().save(updatedClient);
    AttributeAdminClientResponse attributeClientResponse = new AttributeAdminClientResponse(updatedClient);
    return attributeClientResponse;
}
Also used : ColumnMap(edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap) AdminClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)

Example 9 with ColumnMap

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

the class LDAPSQLStore method getByClientID.

@Override
public LDAPEntry getByClientID(Identifier clientID) {
    Connection c = getConnection();
    LDAPEntryKeys keys = new LDAPEntryKeys();
    V newOne = null;
    try {
        PreparedStatement stmt = c.prepareStatement("select * from " + getTable().getFQTablename() + " where " + keys.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()) {
            newOne = create();
            ColumnMap map = rsToMap(rs);
            populate(map, newOne);
        }
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        destroyConnection(c);
        throw new GeneralException("Error: could not get database object", e);
    } finally {
        releaseConnection(c);
    }
    return newOne;
}
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 10 with ColumnMap

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

the class ClientServerTest method testCreatePublicClient.

public void testCreatePublicClient(CMTestStoreProvider tp2) throws Exception {
    // only needs an admin client and map.
    CC cc = setupClients(tp2);
    cc.client.setPublicClient(true);
    tp2.getClientStore().save(cc.client);
    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)

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