Search in sources :

Example 6 with Client

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.");
}
Also used : Set(java.util.Set) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) LinkedList(java.util.LinkedList) Date(java.util.Date) ClientApproval(edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 7 with Client

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);
}
Also used : OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) OA4MPIdentifierProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider) OA2ClientProvider(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider) JSONObject(net.sf.json.JSONObject) OA2ClientMemoryStore(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.OA2ClientMemoryStore) Client(edu.uiuc.ncsa.security.delegation.storage.Client) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter) Test(org.junit.Test)

Example 8 with Client

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);
}
Also used : OA2ClientConverter(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter) ClientConverter(edu.uiuc.ncsa.security.delegation.storage.impl.ClientConverter) OA4MPIdentifierProvider(edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider) JSONObject(net.sf.json.JSONObject) ClientProvider(edu.uiuc.ncsa.security.delegation.storage.ClientProvider) OA2ClientProvider(edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider) Client(edu.uiuc.ncsa.security.delegation.storage.Client) OA2Client(edu.uiuc.ncsa.security.oauth_2_0.OA2Client) ClientMemoryStore(edu.uiuc.ncsa.security.delegation.server.storage.impl.ClientMemoryStore) OA2ClientMemoryStore(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.OA2ClientMemoryStore) Test(org.junit.Test)

Example 9 with Client

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());
}
Also used : Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Example 10 with Client

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());
}
Also used : OA4MPServiceTransaction(edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction) BasicIdentifier(edu.uiuc.ncsa.security.core.util.BasicIdentifier) Client(edu.uiuc.ncsa.security.delegation.storage.Client)

Aggregations

Client (edu.uiuc.ncsa.security.delegation.storage.Client)26 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)8 Test (org.junit.Test)7 ClientApproval (edu.uiuc.ncsa.security.delegation.server.storage.ClientApproval)6 Date (java.util.Date)6 Identifier (edu.uiuc.ncsa.security.core.Identifier)5 OA4MPIdentifierProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.transactions.OA4MPIdentifierProvider)3 OA2ClientMemoryStore (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.OA2ClientMemoryStore)2 OA4MPServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction)2 UnknownClientException (edu.uiuc.ncsa.security.core.exceptions.UnknownClientException)2 ClientProvider (edu.uiuc.ncsa.security.delegation.storage.ClientProvider)2 ClientConverter (edu.uiuc.ncsa.security.delegation.storage.impl.ClientConverter)2 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)2 OA2ClientConverter (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientConverter)2 OA2ClientProvider (edu.uiuc.ncsa.security.oauth_2_0.OA2ClientProvider)2 JSONObject (net.sf.json.JSONObject)2 OA4MPServiceProvider (edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPServiceProvider)1 AssetProvider (edu.uiuc.ncsa.myproxy.oa4mp.client.storage.AssetProvider)1 AdminClient (edu.uiuc.ncsa.myproxy.oa4mp.server.admin.adminClient.AdminClient)1 MultiDSClientStoreProvider (edu.uiuc.ncsa.myproxy.oa4mp.server.storage.MultiDSClientStoreProvider)1