Skip to content

Commit

Permalink
Merge pull request #3 in SUITE/sdk-client-tools-protex from dev/zwass…
Browse files Browse the repository at this point in the history
…all/improvement/PROTEX-21655-port-cc-improvements to release/BDS_7_5_x

* commit 'fe50750d7d2c8f2ce92eff6ab8883b7a44e6f83b':
  PROTEX-21655: Minor refactoring to make code cleaner
  PROTEX-21655: Missed an unnecessarily boxed long
  PROTEX-21655: Ported improvements made to the Code Center 7.2 SDK client
  • Loading branch information
runer112 committed Sep 2, 2016
2 parents 98d047f + fe50750 commit c5b46a7
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.apache.ws.security.WSPasswordCallback;


public class ProgrammedPasswordCallback implements CallbackHandler {

private final CallbackHandler callbackHandler;
Expand All @@ -39,20 +38,20 @@ public ProgrammedPasswordCallback(CallbackHandler callbackHandler) {

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = null;

if (callbacks != null) {
for (Callback callback : callbacks) {
if (callback instanceof WSPasswordCallback) {
pc = (WSPasswordCallback) callback;
handle((WSPasswordCallback) callback);
} else {
throw new UnsupportedCallbackException(callback, "Unsupported callback type " + (callback != null ? callback.getClass().getName() : null)
+ " provided. Only " + WSPasswordCallback.class.getName() + " is supported ");
}
}
}
}

String identifier = pc.getIdentifier();
protected void handle(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
String identifier = callback.getIdentifier();
NameCallback usernameCallback = new NameCallback("Username: ");
PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);

Expand All @@ -61,20 +60,17 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback
String username = usernameCallback.getName();

if (username == null) {
throw new UnsupportedCallbackException(pc,
"Username not set in client. Call constructor method "
+ ProgrammedPasswordCallback.class.getName()
+ "(\"<your username>\", \"<your password>\")");
throw new UnsupportedCallbackException(callback, "Username not set in client. Call constructor method " + ProgrammedPasswordCallback.class.getName()
+ "(\"<your username>\", \"<your password>\")");
}

// set the password for our outgoing message.
if (username.equals(identifier)) {
pc.setPassword(new String(passwordCallback.getPassword()));
callback.setPassword(new String(passwordCallback.getPassword()));
} else {
throw new UnsupportedCallbackException(pc,
"Password not set in client. Call constructor method "
+ ProgrammedPasswordCallback.class.getName()
+ "(\"<your username>\", \"<your password>\")");
throw new UnsupportedCallbackException(callback, "Password not set in client. Call constructor method " + ProgrammedPasswordCallback.class.getName()
+ "(\"<your username>\", \"<your password>\")");
}
}

}
Loading

0 comments on commit c5b46a7

Please sign in to comment.