/** * Create a BinarySecurityToken via a CallbackHandler * @param callbackHandler * @throws WSSecurityException */ public BinarySecurity(CallbackHandler callbackHandler) throws WSSecurityException { if (callbackHandler == null) { LOG.debug("Trying to create a BinarySecurityToken via a null CallbackHandler"); throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE); } TokenElementCallback[] callback = new TokenElementCallback[] {new TokenElementCallback()}; try { callbackHandler.handle(callback); } catch (IOException | UnsupportedCallbackException e) { throw new IllegalStateException( "Exception while creating a token element", e ); } element = callback[0].getTokenElement(); if (element == null) { LOG.debug("CallbackHandler did not return a token element"); throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE); } }