use of org.apache.wss4j.common.ext.WSPasswordCallback in project tdi-studio-se by Talend.
the class HardcodedPassword method handle.
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback c : callbacks) {
if (c instanceof WSPasswordCallback) {
WSPasswordCallback passwordCallback = (WSPasswordCallback) c;
passwordCallback.setPassword(password);
continue;
}
throw new UnsupportedCallbackException(c);
}
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project midpoint by Evolveum.
the class PasswordCallback method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
LOGGER.trace("Invoked PasswordCallback with {} callbacks: {}", callbacks.length, callbacks);
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
String username = pc.getIdentifier();
String wssPasswordType = pc.getType();
LOGGER.trace("Username: '{}', Password type: {}", username, wssPasswordType);
try {
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
pc.setPassword(passwordAuthenticationEvaluatorImpl.getAndCheckUserPassword(connEnv, username));
} catch (Exception e) {
LOGGER.trace("Exception in password callback: {}: {}", e.getClass().getSimpleName(), e.getMessage(), e);
throw new PasswordCallbackException("Authentication failed");
}
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project midpoint by Evolveum.
the class ClientPasswordHandler method handle.
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
// set the password for our message.
pc.setPassword(password != null ? password : Main.ADM_PASSWORD);
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.
the class PasswordCallback method handle.
/**
* 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;
}
}
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.
the class UsernameTokenProvider method createToken.
public TokenProviderResponse createToken(TokenProviderParameters tokenParameters) {
try {
Document doc = DOMUtils.createDocument();
Principal principal = tokenParameters.getPrincipal();
String user = principal.getName();
// Get the password
WSPasswordCallback[] cb = { new WSPasswordCallback(user, WSPasswordCallback.USERNAME_TOKEN) };
STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
stsProperties.getCallbackHandler().handle(cb);
String password = cb[0].getPassword();
if (password == null || "".equals(password)) {
throw new STSException("No password available", STSException.REQUEST_FAILED);
}
UsernameToken ut = new UsernameToken(true, doc, WSConstants.PASSWORD_TEXT);
ut.setName(user);
ut.setPassword(password);
WSSConfig config = WSSConfig.getNewInstance();
ut.setID(config.getIdAllocator().createId("UsernameToken-", ut));
TokenProviderResponse response = new TokenProviderResponse();
response.setToken(ut.getElement());
response.setTokenId(ut.getID());
return response;
} catch (Exception e) {
e.printStackTrace();
throw new STSException("Error creating UsernameToken", e, STSException.REQUEST_FAILED);
}
}
Aggregations