public UsernameToken(boolean milliseconds, Document doc, WSTimeSource timeSource, String pwType) { element = doc.createElementNS(WSConstants.WSSE_NS, "wsse:" + WSConstants.USERNAME_TOKEN_LN); elementUsername = doc.createElementNS(WSConstants.WSSE_NS, "wsse:" + WSConstants.USERNAME_LN); elementUsername.appendChild(doc.createTextNode("")); element.appendChild(elementUsername); if (pwType != null) { elementPassword = doc.createElementNS(WSConstants.WSSE_NS, "wsse:" + WSConstants.PASSWORD_LN); elementPassword.appendChild(doc.createTextNode("")); element.appendChild(elementPassword); passwordType = pwType; if (passwordType.equals(WSConstants.PASSWORD_DIGEST)) { addNonce(doc); addCreated(milliseconds, timeSource, doc); } else { hashed = false; } } }
/** * Creates a Username token. * * The method prepares and initializes a WSSec UsernameToken structure after * the relevant information was set. A Before calling * <code>prepare()</code> all parameters such as user, password, * passwordType etc. must be set. A complete <code>UsernameToken</code> is * constructed. */ public void prepare() { ut = new UsernameToken(precisionInMilliSeconds, getDocument(), wsTimeSource, passwordType); ut.setPasswordsAreEncoded(passwordsAreEncoded); ut.setName(user); if (useDerivedKey) { saltValue = ut.addSalt(getDocument(), saltValue, useMac); ut.addIteration(getDocument(), iteration); } else { ut.setPassword(password); } if (nonce) { ut.addNonce(getDocument()); } if (created) { ut.addCreated(precisionInMilliSeconds, wsTimeSource, getDocument()); } ut.setID(getIdAllocator().createId("UsernameToken-", ut)); }