2011-01-21 6 views
0

Google AuthSub 요청을 인증하고 싶습니다. 기본적으로 개인 키와 해당 인증서를 생성하고,이 인증서를 Google에 업로드하고, Google AuthSub에 대한 이후 통화시 키로 서명해야합니다.Java의 보안 API AuthSub (Google 캘린더 API)

# Generate the RSA keys and certificate 
keytool -genkey -v -alias Example -keystore ./Example.jks\ 
    -keyalg RSA -sigalg SHA1withRSA\ 
    -dname "CN=www.example.com, OU=Engineering, O=My_Company, L=Mountain View, ST=CA, C=US"\ 
    -storepass changeme -keypass changeme 

# Output the public certificate to a file 
keytool -export -rfc -keystore ./Example.jks -storepass changeme \ 
    -alias Example -file mycert.pem 

을 (http://code.google.com/apis/gdata/docs/auth/authsub.html#keytool에 의해 지정된대로)

나는 Google에, mycert.pem을 지정된 증명서를 업로드 : 나는 가장 간단한 방법은 다음과 같이 자바의 키 도구를 사용하는 것입니다 생각합니다. Java 클라이언트에서 다음과 같이 개인 키를로드했습니다.

PrivateKey key = AuthSubUtil.getPrivateKeyFromKeystore(
           "Example.jks", "changeme", "Example", "changeme"); 

이 키를로드하면 예외가 발생하지 않습니다. 이 키는 다음과 같이 AuthSub 호출 중에 사용됩니다.

String requestUrl = 
    AuthSubUtil.getRequestUrl("http://www.example.com/RetrieveToken", 
          "https://www.google.com/calendar/feeds/", 
          true, 
          true); 
... 
// Servlet context, user follows the 'next link' with token attached. 
String onetimeUseToken = AuthSubUtil.getTokenFromReply(
              httpServletRequest.getQueryString()); 

// Exchange for the AuthSub token. 
String sessionToken = AuthSubUtil.exchangeForSessionToken(onetimeUseToken, key); 

// Use the token. 
CalendarService.setAuthSubToken(sessionToken, key); 

// Get calendars from the user. 
URL feedUrl = 
    new URL("https://www.google.com/calendar/feeds/default/owncalendars/full"); 

// Exception is thrown HERE. 
CalendarFeed resultFeed = service.getFeed(feedUrl, CalendarFeed.class); 

토큰을 설정하거나 교환하는 동안 예외가 발생하지 않지만 사용자 자원에 액세스하려고 시도하면 예외가 throw되지 않습니다. 나는 이것을 어떻게 만들지 잘 모르겠습니다. 예외는 다음과 같다 :

Token invalid - Invalid AuthSub token. 

내가 https로 조금 주위 놀았다 : HTTP 대 // : 피드의 URL 및 범위 URL에 대한 //하지만, 작은 성공을 질 수 있습니다 I의 천국이다 t는 특정 조합을 시도했다.

답변

0

위의 모든 작업이 올바르게 작동하는 것처럼 보이지만 관련성이없는 코딩 오류가 발생했습니다. 레코드의 경우 http와 https는 둘 다 일관되게 사용되는 한 작동합니다 (그렇지 않으면 '범위'오류가 발생합니다).