Spring Security 3.0 Google Apps Открыть идентификатор Войти в Использование OpenID4JAVA

StackOverflow https://stackoverflow.com/questions/4223214

Вопрос

Я пытаюсь войти в систему, используя открытый идентификатор Google Apps с библиотекой OpenID4JAVA.

Я открываю услугу пользователя, используя следующий код в классе потребителей:


        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);

Далее я получаю параметры из HTTP-запроса и в свойстве OpenID.CLAYAMED_ID я получаю »http://domain.com/Openid?id=..... "И если я попытаюсь проверить ответ consumerManager.verify(receivingURL.toString(), openidResp, discovered); Исключение брошено: org.openid4java.discovery.yadis.YadisException: 0x706: GET failed on http://domain.com/Openid?id=.... : 404:Not Found.

Чтобы избежать исключения, я попытался изменить список параметров, изменяющий значение «http://domain.com/Openid?id=....." к "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);
        }

Теперь метод consumerManager.verify Не бросается больше исключения, но его статус изменен на неудаче. В журнале появляются следующие ошибки


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.

Я видел на форуме подобную проблему, но решение было изменено consumerManager.verify к consumerManager.verifyNonce. Отказ Я не уверен, что использовать этот метод не создаст проблему безопасности. Есть ли у вас есть идея, что я должен изменить, чтобы сделать мой открытый идентификатор потребителя для работы с OpenID Apps Google?

Это было полезно?

Решение

Приложения Google используются немного другой процесс обнаружения, чем то, что поддерживается в базовой версии OpenID4JAVA. Есть дополнительная библиотека в http://code.google.com/p/step2/ что вы можете бороться с полезными (и борт более высокого уровня в http://code.google.com/p/openid-filter/.)

Я не знаю ни с кем, кто сделал весной интеграцию безопасности с модифицированными классами STEP2, но не должно быть слишком сложно, чтобы изменить код, чтобы настроить шаг2 соответственно. Он построен на OpenID4JAVA и код для написания полагающейся стороны в основном то же самое.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top