我希望用户能够通过HTTP基本身份验证模式登录.
问题是我还希望他们能够再次注销 - 奇怪的是,浏览器似乎并不支持.
这被认为是一种社交黑客风险 - 用户将其机器解锁并且浏览器打开,而其他人可以轻松地访问该网站.请注意,仅关闭浏览器选项卡不足以重置令牌,因此用户可能很容易错过.
所以我想出了一个解决方法,但这是一个完全的问题:
1)将它们重定向到Logoff页面
2)在该页面上激活一个脚本到ajax加载另一个带有伪凭证的页面:
$j.ajax({
url: '<%:Url.Action("LogOff401", new { id = random })%>',
type: 'POST',
username: '<%:random%>',
password: '<%:random%>',
success: function () { alert('logged off'); }
});
Run Code Online (Sandbox Code Playgroud)
3)应该总是第一次返回401(强制传递新凭据),然后只接受伪凭证:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult LogOff401(string id)
{
// if we've been passed HTTP authorisation
string httpAuth = this.Request.Headers["Authorization"];
if (!string.IsNullOrEmpty(httpAuth) &&
httpAuth.StartsWith("basic", StringComparison.OrdinalIgnoreCase))
{
// build the string we expect - don't allow regular users to pass
byte[] enc = Encoding.UTF8.GetBytes(id + ':' + id);
string expected …Run Code Online (Sandbox Code Playgroud) 我在控制器上有一个注销动作,如下所示:
public ActionResult Logoff()
{
var x = Request.IsAuthenticated;
var y = User.Identity.IsAuthenticated;
FormsAuthentication.SignOut();
Session.Abandon();
var a = Request.IsAuthenticated;
var b = User.Identity.IsAuthenticated;
return View();
}
Run Code Online (Sandbox Code Playgroud)
但是,x,y,a和b都是正确的.因此,当我的视图呈现时,它仍然表现得好像用户已登录.有人可以提供解决方案和/或解释吗?
我已经根据django rest框架Docs实现了令牌认证.
从我读到的形式来看,DRF的令牌认证非常简单 - 每个用户一个令牌,令牌不会过期并且始终有效(我是对的吗?).
我知道有更好的做法,但是现在DRF令牌认证对我来说很好.
我的问题是 -使用普通DRF令牌身份验证注销的最佳做法是什么?
我的意思是,当用户注销时,我应该从客户端删除令牌吗?然后登录再次获取令牌?我应该删除令牌并生成一个新令牌吗?
有经验的人吗?
login token logout django-rest-framework http-token-authentication
嘿,当同一个用户登录其他地方时,我正试图让我的php网站基本上"注销"(session_destroy()).有没有办法做到这一点?远程销毁特定会话?
谢谢你们!
斯科特
一个非常简单的要求.登录到Web J2EE 6应用程序后,如何让用户再次注销?
我见过的大多数(全部?)书籍和教程都展示了如何将login/loginerror页面添加到他们的应用程序中,并使用"j_security_check"方法演示安全主体/角色/领域等的使用 - 一切都很好.但是,目前尚不清楚如何赋予用户注销权.实际上,如何在会话超时等之后强制退出?
我正在尝试使用j_spring_security_logout设置我的应用程序的logut但由于某种原因它无法正常工作,我一直收到404错误.
我正在调用这样的函数:
<a href="<c:url value="/j_spring_security_logout"/>"><img border="0" id="logout" src="./img/logout.png" /></a>
我在WebContent/jsp/my应用程序主页面中,登录和注销页面在WebContent/login /中.
我还检查了Spring安全注销的其他帖子问题但是那里给出的解决方案对我不起作用.
在这里你可以看到我的web.xml
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
这是我的spring-security.xml
<http auto-config="true">
<intercept-url pattern="/*" access="ROLE_USER" />
<form-login login-page="/login/login.jsp"
authentication-failure-url="/login/errorLogin.jsp"/>
<logout logout-success-url="/" logout-url="/login/logout.jsp" />
</http>
<beans:bean id="myAuthenticationProvider"
class="myapp.web.authentication.WSAuthenticationProvider">
</beans:bean>
<authentication-manager>
<authentication-provider ref="myAuthenticationProvider"/>
</authentication-manager>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我在rails 3.2.3和capybara上使用ruby来帮助创建请求规范.我的目标是创建一个测试注销的规范请求.网页:
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
Welcome <%= current_user.first_name + " "+ current_user.last_name%>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<a href="#">
<%= link_to "Sign out", destroy_user_session_path, :method => :delete%>
</a>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
对于测试,我有
describe "sign out" do
it "should let user to sign out" do
login_as user, :scope => :user
# click_on "Welcome #{user.first_name} #{user.last_name}"
# Now click on Sign out
end
end
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用capybara点击退出,因为它位于下拉菜单中,因此在页面上不可见.有人知道吗 ?
有没有其他方法可以点击下拉菜单中的元素?
我希望能够以编程方式注销所有登录用户.如何在某些事件上强制注销所有用户?
我使用以下代码从我的系统注销用户.
/**
* This function helps to set the session attribute for the present user to null and then
* removes the attribute itself and this helps in clearing the session
* @param request
* @param response
*/
@RequestMapping(value = AuthConstants.EXIT, method = RequestMethod.POST)
public void exitPrime(HttpServletRequest request, HttpServletResponse response) {
/*Getting session and then invalidating it*/
HttpSession session = request.getSession(false);
if(request.isRequestedSessionIdValid() && session != null)
{
session.invalidate();
}
}
Run Code Online (Sandbox Code Playgroud)
这导致成功注销,但登录时提供的JSESSION ID仍然保留在浏览器中,因为对于任何新用户,在登录时再次使用相同的JSESSION ID.我希望JSESSIONID cookie仅对当前会话有效,一旦用户注销,它将被销毁或无效以便下次完成登录.我的登录代码如下: -
/**
* This method allows …Run Code Online (Sandbox Code Playgroud) 我正在研究使用OpenID connect作为我们的企业应用程序(面向消费者)的SSO协议.一般来说,它的大多数方面都符合我们的需求,除了它处理单一注销的能力,并希望得到一些指导.
我有机会回顾最新的OIDC会话管理规范,以及涉及类似主题的几个堆栈溢出问题:
正如ping所提到的那样,单个注销的处理方式与SAML2不同,因为它更加以用户为中心.这一切都很好,但它仍然不适合实际单点注销的需要.具体来说,以用户为中心的处理(通过有点kludgy iframe通信)仅适用于当前浏览器视图,但不适用于当前未被查看的RP.
例如,用户使用特定的OP登录RP A,B和C. 单点注销只会触发浏览器正在查看的RP的注销; 这将使其他会话挥之不去,这可能是一个安全问题.(如果我错误地分析了这个,请更正).
我已经看到一些在协议之外工作的解决方案(例如父域cookie,或者可能(??)相同的会话存储)但遗憾的是这些解决方案不适合我的需求.
我试图看看我是否可能错过了有关OIDC规范的内容,该规范提出了一个单一的注销协议,涵盖类似于SAML2自己的单一注销的用例?(可能是某些直接OP-> RP通信?甚至是客户端"迭代直通RP"注销?).或者我真的离开了自己为它开发专有解决方案?
BTW,也很好奇是否已经在OIDC委员会讨论过这个问题(我相信它已经有了),以及它是否在路线图中得到解决.
在此先感谢您的帮助!