質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Spring Security

Spring Securityは、Springのサブプロジェクトの一つでWebアプリケーションに必要な機能を追加します。正規ユーザーであるかを確認するための「認証機能」と、ユーザーのアクセスを制御する「認可機能」を簡単に追加することが可能です。

OAuth 2.0

OAuth 2.0(Open Authorization 2.0)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

729閲覧

spring bootを利用したfacebook oauth2認証ログインができません.

1gakiRikuya.

総合スコア10

Spring Security

Spring Securityは、Springのサブプロジェクトの一つでWebアプリケーションに必要な機能を追加します。正規ユーザーであるかを確認するための「認証機能」と、ユーザーのアクセスを制御する「認可機能」を簡単に追加することが可能です。

OAuth 2.0

OAuth 2.0(Open Authorization 2.0)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2019/07/24 13:26

編集2019/07/24 13:38

spring bootを利用したfacebook oauth2認証ログインができません.

spring bootにてoauth2認証を行おうとしています.
ですが, [@EnableOAuth2Sso]アノテーションを利用するためのパッケージをimportしようとすると, どうしても「存在しません」, というエラーになってしまいます.
build.gradleにて

implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.1.RELEASE'

を宣言しているのですが, できません.
どこからどのようにimportすれば良いでしょうか.
ちなみに, このパッケージをimplementationした時点ではエラーは発生しません.

build.gradle

java

1plugins { 2 id 'org.springframework.boot' version '2.1.6.RELEASE' 3 id 'java' 4} 5 6apply plugin: 'io.spring.dependency-management' 7 8group = 'com.teamlab' 9version = '0.0.1-SNAPSHOT' 10sourceCompatibility = '1.8' 11 12configurations { 13 developmentOnly 14 runtimeClasspath { 15 extendsFrom developmentOnly 16 } 17} 18 19repositories { 20 mavenCentral() 21} 22 23dependencies { 24 implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 25 implementation 'org.springframework.boot:spring-boot-starter-security' 26 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 27 implementation 'org.springframework.boot:spring-boot-starter-web' 28 implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.1.RELEASE' 29 developmentOnly 'org.springframework.boot:spring-boot-devtools' 30 runtimeOnly 'com.h2database:h2' 31 runtimeOnly 'mysql:mysql-connector-java' 32 testImplementation 'org.springframework.boot:spring-boot-starter-test' 33 testImplementation 'org.springframework.security:spring-security-test' 34}

OauthController.java

java

1package com.teamlab.OAuthApplication.controller; 2 3import org.springframework.boot.autoconfigure.SpringBootApplication; 4import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 5import org.springframework.stereotype.Controller; 6import org.springframework.web.bind.annotation.GetMapping; 7import org.springframework.web.bind.annotation.RequestMapping; 8import org.springframework.web.bind.annotation.RequestMethod; 9import org.springframework.boot.autoconfigure.security.oauth2.client.*; 10import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; //←ここがimportできませんとなります. 11 12@Controller 13@SpringBootApplication 14@EnableOAuth2Sso //importができないため, このアノテーションも使用できません. 15public class OauthController { 16 17 @RequestMapping(value = "/login", method = RequestMethod.GET) 18 public String login() { 19 return "login"; 20 } 21 22 @RequestMapping(value = "/user", method = RequestMethod.GET) 23 public String user() { 24 return "user"; 25 } 26 27 @RequestMapping(value = "/error", method = RequestMethod.GET) 28 public String error() { 29 return "error"; 30 } 31}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

そのバージョンだと auto-configure はアンサポートです。
facebook もたいしてかわらんはず

oauth2-client を使いましょう。

Spring boot 2.1.5.RELEASE での実装例の一部

SecurityConfiguig

import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity public class SecurityConfiguig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { super.configure(http); http.oauth2Login(); } }

application.yml

spring: security: oauth2: client: registration: google: provider: "google" client-name: "Google" client-id: "[env settings]" client-secret: "[env settings]" redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}" scope: - email - profile

build.gradle

dependencies { implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' }

投稿2019/07/24 15:55

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問