本文整理汇总了Java中org.alfresco.service.cmr.security.AuthenticationService.clearCurrentSecurityContext方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationService.clearCurrentSecurityContext方法的具体用法?Java AuthenticationService.clearCurrentSecurityContext怎么用?Java AuthenticationService.clearCurrentSecurityContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.security.AuthenticationService
的用法示例。
在下文中一共展示了AuthenticationService.clearCurrentSecurityContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearCurrentSecurityContext
import org.alfresco.service.cmr.security.AuthenticationService; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void clearCurrentSecurityContext()
{
for (AuthenticationService authService : getUsableAuthenticationServices())
{
try
{
authService.clearCurrentSecurityContext();
return;
}
catch (AuthenticationException e)
{
// Ignore and chain
}
}
throw new AuthenticationException("Failed to clear security context");
}
示例2: logOut
import org.alfresco.service.cmr.security.AuthenticationService; //导入方法依赖的package包/类
/**
* Invalidate Alfresco ticket and Web/Portlet session and clear the Security context for this thread.
* @param context
*/
public static void logOut(FacesContext context)
{
String ticket = null;
if (Application.inPortalServer())
{
ticket = AlfrescoFacesPortlet.onLogOut(context.getExternalContext().getRequest());
}
else
{
SessionUser user = getCurrentUser(context);
if (user != null)
{
ticket = user.getTicket();
}
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
HttpSession session = request.getSession(false);
if (session != null)
{
session.invalidate();
}
}
// Explicitly invalidate the Alfresco ticket. This no longer happens on session expiry to allow for ticket
// 'sharing'
WebApplicationContext wc = FacesContextUtils.getRequiredWebApplicationContext(context);
AuthenticationService unprotAuthService = (AuthenticationService) wc.getBean(BEAN_UNPROTECTED_AUTH_SERVICE);
if (ticket != null)
{
unprotAuthService.invalidateTicket(ticket);
}
unprotAuthService.clearCurrentSecurityContext();
}
示例3: authenticate
import org.alfresco.service.cmr.security.AuthenticationService; //导入方法依赖的package包/类
/**
* Helper to authenticate the current user using the supplied Ticket value.
*
* @return true if authentication successful, false otherwise.
*/
public static AuthenticationStatus authenticate(
ServletContext context, HttpServletRequest httpRequest, HttpServletResponse httpResponse, String ticket)
throws IOException
{
if (logger.isDebugEnabled())
logger.debug("Authenticate the current user using the supplied Ticket value.");
// setup the authentication context
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
AuthenticationService auth = (AuthenticationService)wc.getBean(AUTHENTICATION_SERVICE);
HttpSession session = httpRequest.getSession();
try
{
// If we already have a cached user, make sure it is for the right ticket
SessionUser user = (SessionUser)session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER);
if (user != null && !user.getTicket().equals(ticket))
{
if (logger.isDebugEnabled())
logger.debug("Found a previously-cached user with the wrong identity.");
session.removeAttribute(AUTHENTICATION_USER);
if (!Application.inPortalServer())
{
if (logger.isDebugEnabled())
logger.debug("The server is not running in a portal, invalidating session.");
session.invalidate();
session = httpRequest.getSession();
}
user = null;
}
// Validate the ticket and associate it with the session
auth.validate(ticket);
if (user == null)
{
if (logger.isDebugEnabled())
logger.debug("Ticket is valid; caching a new user in the session.");
setUser(context, httpRequest, auth.getCurrentUserName(), ticket, false);
}
else if (logger.isDebugEnabled())
logger.debug("Ticket is valid; retaining cached user in session.");
}
catch (AuthenticationException authErr)
{
if (logger.isDebugEnabled())
logger.debug("An AuthenticationException occured: ", authErr);
session.removeAttribute(AUTHENTICATION_USER);
if (!Application.inPortalServer())
{
if (logger.isDebugEnabled())
logger.debug("The server is not running in a portal, invalidating session.");
session.invalidate();
}
return AuthenticationStatus.Failure;
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
logger.debug("Authentication failed due to unexpected error", e);
// Some other kind of serious failure
AuthenticationService unprotAuthService = (AuthenticationService)wc.getBean(UNPROTECTED_AUTH_SERVICE);
unprotAuthService.invalidateTicket(unprotAuthService.getCurrentTicket());
unprotAuthService.clearCurrentSecurityContext();
return AuthenticationStatus.Failure;
}
// As we are authenticating via a ticket, establish the session locale using request headers rather than web client preferences
setupThread(context, httpRequest, httpResponse, false);
return AuthenticationStatus.Success;
}