org.jasig.cas.ticket.registry.TicketRegistry Java Examples

The following examples show how to use org.jasig.cas.ticket.registry.TicketRegistry. 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: OAuth20ProfileControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoTicketGrantingTicketImpl() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.PROFILE_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, TGT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(TGT_ID)).thenReturn(null);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(200, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    assertEquals("{\"error\":\"" + OAuthConstants.EXPIRED_ACCESS_TOKEN + "\"}", mockResponse.getContentAsString());
}
 
Example #2
Source File: OAuth20AccessTokenControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpiredServiceTicket() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ServicesManager servicesManager = mock(ServicesManager.class);
    final List<RegisteredService> services = new ArrayList<RegisteredService>();
    services.add(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
    when(servicesManager.getAllServices()).thenReturn(services);
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    final ServiceTicket serviceTicket = mock(ServiceTicket.class);
    when(serviceTicket.isExpired()).thenReturn(true);
    when(ticketRegistry.getTicket(CODE)).thenReturn(serviceTicket);
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setServicesManager(servicesManager);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(400, mockResponse.getStatus());
    assertEquals("error=" + OAuthConstants.INVALID_GRANT, mockResponse.getContentAsString());
}
 
Example #3
Source File: OAuth20AccessTokenControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoServiceTicket() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ServicesManager servicesManager = mock(ServicesManager.class);
    final List<RegisteredService> services = new ArrayList<RegisteredService>();
    services.add(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
    when(servicesManager.getAllServices()).thenReturn(services);
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(CODE)).thenReturn(null);
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setServicesManager(servicesManager);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(400, mockResponse.getStatus());
    assertEquals("error=" + OAuthConstants.INVALID_GRANT, mockResponse.getContentAsString());
}
 
Example #4
Source File: CentralAuthenticationServiceImpl.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Build the central authentication service implementation.
 *
 * @param ticketRegistry the tickets registry.
 * @param serviceTicketRegistry the service tickets registry.
 * @param authenticationManager the authentication manager.
 * @param ticketGrantingTicketUniqueTicketIdGenerator the TGT id generator.
 * @param uniqueTicketIdGeneratorsForService the map with service and ticket id generators.
 * @param ticketGrantingTicketExpirationPolicy the TGT expiration policy.
 * @param serviceTicketExpirationPolicy the service ticket expiration policy.
 * @param servicesManager the services manager.
 * @param logoutManager the logout manager.
 */
public CentralAuthenticationServiceImpl(final TicketRegistry ticketRegistry,
                                        final TicketRegistry serviceTicketRegistry,
                                        final AuthenticationManager authenticationManager,
                                        final UniqueTicketIdGenerator ticketGrantingTicketUniqueTicketIdGenerator,
                                        final Map<String, UniqueTicketIdGenerator> uniqueTicketIdGeneratorsForService,
                                        final ExpirationPolicy ticketGrantingTicketExpirationPolicy,
                                        final ExpirationPolicy serviceTicketExpirationPolicy,
                                        final ServicesManager servicesManager,
                                        final LogoutManager logoutManager) {
    this.ticketRegistry = ticketRegistry;
    if (serviceTicketRegistry == null) {
        this.serviceTicketRegistry = ticketRegistry;
    } else {
        this.serviceTicketRegistry = serviceTicketRegistry;
    }
    this.authenticationManager = authenticationManager;
    this.ticketGrantingTicketUniqueTicketIdGenerator = ticketGrantingTicketUniqueTicketIdGenerator;
    this.uniqueTicketIdGeneratorsForService = uniqueTicketIdGeneratorsForService;
    this.ticketGrantingTicketExpirationPolicy = ticketGrantingTicketExpirationPolicy;
    this.serviceTicketExpirationPolicy = serviceTicketExpirationPolicy;
    this.servicesManager = servicesManager;
    this.logoutManager = logoutManager;
}
 
Example #5
Source File: TicketRegistryDecoratorTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testEhCacheTicketRegistryWithClearPass() {
    final Cache serviceTicketsCache = new Cache("serviceTicketsCache", 200, false, false, 100, 100);
    final Cache ticketGrantingTicketCache = new Cache("ticketGrantingTicketCache", 200, false, false, 100, 100);

    final CacheManager manager = new CacheManager(this.getClass().getClassLoader().getResourceAsStream("ehcacheClearPass.xml"));
    manager.addCache(serviceTicketsCache);
    manager.addCache(ticketGrantingTicketCache);

    final Map<String, String> map = new HashMap<String, String>();

    final TicketRegistry ticketRegistry = new EhCacheTicketRegistry(serviceTicketsCache, ticketGrantingTicketCache);
    final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map);
    assertNotNull(decorator);

    assertEquals(decorator.serviceTicketCount(), 0);
    assertEquals(decorator.sessionCount(), 0);

    manager.removalAll();
    manager.shutdown();

}
 
Example #6
Source File: OAuth20ProfileControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpiredTicketGrantingTicketImpl() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.PROFILE_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, TGT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(true);
    when(ticketRegistry.getTicket(TGT_ID)).thenReturn(ticketGrantingTicket);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(200, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    assertEquals("{\"error\":\"" + OAuthConstants.EXPIRED_ACCESS_TOKEN + "\"}", mockResponse.getContentAsString());
}
 
Example #7
Source File: CentralAuthenticationServiceImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
/**
 * Build the central authentication service implementation.
 *
 * @param ticketRegistry the tickets registry.
 * @param serviceTicketRegistry the service tickets registry.
 * @param authenticationManager the authentication manager.
 * @param ticketGrantingTicketUniqueTicketIdGenerator the TGT id generator.
 * @param uniqueTicketIdGeneratorsForService the map with service and ticket id generators.
 * @param ticketGrantingTicketExpirationPolicy the TGT expiration policy.
 * @param serviceTicketExpirationPolicy the service ticket expiration policy.
 * @param servicesManager the services manager.
 * @param logoutManager the logout manager.
 */
public CentralAuthenticationServiceImpl(final TicketRegistry ticketRegistry,
                                        final TicketRegistry serviceTicketRegistry,
                                        final AuthenticationManager authenticationManager,
                                        final UniqueTicketIdGenerator ticketGrantingTicketUniqueTicketIdGenerator,
                                        final Map<String, UniqueTicketIdGenerator> uniqueTicketIdGeneratorsForService,
                                        final ExpirationPolicy ticketGrantingTicketExpirationPolicy,
                                        final ExpirationPolicy serviceTicketExpirationPolicy,
                                        final ServicesManager servicesManager,
                                        final LogoutManager logoutManager) {
    this.ticketRegistry = ticketRegistry;
    if (serviceTicketRegistry == null) {
        this.serviceTicketRegistry = ticketRegistry;
    } else {
        this.serviceTicketRegistry = serviceTicketRegistry;
    }
    this.authenticationManager = authenticationManager;
    this.ticketGrantingTicketUniqueTicketIdGenerator = ticketGrantingTicketUniqueTicketIdGenerator;
    this.uniqueTicketIdGeneratorsForService = uniqueTicketIdGeneratorsForService;
    this.ticketGrantingTicketExpirationPolicy = ticketGrantingTicketExpirationPolicy;
    this.serviceTicketExpirationPolicy = serviceTicketExpirationPolicy;
    this.servicesManager = servicesManager;
    this.logoutManager = logoutManager;
}
 
Example #8
Source File: TicketRegistryDecoratorTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyEhCacheTicketRegistryWithClearPass() {
    final Cache serviceTicketsCache = new Cache("serviceTicketsCache", 200, false, false, 100, 100);
    final Cache ticketGrantingTicketCache = new Cache("ticketGrantingTicketCache", 200, false, false, 100, 100);

    final CacheManager manager = new CacheManager(this.getClass().getClassLoader().getResourceAsStream("ehcacheClearPass.xml"));
    manager.addCache(serviceTicketsCache);
    manager.addCache(ticketGrantingTicketCache);

    final Map<String, String> map = new HashMap<>();

    final TicketRegistry ticketRegistry = new EhCacheTicketRegistry(serviceTicketsCache, ticketGrantingTicketCache);
    final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map);
    assertNotNull(decorator);

    assertEquals(decorator.serviceTicketCount(), 0);
    assertEquals(decorator.sessionCount(), 0);

    manager.removalAll();
    manager.shutdown();

}
 
Example #9
Source File: OAuth20ProfileControllerTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyExpiredTicketGrantingTicketImpl() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.PROFILE_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, TGT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(true);
    when(ticketRegistry.getTicket(TGT_ID)).thenReturn(ticketGrantingTicket);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(200, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    assertEquals("{\"error\":\"" + OAuthConstants.EXPIRED_ACCESS_TOKEN + "\"}", mockResponse.getContentAsString());
}
 
Example #10
Source File: OAuth20ProfileControllerTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyNoTicketGrantingTicketImpl() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.PROFILE_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, TGT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(TGT_ID)).thenReturn(null);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(200, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    assertEquals("{\"error\":\"" + OAuthConstants.EXPIRED_ACCESS_TOKEN + "\"}", mockResponse.getContentAsString());
}
 
Example #11
Source File: OAuth20AccessTokenControllerTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyExpiredServiceTicket() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ServicesManager servicesManager = mock(ServicesManager.class);
    final List<RegisteredService> services = new ArrayList<>();
    services.add(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
    when(servicesManager.getAllServices()).thenReturn(services);
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    final ServiceTicket serviceTicket = mock(ServiceTicket.class);
    when(serviceTicket.isExpired()).thenReturn(true);
    when(ticketRegistry.getTicket(CODE)).thenReturn(serviceTicket);
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setServicesManager(servicesManager);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(400, mockResponse.getStatus());
    assertEquals("error=" + OAuthConstants.INVALID_GRANT, mockResponse.getContentAsString());
}
 
Example #12
Source File: OAuth20AccessTokenControllerTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyNoServiceTicket() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ServicesManager servicesManager = mock(ServicesManager.class);
    final List<RegisteredService> services = new ArrayList<>();
    services.add(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
    when(servicesManager.getAllServices()).thenReturn(services);
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(CODE)).thenReturn(null);
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setServicesManager(servicesManager);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(400, mockResponse.getStatus());
    assertEquals("error=" + OAuthConstants.INVALID_GRANT, mockResponse.getContentAsString());
}
 
Example #13
Source File: CentralAuthenticationServiceImpl.java    From taoshop with Apache License 2.0 5 votes vote down vote up
/**
 * Build the central authentication service implementation.
 *
 * @param ticketRegistry  the tickets registry.
 * @param ticketFactory   the ticket factory
 * @param servicesManager the services manager.
 * @param logoutManager   the logout manager.
 */
public CentralAuthenticationServiceImpl(
        final TicketRegistry ticketRegistry,
        final TicketFactory ticketFactory,
        final ServicesManager servicesManager,
        final LogoutManager logoutManager) {

    super(ticketRegistry, ticketFactory, servicesManager, logoutManager);
}
 
Example #14
Source File: TicketRegistryDecoratorTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultTicketRegistryWithClearPass() {

    final TicketRegistry ticketRegistry = new DefaultTicketRegistry();
    final Map<String, String> map = new HashMap<String, String>();
    final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map);
    assertNotNull(decorator);
    assertEquals(decorator.serviceTicketCount(), 0);
    assertEquals(decorator.sessionCount(), 0);
}
 
Example #15
Source File: DefaultTicketRegistryCleanerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
public RegistryCleaner getNewRegistryCleaner(final TicketRegistry ticketRegistry) {
    DefaultTicketRegistryCleaner cleaner = new DefaultTicketRegistryCleaner();
    cleaner.setTicketRegistry(ticketRegistry);
    LogoutManager logoutManager = mock(LogoutManager.class);
    cleaner.setLogoutManager(logoutManager);
    return cleaner;
}
 
Example #16
Source File: OAuth20ProfileControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.PROFILE_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, TGT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(false);
    when(ticketRegistry.getTicket(TGT_ID)).thenReturn(ticketGrantingTicket);
    final Authentication authentication = mock(Authentication.class);
    final Principal principal = mock(Principal.class);
    when(principal.getId()).thenReturn(ID);
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(NAME, VALUE);
    List<String> list = Arrays.asList(VALUE, VALUE);
    map.put(NAME2, list);
    when(principal.getAttributes()).thenReturn(map);
    when(authentication.getPrincipal()).thenReturn(principal);
    when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(200, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    assertEquals("{\"id\":\"" + ID + "\",\"attributes\":[{\"" + NAME + "\":\"" + VALUE + "\"},{\"" + NAME2
            + "\":[\"" + VALUE + "\",\"" + VALUE + "\"]}]}", mockResponse.getContentAsString());
}
 
Example #17
Source File: MultiFactorAwareCentralAuthenticationService.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
/**
 * Method to set the TicketRegistry.
 *
 * @param ticketRegistry the TicketRegistry to set.
 */
public void setTicketRegistry(final TicketRegistry ticketRegistry) {
    this.ticketRegistry = ticketRegistry;

    if (this.serviceTicketRegistry == null) {
        this.serviceTicketRegistry = ticketRegistry;
    }
}
 
Example #18
Source File: TicketRegistryDecoratorTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyDefaultTicketRegistryWithClearPass() {

    final TicketRegistry ticketRegistry = new DefaultTicketRegistry();
    final Map<String, String> map = new HashMap<>();
    final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map);
    assertNotNull(decorator);
    assertEquals(decorator.serviceTicketCount(), 0);
    assertEquals(decorator.sessionCount(), 0);
}
 
Example #19
Source File: DefaultTicketRegistryCleanerTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public RegistryCleaner getNewRegistryCleaner(final TicketRegistry ticketRegistry) {
    this.centralAuthenticationService = new CentralAuthenticationServiceImpl(this.ticketRegistry, this.ticketRegistry,
            mock(AuthenticationManager.class), mock(UniqueTicketIdGenerator.class), Collections.EMPTY_MAP,
            new NeverExpiresExpirationPolicy(), new NeverExpiresExpirationPolicy(), mock(ServicesManager.class),
            mock(LogoutManager.class));

    return new DefaultTicketRegistryCleaner(this.centralAuthenticationService, this.ticketRegistry);
}
 
Example #20
Source File: AbstractCentralAuthenticationServiceTest.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
public TicketRegistry getTicketRegistry() {
    return this.ticketRegistry;
}
 
Example #21
Source File: DefaultTicketRegistryCleaner.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
/**
 * @param ticketRegistry The ticketRegistry to set.
 * @deprecated As of 4.1. Consider using constructors instead.
 */
@Deprecated
public void setTicketRegistry(final TicketRegistry ticketRegistry) {
    logger.warn("Invoking setTicketRegistry() is deprecated and has no impact.");
}
 
Example #22
Source File: BaseOAuthWrapperController.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public void setTicketRegistry(final TicketRegistry ticketRegistry) {
    this.ticketRegistry = ticketRegistry;
}
 
Example #23
Source File: OAuth20AccessTokenController.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public OAuth20AccessTokenController(final ServicesManager servicesManager, final TicketRegistry ticketRegistry,
        final long timeout) {
    this.servicesManager = servicesManager;
    this.ticketRegistry = ticketRegistry;
    this.timeout = timeout;
}
 
Example #24
Source File: OAuth20ProfileController.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public OAuth20ProfileController(final TicketRegistry ticketRegistry) {
    this.ticketRegistry = ticketRegistry;
}
 
Example #25
Source File: OpenIdCredentialsAuthenticationHandler.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public void setTicketRegistry(final TicketRegistry ticketRegistry) {
    this.ticketRegistry = ticketRegistry;
}
 
Example #26
Source File: DefaultTicketRegistryCleanerTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Override
public TicketRegistry getNewTicketRegistry() {
    return new DefaultTicketRegistry();
}
 
Example #27
Source File: CentralAuthenticationServiceImplWithMockitoTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Before
public void prepareNewCAS() {
    this.authentication = mock(Authentication.class);
    when(this.authentication.getAuthenticationDate()).thenReturn(new Date());
    final CredentialMetaData metadata = new BasicCredentialMetaData(TestUtils.getCredentialsWithSameUsernameAndPassword("principal"));
    final Map<String, HandlerResult> successes = new HashMap<>();
    successes.put("handler1", new DefaultHandlerResult(mock(AuthenticationHandler.class), metadata));
    when(this.authentication.getCredentials()).thenReturn(Arrays.asList(metadata));
    when(this.authentication.getSuccesses()).thenReturn(successes);
    when(this.authentication.getPrincipal()).thenReturn(new DefaultPrincipalFactory().createPrincipal(PRINCIPAL));
     
    final Service service1 = TestUtils.getService(SVC1_ID);
    final ServiceTicket stMock = createMockServiceTicket(ST_ID, service1); 
    
    final TicketGrantingTicket tgtRootMock = createRootTicketGrantingTicket();
    
    final TicketGrantingTicket tgtMock = createMockTicketGrantingTicket(TGT_ID, stMock, false,
            tgtRootMock, new ArrayList<Authentication>());
    when(tgtMock.getProxiedBy()).thenReturn(TestUtils.getService("proxiedBy"));

    final List<Authentication> authnListMock = mock(List.class);
    //Size is required to be 2, so that we can simulate proxying capabilities
    when(authnListMock.size()).thenReturn(2);
    when(authnListMock.get(anyInt())).thenReturn(this.authentication);
    when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
    when(stMock.getGrantingTicket()).thenReturn(tgtMock);
    
    final Service service2 = TestUtils.getService(SVC2_ID);
    final ServiceTicket stMock2 = createMockServiceTicket(ST2_ID, service2);
    
    final TicketGrantingTicket tgtMock2 = createMockTicketGrantingTicket(TGT2_ID, stMock2, false, tgtRootMock, authnListMock);        
    
    //Mock TicketRegistry
    this.ticketRegMock = mock(TicketRegistry.class);
    when(ticketRegMock.getTicket(eq(tgtMock.getId()), eq(TicketGrantingTicket.class))).thenReturn(tgtMock);
    when(ticketRegMock.getTicket(eq(tgtMock2.getId()), eq(TicketGrantingTicket.class))).thenReturn(tgtMock2);
    when(ticketRegMock.getTicket(eq(stMock.getId()), eq(ServiceTicket.class))).thenReturn(stMock);
    when(ticketRegMock.getTicket(eq(stMock2.getId()), eq(ServiceTicket.class))).thenReturn(stMock2);
    when(ticketRegMock.getTickets()).thenReturn(Arrays.asList(tgtMock, tgtMock2, stMock, stMock2));

    //Mock ServicesManager
    final RegisteredService mockRegSvc1 = createMockRegisteredService(service1.getId(), true, getServiceProxyPolicy(false));
    final RegisteredService mockRegSvc2 = createMockRegisteredService("test", false, getServiceProxyPolicy(true)); 
    final RegisteredService mockRegSvc3 = createMockRegisteredService(service2.getId(), true, getServiceProxyPolicy(true)); 
    
    final ServicesManager smMock = mock(ServicesManager.class);
    when(smMock.findServiceBy(argThat(new VerifyServiceByIdMatcher(service1.getId())))).thenReturn(mockRegSvc1);
    when(smMock.findServiceBy(argThat(new VerifyServiceByIdMatcher("test")))).thenReturn(mockRegSvc2);
    when(smMock.findServiceBy(argThat(new VerifyServiceByIdMatcher(service2.getId())))).thenReturn(mockRegSvc3);
    
    final Map ticketIdGenForServiceMock = mock(Map.class);
    when(ticketIdGenForServiceMock.containsKey(any())).thenReturn(true);
    when(ticketIdGenForServiceMock.get(any())).thenReturn(new DefaultUniqueTicketIdGenerator());
    
    this.cas = new CentralAuthenticationServiceImpl(ticketRegMock, null, mock(AuthenticationManager.class),
            mock(UniqueTicketIdGenerator.class), ticketIdGenForServiceMock, mock(ExpirationPolicy.class),
            mock(ExpirationPolicy.class), smMock, mock(LogoutManager.class));
}
 
Example #28
Source File: AbstractCentralAuthenticationServiceTest.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public TicketRegistry getTicketRegistry() {
    return this.ticketRegistry;
}
 
Example #29
Source File: CentralAuthenticationServiceImplWithMokitoTests.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Before
public void prepareNewCAS() {
    this.authentication = mock(Authentication.class);
    when(this.authentication.getAuthenticatedDate()).thenReturn(new Date());
    final CredentialMetaData metadata = new BasicCredentialMetaData(TestUtils.getCredentialsWithSameUsernameAndPassword("principal"));
    final Map<String, HandlerResult> successes = new HashMap<String, HandlerResult>();
    successes.put("handler1", new HandlerResult(mock(AuthenticationHandler.class), metadata));
    when(this.authentication.getCredentials()).thenReturn(Arrays.asList(metadata));
    when(this.authentication.getSuccesses()).thenReturn(successes);
    when(this.authentication.getPrincipal()).thenReturn(new SimplePrincipal(PRINCIPAL));
    
    final ServiceTicket stMock = mock(ServiceTicket.class);
    when(stMock.getService()).thenReturn(TestUtils.getService());
    when(stMock.getId()).thenReturn(ST_ID);
    when(stMock.isValidFor(TestUtils.getService())).thenReturn(true);
    
    final TicketGrantingTicket tgtRootMock = mock(TicketGrantingTicket.class);
    when(tgtRootMock.isExpired()).thenReturn(false);
    when(tgtRootMock.getAuthentication()).thenReturn(this.authentication);
    
    final TicketGrantingTicket tgtMock = mock(TicketGrantingTicket.class);
    when(tgtMock.isExpired()).thenReturn(false);
    when(tgtMock.getId()).thenReturn(TGT_ID);
    when(tgtMock.grantServiceTicket(anyString(), argThat(new VerifyServiceByIdMatcher(TestUtils.getService().getId())),
            any(ExpirationPolicy.class), anyBoolean())).thenReturn(stMock);
    when(tgtMock.getRoot()).thenReturn(tgtRootMock);
            
    final List<Authentication> authnListMock = mock(List.class);
    //Size is required to be 2, so that we can simulate proxying capabilities
    when(authnListMock.size()).thenReturn(2);
    when(authnListMock.get(anyInt())).thenReturn(this.authentication);
    when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
    when(stMock.getGrantingTicket()).thenReturn(tgtMock);
    
    final Service service2 = TestUtils.getService(SVC2_ID);
    final ServiceTicket stMock2 = mock(ServiceTicket.class);
    when(stMock2.getService()).thenReturn(service2);
    when(stMock2.getId()).thenReturn(ST2_ID);
    when(stMock2.isValidFor(service2)).thenReturn(true);
    
    final TicketGrantingTicket tgtMock2 = mock(TicketGrantingTicket.class);
    when(tgtMock2.isExpired()).thenReturn(false);
    when(tgtMock2.getId()).thenReturn(TGT2_ID);
    when(tgtMock2.grantServiceTicket(anyString(), argThat(new VerifyServiceByIdMatcher(service2.getId())),
            any(ExpirationPolicy.class), anyBoolean())).thenReturn(stMock2);
    when(tgtMock2.getRoot()).thenReturn(tgtRootMock);
    when(tgtMock2.getChainedAuthentications()).thenReturn(authnListMock);
    when(stMock2.getGrantingTicket()).thenReturn(tgtMock2);
    
    
    //Mock TicketRegistry
    final TicketRegistry ticketRegMock = mock(TicketRegistry.class);
    when(ticketRegMock.getTicket(eq(tgtMock.getId()), eq(TicketGrantingTicket.class))).thenReturn(tgtMock);
    when(ticketRegMock.getTicket(eq(tgtMock2.getId()), eq(TicketGrantingTicket.class))).thenReturn(tgtMock2);
    when(ticketRegMock.getTicket(eq(stMock.getId()), eq(ServiceTicket.class))).thenReturn(stMock);
    when(ticketRegMock.getTicket(eq(stMock2.getId()), eq(ServiceTicket.class))).thenReturn(stMock2);
    
    //Mock ServicesManager
    final RegisteredService mockRegSvc1 = mock(RegisteredService.class);
    when(mockRegSvc1.getServiceId()).thenReturn(SVC1_ID);
    when(mockRegSvc1.isEnabled()).thenReturn(true);
    when(mockRegSvc1.isAllowedToProxy()).thenReturn(false);
    when(mockRegSvc1.getName()).thenReturn(SVC1_ID);

    final RegisteredService mockRegSvc2 = mock(RegisteredService.class);
    when(mockRegSvc2.getServiceId()).thenReturn("test");
    when(mockRegSvc2.isEnabled()).thenReturn(false);
    when(mockRegSvc2.getName()).thenReturn("test");

    final RegisteredService mockRegSvc3 = mock(RegisteredService.class);
    when(mockRegSvc3.getServiceId()).thenReturn(service2.getId());
    when(mockRegSvc3.isEnabled()).thenReturn(true);
    when(mockRegSvc3.isAllowedToProxy()).thenReturn(true);
    when(mockRegSvc3.getName()).thenReturn(service2.getId());
    when(mockRegSvc3.matches(argThat(new VerifyServiceByIdMatcher(service2.getId())))).thenReturn(true);
    
    final ServicesManager smMock = mock(ServicesManager.class);
    when(smMock.findServiceBy(argThat(new VerifyServiceByIdMatcher(SVC1_ID)))).thenReturn(mockRegSvc1);
    when(smMock.findServiceBy(argThat(new VerifyServiceByIdMatcher("test")))).thenReturn(mockRegSvc2);
    when(smMock.findServiceBy(argThat(new VerifyServiceByIdMatcher(SVC2_ID)))).thenReturn(mockRegSvc3);
    
    final Map ticketIdGenForServiceMock = mock(Map.class);
    when(ticketIdGenForServiceMock.containsKey(any())).thenReturn(true);
    when(ticketIdGenForServiceMock.get(any())).thenReturn(new DefaultUniqueTicketIdGenerator());
    
    this.cas = new CentralAuthenticationServiceImpl(ticketRegMock, null, mock(AuthenticationManager.class),
            mock(UniqueTicketIdGenerator.class), ticketIdGenForServiceMock, mock(ExpirationPolicy.class),
            mock(ExpirationPolicy.class), smMock, mock(LogoutManager.class));
}
 
Example #30
Source File: DefaultTicketRegistryCleanerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public TicketRegistry getNewTicketRegistry() {
    return new DefaultTicketRegistry();
}