Search in sources :

Example 1 with CredentialIdentity

use of org.jboss.security.identity.extensions.CredentialIdentity in project wildfly by wildfly.

the class DefaultApplicationClientCallbackHandler method handle.

@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    final SecurityContext context = doPrivileged(SECURITY_CONTEXT);
    for (final Callback current : callbacks) {
        if (current instanceof NameCallback) {
            final NameCallback ncb = (NameCallback) current;
            if (context != null) {
                final Set<Identity> identities = getSubjectInfo(context).getIdentities();
                if (identities.isEmpty()) {
                    ncb.setName(DOLLAR_LOCAL);
                } else {
                    final Identity identity = identities.iterator().next();
                    ncb.setName(identity.getName());
                }
            } else {
                ncb.setName(DOLLAR_LOCAL);
            }
        } else if (current instanceof PasswordCallback) {
            if (context != null) {
                final PasswordCallback pcb = (PasswordCallback) current;
                final Set<Identity> identities = getSubjectInfo(context).getIdentities();
                if (identities.isEmpty()) {
                    throw new UnsupportedCallbackException(current);
                } else {
                    final Identity identity = identities.iterator().next();
                    if (identity instanceof CredentialIdentity) {
                        pcb.setPassword((char[]) ((CredentialIdentity) identity).getCredential());
                    } else {
                        throw new UnsupportedCallbackException(current);
                    }
                }
            }
        } else if (current instanceof RealmCallback) {
            final RealmCallback realmCallback = (RealmCallback) current;
            if (realmCallback.getText() == null) {
                realmCallback.setText(realmCallback.getDefaultText());
            }
        }
    }
}
Also used : CredentialIdentity(org.jboss.security.identity.extensions.CredentialIdentity) RealmCallback(javax.security.sasl.RealmCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) Set(java.util.Set) SecurityContext(org.jboss.security.SecurityContext) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Identity(org.jboss.security.identity.Identity) CredentialIdentity(org.jboss.security.identity.extensions.CredentialIdentity) RealmCallback(javax.security.sasl.RealmCallback)

Aggregations

Set (java.util.Set)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 RealmCallback (javax.security.sasl.RealmCallback)1 SecurityContext (org.jboss.security.SecurityContext)1 Identity (org.jboss.security.identity.Identity)1 CredentialIdentity (org.jboss.security.identity.extensions.CredentialIdentity)1