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


Java Subject.getPublicCredentials方法代码示例

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


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

示例1: getUseridFromWSSubject

import javax.security.auth.Subject; //导入方法依赖的package包/类
/**
 * Returns the unique security name of the first public credentials found in the WSSubject as userid.
 *
 * @return the userid of the caller. If the userid could not be obtained, null is returned.
 */
private static String getUseridFromWSSubject() {
    try {
        Class<?> wsSubjectClass = Class.forName(WSSUBJECT_CLASSNAME);
        Method getCallerSubjectMethod = wsSubjectClass.getMethod(GET_CALLER_SUBJECT_METHOD, (Class<?>[]) null);
        Subject callerSubject = (Subject) getCallerSubjectMethod.invoke(null, (Object[]) null);
        LOGGER.debug("Subject of caller: {}", callerSubject);
        if (callerSubject != null) {
            Set<Object> publicCredentials = callerSubject.getPublicCredentials();
            LOGGER.debug("Public credentials of caller: {}", publicCredentials);
            for (Object pC : publicCredentials) {
                Object o = pC.getClass().getMethod(GET_UNIQUE_SECURITY_NAME_METHOD, (Class<?>[]) null).invoke(pC,
                    (Object[]) null);
                LOGGER.debug("Returning the unique security name of first public credential: {}", o);
                String userIdFound = o.toString();
                String userIdUsed = userIdFound;
                if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
                    userIdUsed = userIdFound.toLowerCase();
                }
                LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
                return userIdUsed;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Could not get user from WSSubject. Going ahead unauthorized.");
    }
    return null;
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:33,代码来源:CurrentUserContext.java

示例2: testAddAll

import javax.security.auth.Subject; //导入方法依赖的package包/类
private static void testAddAll() {
    // Create a well formed subject and additional collections
    Subject mtSubj = makeSubj(false, false, false);
    Set<Principal> morePrincs = new HashSet<>(Arrays.asList(tmplAddPrincs));
    Set<Object> morePubVals = new HashSet<>(Arrays.asList(tmplAddPubVals));
    Set<Object> morePrvVals = new HashSet<>(Arrays.asList(tmplAddPrvVals));

    // Run one success test for each Subject family to verify the
    // overloaded method works as intended.
    Set<Principal> setPrin = mtSubj.getPrincipals();
    Set<Object> setPubCreds = mtSubj.getPublicCredentials();
    Set<Object> setPrvCreds = mtSubj.getPrivateCredentials();
    int prinOrigSize = setPrin.size();
    int pubOrigSize = setPubCreds.size();
    int prvOrigSize = setPrvCreds.size();

    System.out.println("------ addAll() -----");

    // Add the new members, then check the resulting size of the
    // Subject attributes to verify they've increased by the proper
    // amounts.
    if ((validTestCollection(methAdd, setPrin, morePrincs) != true) ||
        (setPrin.size() != prinOrigSize + morePrincs.size()))
    {
        throw new RuntimeException("Failed addAll() on principals");
    }
    if ((validTestCollection(methAdd, setPubCreds,
            morePubVals) != true) ||
        (setPubCreds.size() != pubOrigSize + morePubVals.size()))
    {
        throw new RuntimeException("Failed addAll() on public creds");
    }
    if ((validTestCollection(methAdd, setPrvCreds,
            morePrvVals) != true) ||
        (setPrvCreds.size() != prvOrigSize + morePrvVals.size()))
    {
        throw new RuntimeException("Failed addAll() on private creds");
    }
    System.out.println("Positive addAll() test passed");

    // Now add null elements into each container, then retest
    morePrincs.add(null);
    morePubVals.add(null);
    morePrvVals.add(null);

    System.out.println("* Testing addAll w/ null values on Principals");
    nullTestCollection(methAdd, mtSubj.getPrincipals(), null);
    nullTestCollection(methAdd, mtSubj.getPrincipals(), morePrincs);

    System.out.println("* Testing addAll w/ null values on Public Creds");
    nullTestCollection(methAdd, mtSubj.getPublicCredentials(), null);
    nullTestCollection(methAdd, mtSubj.getPublicCredentials(),
            morePubVals);

    System.out.println("* Testing addAll w/ null values on Private Creds");
    nullTestCollection(methAdd, mtSubj.getPrivateCredentials(), null);
    nullTestCollection(methAdd, mtSubj.getPrivateCredentials(),
            morePrvVals);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:SubjectNullTests.java

示例3: testRemoveAll

import javax.security.auth.Subject; //导入方法依赖的package包/类
private static void testRemoveAll() {
    // Create a well formed subject and additional collections
    Subject mtSubj = makeSubj(false, false, false);
    Set<Principal> remPrincs = new HashSet<>();
    Set<Object> remPubVals = new HashSet<>();
    Set<Object> remPrvVals = new HashSet<>();

    remPrincs.add(new KerberosPrincipal("mtwain/[email protected]"));
    remPubVals.add("mtwain");
    remPrvVals.add("5Cl3M3nz");

    // Run one success test for each Subject family to verify the
    // overloaded method works as intended.
    Set<Principal> setPrin = mtSubj.getPrincipals();
    Set<Object> setPubCreds = mtSubj.getPublicCredentials();
    Set<Object> setPrvCreds = mtSubj.getPrivateCredentials();
    int prinOrigSize = setPrin.size();
    int pubOrigSize = setPubCreds.size();
    int prvOrigSize = setPrvCreds.size();

    System.out.println("------ removeAll() -----");

    // Remove the specified members, then check the resulting size of the
    // Subject attributes to verify they've decreased by the proper
    // amounts.
    if ((validTestCollection(methRemove, setPrin, remPrincs) != true) ||
        (setPrin.size() != prinOrigSize - remPrincs.size()))
    {
        throw new RuntimeException("Failed removeAll() on principals");
    }
    if ((validTestCollection(methRemove, setPubCreds,
            remPubVals) != true) ||
        (setPubCreds.size() != pubOrigSize - remPubVals.size()))
    {
        throw new RuntimeException("Failed removeAll() on public creds");
    }
    if ((validTestCollection(methRemove, setPrvCreds,
            remPrvVals) != true) ||
        (setPrvCreds.size() != prvOrigSize - remPrvVals.size()))
    {
        throw new RuntimeException("Failed removeAll() on private creds");
    }
    System.out.println("Positive removeAll() test passed");

    // Now add null elements into each container, then retest
    remPrincs.add(null);
    remPubVals.add(null);
    remPrvVals.add(null);

    System.out.println("* Testing removeAll w/ null values on Principals");
    nullTestCollection(methRemove, mtSubj.getPrincipals(), null);
    nullTestCollection(methRemove, mtSubj.getPrincipals(), remPrincs);

    System.out.println(
            "* Testing removeAll w/ null values on Public Creds");
    nullTestCollection(methRemove, mtSubj.getPublicCredentials(), null);
    nullTestCollection(methRemove, mtSubj.getPublicCredentials(),
            remPubVals);

    System.out.println(
            "* Testing removeAll w/ null values on Private Creds");
    nullTestCollection(methRemove, mtSubj.getPrivateCredentials(), null);
    nullTestCollection(methRemove, mtSubj.getPrivateCredentials(),
            remPrvVals);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:SubjectNullTests.java

示例4: testRetainAll

import javax.security.auth.Subject; //导入方法依赖的package包/类
private static void testRetainAll() {
    // Create a well formed subject and additional collections
    Subject mtSubj = makeSubj(false, false, false);
    Set<Principal> remPrincs = new HashSet<>(Arrays.asList(tmplAddPrincs));
    Set<Object> remPubVals = new HashSet<>(Arrays.asList(tmplAddPubVals));
    Set<Object> remPrvVals = new HashSet<>(Arrays.asList(tmplAddPrvVals));

    // Add in values that exist within the Subject
    remPrincs.add(princVals[2]);
    remPubVals.add(pubVals[2]);
    remPrvVals.add(privVals[2]);

    // Run one success test for each Subject family to verify the
    // overloaded method works as intended.
    Set<Principal> setPrin = mtSubj.getPrincipals();
    Set<Object> setPubCreds = mtSubj.getPublicCredentials();
    Set<Object> setPrvCreds = mtSubj.getPrivateCredentials();
    int prinOrigSize = setPrin.size();
    int pubOrigSize = setPubCreds.size();
    int prvOrigSize = setPrvCreds.size();

    System.out.println("------ retainAll() -----");

    // Retain the specified members (those that exist in the Subject)
    // and validate the results.
    if (validTestCollection(methRetain, setPrin, remPrincs) == false ||
        setPrin.size() != 1 || setPrin.contains(princVals[2]) == false)
    {
        throw new RuntimeException("Failed retainAll() on principals");
    }

    if (validTestCollection(methRetain, setPubCreds,
            remPubVals) == false ||
        setPubCreds.size() != 1 ||
        setPubCreds.contains(pubVals[2]) == false)
    {
        throw new RuntimeException("Failed retainAll() on public creds");
    }
    if (validTestCollection(methRetain, setPrvCreds,
            remPrvVals) == false ||
        setPrvCreds.size() != 1 ||
        setPrvCreds.contains(privVals[2]) == false)
    {
        throw new RuntimeException("Failed retainAll() on private creds");
    }
    System.out.println("Positive retainAll() test passed");

    // Now add null elements into each container, then retest
    remPrincs.add(null);
    remPubVals.add(null);
    remPrvVals.add(null);

    System.out.println("* Testing retainAll w/ null values on Principals");
    nullTestCollection(methRetain, mtSubj.getPrincipals(), null);
    nullTestCollection(methRetain, mtSubj.getPrincipals(), remPrincs);

    System.out.println(
            "* Testing retainAll w/ null values on Public Creds");
    nullTestCollection(methRetain, mtSubj.getPublicCredentials(), null);
    nullTestCollection(methRetain, mtSubj.getPublicCredentials(),
            remPubVals);

    System.out.println(
            "* Testing retainAll w/ null values on Private Creds");
    nullTestCollection(methRetain, mtSubj.getPrivateCredentials(), null);
    nullTestCollection(methRetain, mtSubj.getPrivateCredentials(),
            remPrvVals);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:SubjectNullTests.java


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