これらの2つのJavaScript関数を作成しました。
function addIpSubmit()
{
var theForm = document.getElementById("login_form");
var userName = theForm.username.value;
userName = theForm.clientip.value + "#" + userName;
theForm.j_username.value = userName;
if(validate_required(theForm.username, "User ID is required"))
{
if( validate_required(theForm.j_password, "Password is required"))
{
theForm.submit();
}
}
}
function validate_required(field, alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);
return false;
}
else
{
return true;
}
}
}
addIpSubmitはログインボタンから呼び出されます。あなたは私がIPアドレスを隠しフィールドに入れるためのbeanを持っているのを見ることができます。 j_username JAASフィールドも隠され、addIpSubmit()関数によって埋められます。
<input id="clientip" type="hidden" name="clientip" value="#{loginMBean.ip}"/>
<input id="j_username" type="hidden" name="j_username" />
<input type="button" name="OtherLogin" value="Login" onclick="addIpSubmit()" />
これは、ユーザー名にipを指定し、JAAS送信機能を呼び出します。その後、ログインモジュールで私はIPアドレスとユーザー名を取得します。
String userid = username;
if(username.contains("#"))
{
ip = username.split("#")[0];
userid = username.split("#")[1];
}
ジャストFacesContext.getCurrentInstance()。getExternalContext()。はgetRemoteUser()は今でip#ユーザーIDを持っていることを覚えておいてください。
JSF Beanを使用して、隠しフィールドのページにIPアドレスを取得できます。問題は、JAASログインモジュールに渡すことです。 – Martlark