use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.
the class AbstractCLIApprover method doIt.
@Override
public void doIt() throws Exception {
Set keys = se.getClientApprovalStore().keySet();
LinkedList<ClientApproval> linkedList = new LinkedList<ClientApproval>();
info("starting approval");
int i = 0;
for (Object k : keys) {
ClientApproval ca = (ClientApproval) se.getClientApprovalStore().get(k);
linkedList.add(ca);
say((i++) + ". " + (ca.isApproved() ? "(A) " : "(D) ") + linkedList.getLast().getIdentifierString());
}
if (linkedList.isEmpty()) {
say("(No entries found. You will need to manually enter the id.)");
}
boolean keepAsking = true;
String inString;
ClientApproval ca = null;
while (keepAsking) {
say("Enter the number of the client to approve or disapprove, OR, enter an id, starting with a " + ID_DELIMITER);
inString = readline();
if (inString.startsWith(ID_DELIMITER)) {
ca = new ClientApproval(new BasicIdentifier(inString.substring(ID_DELIMITER.length())));
keepAsking = false;
} else {
try {
int index = Integer.parseInt(inString);
if (0 <= index && index < linkedList.size()) {
ca = linkedList.get(index);
keepAsking = false;
} else {
say("Sorry, that index is out of range. Try again.");
}
} catch (NumberFormatException xx) {
boolean noInput = inString == null || inString.length() == 0;
say("Woops. Didn't understand " + (noInput ? "(empty)" : "\"" + inString + "\"") + ". Try again.");
}
}
}
if (ca == null) {
// future proof. Should never happen.
warn("No client approval found. Aborting session");
throw new GeneralException("Internal error: Somehow the client approval was not found. Fix that.");
}
Client client = (Client) se.getClientStore().get(ca.getIdentifier());
if (client == null) {
info("No client found for the given identifier. Aborting.");
say("no client found for the id. You probably want to fix that.\nexiting...");
return;
} else {
say("You have chosen the following client");
say(formatClient(client));
}
say("Enter your approver name [" + ANONYMOUS + "]:");
inString = readline();
ca.setApproved(true);
if (inString == null || 0 == inString.length()) {
ca.setApprover(ANONYMOUS);
} else {
ca.setApprover(inString);
}
info("Approver is identifier as " + ca.getApprover());
say("Enter Approve or Deny (A/D) [D]");
inString = readline();
if (inString != null && inString.toLowerCase().equals("a")) {
ca.setApproved(true);
}
info("Approver " + (ca.isApproved() ? "denies" : "allows") + " approval.");
say("Commit changes? (y/n)");
inString = readline();
if (!inString.toLowerCase().equals("y")) {
info("Approval aborted manually. No changes saved.");
say("You didn't explicitly say to save it -- operation aborted.\nexiting...");
return;
}
// update timestamp to now.
ca.setApprovalTimestamp(new Date());
if (pollingDir != null) {
// use polling
File tempFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX, pollingDir);
FileOutputStream fos = new FileOutputStream(tempFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(ca);
fos.flush();
fos.close();
} else {
// do the approval directly
se.getClientApprovalStore().save(ca);
}
info("Approval for client with id \"" + ca.getIdentifierString() + "\" finished.");
}
use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.
the class ClientManagerTest method testOA2Client.
@Test
public void testOA2Client() throws Exception {
OA2ClientProvider clientProvider = new OA2ClientProvider(new OA4MPIdentifierProvider(OA4MPIdentifierProvider.CLIENT_ID));
OA2ClientMemoryStore store = new OA2ClientMemoryStore(clientProvider);
OA2ClientConverter converter = new OA2ClientConverter(clientProvider);
OA2Client c = getOa2Client(store);
JSONObject j = new JSONObject();
converter.toJSON(c, j);
System.out.println(j);
Client c2 = converter.fromJSON(j);
assert c2.equals(c);
}
use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.
the class ClientManagerTest method testClient.
@Test
public void testClient() throws Exception {
ClientProvider clientProvider = new ClientProvider(new OA4MPIdentifierProvider(OA4MPIdentifierProvider.CLIENT_ID));
ClientMemoryStore store = new ClientMemoryStore(clientProvider);
ClientConverter converter = new ClientConverter(clientProvider);
Client c = getClient(store);
JSONObject j = new JSONObject();
converter.toJSON(c, j);
Client c2 = converter.fromJSON(j);
assert c2.equals(c);
}
use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.
the class NewClientStoreTest method testBasic.
public void testBasic(ClientStore clientStore) throws Exception {
Client client = (Client) clientStore.create();
System.out.println("New client ID = " + client.getIdentifier());
client.setHomeUri("urn:test:/home/uri");
client.setSecret(getRandomString(256));
client.setName("Test delegation client");
client.setEmail("test@email.foo.edu");
client.setErrorUri("uri:test:/uh/oh/uri");
client.setProxyLimited(true);
clientStore.save(client);
Client client2 = (Client) clientStore.get(client.getIdentifier());
assert client.equals(client2);
clientStore.remove(client.getIdentifier());
}
use of edu.uiuc.ncsa.security.delegation.storage.Client in project OA4MP by ncsa.
the class NewTransactionTest method testServiceTransaction.
public void testServiceTransaction(TransactionStore transactionStore, TokenForge tokenForge, ClientStore clientStore) throws Exception {
OA4MPServiceTransaction OA4MPServiceTransaction = (OA4MPServiceTransaction) transactionStore.create();
OA4MPServiceTransaction.setCallback(URI.create("http://callback"));
// set lifetime to 10 hours (stored in ms!)
OA4MPServiceTransaction.setLifetime(10 * 60 * 60 * 1000);
OA4MPServiceTransaction.setUsername("FakeUserName");
String mpUN = "myproxy username /with weird $$#@ in=it/#" + System.nanoTime();
OA4MPServiceTransaction.setMyproxyUsername(mpUN);
Client client = (Client) clientStore.create();
client.setIdentifier(new BasicIdentifier(URI.create("test:client:1d/" + System.currentTimeMillis())));
OA4MPServiceTransaction.setAuthorizationGrant(newAG(tokenForge));
OA4MPServiceTransaction.setAuthGrantValid(false);
client.setName("service test name #" + System.nanoTime());
transactionStore.save(OA4MPServiceTransaction);
assert transactionStore.containsKey(OA4MPServiceTransaction.getIdentifier());
assert OA4MPServiceTransaction.equals(transactionStore.get(OA4MPServiceTransaction.getIdentifier()));
assert OA4MPServiceTransaction.equals(transactionStore.get(OA4MPServiceTransaction.getAuthorizationGrant()));
// now emulate doing oauth type transactions with it.
// First leg sets the verifier and user
String r = getRandomString(12);
OA4MPServiceTransaction.setVerifier(newVerifier(tokenForge));
transactionStore.save(OA4MPServiceTransaction);
assert OA4MPServiceTransaction.equals(transactionStore.get(OA4MPServiceTransaction.getVerifier()));
// next leg creates the access tokens and invalidates the temp credentials
OA4MPServiceTransaction.setAccessToken(newAT(tokenForge));
OA4MPServiceTransaction.setAuthGrantValid(false);
OA4MPServiceTransaction.setAccessTokenValid(true);
transactionStore.save(OA4MPServiceTransaction);
assert OA4MPServiceTransaction.equals(transactionStore.get(OA4MPServiceTransaction.getIdentifier()));
assert OA4MPServiceTransaction.equals(transactionStore.get(OA4MPServiceTransaction.getAccessToken()));
OA4MPServiceTransaction.setAccessTokenValid(false);
transactionStore.save(OA4MPServiceTransaction);
assert OA4MPServiceTransaction.equals(transactionStore.get(OA4MPServiceTransaction.getIdentifier()));
// and we're done
transactionStore.remove(OA4MPServiceTransaction.getIdentifier());
assert !transactionStore.containsKey(OA4MPServiceTransaction.getIdentifier());
}
Aggregations