Java Code Examples for org.apache.ws.security.WSPasswordCallback#getPassword()

The following examples show how to use org.apache.ws.security.WSPasswordCallback#getPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientPasswordCallback.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
	log.info("handle({})", callbacks);
	WSPasswordCallback pwdCallback = (WSPasswordCallback) callbacks[0];

	log.debug("identifier: " + pwdCallback.getIdentifier());
	log.debug("usage: " + pwdCallback.getUsage());
	int usage = pwdCallback.getUsage();

	if (usage == WSPasswordCallback.USERNAME_TOKEN) {
		String password = pwdCallback.getPassword();
		Authentication authentication = new UsernamePasswordAuthenticationToken(pwdCallback.getIdentifier(), password);
		authentication = authenticationManager.authenticate(authentication);
		SecurityContextHolder.getContext().setAuthentication(authentication);

		// Return the password to the caller
		pwdCallback.setPassword(password);
	}
}
 
Example 2
Source File: ServerPWCallback.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
	logger.debug("IN");
	for (int i = 0; i < callbacks.length; i++) {
		if (callbacks[i] instanceof WSPasswordCallback) {
			WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
			String userId = pc.getIdentifier();
			logger.debug("UserId found from request: " + userId);
			if (pc.getUsage() == WSPasswordCallback.DECRYPT) {
				logger.debug("WSPasswordCallback.DECRYPT=" + WSPasswordCallback.DECRYPT);
				pc.setPassword("security");
				// } else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
				// logger.debug("WSPasswordCallback.USERNAME_TOKEN = " + pc.getUsage() + " callback usage");
				// // for passwords sent in digest mode we need to provide the password,
				// // because the original one can't be un-digested from the message
				// String password = getPassword(userId);
				// // this will throw an exception if the passwords don't match
				// pc.setPassword(password);
			} else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
				logger.debug("WSPasswordCallback.USERNAME_TOKEN_UNKNOWN = " + pc.getUsage() + " callback usage");
				// for passwords sent in clear-text mode we can compare passwords directly
				// Get the password that was sent
				String password = pc.getPassword();
				// Now pass them to your authentication mechanism
				SpagoBIUserProfile profile = authenticate(userId, password); // throws WSSecurityException.FAILED_AUTHENTICATION on failure
				logger.debug("New userId is " + profile.getUniqueIdentifier());
				userId = profile.getUniqueIdentifier();
			} else {
				logger.error("WSPasswordCallback usage [" + pc.getUsage() + "] not treated.");
				throw new UnsupportedCallbackException(callbacks[i], "WSPasswordCallback usage [" + pc.getUsage() + "] not treated.");
			}
			// Put userId into MessageContext (for services that depend on profiling)
			MessageContext mc = MessageContext.getCurrentContext();
			logger.debug("Setting userId to " + userId);
			mc.setProperty(WSHandlerConstants.USER, userId);
		} else {
			logger.error("Unrecognized Callback");
			throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
		}
	}
}