Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package edu.uiuc.ncsa.myproxy.oa4mp.oauth2.servlet;
  
 
 import java.net.URI;

Created by Jeff Gaynor
on 10/3/13 at 2:03 PM

 
 public class OA2ATServlet extends AbstractAccessTokenServlet {
     @Override
     public void preprocess(TransactionState statethrows Throwable {
         super.preprocess(state);
         String givenRedirect = state.getParameters().get(.);
         //Spec says that the redirect must match one of the ones stored and if not, the request is rejected.
         OA2ClientCheck.check(st.getClient(), givenRedirect);
         // Store the callback the user needs to use for this request, since the spec allows for many.
         st.setCallback(URI.create(state.getParameters().get(.)));
     }

    
The liftime of the refresh token. This is the non-zero minimum of the client's requested lifetime, the user's request at authorization time and the server global limit.

Parameters:
st2
Returns:
 
     protected long computeRefreshLifetime(OA2ServiceTransaction st2) {
         OA2Client client = (OA2Clientst2.getClient();
         long lifetime = Math.max(st2.getRefreshTokenLifetime(), client.getRtLifetime());
         OA2SE oa2SE = (OA2SEgetServiceEnvironment();
         if (oa2SE.getRefreshTokenLifetime() <= 0) {
             throw new NFWException("Internal error: the server-wide default for the refresh token lifetime has not been set.");
         }
         lifetime = Math.min(lifetimeoa2SE.getRefreshTokenLifetime());
         return lifetime;
 
     }
 
     @Override
     protected void doIt(HttpServletRequest requestHttpServletResponse responsethrows Throwable {
         String grantType = getFirstParameterValue(request.);
         if (grantType == null) {
             warn("Error servicing request. No grant type was given. Rejecting request.");
             throw new GeneralException("Error: Could not service request");
         }
         Client client = getClient(request);
         checkClient(client);
 
         if (grantType.equals(.)) {
             doRefresh(requestresponse);
             return;
         }
         if (grantType.equals(.)) {
             IssuerTransactionState state = doDelegation(requestresponse);
             ATIResponse2 atResponse = (ATIResponse2state.getIssuerResponse();
             OA2ServiceTransaction st2 = (OA2ServiceTransactionstate.getTransaction();
             RefreshToken rt = atResponse.getRefreshToken();
             st2.setRefreshToken(rt);
             rt.setExpiresIn(computeRefreshLifetime(st2));
             st2.setRefreshTokenValid(true);
             getTransactionStore().save(st2);
             return;
         }
         warn("Error: grant type was not recognized. Request rejected.");
         throw new ServletException("Error: Unknown request type.");
     }
 
 
     protected OA2ServiceTransaction getByRT(RefreshToken refreshTokenthrows IOException {
        if (refreshToken == null) {
            throw new GeneralException("Error: null refresh token encountered.");
        }
        return rts.get(refreshToken);
    }
    protected OA2TokenForge getTF2() {
        return (OA2TokenForgegetServiceEnvironment().getTokenForge();
    }
        Client c = getClient(request);
        checkClient(c);
        OA2ServiceTransaction t = getByRT(oldRT);
        if (!t.isRefreshTokenValid()) {
            throw new InvalidTokenException("Error: The refresh token is no longer valid");
        }
        t.setRefreshTokenValid(false); // this way if it fails at some point we know it is invalid.
        RTIRequest rtiRequest = new RTIRequest(requestct.getAccessToken());
        RTI2 rtIsuuer = new RTI2(getTF2(), getServiceEnvironment().getServiceAddress());
        RTIResponse rtiResponse = (RTIResponsertIsuuer.process(rtiRequest);
        RefreshToken rt = rtiResponse.getRefreshToken();
        rt.setExpiresIn(computeRefreshLifetime(t));
        t.setRefreshToken(rtiResponse.getRefreshToken());
        t.setRefreshTokenValid(true);
        getTransactionStore().save(t);
        rtiResponse.write(response);
        IssuerTransactionState state = new IssuerTransactionState(
                request,
                response,
                rtiResponse.getParameters(),
                t,
                rtiResponse);
        return state;
    }
    @Override
    public ServiceTransaction verifyAndGet(IssuerResponse iResponsethrows IOException {
        ATResponse atResponse = (ATResponseiResponse;
        TransactionStore transactionStore = getTransactionStore();
        BasicIdentifier basicIdentifier = new BasicIdentifier(atResponse.getParameters().get(.));
        Object o = transactionStore.get(basicIdentifier);
        //ServiceTransaction transaction = (ServiceTransaction) getTransactionStore().get(atResponse.getAccessToken());
        ServiceTransaction transaction = (ServiceTransactiono;
        // Need to do some checking but for now, just return transaction
        //return null;
        return transaction;
    }
New to GrepCode? Check out our FAQ X