我正在尝试使用Apache HttpClient Java库对使用基于表单的身份验证(例如,facebook.com)的网站进行身份验证.
使用这个网站的程序作为一个主要的例子:http://www.elitejavacoder.com/2013/10/http-client-form-based-authentication.html,我能够做到 - 但有一些事情,我我不理解这个节目.这是代码:
package com.elitejavacoder.http.client;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpClientFormAuthentication {
public static void main(String[] agrs) {
String host = "yourhostname.com";
int port = 8080;
String protocol = "http";
DefaultHttpClient client = new DefaultHttpClient();
try {
HttpHost httpHost = new HttpHost(host, port, protocol);
client.getParams().setParameter(ClientPNames.DEFAULT_HOST, httpHost);
HttpGet securedResource = new …Run Code Online (Sandbox Code Playgroud) java j-security-check form-authentication apache-httpclient-4.x
这是我在web.config上的设置:
<authentication mode="Forms">
<forms loginUrl="~/Login/Login" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
在我的控制器上,我几乎没有动作,在我添加[AllowAnonymous]装饰的每个动作上,但我正在从每个动作重定向到Login动作.
我甚至试图将[AllowAnonymous]装饰添加到控制器,但它没有帮助.
谢谢
我有以下代码
int intTimeout = (FormsAuthentication.Timeout.Hours * 60) +
FormsAuthentication.Timeout.Minutes;
var authTicket = new FormsAuthenticationTicket(1, Utility.userCookie, DateTime.Now,
DateTime.Now.AddMinutes(intTimeout), true, cookieValue);
string strEncryptedTicket = HttpUtility.UrlEncode(FormsAuthentication.Encrypt(authTicket));
var authCookie = new HttpCookie(Utility.userCookie, strEncryptedTicket);
authCookie.Expires = authTicket.Expiration;
//FormsAuthentication.RedirectFromLoginPage("", false);
authCookie.Secure = FormsAuthentication.RequireSSL;
//authCookie.Secure = true;
HttpContext.Current.Response.Cookies[Utility.userCookie].Expires = authTicket.Expiration;
HttpContext.Current.Response.Cookies[Utility.userCookie].Value = authCookie.Value;
Run Code Online (Sandbox Code Playgroud)
在web.config下面
<authentication mode="Forms">
<forms timeout="2" slidingExpiration="true" requireSSL="true" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我一直打到页面链接,它仍然会在2分钟后到期.
c# cookies asp.net-mvc form-authentication slidingexpiration
def login_page(request):
form = LoginForm(request.POST or None)
context = {
"form": form
}
print("User logged in")
#print(request.user.is_authenticated())
if form.is_valid():
print(form.cleaned_data)
username = form.cleaned_data.get("username")
password = form.cleaned_data.get("password")
user = authenticate(request, username=username, password=password)
print(user)
print(request.user.is_authenticated())
if user is not None:
print(request.user.is_authenticated())
login(request, user)
# Redirect to a success page.
context['form'] = LoginForm()
return redirect("/")
else:
# Return an 'invalid login' error message.
print("Error")
return render(request, "auth/login.html", context)
Run Code Online (Sandbox Code Playgroud)
你好,我已经开始在 Django 中玩了,但是在一个教程中,当导师点击提交时,它会验证用户......我已经发现堆栈溢出几乎相同的问题,但问题是,一个人有一个字符串变量( username = 'username' )但问题是当我单击提交时出现错误:
User logged in
{'username': 'test123', 'password': 'test'}
None …Run Code Online (Sandbox Code Playgroud) 我正在使用MVC3进行表单身份验证.除了一件事,一切都很好.我想在他/她再次尝试访问LogOn页面时将经过身份验证的用户重定向到另一个页面.那我该怎么做呢?
我在站点登录期间收到此错误.如何解决此问题.
我正在阅读ASP.NET中的表单身份验证,并且无法理解某些时刻:
James输入用户名密码,它们保存在数据库中.来自用户名的cookie将创建,加密并附加到响应中.据我所知,当我们收到请求时,我们需要认识到收到的cookie来自James,因此我们可以显示他的自定义页面.
我想了解的是系统将如何检索用户名表单cookie然后从db加载他的信息?
我创建了一个Web应用程序并添加了一个用于错误记录的ELMAH模块.它正在使用我的本地开发环境:当我访问URL http:// localhost:52584/elmah.axd时,它显示了一个有效的页面:

当我在天蓝色门户网站上传后测试它时,它会显示一个错误页面:

我需要为Azure平台做什么特定配置吗?
此外,我已经在我的Web应用程序上进行了表单身份验证,因此当我尝试elmah.axd时,它将重定向到登录页面,我需要先登录.我想删除该表单身份验证,尤其是对于elmah.axd.我怎样才能实现这一目标?
我正在使用angularjs和Web API.为了验证用户身份,我使用FormAuthenticationTicket(我只使用用户数据创建票证,加密它然后返回到客户端).当客户端发送请求时,他将此加密的cookie添加到其请求的标头中.
在远程服务器上,我解密了故障单,并验证该用户是否合法.在localhost上它完美无缺.在服务器上我有一个错误,并在很短的时间后没有识别用户.经过多次调试后,我注意到有时当服务器尝试解密票证时,他会遇到异常:"加密操作期间发生错误"
我搜索了这个错误,根据我的理解,错误是因为服务器尝试用另一个机器密钥解密票证.
想想也许在web.config中设置机器密钥会解决问题,但我发现的所有文章都在谈论早期的.net框架版本(我使用的是4.5.1).
这是我收到错误时:
FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(enc_ticket);
Run Code Online (Sandbox Code Playgroud)
这是我的web.config:
<configuration><appSettings></appSettings>
<system.web> <compilation debug="true" targetFramework="4.5.1">
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5.1" />
<customErrors mode="Off"/>
<trust level="Full" />
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud) 我们正在将我们的 GWT 应用程序部署到 Wildly 8.1.0 服务器并使用表单身份验证以确保安全。我们的问题是,每次我们的客户的用户名或密码中包含特殊字符(æøåäëö 等)时,他们都无法登录。
我见过其他人有同样的问题:
https://developer.jboss.org/thread/42859?tstart=0
UTF-8 编码的 j_security_check 用户名在 Tomcat 领域中被错误地解码为 Latin-1
但是他们使用的是 Tomcat/Apache/Spring 等,所以我很难找到适合我们设置的解决方案。
Wildly/Undertow 是否有任何配置参数,以便我们在用户登录时确保使用 UTF-8 编码?
我们的 web.xml:
<login-config>
<auth-method>FORM</auth-method>
<realm-name>project-security-policy</realm-name>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/error.html</form-error-page>
</form-login-config>
</login-config>
Run Code Online (Sandbox Code Playgroud)
登录表格:
<form name="loginform" method="post" autocomplete="on" action="j_security_check" accept-charset="UTF-8 ISO-8859-1" onsubmit="return validate_login_form();">
<input id="usernameInput" name="j_username" class="form-input" type="text" placeholder="Username" autofocus="">
<input id="passwordInput" name="j_password" class="form-input" type="password" placeholder="Password">
<input id="submitButton" type="submit" value="Login">
</form>
Run Code Online (Sandbox Code Playgroud) 我正在加密密码,并使用FormsAuthenticationTicket将其存储到会话值,当我检索到密码时,我无法解密密码。
如下加密
string pw="xyz";
FormsAuthenticationTicket ticketpw = new FormsAuthenticationTicket(pw, true, 1000);
string securepw = FormsAuthentication.Encrypt(ticketpw);
Session["password"] = securepw;
Run Code Online (Sandbox Code Playgroud)
我试图像下面尝试解密
1
FormsAuthenticationTicket ticketuname = new FormsAuthenticationTicket(pw, true, 1000);
string secureuname = FormsAuthentication.Decrypt(pw);
Session["password"] = securepw;
Run Code Online (Sandbox Code Playgroud)
试试2
string securepw=FormsAuthentication.Decrypt(pw);
Session["password"] = securepw;
Run Code Online (Sandbox Code Playgroud)
错误-无法将FormAuthenticationTicket转换为字符串
请考虑这种情况:
我有一个项目,它包含一些网页Active Direcotry.我为我的所有网页添加表单身份验证.例如:
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://testdomain.test.com/CN=Users,DC=testdomain,DC=test,DC=com" />
</connectionStrings>
<authorization>
<deny users="?" />
</authorization>
Run Code Online (Sandbox Code Playgroud)
现在我想从表单身份验证中排除一些页面.web.config如何排除某些页面?
谢谢
c# ×5
asp.net ×4
asp.net-mvc ×2
.net ×1
azure ×1
cookies ×1
django ×1
ejb ×1
elmah ×1
jakarta-ee ×1
java ×1
python-3.x ×1
web-config ×1
wildfly ×1
wildfly-8 ×1