2010-11-19 8 views
7

Próbuję zalogować się przy użyciu otwartego identyfikatora Google Apps przy użyciu biblioteki OpenID4Java.Spring Security 3.0 Google Apps - otwórz identyfikator przy użyciu OpenID4Java

odkrywam obsługę użytkownika przy użyciu następującego kodu w klasie konsumentów:

 

     try 
     { 
      discoveries = consumerManager.discover(identityUrl); 
     } 
     catch (DiscoveryException e) 
     { 
      throw new OpenIDConsumerException("Error during discovery", e); 
     } 

     DiscoveryInformation information = consumerManager.associate(discoveries); 
     HttpSession session = req.getSession(true); 
     session.setAttribute(DiscoveryInformation.class.getName(), information); 
     AuthRequest authReq; 

     try 
     { 
      authReq = consumerManager.authenticate(information, returnToUrl, realm); 

      // check for OpenID Simple Registration request needed 
      if (attributesByProvider != null || defaultAttributes != null) 
      { 
       //I set the attributes needed for getting the email of the user 
      } 
     } 
     catch (Exception e) 
     { 
      throw new OpenIDConsumerException("Error processing ConumerManager authentication", e); 
     } 

     return authReq.getDestinationUrl(true); 
 

Następny dostaję parametry z żądania HTTP oraz w nieruchomości openid.claimed_id otrzymam „http://domain.com/openid?id= ....” i jeśli spróbuję zweryfikować odpowiedź, zostanie zgłoszony wyjątek: org.openid4java.discovery.yadis.YadisException: 0x706: GET failed on http://domain.com/openid?id= ... : 404:Not Found.

Aby uniknąć wyjątek próbowałem zmodyfikować listę parametrów Zmiana wartości „http://domain.com/openid?id= ....” do „https://www.google.com/a/domain.com/openid?id= ....”

 

// extract the receiving URL from the HTTP request 
     StringBuffer receivingURL = request.getRequestURL(); 
     String   queryString = request.getQueryString(); 

     // extract the parameters from the authentication response 
     // (which comes in as a HTTP request from the OpenID provider) 
     ParameterList  openidResp = new ParameterList(request.getParameterMap()); 
     Parameter endPoint = openidResp.getParameter("openid.op_endpoint"); 
     if (endPoint != null && endPoint.getValue().startsWith("https://www.google.com/a/")) 
     {   
      Parameter parameter = openidResp.getParameter("openid.claimed_id"); 
      if (parameter != null) 
      { 
       String value = "https://www.google.com/a/" + parameter.getValue().replaceAll("http://", ""); 
       openidResp.set(new Parameter("openid.claimed_id", value)); 
       queryString = queryString.replaceAll("openid.claimed_id=http%3A%2F%2F", "openid.claimed_id=https%3A%2F%2Fwww.google.com%2Fa%2F"); 
      } 
      parameter = openidResp.getParameter("openid.identity"); 
      if (parameter != null) 
      { 
       String value = "https://www.google.com/a/" + parameter.getValue().replaceAll("http://", ""); 
       openidResp.set(new Parameter("openid.identity", value)); 
       queryString = queryString.replaceAll("openid.claimed_id=http%3A%2F%2F", "openid.claimed_id=https%3A%2F%2Fwww.google.com%2Fa%2F"); 
      } 
     } 

     if ((queryString != null) && (queryString.length() > 0)) 
     { 
      receivingURL.append("?").append(queryString); 
     } 

     // retrieve the previously stored discovery information 
     DiscoveryInformation discovered = (DiscoveryInformation) request.getSession().getAttribute(DiscoveryInformation.class.getName()); 

     // verify the response 
     VerificationResult verification; 

     Map userDetails = new HashMap(); 

     try 
     { 
      verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered); 

      // check for OpenID Simple Registration request needed 
      if (attributesByProvider != null || defaultAttributes != null) 
      { 
       //Here I get the value of requested attributes 
      } 
     } 
     catch (Exception e) 
     { 
      throw new OpenIDConsumerException("Error verifying openid response", e); 
     } 

     // examine the verification result and extract the verified identifier 
     Identifier     verified = null; 
     if (verification != null) 
     { 
      verified = verification.getVerifiedId(); 
     } 
     OpenIDAuthenticationToken returnToken; 
     List  attributes = null; 

     if (verified != null) 
      returnToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, verified.getIdentifier(), "some message", attributes); 
     else 
     { 
      Identifier id = discovered.getClaimedIdentifier(); 
      return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE, id == null ? "Unknown" : id.getIdentifier(), "Verification status message: [" + verification.getStatusMsg() + "]", attributes); 
     } 
 

Teraz metoda consumerManager.verify już nie rzuca wyjątek, ale jego status zostaje zmieniony na nieudany. W dzienniku pojawią się następujące błędy

 

09:46:45,424 ERROR ConsumerManager,http-80-1:1759 - No service element found to match the ClaimedID/OP-endpoint in the assertion. 
09:46:45,428 ERROR ConsumerManager,http-80-1:1183 - Discovered information verification failed. 
 

Widziałem na forum podobny problem, ale rozwiązanie było zmienić consumerManager.verify do consumerManager.verifyNonce. Nie jestem pewien, czy użycie tej metody nie spowoduje problemu z bezpieczeństwem. Czy masz pojęcie, co powinienem zmienić, aby mój otwarty id konsument współpracował z Google Apps openid?

Odpowiedz

0

Google Apps wykorzystuje nieco inny proces wykrywania niż to, co jest obsługiwane w podstawowej wersji OpenID4Java. Istnieje biblioteka dodatków pod adresem http://code.google.com/p/step2/, z której możesz walczyć (i na wyższym poziomie w http://code.google.com/p/openid-filter/).

Nie znam nikogo, kto dokonał integracji Spring Security ze zmodyfikowanymi klasami Step2, ale nie powinien. • zbyt trudne jest zmodyfikowanie kodu, aby odpowiednio skonfigurować Krok 2. Jest zbudowany na OpenID4Java, a kod do napisania strony ufającej jest w większości taki sam.

Powiązane problemy