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


Java Subject类代码示例

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


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

示例1: validateServiceTicket

import javax.security.auth.Subject; //导入依赖的package包/类
public static String validateServiceTicket(Subject subject, final byte[] serviceTicket)
    throws GSSException, IllegalAccessException, NoSuchFieldException, ClassNotFoundException,
    PrivilegedActionException {
  // Kerberos version 5 OID
  Oid krb5Oid = KerberosUtils.getOidInstance("GSS_KRB5_MECH_OID");


  // Accept the context and return the client principal name.
  return Subject.doAs(subject, new PrivilegedExceptionAction<String>() {

    @Override
    public String run() throws Exception {
      String clientName = null;
      // Identify the server that communications are being made to.
      GSSManager manager = GSSManager.getInstance();
      GSSContext context = manager.createContext((GSSCredential) null);
      context.acceptSecContext(serviceTicket, 0, serviceTicket.length);
      clientName = context.getSrcName().toString();
      return clientName;
    }
  });
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:KerberosTicketOperations.java

示例2: initialize

import javax.security.auth.Subject; //导入依赖的package包/类
/**
 * Initialize this <code>LoginModule</code> with the specified
 * configuration information.
 *
 * @param subject The <code>Subject</code> to be authenticated
 * @param callbackHandler A <code>CallbackHandler</code> for communicating
 *  with the end user as necessary
 * @param sharedState State information shared with other
 *  <code>LoginModule</code> instances
 * @param options Configuration information for this specific
 *  <code>LoginModule</code> instance
 */
public void initialize(Subject subject, CallbackHandler callbackHandler,
                       Map sharedState, Map options) {
    log.debug("Init");

    // Save configuration values
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;

    // Perform instance-specific initialization
    if (options.get("pathname") != null)
        this.pathname = (String) options.get("pathname");

    // Load our defined Principals
    load();

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:JAASMemoryLoginModule.java

示例3: checkAccessFileEntries

import javax.security.auth.Subject; //导入依赖的package包/类
private void checkAccessFileEntries(Subject subject) {
    if (subject == null) {
        throw new SecurityException(
                "Access denied! No matching entries found in " +
                "the access file [" + accessFile + "] as the " +
                "authenticated Subject is null");
    }
    final Set<Principal> principals = subject.getPrincipals();
    for (Principal p1: principals) {
        if (properties.containsKey(p1.getName())) {
            return;
        }
    }

    final Set<String> principalsStr = new HashSet<>();
    for (Principal p2: principals) {
        principalsStr.add(p2.getName());
    }
    throw new SecurityException(
            "Access denied! No entries found in the access file [" +
            accessFile + "] for any of the authenticated identities " +
            principalsStr);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:ConnectorBootstrap.java

示例4: postProcessFileList

import javax.security.auth.Subject; //导入依赖的package包/类
public void postProcessFileList(ProcessorInfo processorInfo, Subject peerSubject, Throwable downCause, String downMessage) throws Exception {
    logger.log(Level.INFO, " [ PostRename ] Subject: " + peerSubject);
    String filePrefix = System.getProperty(PREFIX, DEFAULT_PREFIX);

    for (int i = 0; i < processorInfo.fileList.length; i++) {
        try {
            String name = processorInfo.fileList[i];
            final String outFilename = processorInfo.destinationDir + File.separator + filePrefix + name;
            final String orgFileName = processorInfo.destinationDir + File.separator + name;
            logger.log(Level.INFO, "Renaming file: " + name + " to: " + filePrefix + name);
            new File(orgFileName).renameTo(new File(outFilename));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:17,代码来源:PostRename.java

示例5: fetchNotification

import javax.security.auth.Subject; //导入依赖的package包/类
@Override
public void fetchNotification(
    String connectionId,
    ObjectName name,
    Notification notification,
    Subject subject)
    throws SecurityException {
    echo("fetchNotification:");
    echo("\tconnectionId: " +  connectionId);
    echo("\tname: " +  name);
    echo("\tnotification: " +  notification);
    echo("\tsubject: " +
         (subject == null ? null : subject.getPrincipals()));
    if (!throwException)
        if (name.getCanonicalName().equals("domain:name=2,type=NB")
            &&
            subject != null
            &&
            subject.getPrincipals().contains(new JMXPrincipal("role")))
            throw new SecurityException();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:NotificationAccessControllerTest.java

示例6: testRequestPickActive

import javax.security.auth.Subject; //导入依赖的package包/类
@Test
public void testRequestPickActive() {
    final AuthenticationContext authCtx = prc.getSubcontext(AuthenticationContext.class);
    final List<Principal> principals = Arrays.<Principal> asList(new TestPrincipal("test3"), new TestPrincipal(
            "test2"));
    final RequestedPrincipalContext rpc = new RequestedPrincipalContext();
    rpc.getPrincipalEvalPredicateFactoryRegistry().register(TestPrincipal.class, "exact",
            new ExactPrincipalEvalPredicateFactory());
    rpc.setOperator("exact");
    rpc.setRequestedPrincipals(principals);
    authCtx.addSubcontext(rpc, true);
    final AuthenticationResult active = new AuthenticationResult("test3", new Subject());
    active.getSubject().getPrincipals().add(new TestPrincipal("test3"));
    authCtx.setActiveResults(Arrays.asList(active));
    authCtx.getPotentialFlows().get("test3").setSupportedPrincipals(ImmutableList.of(principals.get(0)));

    final Event event = action.execute(src);

    ActionTestingSupport.assertProceedEvent(event);
    Assert.assertEquals(active, authCtx.getAuthenticationResult());
}
 
开发者ID:CSCfi,项目名称:shibboleth-idp-oidc-extension,代码行数:22,代码来源:SelectAuthenticationFlowTest.java

示例7: newLoginContext

import javax.security.auth.Subject; //导入依赖的package包/类
private static LoginContext
newLoginContext(String appName, Subject subject,
  javax.security.auth.login.Configuration loginConf)
    throws LoginException {
  // Temporarily switch the thread's ContextClassLoader to match this
  // class's classloader, so that we can properly load HadoopLoginModule
  // from the JAAS libraries.
  Thread t = Thread.currentThread();
  ClassLoader oldCCL = t.getContextClassLoader();
  t.setContextClassLoader(HadoopLoginModule.class.getClassLoader());
  try {
    return new LoginContext(appName, subject, null, loginConf);
  } finally {
    t.setContextClassLoader(oldCCL);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:UserGroupInformation.java

示例8: testIsEmpty

import javax.security.auth.Subject; //导入依赖的package包/类
private static void testIsEmpty() {
    Subject populatedSubj = makeSubj(false, false, false);
    Subject emptySubj = new Subject();

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

    if (populatedSubj.getPrincipals().isEmpty()) {
        throw new RuntimeException(
                "Populated Subject Principals incorrectly returned empty");
    }
    if (emptySubj.getPrincipals().isEmpty() == false) {
        throw new RuntimeException(
                "Empty Subject Principals incorrectly returned non-empty");
    }
    System.out.println("isEmpty() test passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:SubjectNullTests.java

示例9: getServiceCreds

import javax.security.auth.Subject; //导入依赖的package包/类
/**
 * Retrieves the ServiceCreds for the specified server principal from
 * the Subject in the specified AccessControlContext. If not found, and if
 * useSubjectCredsOnly is false, then obtain from a LoginContext.
 *
 * NOTE: This method is also used by JSSE Kerberos Cipher Suites
 */
public static ServiceCreds getServiceCreds(GSSCaller caller,
    String serverPrincipal, AccessControlContext acc)
            throws LoginException {

    Subject accSubj = Subject.getSubject(acc);
    ServiceCreds sc = null;
    if (accSubj != null) {
        sc = ServiceCreds.getInstance(accSubj, serverPrincipal);
    }
    if (sc == null && !GSSUtil.useSubjectCredsOnly(caller)) {
        Subject subject = GSSUtil.login(caller, GSSUtil.GSS_KRB5_MECH_OID);
        sc = ServiceCreds.getInstance(subject, serverPrincipal);
    }
    return sc;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:Krb5Util.java

示例10: getMBeanServerConnection

import javax.security.auth.Subject; //导入依赖的package包/类
public synchronized MBeanServerConnection
        getMBeanServerConnection(Subject delegationSubject)
        throws IOException {

    if (terminated) {
        if (logger.traceOn())
            logger.trace("getMBeanServerConnection","[" + this.toString() +
                    "] already closed.");
        throw new IOException("Connection closed");
    } else if (!connected) {
        if (logger.traceOn())
            logger.trace("getMBeanServerConnection","[" + this.toString() +
                    "] is not connected.");
        throw new IOException("Not connected");
    }

    return getConnectionWithSubject(delegationSubject);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:RMIConnector.java

示例11: getConnectionWithSubject

import javax.security.auth.Subject; //导入依赖的package包/类
private MBeanServerConnection getConnectionWithSubject(Subject delegationSubject) {
    MBeanServerConnection conn = null;

    if (delegationSubject == null) {
        if (nullSubjectConnRef == null
                || (conn = nullSubjectConnRef.get()) == null) {
            conn = new RemoteMBeanServerConnection(null);
            nullSubjectConnRef = new WeakReference<MBeanServerConnection>(conn);
        }
    } else {
        WeakReference<MBeanServerConnection> wr = rmbscMap.get(delegationSubject);
        if (wr == null || (conn = wr.get()) == null) {
            conn = new RemoteMBeanServerConnection(delegationSubject);
            rmbscMap.put(delegationSubject, new WeakReference<MBeanServerConnection>(conn));
        }
    }
    return conn;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:RMIConnector.java

示例12: getUseridFromJAASSubject

import javax.security.auth.Subject; //导入依赖的package包/类
private static String getUseridFromJAASSubject() {
    Subject subject = Subject.getSubject(AccessController.getContext());
    LOGGER.trace("Subject of caller: {}", subject);
    if (subject != null) {
        Set<Principal> principals = subject.getPrincipals();
        LOGGER.trace("Public principals of caller: {}", principals);
        for (Principal pC : principals) {
            if (!(pC instanceof Group)) {
                String userIdFound = pC.getName();
                String userIdUsed = userIdFound;
                if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
                    userIdUsed = userIdFound.toLowerCase();
                }
                LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
                return userIdUsed;
            }
        }
    }
    LOGGER.trace("No userid found in subject!");
    return null;
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:22,代码来源:CurrentUserContext.java

示例13: matches

import javax.security.auth.Subject; //导入依赖的package包/类
public boolean matches(Subject subject, UserPasswordConnectionRequestInfo connectionRequestInfo, UserPasswordManagedConnectionFactory managedConnectionFactory) throws ResourceAdapterInternalException {
    assert managedConnectionFactory != null;

    if (subject != null) {
        Set<PasswordCredential> credentials = subject.getPrivateCredentials(PasswordCredential.class);
        for (PasswordCredential passwordCredential : credentials) {
            if (managedConnectionFactory.equals(passwordCredential.getManagedConnectionFactory())) {
                return (userName == null ? passwordCredential.getUserName() == null : userName.equals(passwordCredential.getUserName())
                    && (password == null ? passwordCredential.getPassword() == null : Arrays.equals(password.toCharArray(), passwordCredential.getPassword())));
            }
        }
        throw new ResourceAdapterInternalException("No credential found for this ManagedConnectionFactory: " + managedConnectionFactory);
    }
    if (connectionRequestInfo != null && connectionRequestInfo.getUserName() != null) {
        return (userName.equals(connectionRequestInfo.getUserName()))
            && (password == null
                ? connectionRequestInfo.getPassword() == null
                : password.equals(connectionRequestInfo.getPassword()));
    }
    return (userName == null ? managedConnectionFactory.getUserName() == null : userName.equals(managedConnectionFactory.getUserName())
        && (password == null ? managedConnectionFactory.getPassword() == null : password.equals(managedConnectionFactory.getPassword())));
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:23,代码来源:CredentialExtractor.java

示例14: removeNotificationListener

import javax.security.auth.Subject; //导入依赖的package包/类
@Override
public void removeNotificationListener(
    String connectionId,
    ObjectName name,
    Subject subject)
    throws SecurityException {
    echo("removeNotificationListener:");
    echo("\tconnectionId: " +  connectionId);
    echo("\tname: " +  name);
    echo("\tsubject: " +
         (subject == null ? null : subject.getPrincipals()));
    if (throwException)
        if (name.getCanonicalName().equals("domain:name=2,type=NB")
            &&
            subject != null
            &&
            subject.getPrincipals().contains(new JMXPrincipal("role")))
            throw new SecurityException();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:NotificationAccessControllerTest.java

示例15: ControlChannel

import javax.security.auth.Subject; //导入依赖的package包/类
/**
 * @param parent
 */
public ControlChannel(GSIServer parent, Socket s, Subject peerSubject, ControlChannelNotifier notifier)
        throws Exception {
    try {

        this.controlSocket = s;
        this.subject = peerSubject;
        this.remoteAddress = s.getInetAddress();
        this.remotePort = s.getPort();
        this.localPort = s.getLocalPort();

        this.notifier = notifier;

        initStreams();
        controlSocket.setTcpNoDelay(true);
        controlSocket.setSoTimeout(1000);

    } catch (Throwable t) {
        close("Cannot instantiate ControlChannel", t);
        throw new Exception(t);
    }
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:25,代码来源:ControlChannel.java


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