Search in sources :

Example 1 with RefreshTokenStore

use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenStore in project OA4MP by ncsa.

the class RefreshTokenStoreTest method testRT.

public void testRT(TransactionStore tStore) throws Exception {
    if (!(tStore instanceof RefreshTokenStore)) {
        // fail here if can't cast
        throw new IllegalStateException("Error: The store " + tStore.getClass().getSimpleName() + " is not of a type RefreshTokenStore");
    }
    RefreshTokenStore rts = (RefreshTokenStore) tStore;
    OA2ServiceTransaction st2 = (OA2ServiceTransaction) tStore.create();
    OA2TokenForge tf2 = new OA2TokenForge("http://localhost/test/");
    RefreshToken rt = tf2.getRefreshToken();
    st2.setRefreshToken(rt);
    // the auth grant is used to retrieve this later and should in this case just be set to the identifier.
    AuthorizationGrant ag = tf2.getAuthorizationGrant(st2.getIdentifierString());
    st2.setAuthorizationGrant(ag);
    st2.setRefreshTokenLifetime(EXPIRES_IN);
    tStore.save(st2);
    OA2ServiceTransaction testST = rts.get(rt);
    assert testST.equals(st2) : "Error: created transaction is not fetched faithfully from the store";
    // get another one and retry since we have to be able to show the store can handle updating the refresh token
    rt = tf2.getRefreshToken();
    st2.setRefreshToken(rt);
    st2.setRefreshTokenValid(false);
    tStore.save(st2);
    assert rts.get(rt).equals(st2) : "Error: updating refresh token fails.";
}
Also used : RefreshTokenStore(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenStore) RefreshToken(edu.uiuc.ncsa.security.delegation.token.RefreshToken) OA2ServiceTransaction(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction) AuthorizationGrant(edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant) OA2TokenForge(edu.uiuc.ncsa.security.oauth_2_0.OA2TokenForge)

Example 2 with RefreshTokenStore

use of edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenStore in project OA4MP by ncsa.

the class OA2ServletInitializer method init.

@Override
public void init() throws ServletException {
    if (isInitRun)
        return;
    super.init();
    OA2SE oa2SE = (OA2SE) getEnvironment();
    MyProxyDelegationServlet mps = (MyProxyDelegationServlet) getServlet();
    try {
        // mps.storeUpdates();
        mps.processStoreCheck(oa2SE.getPermissionStore());
        mps.processStoreCheck(oa2SE.getAdminClientStore());
    } catch (SQLException e) {
        if (DebugUtil.isEnabled()) {
            e.printStackTrace();
        }
        throw new ServletException("Could not update table", e);
    }
    if (oa2SE.isRefreshTokenEnabled()) {
        // We need a different set of policies than the original one.
        MyProxyDelegationServlet.transactionCleanup.getRetentionPolicies().clear();
        MyProxyDelegationServlet.transactionCleanup.addRetentionPolicy(new RefreshTokenRetentionPolicy((RefreshTokenStore) oa2SE.getTransactionStore()));
        oa2SE.getMyLogger().info("Initialized refresh token cleanup thread");
    }
    if (!ClaimSourceFactory.isFactorySet()) {
        ClaimSourceFactory.setFactory(new LDAPClaimSourceFactory());
    }
    try {
        SATFactory.setAdminClientConverter(AdminClientStoreProviders.getAdminClientConverter());
        SATFactory.setClientConverter((ClientConverter<? extends Client>) oa2SE.getClientStore().getACConverter());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServletException(javax.servlet.ServletException) RefreshTokenStore(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenStore) RefreshTokenRetentionPolicy(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenRetentionPolicy) OA2SE(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE) SQLException(java.sql.SQLException) MyProxyDelegationServlet(edu.uiuc.ncsa.myproxy.oa4mp.server.servlet.MyProxyDelegationServlet) LDAPClaimSourceFactory(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.servlet.LDAPClaimSourceFactory) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException)

Aggregations

RefreshTokenStore (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenStore)2 OA2SE (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE)1 OA2ServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction)1 LDAPClaimSourceFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.servlet.LDAPClaimSourceFactory)1 RefreshTokenRetentionPolicy (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenRetentionPolicy)1 MyProxyDelegationServlet (edu.uiuc.ncsa.myproxy.oa4mp.server.servlet.MyProxyDelegationServlet)1 AuthorizationGrant (edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)1 RefreshToken (edu.uiuc.ncsa.security.delegation.token.RefreshToken)1 OA2TokenForge (edu.uiuc.ncsa.security.oauth_2_0.OA2TokenForge)1 SQLException (java.sql.SQLException)1 ServletException (javax.servlet.ServletException)1