Java Code Examples for javax.security.auth.callback.UnsupportedCallbackException

The following are top voted examples for showing how to use javax.security.auth.callback.UnsupportedCallbackException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: bdf2   File: DigestPasswordValidationCallbackHandler.java   Source Code and License 8 votes vote down vote up
@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback) throws IOException,
		UnsupportedCallbackException {
	UserDetails user = loadUserDetails(callback.getPrincipal().getName());
	WSUsernameTokenPrincipal principal = callback.getPrincipal();
	UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
			principal, principal.getPassword(), user.getAuthorities());
	if (logger.isDebugEnabled()) {
		logger.debug("Authentication success: " + authRequest.toString());
	}
	SecurityContextHolder.getContext().setAuthentication(authRequest);
	if (user instanceof IUser) {
		HttpSession session=ContextHolder.getHttpSession();
		session.setAttribute(ContextHolder.LOGIN_USER_SESSION_KEY, user);
		session.setAttribute(ContextHolder.USER_LOGIN_WAY_KEY,IWebservice.WS_LOGIN_WAY);
	}
}
 
Example 2
Project: product-ei   File: SecurityWithServiceDescriptorTest.java   Source Code and License 7 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 3
Project: fcrepo3-security-jaas   File: AuthFilterJAAS.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback c: callbacks) {
        if (c instanceof NameCallback) {
            ((NameCallback) c).setName(username);
        } else if (c instanceof PasswordCallback) {
            ((PasswordCallback) c).setPassword(password.toCharArray());
        }
        else if (c instanceof KeyChoiceCallback) {
            KeyChoiceCallback kcc = (KeyChoiceCallback)c;
            try {
                int idx = kcc.lookupKey(key);
                kcc.setSelectedIndex(idx);
            }
            catch (IllegalArgumentException e) {
                throw new MissingCredsException(kcc);
            }
        }
        else {
            throw new UnsupportedCallbackException(c);
        }
    }
}
 
Example 4
Project: OpenDiabetes   File: JaasAuthBean.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
    boolean didSetName = false;
    boolean didSetPassword = false;
    for (Callback cb : callbacks)
        if (cb instanceof NameCallback) {
            ((NameCallback) cb).setName(u);
            didSetName = true;
        } else if (cb instanceof PasswordCallback) {
            ((PasswordCallback) cb).setPassword(p);
            didSetPassword = true;
        } else {
            throw new UnsupportedCallbackException(cb,
                    "Unsupported Callback type: "
                    + cb.getClass().getName());
        }
    if (!didSetName)
        throw new IllegalStateException(
                "Supplied Callbacks does not include a NameCallback");
    if (!didSetPassword)
        throw new IllegalStateException("Supplied Callbacks "
                + "does not include a PasswordCallback");
}
 
Example 5
Project: cas-5.1.0   File: JaasAuthenticationHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
    Arrays.stream(callbacks).filter(callback -> {
        if (callback.getClass().equals(NameCallback.class)) {
            ((NameCallback) callback).setName(this.userName);
            return false;
        }
        if (callback.getClass().equals(PasswordCallback.class)) {
            ((PasswordCallback) callback).setPassword(this.password.toCharArray());
            return false;
        }
        return true;
    }).findFirst().ifPresent(callback -> {
        throw new RuntimeException(new UnsupportedCallbackException(callback, "Unrecognized Callback"));
    });
}
 
Example 6
Project: jmeter-wssecurity   File: WSSDecryptionPostProcessor.java   Source Code and License 6 votes vote down vote up
@Override
protected Document process(Document document) throws WSSecurityException {
    WSSecurityEngine secEngine = new WSSecurityEngine();

    WSHandlerResult results = secEngine.processSecurityHeader(document, null, 
        new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (Callback callback : callbacks) {
                    if (callback instanceof WSPasswordCallback) {
                        ((WSPasswordCallback)callback).setPassword(getCertPassword());
                    }
                }
            }
        }, getCrypto());

    return document;
}
 
Example 7
Project: message-broker   File: PlainSaslCallbackHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    if (callbacks != null) {
        for (Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
                ((NameCallback) callback).setName(username);
            } else if (callback instanceof PasswordCallback) {
                ((PasswordCallback) callback).setPassword(password);
            } else {
                throw new UnsupportedCallbackException(callback);

            }
        }
        clearCredentials();
    }
}
 
Example 8
Project: oscm   File: UserCredentialsHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieve or display the information requested in the provided Callbacks.
 * 
 * @param callbacks
 *            an array of <code>Callback</code> objects provided by an
 *            underlying security service which contains the information
 *            requested to be retrieved or displayed.
 * 
 * @throws IOException
 *             if an input or output error occurs.
 * 
 * @throws UnsupportedCallbackException
 *             if the implementation of this method does not support one or
 *             more of the Callbacks specified in the <code>callbacks</code>
 *             parameter.
 */
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(wsProxyInfo
                    .getUserCredentials().getUser());
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(wsProxyInfo
                    .getUserCredentials().getPassword().toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 9
Project: oscm   File: WSCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {
    System.out.println("Callback Handler - handle called");
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callbacks[i];
            nameCallback.setName(name);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
            passwordCallback.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    "The submitted Callback is unsupported");
        }
    }
}
 
Example 10
Project: mongosql-auth-java   File: Plain.java   Source Code and License 6 votes vote down vote up
static SaslClient createSaslClient(final String user, final String password) throws SaslException {
    return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, null,
            new CallbackHandler() {
                @Override
                public void handle(final Callback[] callbacks)
                        throws IOException, UnsupportedCallbackException {
                    for (final Callback callback : callbacks) {
                        if (callback instanceof PasswordCallback) {
                            ((PasswordCallback) callback).setPassword(password.toCharArray());
                        } else if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(user);
                        }
                    }
                }
            });
}
 
Example 11
Project: Transwarp-Sample-Code   File: KerberosAuthenticator2.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback ncb = (NameCallback) callback;
            ncb.setName(username);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pwcb = (PasswordCallback) callback;
            pwcb.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(
                    callback,
                    "We got a "
                            + callback.getClass().getCanonicalName()
                            + ", but only NameCallback and PasswordCallback is supported");
        }
    }
}
 
Example 12
Project: dev-courses   File: JaasAuthBean.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
    boolean didSetName = false;
    boolean didSetPassword = false;
    for (Callback cb : callbacks)
        if (cb instanceof NameCallback) {
            ((NameCallback) cb).setName(u);
            didSetName = true;
        } else if (cb instanceof PasswordCallback) {
            ((PasswordCallback) cb).setPassword(p);
            didSetPassword = true;
        } else {
            throw new UnsupportedCallbackException(cb,
                    "Unsupported Callback type: "
                    + cb.getClass().getName());
        }
    if (!didSetName)
        throw new IllegalStateException(
                "Supplied Callbacks does not include a NameCallback");
    if (!didSetPassword)
        throw new IllegalStateException("Supplied Callbacks "
                + "does not include a PasswordCallback");
}
 
Example 13
Project: OpenJSharp   File: NegotiateCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException, IOException {
    for (int i=0; i<callbacks.length; i++) {
        Callback callBack = callbacks[i];

        if (callBack instanceof NameCallback) {
            getAnswer();
            ((NameCallback)callBack).setName(username);
        } else if (callBack instanceof PasswordCallback) {
            getAnswer();
            ((PasswordCallback)callBack).setPassword(password);
            if (password != null) Arrays.fill(password, ' ');
        } else {
            throw new UnsupportedCallbackException(callBack,
                    "Call back not supported");
        }
    }
}
 
Example 14
Project: jerrydog   File: JAASCallbackHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieve the information requested in the provided Callbacks.  This
 * implementation only recognizes <code>NameCallback</code> and
 * <code>PasswordCallback</code> instances.
 *
 * @param callbacks The set of callbacks to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

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

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getDebug() >= 3)
                realm.log("Returning username " + username);
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            if (realm.getDebug() >= 3)
                realm.log("Returning password " + password);
            ((PasswordCallback) callbacks[i]).setPassword
                (password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }


    }

}
 
Example 15
Project: libcwfincore   File: GdaxExchangeConnection.java   Source Code and License 6 votes vote down vote up
@Override
public ExchangeSession openSession(ExchangeLogin login) {
    ApiKeyCallback apiKey = new ApiKeyCallback();
    ApiSecretCallback apiSecret = new ApiSecretCallback();
    PasswordCallback password = new PasswordCallback("GDAX passphrase", false);

    Callback[] callbacks = new Callback[]{
            apiKey,
            apiSecret,
            password
    };
    CallbackHandler callbackHandler = login.getCallbackHandler();
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new RuntimeException(e);
    }

    String apiKeyTxt = apiKey.getApiKey();
    char[] passphrase = password.getPassword();
    SecretKeySpec keySpec = new SecretKeySpec(apiSecret.getSecretData(), "HmacSHA256");
    return new GdaxExchangeSession(this, apiKeyTxt, keySpec, passphrase);
}
 
Example 16
Project: libcwfincore   File: GdaxExchangeCredentials.java   Source Code and License 6 votes vote down vote up
@Override
public CallbackHandler getCallbackHandler() {
    return callbacks -> {
        for (Callback cb : callbacks) {
            if (cb instanceof ApiKeyCallback) {
                ((ApiKeyCallback) cb).setApiKey(apiKey);
            } else if (cb instanceof ApiSecretCallback) {
                ((ApiSecretCallback) cb).setSecretData(apiSecret);
            } else if (cb instanceof PasswordCallback) {
                ((PasswordCallback) cb).setPassword(passphrase);
            } else {
                throw new UnsupportedCallbackException(cb);
            }
        }
    };
}
 
Example 17
Project: OperatieBRP   File: JMXCallbackHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Handles the callbacks; only supports {@link NameCallback} and {@link PasswordCallback}.
 * @throws UnsupportedCallbackException if an unsupported callback is encountered
 */
@Override
public void handle(final Callback[] callbacks)
        throws UnsupportedCallbackException {

    for (final Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(username);

        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback)
                    .setPassword(password.toCharArray());

        } else {
            throw new UnsupportedCallbackException
                    (callback, "Unrecognized Callback");
        }
    }
}
 
Example 18
Project: kafka-0.11.0.0-src-with-comment   File: TestDigestLoginModule.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            nameCallback.setName(nameCallback.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            passwordCallback.setPassword(TestJaasConfig.PASSWORD.toCharArray());
        } else if (callback instanceof RealmCallback) {
            RealmCallback realmCallback = (RealmCallback) callback;
            realmCallback.setText(realmCallback.getDefaultText());
        } else if (callback instanceof AuthorizeCallback) {
            AuthorizeCallback authCallback = (AuthorizeCallback) callback;
            if (TestJaasConfig.USERNAME.equals(authCallback.getAuthenticationID())) {
                authCallback.setAuthorized(true);
                authCallback.setAuthorizedID(authCallback.getAuthenticationID());
            }
        }
    }
}
 
Example 19
Project: jdk8u-jdk   File: NegotiateCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException, IOException {
    for (int i=0; i<callbacks.length; i++) {
        Callback callBack = callbacks[i];

        if (callBack instanceof NameCallback) {
            getAnswer();
            ((NameCallback)callBack).setName(username);
        } else if (callBack instanceof PasswordCallback) {
            getAnswer();
            ((PasswordCallback)callBack).setPassword(password);
            if (password != null) Arrays.fill(password, ' ');
        } else {
            throw new UnsupportedCallbackException(callBack,
                    "Call back not supported");
        }
    }
}
 
Example 20
Project: jdk8u-jdk   File: DynamicConfigurationTest.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 21
Project: openjdk-jdk10   File: NegotiateCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException, IOException {
    for (int i=0; i<callbacks.length; i++) {
        Callback callBack = callbacks[i];

        if (callBack instanceof NameCallback) {
            getAnswer();
            ((NameCallback)callBack).setName(username);
        } else if (callBack instanceof PasswordCallback) {
            getAnswer();
            ((PasswordCallback)callBack).setPassword(password);
            if (password != null) Arrays.fill(password, ' ');
        } else {
            throw new UnsupportedCallbackException(callBack,
                    "Call back not supported");
        }
    }
}
 
Example 22
Project: openjdk-jdk10   File: TestCallbackHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    System.out.println("TestCallbackHandler will get resolved through"
            + " auth.login.defaultCallbackHandler property.");
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName(USER_NAME);
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(
                    PASSWORD.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example 23
Project: openjdk-jdk10   File: DynamicConfigurationTest.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 24
Project: ditb   File: TestHBaseSaslRpcClient.java   Source Code and License 6 votes vote down vote up
@Test
public void testSaslClientCallbackHandler() throws UnsupportedCallbackException {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
  when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());

  final NameCallback nameCallback = mock(NameCallback.class);
  final PasswordCallback passwordCallback = mock(PasswordCallback.class);
  final RealmCallback realmCallback = mock(RealmCallback.class);
  final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class);

  Callback[] callbackArray = {nameCallback, passwordCallback,
      realmCallback, realmChoiceCallback};
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  saslClCallbackHandler.handle(callbackArray);
  verify(nameCallback).setName(anyString());
  verify(realmCallback).setText(anyString());
  verify(passwordCallback).setPassword(any(char[].class));
}
 
Example 25
Project: Camel   File: UTPasswordCallback.java   Source Code and License 6 votes vote down vote up
/**
 * Here, we attempt to get the password from the private 
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        try {
            String id = (String)callback.getClass().getMethod("getIdentifier").invoke(callback);
            String pass = passwords.get(id);
            if (pass != null) {
                callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass);
                return;
            }
        } catch (Exception ex) {
            UnsupportedCallbackException e = new UnsupportedCallbackException(callback);
            e.initCause(ex);
            throw e;
        }
    }
}
 
Example 26
Project: openjdk9   File: NegotiateCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException, IOException {
    for (int i=0; i<callbacks.length; i++) {
        Callback callBack = callbacks[i];

        if (callBack instanceof NameCallback) {
            getAnswer();
            ((NameCallback)callBack).setName(username);
        } else if (callBack instanceof PasswordCallback) {
            getAnswer();
            ((PasswordCallback)callBack).setPassword(password);
            if (password != null) Arrays.fill(password, ' ');
        } else {
            throw new UnsupportedCallbackException(callBack,
                    "Call back not supported");
        }
    }
}
 
Example 27
Project: openjdk9   File: DynamicConfigurationTest.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 28
Project: ipst   File: OfflineApplicationSecurity.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            // prompt the user for a username
            NameCallback nameCallback = (NameCallback) callback;
            nameCallback.setName(username);
        } else if (callback instanceof PasswordCallback) {
            // prompt the user for a password
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            passwordCallback.setPassword(password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized Callback");
        }
    }
}
 
Example 29
Project: helium   File: EjbUtil.java   Source Code and License 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 NameCallback) {
			NameCallback ncb = (NameCallback) callbacks[i];
			ncb.setName(username);
		} else if (callbacks[i] instanceof PasswordCallback) {
			PasswordCallback pcb = (PasswordCallback) callbacks[i];
			pcb.setPassword(password.toCharArray());
		} else {
			throw new UnsupportedCallbackException(
					callbacks[i],
					"Unrecognized Callback");
		}
	}
}
 
Example 30
Project: kafka   File: AbstractLogin.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(nc.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            String errorMessage = "Could not login: the client is being asked for a password, but the Kafka" +
                         " client code does not currently support obtaining a password from the user.";
            throw new UnsupportedCallbackException(callback, errorMessage);
        } else if (callback instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) callback;
            rc.setText(rc.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized SASL Login callback");
        }
    }
}
 
Example 31
Project: kafka   File: TestDigestLoginModule.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callback;
            nameCallback.setName(nameCallback.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callback;
            passwordCallback.setPassword(TestJaasConfig.PASSWORD.toCharArray());
        } else if (callback instanceof RealmCallback) {
            RealmCallback realmCallback = (RealmCallback) callback;
            realmCallback.setText(realmCallback.getDefaultText());
        } else if (callback instanceof AuthorizeCallback) {
            AuthorizeCallback authCallback = (AuthorizeCallback) callback;
            if (TestJaasConfig.USERNAME.equals(authCallback.getAuthenticationID())) {
                authCallback.setAuthorized(true);
                authCallback.setAuthorizedID(authCallback.getAuthenticationID());
            }
        }
    }
}
 
Example 32
Project: sistra   File: UsernamePasswordCallbackHandler.java   Source Code and License 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 NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(username);
        }
        else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        }
        else {
            throw new UnsupportedCallbackException
                    (callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 33
Project: sistra   File: UsernamePasswordCallbackHandler.java   Source Code and License 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 NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(username);
        }
        else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        }
        else {
            throw new UnsupportedCallbackException
                    (callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 34
Project: sistra   File: UsernamePasswordCallbackHandler.java   Source Code and License 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 NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(username);
        }
        else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        }
        else {
            throw new UnsupportedCallbackException
                    (callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 35
Project: sistra   File: UsernamePasswordCallbackHandler.java   Source Code and License 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 NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(username);
        }
        else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        }
        else {
            throw new UnsupportedCallbackException
                    (callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 36
Project: sistra   File: UsernamePasswordCallbackHandler.java   Source Code and License 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 NameCallback) {
            NameCallback ncb = (NameCallback) callbacks[i];
            ncb.setName(username);
        }
        else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) callbacks[i];
            pcb.setPassword(password.toCharArray());
        }
        else {
            throw new UnsupportedCallbackException
                    (callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 37
Project: product-ei   File: PWCBHandler.java   Source Code and License 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 38
Project: eplmp   File: GuestSAM.java   Source Code and License 6 votes vote down vote up
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, "");
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{UserGroupMapping.GUEST_ROLE_ID});
    Callback[] callbacks = {callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;

}
 
Example 39
Project: carbon-identity-framework   File: InMemoryPasswordCallbackHandler.java   Source Code and License 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 40
Project: javify   File: KeyPasswdCmd.java   Source Code and License 6 votes vote down vote up
void start() throws KeyStoreException, NoSuchAlgorithmException, IOException,
    UnsupportedCallbackException, UnrecoverableKeyException,
    CertificateException
{
  if (Configuration.DEBUG)
    log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
  // 1. get the key entry and certificate chain associated to alias
  Key privateKey = getAliasPrivateKey();
  Certificate[] chain = store.getCertificateChain(alias);

  // 2. replace the old entry
  setNewKeyPassword(_newPassword);
  store.setKeyEntry(alias, privateKey, newPasswordChars, chain);

  // 3. persist the key store
  saveKeyStore();
  if (Configuration.DEBUG)
    log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$
}
 
Example 41
Project: antsdb   File: KerberosCallbackHandler.java   Source Code and License 6 votes vote down vote up
/**
 * Handles the callbacks, and sets the user/password detail.
 * @param callbacks the callbacks to handle
 * @throws IOException if an input or output error occurs.
 */
public void handle( Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
	 
  for ( int i=0; i<callbacks.length; i++) {
    if ( callbacks[i] instanceof NameCallback && username != null) {
      NameCallback nc = (NameCallback) callbacks[i];
      nc.setName( username);
    }
    else if ( callbacks[i] instanceof PasswordCallback) {
      PasswordCallback pc = (PasswordCallback) callbacks[i];
      pc.setPassword( password.toCharArray());
    }
    else {
      /*throw new UnsupportedCallbackException(
      callbacks[i], "Unrecognized Callback");*/
    }
  }
}
 
Example 42
Project: Camel   File: UTPasswordCallback.java   Source Code and License 6 votes vote down vote up
/**
 * Here, we attempt to get the password from the private alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    String user = "";

    for (Callback callback : callbacks) {
        String pass = passwords.get(getIdentifier(callback));
        if (pass != null) {
            setPassword(callback, pass);
            return;
        }
        
    }

    // Password not found
    throw new IOException("Password does not exist for the user : " + user);
}
 
Example 43
Project: MyVirtualDirectory   File: UpnPwdCallbackHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
		UnsupportedCallbackException {
	
	for (Callback callback : callbacks) {
		if (callback instanceof TextOutputCallback) {
			 TextOutputCallback tc = (TextOutputCallback) callback;
			 switch (tc.getMessageType()) {
			 	case TextOutputCallback.INFORMATION: logger.info(tc.getMessage()); break;
			 	case TextOutputCallback.ERROR: logger.error(tc.getMessage()); break;
			 	case TextOutputCallback.WARNING: logger.warn(tc.getMessage()); break;
			 }
		} else if (callback instanceof NameCallback) {
			NameCallback nc = (NameCallback) callback;
			nc.setName(upn);
		} else if (callback instanceof PasswordCallback) {
			PasswordCallback pc = (PasswordCallback) callback;
			pc.setPassword(this.password.toCharArray());
		}
	}

}
 
Example 44
Project: drill   File: KerberosFactory.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  for (final Callback callback : callbacks) {
    if (callback instanceof AuthorizeCallback) {
      final AuthorizeCallback authorizeCallback = (AuthorizeCallback) callback;
      if (!authorizeCallback.getAuthenticationID()
          .equals(authorizeCallback.getAuthorizationID())) {
        throw new SaslException("Drill expects authorization ID and authentication ID to match. " +
            "Use inbound impersonation feature so one entity can act on behalf of another.");
      } else {
        authorizeCallback.setAuthorized(true);
      }
    } else {
      throw new UnsupportedCallbackException(callback);
    }
  }
}
 
Example 45
Project: nics-tools   File: LoginTest.java   Source Code and License 6 votes vote down vote up
protected boolean login(AuthContext lc)
    throws UnsupportedCallbackException {
    boolean succeed = false;
    Callback[] callbacks = null;

    // get information requested from module
    while (lc.hasMoreRequirements()) {
        callbacks = lc.getRequirements();
        if (callbacks != null) {
            addLoginCallbackMessage(callbacks);
            lc.submitRequirements(callbacks);
        }
    }

    if (lc.getStatus() == AuthContext.Status.SUCCESS) {
        System.out.println("Login succeeded.");
        succeed = true;
    } else if (lc.getStatus() == AuthContext.Status.FAILED) {
        System.out.println("Login failed.");
    } else {
        System.out.println("Unknown status: " + lc.getStatus());
    }

    return succeed;
}
 
Example 46
Project: nics-tools   File: FailedLoginTest.java   Source Code and License 6 votes vote down vote up
private void addLoginCallbackMessage(Callback[] callbacks)
throws UnsupportedCallbackException {
    int i = 0;
    try {
        for (i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof TextOutputCallback) {
                handleTextOutputCallback((TextOutputCallback)callbacks[i]);
            } else if (callbacks[i] instanceof NameCallback) {
                handleNameCallback((NameCallback)callbacks[i]);
            } else if (callbacks[i] instanceof PasswordCallback) {
                handlePasswordCallback((PasswordCallback)callbacks[i]);
            } else if (callbacks[i] instanceof TextInputCallback) {
                handleTextInputCallback((TextInputCallback)callbacks[i]);
            } else if (callbacks[i] instanceof ChoiceCallback) {
                handleChoiceCallback((ChoiceCallback)callbacks[i]);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new UnsupportedCallbackException(callbacks[i],e.getMessage());
    }
}
 
Example 47
Project: document-management-system   File: ClientPasswordCallback.java   Source Code and License 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 48
Project: registry   File: AbstractLogin.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(nc.getDefaultName());
        } else if (callback instanceof PasswordCallback) {
            String errorMessage = "Could not login: the client is being asked for a password, but this " +
                    " module does not currently support obtaining a password from the user.";
            throw new UnsupportedCallbackException(callback, errorMessage);
        } else if (callback instanceof RealmCallback) {
            RealmCallback rc = (RealmCallback) callback;
            rc.setText(rc.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(callback, "Unrecognized Login callback");
        }
    }
}
 
Example 49
Project: engerek   File: PasswordCallback.java   Source Code and License 6 votes vote down vote up
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");
     }
}
 
Example 50
Project: Camel   File: KeystorePasswordCallback.java   Source Code and License 6 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 (Callback callback : callbacks) {
        String pass = passwords.get(getIdentifier(callback));
        String type = getPasswordType(callback);
        if (type.endsWith("#PasswordDigest")) {
            if (pass != null) {
                setPassword(callback, pass);
                return;
            }
        } 
        if (type.endsWith("#PasswordText")) {
            // Code for CXF 2.4.X
            if (getPassword(callback) == null) {
                setPassword(callback, pass);
                return;
            }
        }
    }
}
 
Example 51
Project: Wiab.pro   File: HttpRequestBasedCallbackHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
  for (Callback c : callbacks) {
    if (c instanceof NameCallback) {
      if (parameters.containsKey(ADDRESS_FIELD)) {
        ((NameCallback) c).setName(parameters.getString(ADDRESS_FIELD));
      }
    } else if (c instanceof PasswordCallback) {
      if (parameters.containsKey(PASSWORD_FIELD)) {
        String password = parameters.getString(PASSWORD_FIELD);
        ((PasswordCallback) c).setPassword(password.toCharArray());
      }
    } else {
      throw new UnsupportedCallbackException(c);
    }
  }
}
 
Example 52
Project: javify   File: StorePasswdCmd.java   Source Code and License 6 votes vote down vote up
protected void setNewKeystorePassword(String password) throws IOException,
    UnsupportedCallbackException
{
  if (password != null)
    newStorePasswordChars = password.toCharArray();
  else
    {
      boolean ok = false;
      Callback[] prompts = new Callback[1];
      Callback[] errors = new Callback[1];
      for (int i = 0; i < 3; i++)
        if (prompt4NewPassword(getCallbackHandler(), prompts, errors))
          {
            ok = true;
            break;
          }
      if (! ok)
        throw new SecurityException(Messages.getString("StorePasswdCmd.19")); //$NON-NLS-1$
    }
}
 
Example 53
Project: Camel   File: UTPasswordCallback.java   Source Code and License 6 votes vote down vote up
/**
 * Here, we attempt to get the password from the private 
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        try {
            String id = (String)callback.getClass().getMethod("getIdentifier").invoke(callback);

            String pass = passwords.get(id);
            if (pass != null) {
                callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass);
                return;
            }
        } catch (Exception ex) {
            UnsupportedCallbackException e = new UnsupportedCallbackException(callback);
            e.initCause(ex);
            throw e;
        }
    }
}
 
Example 54
Project: lookaside_java-1.8.0-openjdk   File: NegotiateCallbackHandler.java   Source Code and License 6 votes vote down vote up
public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException, IOException {
    for (int i=0; i<callbacks.length; i++) {
        Callback callBack = callbacks[i];

        if (callBack instanceof NameCallback) {
            getAnswer();
            ((NameCallback)callBack).setName(username);
        } else if (callBack instanceof PasswordCallback) {
            getAnswer();
            ((PasswordCallback)callBack).setPassword(password);
            if (password != null) Arrays.fill(password, ' ');
        } else {
            throw new UnsupportedCallbackException(callBack,
                    "Call back not supported");
        }
    }
}
 
Example 55
Project: lookaside_java-1.8.0-openjdk   File: DynamicConfigurationTest.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 56
Project: drill   File: PlainFactory.java   Source Code and License 6 votes vote down vote up
@Override
public SaslClient createSaslClient(final UserGroupInformation ugi, final Map<String, ?> properties)
    throws SaslException {
  final String userName = (String) properties.get(DrillProperties.USER);
  final String password = (String) properties.get(DrillProperties.PASSWORD);

  return FastSaslClientFactory.getInstance().createSaslClient(new String[]{SIMPLE_NAME},
      null /** authorization ID */, null, null, properties, new CallbackHandler() {
        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
          for (final Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
              NameCallback.class.cast(callback).setName(userName);
              continue;
            }
            if (callback instanceof PasswordCallback) {
              PasswordCallback.class.cast(callback).setPassword(password.toCharArray());
              continue;
            }
            throw new UnsupportedCallbackException(callback);
          }
        }
      });
}
 
Example 57
Project: fcrepo3-security-jaas   File: XmlUsersFileModule.java   Source Code and License 5 votes vote down vote up
@Override
public boolean login() throws LoginException {
    if (debug) {
        logger.debug(this.getClass().getName() + " login called.");
    }

    if (Constants.FEDORA_HOME == null || "".equals(Constants.FEDORA_HOME.trim())) {
        logger.error("FEDORA_HOME constant is not set");
        return false;
    }

    final NameCallback nc = new NameCallback("username");
    final PasswordCallback pc = new PasswordCallback("password", false);
    final Callback[] callbacks = new Callback[] {
            nc, pc
    };

    try {
        handler.handle(callbacks);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new LoginException("IOException occured: " + ioe.getMessage());
    } catch (UnsupportedCallbackException ucbe) {
        ucbe.printStackTrace();
        throw new LoginException("UnsupportedCallbackException encountered: "
                + ucbe.getMessage());
    }

    // Grab the username and password from the callbacks.
    final String username = nc.getName();
    final String password = new String(pc.getPassword());

    successLogin = authenticate(username, password);

    return successLogin;
}
 
Example 58
Project: springboot-shiro-cas-mybatis   File: JaasAuthenticationHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(final Callback[] callbacks)
    throws UnsupportedCallbackException {
    for (final Callback callback : callbacks) {
        if (callback.getClass().equals(NameCallback.class)) {
            ((NameCallback) callback).setName(this.userName);
        } else if (callback.getClass().equals(PasswordCallback.class)) {
            ((PasswordCallback) callback).setPassword(this.password
                .toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback,
                "Unrecognized Callback");
        }
    }
}
 
Example 59
Project: springboot-shiro-cas-mybatis   File: JaasAuthenticationHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(final Callback[] callbacks)
    throws UnsupportedCallbackException {
    for (final Callback callback : callbacks) {
        if (callback.getClass().equals(NameCallback.class)) {
            ((NameCallback) callback).setName(this.userName);
        } else if (callback.getClass().equals(PasswordCallback.class)) {
            ((PasswordCallback) callback).setPassword(this.password
                .toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback,
                "Unrecognized Callback");
        }
    }
}
 
Example 60
Project: cas-5.1.0   File: RealmPasswordVerificationCallbackHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    Arrays.stream(callbacks)
            .filter(WSPasswordCallback.class::isInstance)
            .map(WSPasswordCallback.class::cast)
            .forEach(c -> {
                LOGGER.debug("Evaluating [{}]", c.getIdentifier());
                c.setPassword(this.psw);
                LOGGER.debug("Authenticated [{}] successfully.", c.getIdentifier());
            });
}