本文整理汇总了Java中weblogic.servlet.security.ServletAuthentication类的典型用法代码示例。如果您正苦于以下问题:Java ServletAuthentication类的具体用法?Java ServletAuthentication怎么用?Java ServletAuthentication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletAuthentication类属于weblogic.servlet.security包,在下文中一共展示了ServletAuthentication类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import weblogic.servlet.security.ServletAuthentication; //导入依赖的package包/类
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)req;
HttpSession session = request.getSession();
ncl.debug("AuthenticateFilter doFilter.");
if(req.getAttribute("cancelSession") != null) {
ncl.info("Cancelled session due to session timeout.");
ServletAuthentication.invalidateAll(request);
}
else if(session != null) {
Date fiveMinutesAgo = DateUtils.addMinutes(new Date(), -5);
//check that the time the session was last accessed was after 5 minutes ago..
Date timeLastAccessed = new Date(session.getLastAccessedTime());
if(timeLastAccessed.before(fiveMinutesAgo)) {
session.invalidate();
//make the user log back in.
ServletAuthentication.invalidateAll(request);
}
}
}
示例2: weblogicLogout
import weblogic.servlet.security.ServletAuthentication; //导入依赖的package包/类
/**
* Standar way: invalidateSession. But keep in mind: "the user's
* authentication information still remains valid and is stored in the
* context of the server or virtual host" See http://download.oracle.com/
* docs/cd/E17904_01/web.1111/e13712/sessions.htm#WBAPP300 The servlet
* specification does not provide an API for logging
*
* @param request
* @param isDebugEnabled
* @throws ServletException
*/
public static void weblogicLogout(HttpServletRequest request,
boolean isDebugEnabled) throws ServletException {
// Get user info. Debugging purposes
String userName = null;
if (isDebugEnabled) {
try {
userName = request.getUserPrincipal().getName();
nc.notice("Logging out user: " + userName);
} catch (Exception e) {
nc.error(e.getMessage());
}
}
// Invalidates all the sessions for the current user only (that is, the
// current cookie), and since the cookie is no longer required, kills
// the cookie too.
ServletAuthentication.invalidateAll(request);
// Kills the current cookie.
ServletAuthentication.killCookie(request);
if (isDebugEnabled) {
if (userName!=null){
nc.notice(userName + " has been logging out");
} else {
nc.notice("The session has been already killed: cookies deletion/expiration");
}
}
}
示例3: doAuthentication
import weblogic.servlet.security.ServletAuthentication; //导入依赖的package包/类
/** {@inheritDoc} */
public Principal doAuthentication(String username, Object credentials)
{
Principal principal = null;
String password = extractPassword(credentials);
if (password != null)
{
// Test for the presence of a response here (rather than request) because NIO
// endpoints require the alternate code path and they don't populate the response
// in FlexContext.
HttpServletResponse response = FlexContext.getHttpResponse();
if (response != null)
{
HttpServletRequest request = FlexContext.getHttpRequest();
int result = ServletAuthentication.FAILED_AUTHENTICATION;
try
{
result = ServletAuthentication.login(username, password,
request);
}
catch (LoginException e)
{
}
catch (NoSuchMethodError noSuchMethodError)
{
//even though we're not supporting WebLogic 7 anymore...
// Weblogic 7.0.4 didn't have login(), so try weak().
result = ServletAuthentication.weak(username, password,
request);
}
if (result != ServletAuthentication.FAILED_AUTHENTICATION)
{
// To authorize against the Groups defined via the WL console, we need
// to have a SubjectPrincipal. Because we do not need a principal to authorize
// against web.xml / weblogic.xml, always save the SubjectPrincipal
principal = getSubjectPrincipal(username, password);
}
}
else // Code path for NIO endpoints.
{
principal = getSubjectPrincipal(username, password);
}
}
return principal;
}
示例4: logout
import weblogic.servlet.security.ServletAuthentication; //导入依赖的package包/类
/** {@inheritDoc} */
public boolean logout(Principal principal)
{
HttpServletResponse response = FlexContext.getHttpResponse();
if (response != null)
{
// Destroy the Principal maintained by the app server.
HttpServletRequest request = FlexContext.getHttpRequest();
ServletAuthentication.logout(request);
}
// else, current non-servlet session will be automatically invalidated, destroying any active Principal.
return true;
}