javax.security.auth.callback.Callback Java Examples

The following examples show how to use javax.security.auth.callback.Callback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientCertCallbackHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof AuthorizeCallback) {
            AuthorizeCallback acb = (AuthorizeCallback) current;
            boolean authorized = acb.getAuthenticationID().equals(acb.getAuthorizationID());
            if (authorized == false) {
                SECURITY_LOGGER.tracef(
                        "Checking 'AuthorizeCallback', authorized=false, authenticationID=%s, authorizationID=%s.",
                        acb.getAuthenticationID(), acb.getAuthorizationID());
            }
            acb.setAuthorized(authorized);
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example #2
Source File: KerberosFactory.java    From Bats with Apache License 2.0 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 #3
Source File: DigestCallbackHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    boolean foundCallback = false;
    Callback firstUnknown = null;
    int count = callbacks != null ? callbacks.length : 0;
    for (int n = 0; n < count; n++) {
        Callback c = callbacks[n];
        if (c instanceof MapCallback) {
            MapCallback mc = (MapCallback) c;
            mc.setInfo(RFC2617Digest.USERNAME, username);
            mc.setInfo(RFC2617Digest.CNONCE, cnonce);
            mc.setInfo(RFC2617Digest.NONCE, nonce);
            mc.setInfo(RFC2617Digest.NONCE_COUNT, nc);
            mc.setInfo(RFC2617Digest.QOP, qop);
            mc.setInfo(RFC2617Digest.REALM, realm);
            mc.setInfo(RFC2617Digest.A2HASH, md5a2);
            foundCallback = true;
        } else if (firstUnknown == null) {
            firstUnknown = c;
        }
    }
    if (foundCallback == false)
        throw PicketBoxMessages.MESSAGES.unableToHandleCallback(firstUnknown, this.getClass().getName(),
                firstUnknown.getClass().getCanonicalName());
}
 
Example #4
Source File: LdapCallbackHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException
{
	if(userName == null)
	{
		userName = getUserName(callbacks);
	}
	for (int i = 0; i < callbacks.length; i++)
	{
		Callback callback = callbacks[i];
		try
		{
			this.handleCallBack( callback );
		}
		catch (NamingException e)
		{
			throw new IOException(e);
		}
	}
}
 
Example #5
Source File: WSSUsernameCallbackHandler.java    From steady with Apache License 2.0 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 DelegationCallback) {
            DelegationCallback callback = (DelegationCallback) callbacks[i];
            Message message = callback.getCurrentMessage();
            
            String username = 
                (String)message.getContextualProperty(SecurityConstants.USERNAME);
            if (username != null) {
                Node contentNode = message.getContent(Node.class);
                Document doc = null;
                if (contentNode != null) {
                    doc = contentNode.getOwnerDocument();
                } else {
                    doc = DOMUtils.createDocument();
                }
                UsernameToken usernameToken = createWSSEUsernameToken(username, doc);
                callback.setToken(usernameToken.getElement());
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example #6
Source File: AuthentcationTypeCallbackHandler.java    From cxf-fediz with Apache License 2.0 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 WAuthCallback) {
            WAuthCallback callback = (WAuthCallback) callbacks[i];
            String authenticationType = (String)callback.getRequest().getAttribute("wauth");
            if (authenticationType == null || authenticationType.length() == 0) {
                LOG.debug("No authentication type found in request");
            } else {
                LOG.info("Authentication type '" + authenticationType + "' found in request");
                callback.setWauth(authenticationType);
            }

        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example #7
Source File: SAML1CallbackHandler.java    From steady with Apache License 2.0 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 SAMLCallback) {
            SAMLCallback callback = (SAMLCallback) callbacks[i];
            callback.setSamlVersion(SAMLVersion.VERSION_11);
            SubjectBean subjectBean = 
                new SubjectBean(
                    subjectName, subjectQualifier, confirmationMethod
                );
            if (SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
                try {
                    KeyInfoBean keyInfo = createKeyInfo();
                    subjectBean.setKeyInfo(keyInfo);
                } catch (Exception ex) {
                    throw new IOException("Problem creating KeyInfo: " +  ex.getMessage());
                }
            }
            createAndSetStatement(subjectBean, callback);
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example #8
Source File: AbstractSTSClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Element getDelegationSecurityToken(Object delegationObject) throws Exception {
    if (delegationObject != null) {
        final boolean isString = delegationObject instanceof String;
        final boolean isElement = delegationObject instanceof Element;
        final boolean isCallbackHandler = delegationObject instanceof CallbackHandler;
        if (isString) {
            final Document doc =
                StaxUtils.read(new StringReader((String) delegationObject));
            return doc.getDocumentElement();
        } else if (isElement) {
            return (Element) delegationObject;
        } else if (isCallbackHandler) {
            DelegationCallback callback = new DelegationCallback(message);
            ((CallbackHandler)delegationObject).handle(new Callback[]{callback});
            return callback.getToken();
        }
    }
    return null;
}
 
Example #9
Source File: NegotiateCallbackHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 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 #10
Source File: HostControllerConnection.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            String defaultText = rcb.getDefaultText();
            rcb.setText(defaultText); // For now just use the realm suggested.
        } else if (current instanceof RealmChoiceCallback) {
            throw new UnsupportedCallbackException(current, "Realm choice not currently supported.");
        } else if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(authKey.toCharArray());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example #11
Source File: NegotiateCallbackHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 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 #12
Source File: TestUserPasswordLoginModule.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
    NameCallback nameCallback = new NameCallback("User");
    PasswordCallback passwordCallback = new PasswordCallback("Password", false);
    Callback[] callbacks = new Callback[] {nameCallback, passwordCallback};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new LoginException(e.getMessage());
    }
    String userName = nameCallback.getName();
    String password = new String(passwordCallback.getPassword());
    if (!TESTUSER.equals(userName)) {
        throw new LoginException("wrong username");
    }
    if (!TESTPASS.equals(password)) {
        throw new LoginException("wrong password");
    }
    subject.getPrincipals().add(new SimplePrincipal(userName));
    subject.getPrincipals().add(new SimpleGroup(TESTGROUP));
    return true;
}
 
Example #13
Source File: RbacAdminCallbackHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(userName);
            System.out.println("set user " + userName);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password.toCharArray());
            System.out.println("set password " + password);
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example #14
Source File: UpnPwdCallbackHandler.java    From MyVirtualDirectory with Apache License 2.0 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 #15
Source File: ScriptLoginModule.java    From tomee with Apache License 2.0 6 votes vote down vote up
private UserData getUserData() throws LoginException {
    final Callback[] callbacks = new Callback[2];

    callbacks[0] = new NameCallback("Username: ");
    callbacks[1] = new PasswordCallback("Password: ", false);
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final IOException ioe) {
        throw new LoginException(ioe.getMessage());
    } catch (final UnsupportedCallbackException uce) {
        throw new LoginException(uce.getMessage() + " not available to obtain information from user");
    }

    final String user = ((NameCallback) callbacks[0]).getName();

    char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
    if (tmpPassword == null) {
        tmpPassword = new char[0];
    }

    final String password = new String(tmpPassword);

    return new UserData(user, password);
}
 
Example #16
Source File: SSLAndKerberosTest.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
protected Subject loginTestUser() throws LoginException, IOException {
    LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    PasswordCallback passwordCallback = (PasswordCallback) callback;
                    passwordCallback.setPassword(TESTPASS.toCharArray());
                }
                if (callback instanceof NameCallback) {
                    NameCallback nameCallback = (NameCallback) callback;
                    nameCallback.setName(TESTUSER);
                }
            }
        }
    });
    // attempt authentication
    lc.login();
    return lc.getSubject();
}
 
Example #17
Source File: MyDeployer.java    From wildfly-samples with MIT License 6 votes vote down vote up
static ModelControllerClient createClient(final InetAddress host, final int port,
        final String username, final String password) {

    final CallbackHandler callbackHandler = new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback current : callbacks) {
                if (current instanceof NameCallback) {
                    NameCallback ncb = (NameCallback) current;
                    ncb.setName(username);
                } else if (current instanceof PasswordCallback) {
                    PasswordCallback pcb = (PasswordCallback) current;
                    pcb.setPassword(password.toCharArray());
                } else {
                    throw new UnsupportedCallbackException(current);
                }
            }
        }
    };

    return ModelControllerClient.Factory.create(host, port, callbackHandler);
}
 
Example #18
Source File: ClientIdHomeRealmDiscovery.java    From cxf-fediz with Apache License 2.0 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 HomeRealmCallback) {
            HomeRealmCallback callback = (HomeRealmCallback) callbacks[i];

            HttpServletRequest request = callback.getRequest();
            String clientId = request.getParameter("client_id");

            if (clientId != null) {
                ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();
                OAuthDataProvider dataManager = (OAuthDataProvider)ctx.getBean("oauthProvider");

                Client client = dataManager.getClient(clientId);
                if (client != null) {
                    callback.setHomeRealm(client.getHomeRealm());
                    LOG.debug("Retrieved home realm {}", callback.getHomeRealm());
                }

            }

        } else {
            LOG.warn("Callback is not an instance of HomeRealmCallback: {}", callbacks[i]);
        }
    }
}
 
Example #19
Source File: GhidraServer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public Callback[] getAuthenticationCallbacks() throws RemoteException {
	log.info("Authentication callbacks requested by " + RepositoryManager.getRMIClient());
	try {
		Callback[] callbacks =
			authModule != null ? authModule.getAuthenticationCallbacks() : null;
		if (sshAuthModule != null) {
			callbacks = sshAuthModule.addAuthenticationCallbacks(callbacks);
		}
		if (anonymousAuthModule != null &&
			(authModule == null || authModule.anonymousCallbacksAllowed())) {
			callbacks = anonymousAuthModule.addAuthenticationCallbacks(callbacks);
		}
		return callbacks;
	}
	catch (Throwable t) {
		log.error("Failed to generate authentication callbacks", t);
		throw new RemoteException("Failed to generate authentication callbacks", t);
	}
}
 
Example #20
Source File: NegotiateCallbackHandler.java    From TencentKona-8 with GNU General Public License v2.0 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 #21
Source File: WSSUsernameCallbackHandler.java    From cxf with Apache License 2.0 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 DelegationCallback) {
            DelegationCallback callback = (DelegationCallback) callbacks[i];
            Message message = callback.getCurrentMessage();

            String username =
                (String)SecurityUtils.getSecurityPropertyValue(SecurityConstants.USERNAME, message);
            if (username != null) {
                Node contentNode = message.getContent(Node.class);
                Document doc = null;
                if (contentNode != null) {
                    doc = contentNode.getOwnerDocument();
                } else {
                    doc = DOMUtils.getEmptyDocument();
                }
                UsernameToken usernameToken = createWSSEUsernameToken(username, doc);
                callback.setToken(usernameToken.getElement());
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example #22
Source File: OneKDC.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) {
    String user = OneKDC.USER;
    char[] pass = OneKDC.PASS;
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("Callback for name: " + user);
            ((NameCallback) callback).setName(user);
        }
        if (callback instanceof PasswordCallback) {
            System.out.println("Callback for pass: "
                    + new String(pass));
            ((PasswordCallback) callback).setPassword(pass);
        }
    }
}
 
Example #23
Source File: SAMLSPCallbackHandler.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof WSPasswordCallback) {
            WSPasswordCallback wspc = (WSPasswordCallback) callback;
            wspc.setPassword(keyPass);
        }
    }
}
 
Example #24
Source File: SaslNettyServer.java    From herddb with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            handleNameCallback((NameCallback) callback);
        } else if (callback instanceof PasswordCallback) {
            handlePasswordCallback((PasswordCallback) callback);
        } else if (callback instanceof RealmCallback) {
            handleRealmCallback((RealmCallback) callback);
        } else if (callback instanceof AuthorizeCallback) {
            handleAuthorizeCallback((AuthorizeCallback) callback);
        }
    }
}
 
Example #25
Source File: OneKDC.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) {
    String user = OneKDC.USER;
    char[] pass = OneKDC.PASS;
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("Callback for name: " + user);
            ((NameCallback) callback).setName(user);
        }
        if (callback instanceof PasswordCallback) {
            System.out.println("Callback for pass: "
                    + new String(pass));
            ((PasswordCallback) callback).setPassword(pass);
        }
    }
}
 
Example #26
Source File: OneKDC.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) {
    String user = OneKDC.USER;
    char[] pass = OneKDC.PASS;
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            System.out.println("Callback for name: " + user);
            ((NameCallback) callback).setName(user);
        }
        if (callback instanceof PasswordCallback) {
            System.out.println("Callback for pass: "
                    + new String(pass));
            ((PasswordCallback) callback).setPassword(pass);
        }
    }
}
 
Example #27
Source File: Confirm.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Provide answer in an individual stream so that the program
    // does not block.
    System.setIn(new ByteArrayInputStream("1\n".getBytes()));

    new TextCallbackHandler().handle(new Callback[]{
        new ConfirmationCallback("Prince", ConfirmationCallback.INFORMATION,
                new String[]{"To be", "Not to be"}, 0)});
}
 
Example #28
Source File: Helper.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks)
        throws UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword(
                    password.toCharArray());
        } else if (callback instanceof NameCallback) {
            ((NameCallback)callback).setName(name);
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example #29
Source File: APIManagerOAuthCallbackHandler.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    if (callbacks != null && callbacks.length > 0){
        OAuthCallback oauthCallback = (OAuthCallback) callbacks[0];
        if (OAuthCallback.OAuthCallbackType.ACCESS_DELEGATION_AUTHZ.equals(
                oauthCallback.getCallbackType())){
            oauthCallback.setAuthorized(true);
        }
        if (OAuthCallback.OAuthCallbackType.ACCESS_DELEGATION_TOKEN.equals(
                oauthCallback.getCallbackType())){
            oauthCallback.setAuthorized(true);
        }
        if (OAuthCallback.OAuthCallbackType.SCOPE_VALIDATION_AUTHZ.equals(
                oauthCallback.getCallbackType())){
            //Validate scopes in callback using scope issuers
            ScopesIssuer.getInstance().setScopes(oauthCallback);
            oauthCallback.setValidScope(true);
        }
        if (OAuthCallback.OAuthCallbackType.SCOPE_VALIDATION_TOKEN.equals(
                oauthCallback.getCallbackType())){
            String[] scopes = oauthCallback.getRequestedScope();
            //If no scopes have been requested.
            if(scopes == null || scopes.length == 0){
               //Issue a default scope. The default scope can only be used to access resources which are
               // not associated to a scope
               scopes = new String[]{APIConstants.OAUTH2_DEFAULT_SCOPE};
            }
            oauthCallback.setApprovedScope(scopes);
            oauthCallback.setValidScope(true);
        }
    }
}
 
Example #30
Source File: CleanState.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void go() throws Exception {
    Krb5LoginModule krb5 = new Krb5LoginModule();

    final String name = OneKDC.USER;
    final char[] password = OneKDC.PASS;
    char[] badpassword = "hellokitty".toCharArray();

    Map<String,String> map = new HashMap<>();
    map.put("useTicketCache", "false");
    map.put("doNotPrompt", "false");
    map.put("tryFirstPass", "true");
    Map<String,Object> shared = new HashMap<>();
    shared.put("javax.security.auth.login.name", name);
    shared.put("javax.security.auth.login.password", badpassword);

    krb5.initialize(new Subject(), new CallbackHandler() {
        @Override
        public void handle(Callback[] callbacks) {
            for(Callback callback: callbacks) {
                if (callback instanceof NameCallback) {
                    ((NameCallback)callback).setName(name);
                }
                if (callback instanceof PasswordCallback) {
                    ((PasswordCallback)callback).setPassword(password);
                }
            }
        }
    }, shared, map);
    krb5.login();
}