当前位置: 首页>>代码示例>>Java>>正文


Java NameCallback类代码示例

本文整理汇总了Java中javax.security.auth.callback.NameCallback的典型用法代码示例。如果您正苦于以下问题:Java NameCallback类的具体用法?Java NameCallback怎么用?Java NameCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NameCallback类属于javax.security.auth.callback包,在下文中一共展示了NameCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: map

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
@Override
public Optional<Subject> map(final Optional<Object> wrapper) {
    try {
        LOG.info("logging in user as {}", username);
        LoginContext lc = new LoginContext("PropertyFile", callbacks -> {
            LOG.info("Callback Handler invoked ");
            Stream.of(callbacks).forEach(cb -> {
                if (cb instanceof NameCallback) {
                    ((NameCallback) cb).setName(username);
                } else if (cb instanceof PasswordCallback) {
                    ((PasswordCallback) cb).setPassword(password.toCharArray());
                }
            });
        });
        lc.login();
        return Optional.of(lc.getSubject());
    } catch (LoginException e) {
        LOG.error("Authentication failed", e);
        return Optional.empty();
    }
}
 
开发者ID:gmuecke,项目名称:boutique-de-jus,代码行数:22,代码来源:LoginModuleAuthSupport.java

示例2: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:discoverygarden,项目名称:fcrepo3-security-jaas,代码行数:23,代码来源:AuthFilterJAAS.java

示例3: login

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
@Override
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:MockLoginModule.java

示例4: login

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if ("test".equals(userName) && "test".equals(password)) {
        return true;
    }

    throw new LoginException();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:MockLoginModule.java

示例5: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
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");
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:24,代码来源:JaasAuthBean.java

示例6: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
@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"));
    });
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:JaasAuthenticationHandler.java

示例7: fillResultFromCallback

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
private void fillResultFromCallback ( final Callback cb, final javax.security.auth.callback.Callback jcb )
{
    if ( cb instanceof TextCallback && jcb instanceof TextInputCallback )
    {
        ( (TextCallback)cb ).setValue ( ( (TextInputCallback)jcb ).getText () );
    }
    else if ( cb instanceof UserNameCallback && jcb instanceof NameCallback )
    {
        ( (UserNameCallback)cb ).setValue ( ( (NameCallback)jcb ).getName () );
    }
    else if ( cb instanceof PasswordCallback && jcb instanceof javax.security.auth.callback.PasswordCallback )
    {
        ( (PasswordCallback)cb ).setPassword ( String.valueOf ( ( (javax.security.auth.callback.PasswordCallback)jcb ).getPassword () ) );
    }
    else
    {
        cb.cancel ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:JavaCallbackHandler.java

示例8: convert

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
private javax.security.auth.callback.Callback convert ( final Callback cb )
{
    if ( cb instanceof UserNameCallback )
    {
        return new NameCallback ( ( (UserNameCallback)cb ).getLabel () );
    }
    else if ( cb instanceof TextCallback )
    {
        return new TextInputCallback ( ( (TextCallback)cb ).getLabel () );
    }
    if ( cb instanceof PasswordCallback )
    {
        return new javax.security.auth.callback.PasswordCallback ( ( (PasswordCallback)cb ).getLabel (), false );
    }
    return null;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:JavaCallbackHandler.java

示例9: login

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
public boolean login() throws LoginException {
    final Callback[] callbacks = new Callback[] {new NameCallback("f"), new PasswordCallback("f", false)};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final Exception e) {
        throw new LoginException();
    }

    final String userName = ((NameCallback) callbacks[0]).getName();
    final String password = new String(((PasswordCallback) callbacks[1]).getPassword());

    if (userName.equals("test") && password.equals("test")) {
        return true;
    }

    throw new LoginException();
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:18,代码来源:MockLoginModule.java

示例10: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:17,代码来源:PlainSaslCallbackHandler.java

示例11: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
/**
 * 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");
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:UserCredentialsHandler.java

示例12: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
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");
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:WSCallbackHandler.java

示例13: createSaslClient

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
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);
                        }
                    }
                }
            });
}
 
开发者ID:mongodb,项目名称:mongosql-auth-java,代码行数:17,代码来源:Plain.java

示例14: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
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");
        }
    }
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:19,代码来源:KerberosAuthenticator2.java

示例15: handle

import javax.security.auth.callback.NameCallback; //导入依赖的package包/类
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");
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:NegotiateCallbackHandler.java


注:本文中的javax.security.auth.callback.NameCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。