📄 safenetlunacatoken.java.luna
字号:
/************************************************************************* * * * EJBCA: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/package org.ejbca.core.model.ca.catoken;import java.security.KeyStore;import org.apache.log4j.Logger;import com.chrysalisits.crypto.LunaTokenManager;/** * @author lars * @version $Id: SafeNetLunaCAToken.java.luna,v 1.6 2006/09/28 06:39:38 primelars Exp $ * */public class SafeNetLunaCAToken extends BaseCAToken implements IHardCAToken { /** Log4j instance */ private static final Logger log = Logger.getLogger(SafeNetLunaCAToken.class); static final private String SLOT_LABEL_KEY = "slotLabel"; static final private String PROVIDER_NAME = "LunaJCAProvider"; static final private String PROVIDER_CLASS = "com.chrysalisits.crypto.LunaJCAProvider"; static int nrActivatedLunaTokens = 0; boolean isActivated; /** * @throws InstantiationException * @throws IllegalAccessException */ public SafeNetLunaCAToken() throws InstantiationException, IllegalAccessException { super(PROVIDER_CLASS, PROVIDER_NAME, SLOT_LABEL_KEY); isActivated = false; } /* (non-Javadoc) * @see org.ejbca.core.model.ca.catoken.IHardCAToken#activate(java.lang.String) */ public void activate(String authCode) throws CATokenOfflineException, CATokenAuthenticationFailedException { if ( isActivated ) return; final LunaTokenManager tokenManager = LunaTokenManager.getInstance(); try { if ( !tokenManager.isLoggedIn() ) { nrActivatedLunaTokens = 0; if ( sSlotLabel!=null && sSlotLabel.length()>0 ) tokenManager.Login(sSlotLabel, authCode); else tokenManager.Login(authCode); } KeyStore keyStore = KeyStore.getInstance("Luna"); keyStore.load(null, null); nrActivatedLunaTokens++; isActivated = true; setKeys(keyStore, null); } catch( Throwable t ) { log.error("Authentication failed: ", t); deactivate(); if ( t instanceof Error ) { throw (Error)t; } else { CATokenAuthenticationFailedException failedE = new CATokenAuthenticationFailedException(t.toString()); failedE.initCause(t); throw failedE; } } } /* (non-Javadoc) * @see org.ejbca.core.model.ca.catoken.IHardCAToken#deactivate() */ public boolean deactivate(){ if ( isActivated ) { nrActivatedLunaTokens--; isActivated = false; final LunaTokenManager tokenManager = LunaTokenManager.getInstance(); if ( nrActivatedLunaTokens<1 && tokenManager.isLoggedIn() ) { tokenManager.Logout(); log.info("Logged off"); } } return super.deactivate(); } public int getCATokenStatus() { if ( !isActivated ) return IHardCAToken.STATUS_OFFLINE; final LunaTokenManager tokenManager = LunaTokenManager.getInstance(); if ( tokenManager.isLoggedIn() ) return IHardCAToken.STATUS_ACTIVE; else { isActivated = false; super.deactivate(); return IHardCAToken.STATUS_OFFLINE; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -