org.jasig.cas.ticket.ExpirationPolicy Java Examples

The following examples show how to use org.jasig.cas.ticket.ExpirationPolicy. 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: CentralAuthenticationServiceImplWithMockitoTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
private TicketGrantingTicket createMockTicketGrantingTicket(final String id,
        final ServiceTicket svcTicket, final boolean isExpired, 
        final TicketGrantingTicket root, final List<Authentication> chainedAuthnList) {
    final TicketGrantingTicket tgtMock = mock(TicketGrantingTicket.class);
    when(tgtMock.isExpired()).thenReturn(isExpired);
    when(tgtMock.getId()).thenReturn(id);

    final String svcId = svcTicket.getService().getId();
    when(tgtMock.grantServiceTicket(anyString(), argThat(new VerifyServiceByIdMatcher(svcId)),
            any(ExpirationPolicy.class), anyBoolean())).thenReturn(svcTicket);
    when(tgtMock.getRoot()).thenReturn(root);
    when(tgtMock.getChainedAuthentications()).thenReturn(chainedAuthnList);
    when(svcTicket.getGrantingTicket()).thenReturn(tgtMock);   
    
    return tgtMock;
}
 
Example #2
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 #3
Source File: CentralAuthenticationServiceImplTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test(expected=TicketException.class)
    public void verifyGrantServiceTicketWithExpiredTicketGrantingTicket() throws Exception {
        ((CentralAuthenticationServiceImpl) getCentralAuthenticationService()).setTicketGrantingTicketExpirationPolicy(
                new ExpirationPolicy() {
            private static final long serialVersionUID = 1L;

            public boolean isExpired(final TicketState ticket) {
                return true;
            }});

    final TicketGrantingTicket ticketId = getCentralAuthenticationService()
        .createTicketGrantingTicket(
            TestUtils.getCredentialsWithSameUsernameAndPassword());
    try {
        getCentralAuthenticationService().grantServiceTicket(ticketId.getId(),
            TestUtils.getService());
    } finally {
        ((CentralAuthenticationServiceImpl) getCentralAuthenticationService()).setTicketGrantingTicketExpirationPolicy(
                new NeverExpiresExpirationPolicy());
    }
}
 
Example #4
Source File: CentralAuthenticationServiceImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test(expected=TicketException.class)
    public void testGrantServiceTicketWithExpiredTicketGrantingTicket() throws Exception {
        ((CentralAuthenticationServiceImpl) getCentralAuthenticationService()).setTicketGrantingTicketExpirationPolicy(
                new ExpirationPolicy() {
            private static final long serialVersionUID = 1L;

            public boolean isExpired(final TicketState ticket) {
                return true;
            }});
    final String ticketId = getCentralAuthenticationService()
        .createTicketGrantingTicket(
            TestUtils.getCredentialsWithSameUsernameAndPassword());
    try {
        getCentralAuthenticationService().grantServiceTicket(ticketId,
            TestUtils.getService());
    } finally {
        ((CentralAuthenticationServiceImpl) getCentralAuthenticationService()).setTicketGrantingTicketExpirationPolicy(
                new NeverExpiresExpirationPolicy());
    }
}
 
Example #5
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 #6
Source File: HazelcastTicketRegistryTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public ServiceTicket grantServiceTicket(final String id,
                                        final Service service,
                                        final ExpirationPolicy expirationPolicy,
                                        final boolean credentialsProvided) {
    return null;
}
 
Example #7
Source File: ClientActionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyFinishAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");

    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute(ClientAction.THEME, MY_THEME);
    mockSession.setAttribute(ClientAction.LOCALE, MY_LOCALE);
    mockSession.setAttribute(ClientAction.METHOD, MY_METHOD);
    final Service service = new SimpleWebApplicationServiceImpl(MY_SERVICE);
    mockSession.setAttribute(ClientAction.SERVICE, service);
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final FacebookClient facebookClient = new MockFacebookClient();
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient);

    final TicketGrantingTicket tgt = new TicketGrantingTicketImpl(TGT_ID, mock(Authentication.class), mock(ExpirationPolicy.class));
    final CentralAuthenticationService casImpl = mock(CentralAuthenticationService.class);
    when(casImpl.createTicketGrantingTicket(any(Credential.class))).thenReturn(tgt);
    final ClientAction action = new ClientAction(casImpl, clients);
    final Event event = action.execute(mockRequestContext);
    assertEquals("success", event.getId());
    assertEquals(MY_THEME, mockRequest.getAttribute(ClientAction.THEME));
    assertEquals(MY_LOCALE, mockRequest.getAttribute(ClientAction.LOCALE));
    assertEquals(MY_METHOD, mockRequest.getAttribute(ClientAction.METHOD));
    assertEquals(MY_SERVICE, mockRequest.getAttribute(ClientAction.SERVICE));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final MutableAttributeMap requestScope = mockRequestContext.getRequestScope();
    assertEquals(service, flowScope.get(ClientAction.SERVICE));
    assertEquals(TGT_ID, flowScope.get(TGT_NAME));
    assertEquals(TGT_ID, requestScope.get(TGT_NAME));
}
 
Example #8
Source File: AbstractDistributedTicketRegistry.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceTicket grantServiceTicket(final String id, final Service service,
        final ExpirationPolicy expirationPolicy, final boolean credentialsProvided) {
    final ServiceTicket t = this.getTicket().grantServiceTicket(id, service,
            expirationPolicy, credentialsProvided);
    updateTicket();
    return t;
}
 
Example #9
Source File: AbstractDistributedTicketRegistry.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Override
public TicketGrantingTicket grantTicketGrantingTicket(final String id,
        final Authentication authentication, final ExpirationPolicy expirationPolicy) {
    final TicketGrantingTicket t = this.getTicket().grantTicketGrantingTicket(id,
            authentication, expirationPolicy);
    updateTicket();
    return t;
}
 
Example #10
Source File: KryoTranscoderTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public ServiceTicket grantServiceTicket(
        final String id,
        final Service service,
        final ExpirationPolicy expirationPolicy,
        final boolean credentialsProvided) {
    this.usageCount++;
    return new MockServiceTicket(id);
}
 
Example #11
Source File: MockTicketGrantingTicket.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
public ServiceTicket grantServiceTicket(
        final String id,
        final Service service,
        final ExpirationPolicy expirationPolicy,
        final boolean credentialsProvided) {
    usageCount++;
    return new MockServiceTicket(id, service, this);
}
 
Example #12
Source File: AbstractDistributedTicketRegistry.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public ServiceTicket grantServiceTicket(final String id, final Service service,
        final ExpirationPolicy expirationPolicy, final boolean credentialsProvided) {
    final ServiceTicket t = this.getTicket().grantServiceTicket(id, service,
            expirationPolicy, credentialsProvided);
    updateTicket();
    return t;
}
 
Example #13
Source File: CentralAuthenticationServiceImplTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * This test checks that the TGT destruction happens properly for a remote registry.
 * It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
 *
 * @throws AuthenticationException
 * @throws org.jasig.cas.ticket.TicketException
 */
@Test
public void verifyDestroyRemoteRegistry() throws TicketException, AuthenticationException {
    final MockOnlyOneTicketRegistry registry = new MockOnlyOneTicketRegistry();
    final TicketGrantingTicketImpl tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class),
            mock(ExpirationPolicy.class));
    final MockExpireUpdateTicketLogoutManager logoutManager = new MockExpireUpdateTicketLogoutManager(registry);
    // consider authentication has happened and the TGT is in the registry
    registry.addTicket(tgt);
    // create a new CASimpl
    final CentralAuthenticationServiceImpl cas = new CentralAuthenticationServiceImpl(registry,  null,  null, null, null, null, null,
            null, logoutManager);
    // destroy to mark expired and then delete : the opposite would fail with a "No ticket to update" error from the registry
    cas.destroyTicketGrantingTicket(tgt.getId());
}
 
Example #14
Source File: KryoTranscoderTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceTicket grantServiceTicket(
        final String id,
        final Service service,
        final ExpirationPolicy expirationPolicy,
        final boolean credentialsProvided) {
    this.usageCount++;
    return new MockServiceTicket(id);
}
 
Example #15
Source File: AbstractDistributedTicketRegistry.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public TicketGrantingTicket grantTicketGrantingTicket(final String id,
        final Authentication authentication, final ExpirationPolicy expirationPolicy) {
    final TicketGrantingTicket t = this.getTicket().grantTicketGrantingTicket(id,
            authentication, expirationPolicy);
    updateTicket();
    return t;
}
 
Example #16
Source File: MockTicketGrantingTicket.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public ServiceTicket grantServiceTicket(
        final String id,
        final Service service,
        final ExpirationPolicy expirationPolicy,
        final boolean credentialsProvided) {
    usageCount++;
    return new MockServiceTicket(id, service, this);
}
 
Example #17
Source File: CentralAuthenticationServiceImplTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks that the TGT destruction happens properly for a remote registry.
 * It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
 *
 * @throws AuthenticationException
 * @throws TicketException
 */
@Test
public void testDestroyRemoteRegistry() throws TicketException, AuthenticationException {
    final MockOnlyOneTicketRegistry registry = new MockOnlyOneTicketRegistry();
    final TicketGrantingTicketImpl tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class),
            mock(ExpirationPolicy.class));
    final MockExpireUpdateTicketLogoutManager logoutManager = new MockExpireUpdateTicketLogoutManager(registry);
    // consider authentication has happened and the TGT is in the registry
    registry.addTicket(tgt);
    // create a new CASimpl
    final CentralAuthenticationServiceImpl cas = new CentralAuthenticationServiceImpl(registry,  null,  null, null, null, null, null,
            null, logoutManager);
    // destroy to mark expired and then delete : the opposite would fail with a "No ticket to update" error from the registry
    cas.destroyTicketGrantingTicket(tgt.getId());
}
 
Example #18
Source File: RememberMeDelegatingExpirationPolicy.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
public void setRememberMeExpirationPolicy(
    final ExpirationPolicy rememberMeExpirationPolicy) {
    this.rememberMeExpirationPolicy = rememberMeExpirationPolicy;
}
 
Example #19
Source File: MockServiceTicket.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public TicketGrantingTicket grantTicketGrantingTicket(
        final String id,
        final Authentication authentication,
        final ExpirationPolicy expirationPolicy) {
    return null;
}
 
Example #20
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 #21
Source File: CentralAuthenticationServiceImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
/**
 * @param serviceTicketExpirationPolicy a ST expiration policy.
 */
public void setServiceTicketExpirationPolicy(final ExpirationPolicy serviceTicketExpirationPolicy) {
    this.serviceTicketExpirationPolicy = serviceTicketExpirationPolicy;
}
 
Example #22
Source File: CentralAuthenticationServiceImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
/**
 * @param ticketGrantingTicketExpirationPolicy a TGT expiration policy.
 */
public void setTicketGrantingTicketExpirationPolicy(final ExpirationPolicy ticketGrantingTicketExpirationPolicy) {
    this.ticketGrantingTicketExpirationPolicy = ticketGrantingTicketExpirationPolicy;
}
 
Example #23
Source File: KryoTranscoderTests.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public TicketGrantingTicket grantTicketGrantingTicket(final String id, final Authentication authentication,
        final ExpirationPolicy expirationPolicy) {
    return null;
}
 
Example #24
Source File: RememberMeDelegatingExpirationPolicy.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public void setSessionExpirationPolicy(final ExpirationPolicy sessionExpirationPolicy) {
    this.sessionExpirationPolicy = sessionExpirationPolicy;
}
 
Example #25
Source File: RememberMeDelegatingExpirationPolicy.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
public void setRememberMeExpirationPolicy(
    final ExpirationPolicy rememberMeExpirationPolicy) {
    this.rememberMeExpirationPolicy = rememberMeExpirationPolicy;
}
 
Example #26
Source File: KryoTranscoderTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
public TicketGrantingTicket grantTicketGrantingTicket(final String id, final Authentication authentication,
        final ExpirationPolicy expirationPolicy) {
    return null;
}
 
Example #27
Source File: HazelcastTicketRegistryTests.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Override
public TicketGrantingTicket grantTicketGrantingTicket(final String id,
                                                      final Authentication authentication,
                                                      final ExpirationPolicy expirationPolicy) {
    return null;
}
 
Example #28
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 #29
Source File: MockServiceTicket.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
public TicketGrantingTicket grantTicketGrantingTicket(
        final String id,
        final Authentication authentication,
        final ExpirationPolicy expirationPolicy) {
    return null;
}
 
Example #30
Source File: CentralAuthenticationServiceImpl.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
/**
 * @param serviceTicketExpirationPolicy a ST expiration policy.
 */
public void setServiceTicketExpirationPolicy(final ExpirationPolicy serviceTicketExpirationPolicy) {
    this.serviceTicketExpirationPolicy = serviceTicketExpirationPolicy;
}