use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.permissions.PermissionServer in project OA4MP by ncsa.
the class ClientServerTest method testRemove.
public void testRemove(CMTestStoreProvider tp2) throws Exception {
CC cc = setupClients(tp2);
// so approve this
ClientServer server = new ClientServer(tp2.getCOSE());
ApproveRequest approveRequest = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionApprove(), cc.client, null);
server.process(approveRequest);
assert tp2.getClientApprovalStore().containsKey(cc.client.getIdentifier());
assert tp2.getClientApprovalStore().get(cc.client.getIdentifier()).isApproved();
assert !tp2.getPermissionStore().get(cc.adminClient.getIdentifier(), cc.client.getIdentifier()).isEmpty();
AdminClient ac2 = getAdminClient(tp2.getAdminClientStore());
PermissionServer permissionServer = new PermissionServer(tp2.getCOSE());
AddClientRequest addClientRequest = RequestFactory.createRequest(ac2, new TypePermission(), new ActionAdd(), cc.client, null);
permissionServer.process(addClientRequest);
assert !tp2.getPermissionStore().get(ac2.getIdentifier(), cc.client.getIdentifier()).isEmpty();
// ok, so now we have a couple of admin clients with permissions on this client and it is approved. Let's
// see if everything gets cleaned out.
RemoveRequest removeRequest = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionRemove(), cc.client, null);
server.process(removeRequest);
assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
assert !tp2.getClientApprovalStore().containsKey(cc.client.getIdentifier());
assert tp2.getPermissionStore().get(cc.adminClient.getIdentifier(), cc.client.getIdentifier()).isEmpty();
assert tp2.getPermissionStore().get(ac2.getIdentifier(), cc.client.getIdentifier()).isEmpty();
}
use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.cm.util.permissions.PermissionServer 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);
}
Aggregations