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

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

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

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

Java

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

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Q&A

0回答

1057閲覧

Spring Securityの複数ログイン画面の実装方法について

takoyaki-ccc

総合スコア17

Spring Security

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

Java

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

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

0グッド

1クリップ

投稿2018/07/24 11:56

編集2018/07/25 03:44

皆様初めまして

私は現在、Spring3.2の既存のシステムの改修に関わっています。
そこで既存のログイン画面とは別にログイン画面を設け、新しいログイン画面(管理者用)からは別の認証方法でログインをさせるという処理を実装をしている部分でつまづいております。

以下、Spring security3.2のソースになります

java

1<?xml version="1.0" encoding="UTF-8"?> 2<beans:beans xmlns="http://www.springframework.org/schema/security" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:beans="http://www.springframework.org/schema/beans" 5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 6 xsi:schemaLocation=" 7 http://www.springframework.org/schema/beans 8 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 9 http://www.springframework.org/schema/security 10 http://www.springframework.org/schema/security/spring-security-3.2.xsd 11 http://www.springframework.org/schema/context 12 http://www.springframework.org/schema/context/spring-context.xsd"> 13 14 <!-- 静的リソースは認証対象外 --> 15 <http pattern="/resources/**" security="none"/> 16 <!-- APIリソースは認証対象外 --> 17 <http pattern="/api/**" security="none"/> 18 <!-- Login画面は認証対象外 --> 19 <http pattern="/user/login*" security="none" /> 20 <http pattern="/user/login/error*" security="none" /> 21 22 <!-- 管理者用の設定 start --> 23 <http pattern="/admin**" auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint" > 24 <custom-filter 25 position="FORM_LOGIN_FILTER" 26 ref="applicationUsernamePasswordAuthenticationFilter" /> 27 <logout logout-url="/user/logout" logout-success-url="/user/login?timeout=false" invalidate-session="true" /> 28 </http> 29 <!-- 管理者用の設定 end --> 30 31 <http auto-config="true" authentication-manager-ref="userAuthenticationManager"> 32 <intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" /> 33    <!-- ユーザの設定 --> 34 <form-login 35 login-page="/user/login?timeout=false" 36 default-target-url="/user/index" 37 authentication-failure-url="/user/login/error?errorType=typeMiss" 38 login-processing-url="/j_spring_security_check" 39 always-use-default-target="true" /> 40 <logout logout-url="/user/logout" 41 logout-success-url="/user/login?timeout=false" 42 invalidate-session="true" /> 43 <anonymous granted-authority="ROLE_ANONYMOUS" /> 44 <access-denied-handler error-page="/user/login/error?errorType=noAuthority" /> 45 </http> 46 47 <context:property-placeholder location="classpath:jdbc.properties"/> 48 49 <!-- データソースの設定 --> 50 <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 51 <beans:property name="driverClassName" value="${jdbc.driverClassName}" /> 52 <beans:property name="url" value="${jdbc.url}" /> 53 <beans:property name="username" value="${jdbc.username}" /> 54 <beans:property name="password" value="${jdbc.password}" /> 55 </beans:bean> 56 57 <authentication-manager id="userAuthenticationManager"> 58 <authentication-provider> 59 <password-encoder hash="sha-256" > 60 <salt-source user-property="username" /> 61 </password-encoder> 62 63 <jdbc-user-service data-source-ref="dataSource" 64 users-by-username-query=" 65 select 66 login_id as username 67 , login_password as password 68 , true as enabled 69 from 70 m_login 71 where 72 login_id=? 73 and delete_flg = 0" 74 authorities-by-username-query=" 75 select 76 login_id as username 77 , login_authority as authority 78 from 79 m_login 80 where 81 login_id=?" /> 82 </authentication-provider> 83 </authentication-manager> 84 85 <beans:bean id="userDetailsService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl"> 86 <beans:property name="dataSource" ref="dataSource"/> 87 </beans:bean> 88 89 90 <beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 91 <beans:constructor-arg value="/admin/test" /> 92 </beans:bean> 93 94 <beans:bean id="applicationUsernamePasswordAuthenticationFilter" class="com.capitarise.xxxx.admin.filter.ApplicationUsernamePasswordAuthenticationFilter"> 95 <beans:property name="authenticationManager" ref="adminAuthenticationManager" /> 96 <beans:property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" /> 97 <beans:property name="authenticationFailureHandler" ref="authenticationFailureHandler" /> 98 <beans:property name="filterProcessesUrl" value="/authentication" /> 99 </beans:bean> 100 101 <beans:bean id="authenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"> 102 <beans:property name="defaultTargetUrl" value="/admin/check"/> 103 </beans:bean> 104 105  <!-- 気になる箇所① --> 106 <beans:bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler"> 107 <beans:property name="defaultFailureUrl" value="/admin/test"/> 108 </beans:bean> 109 110 <authentication-manager alias="adminAuthenticationManager"> 111 <authentication-provider ref="applicationUsernamePasswordAuthenticationProvider" /> 112 </authentication-manager> 113 114 <beans:bean id="applicationUsernamePasswordAuthenticationProvider" class="com.capitarise.xxxx.admin.provider.ApplicationUsernamePasswordAuthenticationProvider"> 115 </beans:bean> 116 117</beans:beans>

上記のように修正し「/admin/test」のURLを叩いてみたところ、上記の「ユーザの設定」に記載されている「/user/login?timeout=false」に飛んでしまいました。
私の認識としては、「/admin」の場合は「気になる箇所①」で設定した「/admin/test」に、
それ以外は「/user/login?timeout=false」が最初に開かれる想定であったのですが、私の認識が間違っているようでした・・

どの部分を直せば想定通り「/admin/test」からログインページを開き別の処理を行えるのか、ご存知の方がいらっしゃいましたら、ご教授願えますでしょうか?
宜しくお願い致します。

Springのバージョン:3.2.2
Spring Security:3.2.10
参考サイト

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

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

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

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

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

m.ts10806

2018/07/24 13:03 編集

宿題・宿題代行サイトではないので「課題」と書いてしまうと回答を躊躇う回答者も多いです(自分でやらないと意味がない・身にならないというスタンス。もちろん仕事であっても作業依頼を請け負う場でもないので同様です。) 「質問するときのヒント」を熟読し、もう少し質問の書き方を工夫してみてください。質問は編集することができるので、質問タイトル・本文を調整してください。 https://teratail.com/help/question-tips
takoyaki-ccc

2018/07/25 00:59

>mts10806 様 ご指摘いただきありがとうございます。本文及びソースを修正しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問