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

The following examples show how to use org.apache.ws.security.WSPasswordCallback#setPassword() . 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: SecureAxisServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[0];
        String id = pwcb.getIdentifer();
        int usage = pwcb.getUsage();

        if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {
            // Logic to get the private key password for signture or decryption
            if ("client".equals(id)) {
                pwcb.setPassword("automation");

            } else if ("service".equals(id)) {
                pwcb.setPassword("automation");

            } else if ("wso2carbon".equals(id)) {
                pwcb.setPassword("wso2carbon");

            } else if ("alice".equals(id)) {
                pwcb.setPassword("password");

            } else if ("bob".equals(id)) {
                pwcb.setPassword("password");

            }
        }
    }
 
Example 2
Source File: InMemoryPasswordCallbackHandler.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
            String id = pc.getIdentifier();
            if (keystorePassword.get(id) != null) {
                pc.setPassword(keystorePassword.get(id));
            } else {
                throw new UnsupportedCallbackException(callbacks[i], "no password found for " + id);
            }
        }

    }
}
 
Example 3
Source File: PWCBHandler.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {

        //When the server side need to authenticate the user
        WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
        if (pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
            if(pwcb.getIdentifer().equals("alice") && pwcb.getPassword().equals("bobPW")) {
                return;
            } else {
                throw new UnsupportedCallbackException(callbacks[i], "check failed");
            }
        }

        //When the client requests for the password to be added in to the
        //UT element
        pwcb.setPassword("bobPW");
    }
}
 
Example 4
Source File: SecureAxisServiceClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[0];
        String id = pwcb.getIdentifer();
        int usage = pwcb.getUsage();

        if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {
            // Logic to get the private key password for signture or decryption
            if ("client".equals(id)) {
                pwcb.setPassword("automation");

            } else if ("service".equals(id)) {
                pwcb.setPassword("automation");

            } else if ("wso2carbon".equals(id)) {
                pwcb.setPassword("wso2carbon");

            } else if ("alice".equals(id)) {
                pwcb.setPassword("password");

            } else if ("bob".equals(id)) {
                pwcb.setPassword("password");

            }
        }
    }
 
Example 5
Source File: SecurityWithServiceDescriptorTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

		WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[0];
		String id = pwcb.getIdentifier();
		int usage = pwcb.getUsage();

		if (usage == WSPasswordCallback.USERNAME_TOKEN) {

			if ("admin".equals(id)) {
				pwcb.setPassword("admin");
			} else if ("[email protected]".equals(id)) {
				pwcb.setPassword("admin123");
			}

		} else if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {

			if ("wso2carbon".equals(id)) {
				pwcb.setPassword("wso2carbon");
			}
		}
	}
 
Example 6
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 7
Source File: ClientCredentialsHolder.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
		UnsupportedCallbackException {
	for (int i = 0; i < callbacks.length; i++) {
		if (callbacks[i] instanceof WSPasswordCallback) {
               WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
               // We need the password to fill in, so the usage code must
               // match the WSPasswordCallback.USERNAME_TOKEN value
               // i.e. "2"
               if (pc.getUsage() != WSPasswordCallback.USERNAME_TOKEN) {
                   throw new UnsupportedCallbackException(callbacks[i],
                       "Usage code was not USERNAME_TOKEN - value was "
                       + pc.getUsage());
               }
               pc.setPassword(password); 
		} else {
			throw new UnsupportedCallbackException(callbacks[i],
					"Unrecognized Callback");
		}
	}
}
 
Example 8
Source File: KeystorePasswordCallback.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * It attempts to get the password from the private
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
 
Example 9
Source File: ClientUserPasswordCallbackHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback passwordCallback = (WSPasswordCallback) callbacks[i];
            passwordCallback.setPassword(this.password);
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    "Unrecognized Callback");
        }
    }
}
 
Example 10
Source File: KeystorePasswordCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * It attempts to get the password from the private 
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
 
Example 11
Source File: TestPwdCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
        }
    }
}
 
Example 12
Source File: KeystorePasswordCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * It attempts to get the password from the private 
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
 
Example 13
Source File: TestPwdCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
        }
    }
}
 
Example 14
Source File: KeystorePasswordCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * It attempts to get the password from the private 
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
 
Example 15
Source File: TestPwdCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
        }
    }
}
 
Example 16
Source File: KeystorePasswordCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * It attempts to get the password from the private 
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
 
Example 17
Source File: TestPwdCallback.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
        }
    }
}
 
Example 18
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");
		}
	}
}