Search in sources :

Example 11 with ClientApproval

use of edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval in project OA4MP by ncsa.

the class NewCAStoreTest method testApprovalStore.

public void testApprovalStore(ClientStore clientStore, ClientApprovalStore caStore) throws Exception {
    // put one in, get it back, make sure it matches.
    Client client = (Client) clientStore.create();
    client.setHomeUri("urn:test:/home/uri/" + getRandomString(32));
    client.setSecret(getRandomString(256));
    client.setName("Test client" + getRandomString(32));
    client.setEmail(getRandomString(32) + "@email.foo.edu");
    client.setErrorUri("uri:test:/uh/oh/uri/" + getRandomString(32));
    clientStore.save(client);
    ClientApproval ca = (ClientApproval) caStore.create();
    ca.setApprover("test-approver");
    ca.setApproved(true);
    ca.setApprovalTimestamp(new Date());
    ca.setIdentifier(client.getIdentifier());
    caStore.save(ca);
    ClientApproval ca1 = (ClientApproval) caStore.get(ca.getIdentifier());
    assert ca.equals(ca1);
    caStore.remove(ca.getIdentifier());
    clientStore.remove(client);
}
Also used : ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) Client(edu.uiuc.ncsa.security.delegation.storage.Client) Date(java.util.Date)

Example 12 with ClientApproval

use of edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval in project OA4MP by ncsa.

the class ClientServer method unapprove.

public ClientResponse unapprove(UnapproveRequest request) {
    canApprove(request);
    ClientApproval approval = (ClientApproval) getClientApprovalStore().get(request.getClient().getIdentifier());
    OA2ClientApprovalKeys keys = new OA2ClientApprovalKeys();
    if (request.getAttributes() != null && request.getAttributes().containsKey(keys.approver())) {
        approval.setApprover(String.valueOf(request.getAttributes().get(keys.approver())));
    } else {
        approval.setApprover(request.getAdminClient().getIdentifierString());
    }
    approval.setApproved(false);
    getClientApprovalStore().save(approval);
    return new ClientResponse();
}
Also used : ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) OA2ClientApprovalKeys(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientApprovalKeys)

Example 13 with ClientApproval

use of edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval 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 14 with ClientApproval

use of edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval in project OA4MP by ncsa.

the class ClientServerTest method testApprove.

public void testApprove(CMTestStoreProvider tp2) throws Exception {
    CC cc = setupClients(tp2);
    ApproveRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionApprove(), cc.client, null);
    ClientServer server = new ClientServer(tp2.getCOSE());
    ClientResponse resp = (ClientResponse) server.process(req);
    ClientApproval approval = tp2.getClientApprovalStore().get(cc.client.getIdentifier());
    assert approval != null : "No approval found";
    assert approval.isApproved();
}
Also used : ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) TypeClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)

Example 15 with ClientApproval

use of edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval in project OA4MP by ncsa.

the class ClientServerTest method testUnapprove.

public void testUnapprove(CMTestStoreProvider tp2) throws Exception {
    CC cc = setupClients(tp2);
    // approve it first.
    ApproveRequest req0 = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionApprove(), cc.client, null);
    ClientServer server = new ClientServer(tp2.getCOSE());
    ClientResponse resp0 = (ClientResponse) server.process(req0);
    UnapproveRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionUnapprove(), cc.client, null);
    ClientResponse resp = (ClientResponse) server.process(req);
    ClientApproval approval = tp2.getClientApprovalStore().get(cc.client.getIdentifier());
    assert approval != null : "No approval found";
    assert !approval.isApproved();
}
Also used : ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) TypeClient(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)

Aggregations

ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)26 Client (edu.uiuc.ncsa.security.delegation.storage.Client)6 Date (java.util.Date)5 ClientApprovalProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.ClientApprovalProvider)3 ClientApproverConverter (edu.uiuc.ncsa.myproxy.oa4mp.server.util.ClientApproverConverter)3 Identifier (edu.uiuc.ncsa.security.core.Identifier)3 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)3 BaseClient (edu.uiuc.ncsa.security.delegation.storage.BaseClient)3 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)3 LinkedList (java.util.LinkedList)3 TypeClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.things.types.TypeClient)2 DSFSClientApprovalStore (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.filestore.DSFSClientApprovalStore)2 FilePermissionsException (edu.uiuc.ncsa.security.core.exceptions.FilePermissionsException)2 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)2 MyConfigurationException (edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)2 ClientApprovalStore (edu.uiuc.ncsa.security.delegation.server.storage.ClientApprovalStore)2 FSClientApprovalStore (edu.uiuc.ncsa.security.delegation.server.storage.impl.FSClientApprovalStore)2 OA2ClientApprovalKeys (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientApprovalKeys)2 File (java.io.File)2 Set (java.util.Set)2