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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations