Search in sources :

Example 1 with OA4MPServiceTransaction

use of edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction 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)

Example 2 with OA4MPServiceTransaction

use of edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction in project OA4MP by ncsa.

the class TransactionStoreTest method testServiceTransaction.

@Test
public void testServiceTransaction() throws Exception {
    OA4MPServiceTransaction OA4MPServiceTransaction = (OA4MPServiceTransaction) getStore().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 = getTSProvider().getClientStore().create();
    client.setIdentifier(new BasicIdentifier(URI.create("test:client:1d/" + System.currentTimeMillis())));
    OA4MPServiceTransaction.setAuthorizationGrant(newAG());
    OA4MPServiceTransaction.setAuthGrantValid(false);
    client.setName("service test name #" + System.nanoTime());
    getStore().save(OA4MPServiceTransaction);
    assert getStore().containsKey(OA4MPServiceTransaction.getIdentifier());
    assert OA4MPServiceTransaction.equals(getStore().get(OA4MPServiceTransaction.getIdentifier()));
    assert OA4MPServiceTransaction.equals(getStore().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());
    getStore().save(OA4MPServiceTransaction);
    assert OA4MPServiceTransaction.equals(getStore().get(OA4MPServiceTransaction.getVerifier()));
    // next leg creates the access tokens and invalidates the temp credentials
    OA4MPServiceTransaction.setAccessToken(newAT());
    OA4MPServiceTransaction.setAuthGrantValid(false);
    OA4MPServiceTransaction.setAccessTokenValid(true);
    getStore().save(OA4MPServiceTransaction);
    assert OA4MPServiceTransaction.equals(getStore().get(OA4MPServiceTransaction.getIdentifier()));
    assert OA4MPServiceTransaction.equals(getStore().get(OA4MPServiceTransaction.getAccessToken()));
    OA4MPServiceTransaction.setAccessTokenValid(false);
    getStore().save(OA4MPServiceTransaction);
    assert OA4MPServiceTransaction.equals(getStore().get(OA4MPServiceTransaction.getIdentifier()));
    // and we're done
    getStore().remove(OA4MPServiceTransaction.getIdentifier());
    assert !getStore().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) Test(org.junit.Test)

Example 3 with OA4MPServiceTransaction

use of edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction in project OA4MP by ncsa.

the class AbstractConfigurationLoader method getTSP.

protected Provider<TransactionStore> getTSP() {
    if (tsp == null) {
        final DSTransactionProvider tp = new DSTransactionProvider<OA4MPServiceTransaction>();
        TransactionConverter<OA4MPServiceTransaction> tc = new TransactionConverter(tp, getTokenForgeProvider().get(), (ClientStore<? extends Client>) getCSP().get());
        MultiDSTransactionStoreProvider storeProvider = new MultiDSTransactionStoreProvider(cn, isDefaultStoreDisabled(), loggerProvider.get(), tp);
        storeProvider.addListener(new DSSQLTransactionStoreProvider(cn, getMySQLConnectionPoolProvider(), OA4MPConfigTags.MYSQL_STORE, getCSP(), tp, getTokenForgeProvider(), tc));
        storeProvider.addListener(new DSSQLTransactionStoreProvider(cn, getMariaDBConnectionPoolProvider(), OA4MPConfigTags.MARIADB_STORE, getCSP(), tp, getTokenForgeProvider(), tc));
        storeProvider.addListener(new DSSQLTransactionStoreProvider(cn, getPgConnectionPoolProvider(), OA4MPConfigTags.POSTGRESQL_STORE, getCSP(), tp, getTokenForgeProvider(), tc));
        storeProvider.addListener(new DSFSTransactionStoreProvider(cn, tp, getTokenForgeProvider(), tc));
        storeProvider.addListener(new TypedProvider<TransactionStore>(cn, OA4MPConfigTags.MEMORY_STORE, OA4MPConfigTags.TRANSACTIONS_STORE) {

            @Override
            public Object componentFound(CfgEvent configurationEvent) {
                if (checkEvent(configurationEvent)) {
                    return get();
                }
                return null;
            }

            @Override
            public TransactionStore get() {
                return new TransactionMemoryStore(tp);
            }
        });
        tsp = storeProvider;
    }
    return tsp;
}
Also used : OA4MPServiceTransaction(edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction) CfgEvent(edu.uiuc.ncsa.security.core.configuration.provider.CfgEvent) TransactionMemoryStore(edu.uiuc.ncsa.security.delegation.storage.impl.TransactionMemoryStore) TransactionStore(edu.uiuc.ncsa.security.delegation.storage.TransactionStore)

Aggregations

OA4MPServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.server.OA4MPServiceTransaction)3 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)2 Client (edu.uiuc.ncsa.security.delegation.storage.Client)2 CfgEvent (edu.uiuc.ncsa.security.core.configuration.provider.CfgEvent)1 TransactionStore (edu.uiuc.ncsa.security.delegation.storage.TransactionStore)1 TransactionMemoryStore (edu.uiuc.ncsa.security.delegation.storage.impl.TransactionMemoryStore)1 Test (org.junit.Test)1