Java 8 Subject - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Subject class.

This code example shows how to use the following methods:
        UserInfo userInfo = channel.getConnection().getUserInfo(); 
        final Subject subject; 
        if (userInfo instanceof SubjectUserInfo) { 
            subject = ((SubjectUserInfo) userInfo).getSubject(); 
        } else { 
            subject = new Subject(); 
        } 
 
        handler.addHandlerFactory(new ModelControllerClientOperationHandler(getController(), handler, subject)); 
 
        channel.receiveMessage(handler.getReceiver()); 
        return handler; 
    } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals
    public String getUserName() {
        return userName;
    } 
 
    public Collection<Principal> getPrincipals() {
        return subject.getPrincipals();
    } 
 
    public Subject getSubject() {
        return subject;
    } 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals, getPrivateCredentials
 
        options.put("cacheAssertions", "true");
        options.put("cacheTimeout", "1");
 
        server.content = SUCCESS_RESPONSE.getBytes(server.encoding);
        module.initialize(
                subject,
                new ServiceAndTicketCallbackHandler(SERVICE, TICKET),
                new HashMap<String, Object>(),
                options);
        module.login();
        module.commit();
        assertEquals(this.subject.getPrincipals().size(), 3);
        assertEquals(TICKET, this.subject.getPrivateCredentials().iterator().next().toString());
 
        // Logout should destroy all authenticated state data including assertion cache entries 
        module.logout();
        assertEquals(0, subject.getPrincipals().size());
        assertEquals(0, subject.getPrivateCredentials().size());
        server.content = FAILURE_RESPONSE.getBytes(server.encoding);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals, getPrivateCredentials
			return false; 
		} 
 
		Subject subject = getSubject();
 
		Set<Principal> principals = subject.getPrincipals();
 
		principals.add(getPrincipal());
 
		Set<Object> privateCredentials = subject.getPrivateCredentials();
 
		privateCredentials.add(getPassword()); 
 
		try { 
			Principal group = (Principal)InstanceFactory.newInstance(
				_JGROUP, String.class, "Roles");
			Object role = InstanceFactory.newInstance( 
				_JROLE, String.class, "users");
 
			MethodKey methodKey = new MethodKey(
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals, getPrivateCredentials, getPublicCredentials
    /** 
     * javax.security.auth.Subject#Subject() 
     */ 
    public void test_Constructor_01() { 
        try { 
            Subject s = new Subject();
            assertNotNull("Null object returned", s);
            assertTrue("Set of principal is not empty", s.getPrincipals().isEmpty());
            assertTrue("Set of private credentials is not empty", s.getPrivateCredentials().isEmpty());
            assertTrue("Set of public credentials is not empty", s.getPublicCredentials().isEmpty());
        } catch (Exception e) {
            fail("Unexpected exception: " + e);
        } 
    } 
 
    /** 
     * javax.security.auth.Subject#doAs(Subject subject, PrivilegedAction action) 
     */ 
    public void test_doAs_01() { 
        Subject subj = new Subject();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:doAs
    public static <T> T doAs(Subject subject, java.security.PrivilegedExceptionAction<T> action)
            throws java.security.PrivilegedActionException { 
        final AccessAuditContext previous = contextThreadLocal.get();
        try { 
            contextThreadLocal.set(new AccessAuditContext());
            return Subject.doAs(subject, action);
        } finally { 
            contextThreadLocal.set(previous);
        } 
    } 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
  public static <T> T doAs(String principal, final Callable<T> callable) throws Exception {
    LoginContext loginContext = null;
    try { 
      Set<Principal> principals = new HashSet<Principal>();
      principals.add(new KerberosPrincipal(KerberosTestUtils.getClientPrincipal()));
      Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
      loginContext = new LoginContext("", subject, null, new KerberosConfiguration(principal));
      loginContext.login();
      subject = loginContext.getSubject();
      return Subject.doAs(subject, new PrivilegedExceptionAction<T>() {
        @Override 
        public T run() throws Exception { 
          return callable.call();
        } 
      }); 
    } catch (PrivilegedActionException ex) {
      throw ex.getException();
    } finally { 
      if (loginContext != null) {
        loginContext.logout();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals, getPrivateCredentials, getPublicCredentials
public class SubjectTest extends SerializationTest { 
 
    @Override 
    protected Object[] getData() {
 
        Subject subject = new Subject();
 
        return new Object[] { subject, subject.getPrincipals(),
                subject.getPrivateCredentials(), subject.getPublicCredentials() };
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals
        return false; 
    } 
 
    @Override 
    public boolean commit() throws LoginException { 
        Set<Principal> principals = subject.getPrincipals();
        Group callerPrincipal = new SimpleGroup("CallerPrincipal");
        callerPrincipal.addMember(new SimplePrincipal(username));
        principals.add(callerPrincipal);
        Group roles = new SimpleGroup("Roles");
        if (username.equals("anil"))
            roles.addMember(new SimplePrincipal("gooduser"));
        if (username.equals("marcus"))
            roles.addMember(new SimplePrincipal("superuser"));
        principals.add(roles);
        return true; 
    } 
 
    @Override 
    public boolean abort() throws LoginException { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPrincipals
        return false; 
    } 
 
 
    public boolean commit() throws LoginException { 
        Set<Principal> principals = subject.getPrincipals();
        Group callerPrincipal = new SimpleGroup("CallerPrincipal");
        callerPrincipal.addMember(new SimplePrincipal(username));
        principals.add(callerPrincipal);
        Group roles = new SimpleGroup("Roles");
        if (username.equals("anil"))
            roles.addMember(new SimplePrincipal("gooduser"));
        if (username.equals("marcus"))
            roles.addMember(new SimplePrincipal("superuser"));
        principals.add(roles);
        return true; 
    } 
 
 
    public boolean abort() throws LoginException { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 Subject Methods: