org.jasig.cas.ticket.TicketGrantingTicketImpl Java Examples
The following examples show how to use
org.jasig.cas.ticket.TicketGrantingTicketImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxyControllerTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyExistingPGT() throws Exception { final TicketGrantingTicket ticket = new TicketGrantingTicketImpl( "ticketGrantingTicketId", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); getTicketRegistry().addTicket(ticket); final MockHttpServletRequest request = new MockHttpServletRequest(); request .addParameter("pgt", ticket.getId()); request.addParameter( "targetService", "testDefault"); assertTrue(this.proxyController.handleRequestInternal(request, new MockHttpServletResponse()).getModel().containsKey( "ticket")); }
Example #2
Source File: DistributedTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
@Test public void testUpdateOfRegistry() { final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); this.ticketRegistry.addTicket(t); final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket("test"); final ServiceTicket s = returned.grantServiceTicket("test2", TestUtils.getService(), new NeverExpiresExpirationPolicy(), true); this.ticketRegistry.addTicket(s); final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2"); assertNotNull(s2.grantTicketGrantingTicket("ff", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); assertTrue(s2.isValidFor(TestUtils.getService())); assertTrue(this.wasTicketUpdated); returned.markTicketExpired(); assertTrue(t.isExpired()); }
Example #3
Source File: OpenIdSingleSignOnActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
@Test public void testSuccessfulServiceTicket() throws Exception { final MockRequestContext context = new MockRequestContext(); final MockHttpServletRequest request = new MockHttpServletRequest(); final Authentication authentication = TestUtils.getAuthentication("scootman28"); final TicketGrantingTicket t = new TicketGrantingTicketImpl("TGT-11", authentication, new NeverExpiresExpirationPolicy()); this.ticketRegistry.addTicket(t); request.setParameter("openid.identity", "http://openid.aol.com/scootman28"); request.setParameter("openid.return_to", "http://www.cnn.com"); final OpenIdService service = OpenIdService.createServiceFrom(request); context.getFlowScope().put("service", service); context.getFlowScope().put("ticketGrantingTicketId", t.getId()); context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse())); assertEquals("success", this.action.execute(context).getId()); }
Example #4
Source File: JpaTicketRegistry.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
/** * Delete the TGt and all of its service tickets. * * @param ticket the ticket */ private void deleteTicketAndChildren(final Ticket ticket) { final List<TicketGrantingTicketImpl> ticketGrantingTicketImpls = entityManager .createQuery("select t from TicketGrantingTicketImpl t where t.ticketGrantingTicket.id = :id", TicketGrantingTicketImpl.class) .setLockMode(LockModeType.PESSIMISTIC_WRITE) .setParameter("id", ticket.getId()) .getResultList(); final List<ServiceTicketImpl> serviceTicketImpls = entityManager .createQuery("select s from ServiceTicketImpl s where s.ticketGrantingTicket.id = :id", ServiceTicketImpl.class) .setParameter("id", ticket.getId()) .getResultList(); for (final ServiceTicketImpl s : serviceTicketImpls) { removeTicket(s); } for (final TicketGrantingTicketImpl t : ticketGrantingTicketImpls) { deleteTicketAndChildren(t); } removeTicket(ticket); }
Example #5
Source File: ProxyControllerTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
@Test public void testExistingPGT() throws Exception { final TicketGrantingTicket ticket = new TicketGrantingTicketImpl( "ticketGrantingTicketId", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); getTicketRegistry().addTicket(ticket); MockHttpServletRequest request = new MockHttpServletRequest(); request .addParameter("pgt", ticket.getId()); request.addParameter( "targetService", "testDefault"); assertTrue(this.proxyController.handleRequestInternal(request, new MockHttpServletResponse()).getModel().containsKey( "ticket")); }
Example #6
Source File: JpaTicketRegistry.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Transactional(readOnly=true) @Override public Collection<Ticket> getTickets() { final List<TicketGrantingTicketImpl> tgts = entityManager .createQuery("select t from TicketGrantingTicketImpl t", TicketGrantingTicketImpl.class) .getResultList(); final List<ServiceTicketImpl> sts = entityManager .createQuery("select s from ServiceTicketImpl s", ServiceTicketImpl.class) .getResultList(); final List<Ticket> tickets = new ArrayList<>(); tickets.addAll(tgts); tickets.addAll(sts); return tickets; }
Example #7
Source File: CentralAuthenticationServiceImpl.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
/** * @throws IllegalArgumentException if the credentials are null. */ @Audit( action="TICKET_GRANTING_TICKET", actionResolverName="CREATE_TICKET_GRANTING_TICKET_RESOLVER", resourceResolverName="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER") @Profiled(tag = "CREATE_TICKET_GRANTING_TICKET", logFailuresSeparately = false) @Transactional(readOnly = false) public String createTicketGrantingTicket(final Credential... credentials) throws AuthenticationException, TicketException { Assert.notNull(credentials, "credentials cannot be null"); final Authentication authentication = this.authenticationManager.authenticate(credentials); final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl( this.ticketGrantingTicketUniqueTicketIdGenerator .getNewTicketId(TicketGrantingTicket.PREFIX), authentication, this.ticketGrantingTicketExpirationPolicy); this.ticketRegistry.addTicket(ticketGrantingTicket); return ticketGrantingTicket.getId(); }
Example #8
Source File: JpaTicketRegistry.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
private void deleteTicketAndChildren(final Ticket ticket) { final List<TicketGrantingTicketImpl> ticketGrantingTicketImpls = entityManager .createQuery("select t from TicketGrantingTicketImpl t where t.ticketGrantingTicket.id = :id", TicketGrantingTicketImpl.class) .setLockMode(LockModeType.PESSIMISTIC_WRITE) .setParameter("id", ticket.getId()) .getResultList(); final List<ServiceTicketImpl> serviceTicketImpls = entityManager .createQuery("select s from ServiceTicketImpl s where s.ticketGrantingTicket.id = :id", ServiceTicketImpl.class) .setParameter("id", ticket.getId()) .getResultList(); for (final ServiceTicketImpl s : serviceTicketImpls) { removeTicket(s); } for (final TicketGrantingTicketImpl t : ticketGrantingTicketImpls) { deleteTicketAndChildren(t); } removeTicket(ticket); }
Example #9
Source File: MultiFactorAwareCentralAuthenticationService.java From cas-mfa with Apache License 2.0 | 6 votes |
@Override @Audit( action="TICKET_GRANTING_TICKET", actionResolverName="CREATE_TICKET_GRANTING_TICKET_RESOLVER", resourceResolverName="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER") @Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER") @Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER") @Counted(name="CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic=true) public TicketGrantingTicket createTicketGrantingTicket(final Credential... credentials) throws TicketException { final MultiFactorCredentials mfaCredentials = (MultiFactorCredentials) credentials[0]; final Authentication authentication = mfaCredentials.getAuthentication(); if (authentication == null) { throw new TicketCreationException(new RuntimeException("Authentication cannot be null")); } final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl( this.ticketGrantingTicketUniqueTicketIdGenerator.getNewTicketId(TicketGrantingTicket.PREFIX), authentication, this.ticketGrantingTicketExpirationPolicy); this.ticketRegistry.addTicket(ticketGrantingTicket); return ticketGrantingTicket; }
Example #10
Source File: DistributedTicketRegistryTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyUpdateOfRegistry() { final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); this.ticketRegistry.addTicket(t); final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket("test"); final ServiceTicket s = returned.grantServiceTicket("test2", TestUtils.getService(), new NeverExpiresExpirationPolicy(), true); this.ticketRegistry.addTicket(s); final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2"); assertNotNull(s2.grantTicketGrantingTicket("ff", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); assertTrue(s2.isValidFor(TestUtils.getService())); assertTrue(this.wasTicketUpdated); returned.markTicketExpired(); assertTrue(t.isExpired()); }
Example #11
Source File: KryoTranscoderTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
public KryoTranscoderTests(final int bufferSize) { this.principalAttributes = new HashMap<String, Object>(); this.principalAttributes.put(ST_ID, TGT_ID); transcoder = new KryoTranscoder(bufferSize); final Map<Class<?>, Serializer> serializerMap = new HashMap<Class<?>, Serializer>(); serializerMap.put( MockServiceTicket.class, new FieldSerializer(transcoder.getKryo(), MockServiceTicket.class)); serializerMap.put( MockTicketGrantingTicket.class, new FieldSerializer(transcoder.getKryo(), MockTicketGrantingTicket.class)); serializerMap.put( TicketGrantingTicketImpl.class, new FieldSerializer(transcoder.getKryo(), TicketGrantingTicketImpl.class)); serializerMap.put( ServiceTicketImpl.class, new FieldSerializer(transcoder.getKryo(), ServiceTicketImpl.class)); transcoder.setSerializerMap(serializerMap); transcoder.initialize(); }
Example #12
Source File: OpenIdSingleSignOnActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifySuccessfulServiceTicket() throws Exception { final MockRequestContext context = new MockRequestContext(); final MockHttpServletRequest request = new MockHttpServletRequest(); final Authentication authentication = TestUtils.getAuthentication("scootman28"); final TicketGrantingTicket t = new TicketGrantingTicketImpl("TGT-11", authentication, new NeverExpiresExpirationPolicy()); this.ticketRegistry.addTicket(t); request.setParameter(OpenIdConstants.OPENID_IDENTITY, "http://openid.aol.com/scootman28"); request.setParameter(OpenIdConstants.OPENID_RETURNTO, "http://www.cnn.com"); final OpenIdService service = OpenIdService.createServiceFrom(request, null); context.getFlowScope().put("service", service); context.getFlowScope().put("ticketGrantingTicketId", t.getId()); context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse())); assertEquals("success", this.action.execute(context).getId()); }
Example #13
Source File: ProxyControllerTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testNotAuthorizedPGT() throws Exception { final TicketGrantingTicket ticket = new TicketGrantingTicketImpl("ticketGrantingTicketId", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); getTicketRegistry().addTicket(ticket); final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("pgt", ticket.getId()); request.addParameter("targetService", "service"); final Map<String, Object> map = this.proxyController.handleRequestInternal(request, new MockHttpServletResponse()).getModel(); assertTrue(!map.containsKey("ticket")); }
Example #14
Source File: TimeoutExpirationPolicyTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { this.expirationPolicy = new TimeoutExpirationPolicy(TIMEOUT); this.ticket = new TicketGrantingTicketImpl("test", TestUtils .getAuthentication(), this.expirationPolicy); }
Example #15
Source File: JBossCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetExistingTicketWithProperClass() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); this.ticketRegistry.getTicket("TEST", TicketGrantingTicket.class); } catch (final Exception e) { fail("Caught an exception. But no exception should have been thrown."); } }
Example #16
Source File: JBossCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
/** * Method to add a TicketGrantingTicket to the ticket cache. This should add * the ticket and return. Failure upon any exception. */ @Test public void testAddTicketToCache() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); } catch (final Exception e) { fail("Caught an exception. But no exception should have been thrown."); } }
Example #17
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetTicketsFromRegistryEqualToTicketsAdded() { final Collection<Ticket> tickets = new ArrayList<Ticket>(); for (int i = 0; i < TICKETS_IN_REGISTRY; i++) { final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl("TEST" + i, TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); final ServiceTicket st = ticketGrantingTicket.grantServiceTicket("tests" + i, getService(), new NeverExpiresExpirationPolicy(), false); tickets.add(ticketGrantingTicket); tickets.add(st); this.ticketRegistry.addTicket(ticketGrantingTicket); this.ticketRegistry.addTicket(st); } try { Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets(); assertEquals("The size of the registry is not the same as the collection.", ticketRegistryTickets.size(), tickets.size()); for (final Ticket ticket : tickets) { if (!ticketRegistryTickets.contains(ticket)) { fail("Ticket was added to registry but was not found in retrieval of collection of all tickets."); } } } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #18
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testDeleteNullTicket() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); assertFalse("Ticket was deleted.", this.ticketRegistry.deleteTicket(null)); } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #19
Source File: RememberMeDelegatingExpirationPolicyTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testTicketExpirationWithRememberMe() { final Authentication authentication = TestUtils.getAuthentication( new SimplePrincipal("test"), Collections.<String, Object>singletonMap( RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, true)); final TicketGrantingTicketImpl t = new TicketGrantingTicketImpl("111", authentication, this.p); assertFalse(t.isExpired()); t.grantServiceTicket("55", TestUtils.getService(), this.p, false); assertTrue(t.isExpired()); }
Example #20
Source File: AbstractTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testDeleteExistingTicket() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); assertTrue("Ticket was not deleted.", this.ticketRegistry.deleteTicket("TEST")); } catch (final Exception e) { fail("Caught an exception. But no exception should have been thrown."); } }
Example #21
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testDeleteNonExistingTicket() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); assertFalse("Ticket was deleted.", this.ticketRegistry.deleteTicket("TEST1")); } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #22
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testDeleteExistingTicket() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); assertTrue("Ticket was not deleted.", this.ticketRegistry.deleteTicket("TEST")); } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #23
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetExistingTicket() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); this.ticketRegistry.getTicket("TEST"); } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #24
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetExistingTicketWithInproperClass() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); this.ticketRegistry.getTicket("TEST", ServiceTicket.class); } catch (final ClassCastException e) { return; } fail("ClassCastException expected."); }
Example #25
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetExistingTicketWithProperClass() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); this.ticketRegistry.getTicket("TEST", TicketGrantingTicket.class); } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #26
Source File: EhCacheTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
/** * Method to add a TicketGrantingTicket to the ticket cache. This should add * the ticket and return. Failure upon any exception. */ @Test public void testAddTicketToCache() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); } catch (final Exception e) { logger.error(e.getMessage(), e); fail("Caught an exception. But no exception should have been thrown."); } }
Example #27
Source File: AbstractTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetTicketsFromRegistryEqualToTicketsAdded() { final Collection<Ticket> tickets = new ArrayList<Ticket>(); for (int i = 0; i < TICKETS_IN_REGISTRY; i++) { final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl("TEST" + i, TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); final ServiceTicket st = ticketGrantingTicket.grantServiceTicket("tests" + i, TestUtils.getService(), new NeverExpiresExpirationPolicy(), false); tickets.add(ticketGrantingTicket); tickets.add(st); this.ticketRegistry.addTicket(ticketGrantingTicket); this.ticketRegistry.addTicket(st); } try { Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets(); assertEquals("The size of the registry is not the same as the collection.", ticketRegistryTickets.size(), tickets.size()); for (final Ticket ticket : tickets) { if (!ticketRegistryTickets.contains(ticket)) { fail("Ticket was added to registry but was not found in retrieval of collection of all tickets."); } } } catch (final Exception e) { fail("Caught an exception. But no exception should have been thrown."); } }
Example #28
Source File: AbstractTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetExistingTicketWithInproperClass() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); this.ticketRegistry.getTicket("TEST", ServiceTicket.class); } catch (final ClassCastException e) { return; } fail("ClassCastfinal Exception expected."); }
Example #29
Source File: AbstractTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
/** * Method to add a TicketGrantingTicket to the ticket cache. This should add * the ticket and return. Failure upon any exception. */ @Test public void testAddTicketToCache() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); } catch (final Exception e) { fail("Caught an exception. But no exception should have been thrown."); } }
Example #30
Source File: AbstractTicketRegistryTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testGetExistingTicketWithProperClass() { try { this.ticketRegistry.addTicket(new TicketGrantingTicketImpl("TEST", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy())); this.ticketRegistry.getTicket("TEST", TicketGrantingTicket.class); } catch (final Exception e) { fail("Caught an exception. But no exception should have been thrown."); } }