Package org.apache.shindig.gadgets.oauth2

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message


   
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
       
      OAuth2Message requestMessage = null;
        try{
            requestMessage = OAuth2Servlet.getMessage(request, null);
           
            OAuth2Client client = SampleOAuth2Provider.getClient(requestMessage);
           
            SampleOAuth2Provider.VALIDATOR.validateRequestMessageForAuthorization(requestMessage,client);
           
            sendToAuthorizePage(request, response, client);

       
        } catch (Exception e){
            Boolean sendBodyInJson = false;
            Boolean withAuthHeader = false;
            if (e instanceof OAuth2ProblemException){
              OAuth2ProblemException problem = (OAuth2ProblemException) e;
              problem.setParameter(OAuth2.REDIRECT_URI,OAuth2.decodePercent(requestMessage.getParameter(OAuth2.REDIRECT_URI)));
              problem.setParameter(OAuth2ProblemException.HTTP_STATUS_CODE,new Integer(302));
              /* it can be removed at here */
              if(requestMessage.getParameter(OAuth2.STATE)!=null){
                  problem.setParameter(OAuth2.STATE, requestMessage.getParameter(OAuth2.STATE));
                }
            }
           
            SampleOAuth2Provider.handleException(e, request, response, sendBodyInJson, withAuthHeader);
        }
View Full Code Here


    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException{
       
        try{
            OAuth2Message requestMessage = OAuth2Servlet.getMessage(request, null);
           
            OAuth2Client client = SampleOAuth2Provider.getClient(requestMessage);
           
            String userId = request.getParameter("userId");
            if(userId == null){
              SampleOAuth2Provider.VALIDATOR.validateRequestMessageForAuthorization(requestMessage,client);
                sendToAuthorizePage(request, response, client);
            }
           
            OAuth2Accessor accessor = new OAuth2Accessor(client);           
           
            // set userId in accessor and mark it as authorized
            SampleOAuth2Provider.markAsAuthorized(accessor, userId);


            String requested = requestMessage.getParameter(OAuth2.RESPONSE_TYPE);
            if (requested.equals(OAuth2.ResponseType.CODE)) {
                SampleOAuth2Provider.generateCode(accessor);
                returnToConsumer(request, response, accessor);
            }else if (requested.equals(OAuth2.ResponseType.TOKEN)){
                // generate refresh token here but do not send back that
View Full Code Here

            response.reset();
            response.setStatus(Integer.parseInt(httpCode.toString()));
           
           
            OAuth2Message message = new OAuth2Message(null, null, problem.getParameters().entrySet());  
            if(withAuthHeader){
              response.addHeader("WWW-Authenticate", message.getWWWAuthenticateHeader(realm));
            }

            List<Map.Entry<String, String>> sendBackErrorParameters = new ArrayList<Map.Entry<String, String>>(SEND_BACK_ERROR_PARAMETERS.size());
            for (Map.Entry parameter : message.getParameters()) {
                if(SEND_BACK_ERROR_PARAMETERS.contains(parameter.getKey()))
                {
                    sendBackErrorParameters.add(parameter);
                }
            }
View Full Code Here

  }

  @Test
  public void testStoreOAuth2Accessor_1() throws Exception {
    final OAuth2Store store = MockUtils.getDummyStore(this.cache, null, null);
    OAuth2Accessor accessor = new BasicOAuth2Accessor("XXX", "YYY", "ZZZ", "", false, store, "AAA");

    final Integer result = this.cache.storeOAuth2Accessor(accessor);

    Assert.assertEquals(-1664180105, result.intValue());

    accessor = this.cache.getOAuth2Accessor(result);

    Assert.assertNotNull(accessor);
    Assert.assertEquals("XXX", accessor.getGadgetUri());
    Assert.assertEquals("YYY", accessor.getServiceName());
    Assert.assertEquals("ZZZ", accessor.getUser());
    Assert.assertEquals("", accessor.getScope());
    Assert.assertEquals(false, accessor.isAllowModuleOverrides());
    Assert.assertEquals("AAA", accessor.getRedirectUri());
    Assert.assertEquals("-1664180105", accessor.getState());
  }
View Full Code Here

  }

  @Test(expected = OAuth2RequestException.class)
  public void testGetAuthorizationRequest_1() throws Exception {
    final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth;
    final OAuth2Accessor accessor = null;

    final String completeAuthorizationUrl = "xxx";

    fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl);
  }
View Full Code Here

  }

  @Test(expected = OAuth2RequestException.class)
  public void testGetAuthorizationRequest_2() throws Exception {
    final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();

    final String completeAuthorizationUrl = null;

    fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl);
  }
View Full Code Here

  }

  @Test(expected = OAuth2RequestException.class)
  public void testGetAuthorizationRequest_3() throws Exception {
    final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error();

    final String completeAuthorizationUrl = "xxx";

    fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl);
  }
View Full Code Here

  }

  @Test(expected = OAuth2RequestException.class)
  public void testGetAuthorizationRequest_4() throws Exception {
    final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final String completeAuthorizationUrl = "xxx";

    fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl);
  }
View Full Code Here

  }

  @Test
  public void testGetAuthorizationRequest_5() throws Exception {
    final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_ClientCredentials();
    final String completeAuthorizationUrl = "xxx";

    final HttpRequest result = fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl);

    Assert.assertNotNull(result);
View Full Code Here

  }

  @Test(expected = OAuth2RequestException.class)
  public void testGetCompleteUrl_1() throws Exception {
    final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth;
    final OAuth2Accessor accessor = null;
    fixture.getCompleteUrl(accessor);
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.oauth2.OAuth2Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.