0

Я хочу добавить аромат Google Plus в код, включенный в этот Tutorial, однако во время входа в систему я получаю следующее предупреждающее сообщение от Log4J.spring-social-google authentication не перенаправляет на страницу формы регистрации

WARN - RestTemplate - запрос GET для «https://www.googleapis.com/plus/v1/people/me» привел к 403 (Запрещено); вызова обработчика ошибок

и вместо перенаправления в регистрационной форме, как это для Facebook и Twitter вкусами я попадаю еще раз на страницу входа в систему.

DEBUG - LoginController - просмотр страницы входа.

Код учебника доступен here. Это те изменения, которые я сделал для него.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>net.petrikainulainen.spring.social.signin</groupId> 
    <artifactId>spring-mvc-normal</artifactId> 
    <packaging>war</packaging> 
    <version>0.1</version> 
    <name>Spring Social Sign In MVC Normal</name> 
    <description> 
     This example demonstrates how you can integration Spring Social 1.1.0, 
     Spring Security 3.2.0, and a "normal" Spring MVC application. 

     You can create an user account by using either "normal" form registration or 
     sign in by using a social media service. 
    </description> 

    <properties> 
     <hibernate.version>4.2.4.Final</hibernate.version> 
     <liquibase.version>3.1.1</liquibase.version> 
     <mysql.connector.version>5.1.26</mysql.connector.version> 
     <slf4j.version>1.7.5</slf4j.version> 
     <spring.version>4.0.0.RELEASE</spring.version> 
     <spring.data.jpa.version>1.4.3.RELEASE</spring.data.jpa.version> 
     <spring.security.version>3.2.0.RELEASE</spring.security.version> 
     <spring.social.version>1.1.2.RELEASE</spring.social.version> 
     <spring.social.facebook.version>2.0.3.RELEASE</spring.social.facebook.version> 
     <spring.social.twitter.version>1.1.2.RELEASE</spring.social.twitter.version> 

     <build.profile.id>dev</build.profile.id> 
     <jdk.version>1.7</jdk.version> 
     <skip.integration.tests>true</skip.integration.tests> 
     <skip.unit.tests>false</skip.unit.tests> 

     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <profiles> 
     <profile> 
      <id>dev</id> 
      <properties> 
       <build.profile.id>dev</build.profile.id> 
      </properties> 
     </profile> 
     <profile> 
      <id>integration-test</id> 
      <properties> 
       <build.profile.id>integration-test</build.profile.id> 
       <skip.integration.tests>false</skip.integration.tests> 
       <skip.unit.tests>true</skip.unit.tests> 
      </properties> 
     </profile> 
    </profiles> 

    <build> 
     <finalName>spring-social-normal-mvc</finalName> 
     <filters> 
      <filter>profiles/${build.profile.id}/config.properties</filter> 
      <filter>profiles/${build.profile.id}/socialConfig.properties</filter> 
     </filters> 
     <resources> 
      <resource> 
       <filtering>true</filtering> 
       <directory>src/main/resources</directory> 
       <excludes> 
        <exclude>**/messages*.properties</exclude> 
       </excludes> 
      </resource> 
      <resource> 
       <filtering>false</filtering> 
       <directory>src/main/resources</directory> 
       <includes> 
        <include>**/messages*.properties</include> 
       </includes> 
      </resource> 
     </resources> 

     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.8</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>copy</goal> 
         </goals> 
         <configuration> 
          <artifactItems> 
           <artifactItem> 
            <groupId>com.github.jsimone</groupId> 
            <artifactId>webapp-runner</artifactId> 
            <version>8.0.24.1</version> 
            <destFileName>webapp-runner.jar</destFileName> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <execution> 
         <id>add-integration-test-sources</id> 
         <phase>generate-test-sources</phase> 
         <goals> 
          <goal>add-test-source</goal> 
         </goals> 
         <configuration> 
          <sources> 
           <source>src/integration-test/java</source> 
          </sources> 
         </configuration> 
        </execution> 
        <execution> 
         <id>add-integration-test-resources</id> 
         <phase>generate-test-resources</phase> 
         <goals> 
          <goal>add-test-resource</goal> 
         </goals> 
         <configuration> 
          <resources> 
           <resource> 
            <directory>src/integration-test/resources</directory> 
           </resource> 
           <resource> 
            <directory>etc/db</directory> 
           </resource> 
          </resources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <!-- Used for unit tests --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.16</version> 
       <configuration> 
        <argLine>${surefireArgLine}</argLine> 
        <!-- Skips unit tests if the value of skip.unit.tests property is true --> 
        <skipTests>${skip.unit.tests}</skipTests> 
        <excludes> 
         <exclude>**/IT*.java</exclude> 
        </excludes> 
       </configuration> 
      </plugin> 
      <!-- Used for integration tests --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-failsafe-plugin</artifactId> 
       <version>2.16</version> 
       <configuration> 
        <argLine>${failsafeArgLine}</argLine> 
       </configuration> 
       <executions> 
        <!-- States that both integration-test and verify goals of the Failsafe Maven plugin are executed. --> 
        <execution> 
         <id>integration-tests</id> 
         <goals> 
          <goal>integration-test</goal> 
          <goal>verify</goal> 
         </goals> 
         <configuration> 
          <!-- Skips integration tests if the value of skip.integration.tests property is true --> 
          <skipTests>${skip.integration.tests}</skipTests> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.jacoco</groupId> 
       <artifactId>jacoco-maven-plugin</artifactId> 
       <version>0.7.5.201505241946</version> 
       <executions> 
        <!-- 
         Prepares the property pointing to the JaCoCo runtime agent which 
         is passed as VM argument when Maven the Surefire plugin is executed. 
        --> 
        <execution> 
         <id>pre-unit-test</id> 
         <goals> 
          <goal>prepare-agent</goal> 
         </goals> 
         <configuration> 
          <!-- Sets the path to the file which contains the execution data. --> 
          <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> 
          <!-- 
           Sets the name of the property containing the settings 
           for JaCoCo runtime agent. 
          --> 
          <propertyName>surefireArgLine</propertyName> 
         </configuration> 
        </execution> 
        <!-- 
         Ensures that the code coverage report for unit tests is created after 
         unit tests have been run. 
        --> 
        <execution> 
         <id>post-unit-test</id> 
         <phase>test</phase> 
         <goals> 
          <goal>report</goal> 
         </goals> 
         <configuration> 
          <!-- Sets the path to the file which contains the execution data. --> 
          <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> 
          <excludes> 
           <exclude>net/petrikainulainen/spring/social/signinmvc/config/**</exclude> 
          </excludes> 
          <!-- Sets the output directory for the code coverage report. --> 
          <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>${jdk.version}</source> 
        <target>${jdk.version}</target> 
        <encoding>${project.build.sourceEncoding}</encoding> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <encoding>${project.build.sourceEncoding}</encoding> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.liquibase</groupId> 
       <artifactId>liquibase-maven-plugin</artifactId> 
       <version>${liquibase.version}</version> 
       <dependencies> 
        <dependency> 
         <groupId>mysql</groupId> 
         <artifactId>mysql-connector-java</artifactId> 
         <version>${mysql.connector.version}</version> 
        </dependency> 
       </dependencies> 
       <configuration> 
        <propertyFile>target/classes/liquibase.properties</propertyFile> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.mortbay.jetty</groupId> 
       <artifactId>jetty-maven-plugin</artifactId> 
       <version>8.1.12.v20130726</version> 
       <configuration> 
        <stopKey>todostop</stopKey> 
        <stopPort>9999</stopPort> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <!-- Spring Framework --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-aop</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-beans</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context-support</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-jdbc</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-tx</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <!-- Spring Security --> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-core</artifactId> 
      <version>${spring.security.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>${spring.security.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-taglibs</artifactId> 
      <version>${spring.security.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>${spring.security.version}</version> 
     </dependency> 

     <!-- Use Apache HttpClient as HTTP Client --> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient</artifactId> 
      <version>4.3.2</version> 
     </dependency> 

     <!-- Spring Social --> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-config</artifactId> 
      <version>${spring.social.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-core</artifactId> 
      <version>${spring.social.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-security</artifactId> 
      <version>${spring.social.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-web</artifactId> 
      <version>${spring.social.version}</version> 
     </dependency> 
     <!-- Spring Social Facebook --> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-facebook</artifactId> 
      <version>${spring.social.facebook.version}</version> 
      <exclusions> 
       <exclusion> 
        <artifactId>spring-social-core</artifactId> 
        <groupId>org.springframework.social</groupId> 
       </exclusion> 
       <exclusion> 
        <artifactId>spring-social-config</artifactId> 
        <groupId>org.springframework.social</groupId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <!-- Spring Social Twitter --> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-twitter</artifactId> 
      <version>${spring.social.twitter.version}</version> 
     </dependency> 
     <!-- Spring Social Google --> 
     <dependency> 
      <groupId>org.springframework.social</groupId> 
      <artifactId>spring-social-google</artifactId> 
      <version>1.0.0.RELEASE</version> 
     </dependency> 
     <!-- CGLIB --> 
     <dependency> 
      <groupId>cglib</groupId> 
      <artifactId>cglib</artifactId> 
      <version>2.2.2</version> 
     </dependency> 

     <!-- Hibernate Validator --> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-validator</artifactId> 
      <version>4.2.0.Final</version> 
     </dependency> 

     <!-- Sitemesh --> 
     <dependency> 
      <groupId>org.sitemesh</groupId> 
      <artifactId>sitemesh</artifactId> 
      <version>3.0-alpha-2</version> 
     </dependency> 

     <!-- Servlet API 3.0 --> 
     <dependency> 
      <groupId>org.glassfish</groupId> 
      <artifactId>javax.servlet</artifactId> 
      <version>3.0</version> 
      <scope>provided</scope> 
     </dependency> 

     <!-- JSTL --> 
     <dependency> 
      <groupId>javax.servlet.jsp</groupId> 
      <artifactId>jsp-api</artifactId> 
      <version>2.1</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.1.2</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>taglibs</groupId> 
      <artifactId>standard</artifactId> 
      <version>1.1.2</version> 
      <scope>compile</scope> 
     </dependency> 

     <!-- Spring Data JPA --> 
     <dependency> 
      <groupId>org.springframework.data</groupId> 
      <artifactId>spring-data-jpa</artifactId> 
      <version>${spring.data.jpa.version}</version> 
     </dependency> 
     <!-- Hibernate --> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>${hibernate.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>${hibernate.version}</version> 
     </dependency> 

     <!-- MySQL --> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>${mysql.connector.version}</version> 
     </dependency> 

     <!-- PostgreSQL --> 
     <dependency> 
      <groupId>org.postgresql</groupId> 
      <artifactId>postgresql</artifactId> 
      <version>9.3-1102-jdbc41</version> 
     </dependency> 

     <!-- H2 Database --> 
     <dependency> 
      <groupId>com.h2database</groupId> 
      <artifactId>h2</artifactId> 
      <version>1.3.173</version> 
     </dependency> 

     <!-- BoneCP --> 
     <dependency> 
      <groupId>com.jolbox</groupId> 
      <artifactId>bonecp</artifactId> 
      <version>0.7.1.RELEASE</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-lang3</artifactId> 
      <version>3.1</version> 
     </dependency> 

     <!-- Logging --> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>${slf4j.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>${slf4j.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 

     <!-- Joda --> 
     <dependency> 
      <groupId>joda-time</groupId> 
      <artifactId>joda-time</artifactId> 
      <version>2.3</version> 
     </dependency> 

     <dependency> 
      <groupId>org.jadira.usertype</groupId> 
      <artifactId>usertype.spi</artifactId> 
      <version>3.0.0.GA</version> 
     </dependency> 

     <dependency> 
      <groupId>org.jadira.usertype</groupId> 
      <artifactId>usertype.core</artifactId> 
      <version>3.0.0.GA</version> 
     </dependency> 

     <!-- TESTING DEPENDENCIES --> 
     <dependency> 
      <groupId>org.assertj</groupId> 
      <artifactId>assertj-core</artifactId> 
      <version>1.6.0</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.hamcrest</groupId> 
      <artifactId>hamcrest-all</artifactId> 
      <version>1.3</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
      <exclusions> 
       <exclusion> 
        <artifactId>hamcrest-core</artifactId> 
        <groupId>org.hamcrest</groupId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.mockito</groupId> 
      <artifactId>mockito-all</artifactId> 
      <version>1.9.5</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.catch-exception</groupId> 
      <artifactId>catch-exception</artifactId> 
      <version>1.2.0</version> 
      <exclusions> 
       <exclusion> 
        <groupId>org.mockito</groupId> 
        <artifactId>mockito-core</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-test</artifactId> 
      <version>${spring.version}</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.github.springtestdbunit</groupId> 
      <artifactId>spring-test-dbunit</artifactId> 
      <version>1.1.0</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.dbunit</groupId> 
      <artifactId>dbunit</artifactId> 
      <version>2.4.9</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.liquibase</groupId> 
      <artifactId>liquibase-core</artifactId> 
      <version>${liquibase.version}</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

ресурсы/application.properties - добавлены следующие строки

#Google 
spring.social.google.appId=[here my appId] 
spring.social.google.appSecret=[here my appSecret] 

Остальные изменения представлены в репозитории GitHub я имею forked.

приложение должно быть начато

mvn jetty:run -P dev -Djetty.port=8090 

jetty.port может быть, конечно, опущена, если порт 8080 бесплатно, чтобы быть связанным.

Я прочитал где-то, что запрос Google Plus должен быть POST, но он не дал мне никакого другого результата, поэтому код в login.jsp выглядит следующим образом

<div class="row social-button-row"> 
    <div class="col-lg-4"> 
     <!--form method="POST" action="${pageContext.request.contextPath}/auth/google?scope=email"> 
      <button type="submit" class="btn btn-google-plus"><i class="icon-google-plus"></i> | <spring:message code="label.google.sign.in.button"/></button> 
     </form--> 
     <a href="${pageContext.request.contextPath}/auth/google?scope=email"><button type="submit" class="btn btn-google-plus"><i class="icon-google-plus"></i> | <spring:message code="label.google.sign.in.button"/></button></a> 
    </div> 
</div> 

Кто-нибудь сталкивался и решил эту проблему? С Twitter и Facebook он работает без проблем.

EDIT

Я заметил, что после того, как рукопожатие с Facebook или Twitter, я попадаю на /singup страницу, если учетная запись еще не существует. Однако с Google Plus я перенаправляюсь на /signin, который, конечно же, перенаправляется на /login, потому что в базе данных еще нет учетной записи пользователя.

ответ

0

Проблема заключалась в том, что Google+ API не был включен для моего приложения в Google Developers' Console. Почему он не включен по умолчанию, я понятия не имею.

Также этот project помог мне много узнать причину проблемы.

WARNING:  Response body: { 
"error": { 
    "errors": [ 
    { 
    "domain": "usageLimits", 
    "reason": "accessNotConfigured", 
    "message": "Access Not Configured. The API (Google+ API) is not enabled for your project. Please use the Google Developers Console to update your configuration.", 
    "extendedHelp": "https://console.developers.google.com" 
    } 
    ], 
    "code": 403, 
    "message": "Access Not Configured. The API (Google+ API) is not enabled for your project. Please use the Google Developers Console to update your configuration." 
} 
} 

Google+ API enable in GDC

+0

Есть несколько API, предоставляемых Google, некоторые даже требуют денег, чтобы позволить (я думаю Compute Engine). У меня была такая же проблема с API Карт Google, она также не была включена по умолчанию. Я собирался ответить на все то же самое, но я думал, что вы уже знали, и у меня есть шанс получить первую награду xD –

+0

Привет, У меня есть некоторые проблемы с Spring Social Twitter. В течение некоторого времени было возможно получить данные электронной почты из учетной записи пользователя Twitter. Что нужно сделать, так это специально запросить такое разрешение Twitter. Я сделал это, и даже если метод 'getEmail'' UserProfile возвращает 'null' для Twitter. Я открыл [выпуск] (https://github.com/spring-projects/spring-social-twitter/issues/97), что в репозитории Spring Social Twitter GitHub. Если вы в состоянии мне помочь, я продолжу этот вопрос и дам щедрость в ваши руки. :) Я использую SST версию 1.1.2.RELEASE. – Jagger

+0

Хорошо, я рассмотрю это. Я провел несколько экспериментов с Spring Social Twitter для Streams, но не с электронной почтой. Я вижу, могу ли я получить электронную почту Пользователей. :) –