Web ベースのフォーム ログイン認証が機能しj_securtiy_check
ています。プログラムによるログイン認証で変更したいと考えています。サーブレットに渡されたユーザー名とパスワードを認証させる適切な方法は何ですか? サーブレットは明らかに保護されていません。
この server.xml レルムで実験を行っています。
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="UserDatabase"
userTable="app_user" userNameCol="login_name" userCredCol="password_value"
userRoleTable="user_perm" roleNameCol="permission_name"
allRolesMode="authOnly" digest="MD5"
/>
この理由は、保護されていない loginServlet にログイン情報を送信する Java Webstart クライアントがあるためです。このサーブレットは現在、JOSSO シングル サインオン サービスに対して認証を行っていますが、これを削除して、単純な tomcat7 認証を最初に使用したいと考えています。その後、最終的に OpenAM に移行します。プログラムで JSSESSIONIDSSO 値を生成し、これを Cookie に詰め込むことができれば。
これは私が見つけたいくつかのコードです。これは認証を呼び出す正しい方法ですか?
ApplicationContextFacade acf = (ApplicationContextFacade) this.getServletContext();
Field privateField = ApplicationContextFacade.class.getDeclaredField("context");
privateField.setAccessible(true);
ApplicationContext appContext = (ApplicationContext) privateField.get(acf);
Field privateField2 = ApplicationContext.class.getDeclaredField("context");
privateField2.setAccessible(true);
StandardContext stdContext = (StandardContext) privateField2.get(appContext);
Realm realm = stdContext.getRealm();
Principal principal = realm.authenticate(loginBean.getUsername(), loginBean.getPassword());
if (principal == null)
{
return 0;
}
GenericPrincipal genericPrincipal = (GenericPrincipal) principal;
System.out.println ("genericPrincipal=" + genericPrincipal.toString());