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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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$
}