@Test public void activateToken() throws Exception { char[] password = "foobar".toCharArray(); tokenService.activateToken("token-should-be-activatable", password); try { tokenService.activateToken(WRONG_SOFTTOKEN_PIN_TOKEN_ID, password); fail("should have thrown exception"); } catch (TokenService.PinIncorrectException expected) { } try { tokenService.activateToken(WRONG_HSM_PIN_TOKEN_ID, password); fail("should have thrown exception"); } catch (TokenService.PinIncorrectException expected) { } try { tokenService.activateToken(UNKNOWN_LOGIN_FAIL_TOKEN_ID, password); fail("should have thrown exception"); } catch (CodedException expected) { assertEquals(LOGIN_FAILED_FAULT_CODE, expected.getFaultCode()); assertEquals("dont know what happened", expected.getFaultString()); } try { tokenService.activateToken(TOKEN_NOT_FOUND_TOKEN_ID, password); fail("should have thrown exception"); } catch (TokenNotFoundException expected) { } try { tokenService.activateToken(UNRECOGNIZED_FAULT_CODE_TOKEN_ID, password); fail("should have thrown exception"); } catch (CodedException expected) { assertEquals("foo", expected.getFaultCode()); assertEquals("bar", expected.getFaultString()); } }
public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException { TokenInfo tokenInfo = getToken(id); auditDataHelper.put(tokenInfo); possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo); try { signerProxyFacade.activateToken(id, password); } catch (CodedException e) { if (isCausedByTokenNotFound(e)) { throw new TokenNotFoundException(e); } else if (isCausedByIncorrectPin(e)) { throw new PinIncorrectException(e); } else { throw e; } } catch (Exception other) { throw new SignerNotReachableException("token activation failed", other); } }
TokenService { public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException { TokenInfo tokenInfo = getToken(id); auditDataHelper.put(tokenInfo); possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo); try { signerProxyFacade.activateToken(id, password); } catch (CodedException e) { if (isCausedByTokenNotFound(e)) { throw new TokenNotFoundException(e); } else if (isCausedByIncorrectPin(e)) { throw new PinIncorrectException(e); } else { throw e; } } catch (Exception other) { throw new SignerNotReachableException("token activation failed", other); } } }
TokenService { public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException { TokenInfo tokenInfo = getToken(id); auditDataHelper.put(tokenInfo); possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo); try { signerProxyFacade.activateToken(id, password); } catch (CodedException e) { if (isCausedByTokenNotFound(e)) { throw new TokenNotFoundException(e); } else if (isCausedByIncorrectPin(e)) { throw new PinIncorrectException(e); } else { throw e; } } catch (Exception other) { throw new SignerNotReachableException("token activation failed", other); } } @Autowired  TokenService(SignerProxyFacade signerProxyFacade,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            AuditDataHelper auditDataHelper); }
TokenService { public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException { TokenInfo tokenInfo = getToken(id); auditDataHelper.put(tokenInfo); possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo); try { signerProxyFacade.activateToken(id, password); } catch (CodedException e) { if (isCausedByTokenNotFound(e)) { throw new TokenNotFoundException(e); } else if (isCausedByIncorrectPin(e)) { throw new PinIncorrectException(e); } else { throw e; } } catch (Exception other) { throw new SignerNotReachableException("token activation failed", other); } } @Autowired  TokenService(SignerProxyFacade signerProxyFacade,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            AuditDataHelper auditDataHelper); List<TokenInfo> getAllTokens(); List<CertificateInfo> getSignCertificates(ClientType clientType); List<CertificateInfo> getAllCertificates(ClientType clientType); void activateToken(String id, char[] password); void deactivateToken(String id); TokenInfo getToken(String id); TokenInfo updateTokenFriendlyName(String tokenId, String friendlyName); TokenInfo getTokenForKeyId(String keyId); TokenInfoAndKeyId getTokenAndKeyIdForCertificateHash(String hash); boolean isSoftwareTokenInitialized(); TokenInitStatusInfo getSoftwareTokenInitStatus(); TokenInfoAndKeyId getTokenAndKeyIdForCertificateRequestId(String csrId); boolean hasHardwareTokens(); }
TokenService { public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException { TokenInfo tokenInfo = getToken(id); auditDataHelper.put(tokenInfo); possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo); try { signerProxyFacade.activateToken(id, password); } catch (CodedException e) { if (isCausedByTokenNotFound(e)) { throw new TokenNotFoundException(e); } else if (isCausedByIncorrectPin(e)) { throw new PinIncorrectException(e); } else { throw e; } } catch (Exception other) { throw new SignerNotReachableException("token activation failed", other); } } @Autowired  TokenService(SignerProxyFacade signerProxyFacade,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            AuditDataHelper auditDataHelper); List<TokenInfo> getAllTokens(); List<CertificateInfo> getSignCertificates(ClientType clientType); List<CertificateInfo> getAllCertificates(ClientType clientType); void activateToken(String id, char[] password); void deactivateToken(String id); TokenInfo getToken(String id); TokenInfo updateTokenFriendlyName(String tokenId, String friendlyName); TokenInfo getTokenForKeyId(String keyId); TokenInfoAndKeyId getTokenAndKeyIdForCertificateHash(String hash); boolean isSoftwareTokenInitialized(); TokenInitStatusInfo getSoftwareTokenInitStatus(); TokenInfoAndKeyId getTokenAndKeyIdForCertificateRequestId(String csrId); boolean hasHardwareTokens();  }