Search in sources :

Example 6 with RefreshToken

use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.

the class OA2ATServlet method doRefresh.

protected TransactionState doRefresh(OA2Client c, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    RefreshToken oldRT = getTF2().getRefreshToken(request.getParameter(OA2Constants.REFRESH_TOKEN));
    if (c == null) {
        throw new InvalidTokenException("Could not find the client associated with refresh token \"" + oldRT + "\"");
    }
    OA2ServiceTransaction t = getByRT(oldRT);
    if ((!((OA2SE) getServiceEnvironment()).isRefreshTokenEnabled()) || (!c.isRTLifetimeEnabled())) {
        throw new OA2ATException(OA2Errors.REQUEST_NOT_SUPPORTED, "Refresh tokens are not supported on this server");
    }
    if (t == null || !t.isRefreshTokenValid()) {
        throw new OA2ATException(OA2Errors.INVALID_REQUEST, "Error: The refresh token is no longer valid.");
    }
    // this way if it fails at some point we know it is invalid.
    t.setRefreshTokenValid(false);
    AccessToken at = t.getAccessToken();
    RTIRequest rtiRequest = new RTIRequest(request, c, at);
    RTI2 rtIsuuer = new RTI2(getTF2(), getServiceEnvironment().getServiceAddress());
    RTIResponse rtiResponse = (RTIResponse) rtIsuuer.process(rtiRequest);
    rtiResponse.setSignToken(c.isSignTokens());
    populateClaims(request, rtiResponse.getParameters(), t);
    RefreshToken rt = rtiResponse.getRefreshToken();
    rt.setExpiresIn(computeRefreshLifetime(t));
    t.setRefreshToken(rtiResponse.getRefreshToken());
    t.setRefreshTokenValid(true);
    t.setAccessToken(rtiResponse.getAccessToken());
    // At this point, key in the transaction store is the grant, so changing the access token
    // over-writes the current value. This practically invalidates the previous access token.
    // this is necessary to clear any caches.
    getTransactionStore().remove(t.getIdentifier());
    ArrayList<String> targetScopes = new ArrayList<>();
    OA2SE oa2SE = (OA2SE) getServiceEnvironment();
    // set true if something is requested we don't support
    boolean returnScopes = false;
    for (String s : t.getScopes()) {
        if (oa2SE.getScopes().contains(s)) {
            targetScopes.add(s);
        } else {
            returnScopes = true;
        }
    }
    if (returnScopes) {
        rtiResponse.setSupportedScopes(targetScopes);
    }
    rtiResponse.setScopeHandlers(setupScopeHandlers(t, oa2SE));
    rtiResponse.setServiceTransaction(t);
    rtiResponse.setJsonWebKey(oa2SE.getJsonWebKeys().getDefault());
    getTransactionStore().save(t);
    rtiResponse.write(response);
    IssuerTransactionState state = new IssuerTransactionState(request, response, rtiResponse.getParameters(), t, rtiResponse);
    return state;
}
Also used : IssuerTransactionState(edu.uiuc.ncsa.myproxy.oa4mp.server.servlet.IssuerTransactionState) OA2SE(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE) ArrayList(java.util.ArrayList) RefreshToken(edu.uiuc.ncsa.security.delegation.token.RefreshToken) AccessToken(edu.uiuc.ncsa.security.delegation.token.AccessToken) OA2ServiceTransaction(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction)

Example 7 with RefreshToken

use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.

the class OA2TConverter method fromMap.

@Override
public V fromMap(ConversionMap<String, Object> map, V v) {
    V st = super.fromMap(map, v);
    Object refreshToken = map.get(getTCK().refreshToken());
    if (refreshToken != null) {
        if (refreshToken instanceof RefreshToken) {
            st.setRefreshToken((RefreshToken) refreshToken);
        } else {
            st.setRefreshToken(getTF2().getRefreshToken(refreshToken.toString()));
        }
    }
    st.setRefreshTokenValid(map.getBoolean(getTCK().refreshTokenValid()));
    st.setRefreshTokenLifetime(map.getLong(getTCK().expiresIn()));
    st.setCallback(map.getURI(getTCK().callbackUri()));
    st.setNonce(map.getString(getTCK().nonce()));
    if (map.get(getTCK().scopes()) != null) {
        net.sf.json.JSONArray json = (JSONArray) JSONSerializer.toJSON(map.get(getTCK().scopes()));
        Collection<String> zzz = (Collection<String>) JSONSerializer.toJava(json);
        st.setScopes(zzz);
    }
    if (map.get(getTCK().authTime()) != null) {
        st.setAuthTime(map.getDate(getTCK().authTime));
    }
    if (map.get(getTCK().flowStates()) != null) {
        st.setFlowStates(new FlowStates((JSONObject) JSONSerializer.toJSON(map.get(getTCK().flowStates()))));
    } else {
        st.setFlowStates(new FlowStates());
    }
    return st;
}
Also used : RefreshToken(edu.uiuc.ncsa.security.delegation.token.RefreshToken) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) JSONArray(net.sf.json.JSONArray) Collection(java.util.Collection) JSONObject(net.sf.json.JSONObject) FlowStates(edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.FlowStates)

Example 8 with RefreshToken

use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.

the class OA2AssetConverter method fromMap.

@Override
public Asset fromMap(ConversionMap<String, Object> map, Asset asset) {
    OA2Asset a = (OA2Asset) super.fromMap(map, asset);
    String rawCR = map.getString(getASK().certReq());
    if (rawCR != null) {
        MyPKCS10CertRequest certReq = CertUtil.fromStringToCertReq(rawCR);
        a.setCertReq(certReq);
    }
    String at = map.getString(getASK().accessToken());
    if (at != null)
        a.setAccessToken(new AccessTokenImpl(URI.create(at)));
    String rt = map.getString(getASK().refreshToken());
    if (rt != null) {
        RefreshToken refreshToken = new OA2RefreshTokenImpl(URI.create(rt));
        refreshToken.setExpiresIn(map.getLong(getASK().refreshLifetime()));
        a.setRefreshToken(refreshToken);
    }
    String state = map.getString(getASK().state());
    if (state != null) {
        a.setState(state);
    }
    a.setNonce(map.getString(getASK().nonce()));
    if (map.containsKey(OA2Claims.ISSUED_AT)) {
        a.setIssuedAt(map.getDate(OA2Claims.ISSUED_AT));
    }
    return a;
}
Also used : RefreshToken(edu.uiuc.ncsa.security.delegation.token.RefreshToken) AccessTokenImpl(edu.uiuc.ncsa.security.delegation.token.impl.AccessTokenImpl) MyPKCS10CertRequest(edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest) OA2RefreshTokenImpl(edu.uiuc.ncsa.security.oauth_2_0.OA2RefreshTokenImpl)

Aggregations

RefreshToken (edu.uiuc.ncsa.security.delegation.token.RefreshToken)8 OA2ServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction)4 IssuerTransactionState (edu.uiuc.ncsa.myproxy.oa4mp.server.servlet.IssuerTransactionState)2 AccessToken (edu.uiuc.ncsa.security.delegation.token.AccessToken)2 AccessTokenImpl (edu.uiuc.ncsa.security.delegation.token.impl.AccessTokenImpl)2 OA2RefreshTokenImpl (edu.uiuc.ncsa.security.oauth_2_0.OA2RefreshTokenImpl)2 OA2SE (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE)1 FlowStates (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.flows.FlowStates)1 RefreshTokenStore (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.storage.RefreshTokenStore)1 Identifier (edu.uiuc.ncsa.security.core.Identifier)1 InvalidTimestampException (edu.uiuc.ncsa.security.core.exceptions.InvalidTimestampException)1 AuthorizationGrant (edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)1 OA2TokenForge (edu.uiuc.ncsa.security.oauth_2_0.OA2TokenForge)1 MyPKCS10CertRequest (edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1