⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jaasauthmodule.java

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JAVA
字号:
/** * @version $Id: JaasAuthModule.java 4496 2006-02-08 20:27:04Z wehrens $ */package org.gridsphere.services.core.security.auth.modules.impl;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.gridsphere.services.core.user.User;import org.gridsphere.services.core.security.auth.AuthenticationException;import org.gridsphere.services.core.security.auth.modules.LoginAuthModule;import org.gridsphere.services.core.security.auth.modules.impl.descriptor.AuthModuleDefinition;import javax.security.auth.login.*;public class JaasAuthModule extends BaseAuthModule implements LoginAuthModule {    private String contextName = "Gridsphere";        private Log log = LogFactory.getLog(JaasAuthModule.class);    public JaasAuthModule(AuthModuleDefinition moduleDef) {        super(moduleDef);    }    public void checkAuthentication(User user, String password) throws AuthenticationException {		String username = user.getUserName();        if (log.isDebugEnabled()) log.debug("beginning authentication for '" + username + "'");		LoginContext loginContext;		// Create the LoginContext		try{			loginContext = new LoginContext(contextName, new JaasCallbackHandler(username, password));			if (log.isDebugEnabled()) log.debug("got loginContext");		} catch (SecurityException e) {		    if (log.isDebugEnabled()) log.debug("SecurityException: " + e);			throw new AuthenticationException("key4", e);		} catch (LoginException e) {		    if (log.isDebugEnabled()) log.debug("LoginException: " + e);      		throw new AuthenticationException("key4", e);		}		// Attempt login		try{			loginContext.login();			if (log.isDebugEnabled()) log.debug("login successful");		} catch (FailedLoginException e) {		    if (log.isDebugEnabled()) log.debug("login failed: " + e.getMessage());			throw new AuthenticationException("key4", e);		} catch (AccountExpiredException e) {		    if (log.isDebugEnabled()) log.debug("account expired");			throw new AuthenticationException("key1");		} catch (CredentialExpiredException e) {		    if (log.isDebugEnabled()) log.debug("credentials expired");			throw new AuthenticationException("key2", e);		} catch (Exception e) {		    if (log.isDebugEnabled()) log.debug("unexpected failure: " + e.getMessage());			throw new AuthenticationException("key3", e);		}    }    public String getContextName() {        return contextName;    }    public void setContextName(String contextName) {        if (log.isDebugEnabled()) log.debug("setting contextName = '" + contextName + "'");        this.contextName = contextName;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -