Code example for Subject

Methods: getPrincipals, getPrivateCredentials

0
 
        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);
 
        // Verify we can't log in again with same ticket 
        module.initialize(
                subject,
                new ServiceAndTicketCallbackHandler(SERVICE, TICKET),
                new HashMap<String, Object>(),
                options);
        try { 
            module.login();
            module.commit();
            Assert.fail("Login should have failed.");
        } catch (LoginException e) {
            assertEquals(TicketValidationException.class, e.getCause().getClass());
        } 
        assertEquals(0, this.subject.getPrincipals().size());
        assertEquals(0, this.subject.getPrivateCredentials().size());
    } 
 
    /** 
     * Verify that cached assertions that are expired are never be accessible 
     * by {@link org.jasig.cas.client.jaas.CasLoginModule#login()} method.