Search in sources :

Example 1 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class TicketOrCredentialPrincipalResolverTests method verifyResolverTicketGrantingTicket.

@Test
public void verifyResolverTicketGrantingTicket() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), c);
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), CoreAuthenticationTestUtils.getService(), ctx);
    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    when(jp.getArgs()).thenReturn(new Object[] { ticketId.getId() });
    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 2 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class TicketOrCredentialPrincipalResolverTests method verifyResolverCredential.

@Test
public void verifyResolverCredential() {
    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    when(jp.getArgs()).thenReturn(new Object[] { c });
    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.toString());
}
Also used : Credential(org.apereo.cas.authentication.Credential) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 3 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class ChainingPrincipalResolverTests method examineSupports.

@Test
public void examineSupports() throws Exception {
    final Credential credential = mock(Credential.class);
    when(credential.getId()).thenReturn("a");
    final PrincipalResolver resolver1 = mock(PrincipalResolver.class);
    when(resolver1.supports(eq(credential))).thenReturn(true);
    final PrincipalResolver resolver2 = mock(PrincipalResolver.class);
    when(resolver2.supports(eq(credential))).thenReturn(false);
    final ChainingPrincipalResolver resolver = new ChainingPrincipalResolver();
    resolver.setChain(Arrays.asList(resolver1, resolver2));
    assertTrue(resolver.supports(credential));
}
Also used : Credential(org.apereo.cas.authentication.Credential) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) Test(org.junit.Test)

Example 4 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class ChainingPrincipalResolverTests method examineResolve.

@Test
public void examineResolve() throws Exception {
    final Credential credential = mock(Credential.class);
    when(credential.getId()).thenReturn("input");
    final PrincipalResolver resolver1 = mock(PrincipalResolver.class);
    when(resolver1.supports(eq(credential))).thenReturn(true);
    when(resolver1.resolve(eq(credential), any(Principal.class), any(AuthenticationHandler.class))).thenReturn(principalFactory.createPrincipal("output"));
    final PrincipalResolver resolver2 = mock(PrincipalResolver.class);
    when(resolver2.supports(any(Credential.class))).thenReturn(true);
    when(resolver2.resolve(any(Credential.class), any(Principal.class), any(AuthenticationHandler.class))).thenReturn(principalFactory.createPrincipal("output", Collections.<String, Object>singletonMap("mail", "final@example.com")));
    final ChainingPrincipalResolver resolver = new ChainingPrincipalResolver();
    resolver.setChain(Arrays.asList(resolver1, resolver2));
    final Principal principal = resolver.resolve(credential, any(Principal.class), new SimpleTestUsernamePasswordAuthenticationHandler());
    assertEquals("output", principal.getId());
    assertEquals("final@example.com", principal.getAttributes().get("mail"));
}
Also used : Credential(org.apereo.cas.authentication.Credential) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) Test(org.junit.Test)

Example 5 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyNoAttributesWithPrincipal.

@Test
public void verifyNoAttributesWithPrincipal() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
    resolver.setPrincipalAttributeName(CoreAuthenticationTestUtils.CONST_USERNAME);
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final Principal p = resolver.resolve(c, null);
    assertNotNull(p);
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) Credential(org.apereo.cas.authentication.Credential) Test(org.junit.Test)

Aggregations

Credential (org.apereo.cas.authentication.Credential)43 Test (org.junit.Test)27 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)19 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)13 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)11 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)10 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)10 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)9 Service (org.apereo.cas.authentication.principal.Service)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)7 MockServletContext (org.springframework.mock.web.MockServletContext)7 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)7 MockRequestContext (org.springframework.webflow.test.MockRequestContext)7 HashMap (java.util.HashMap)6 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)5 AuthenticationResultBuilder (org.apereo.cas.authentication.AuthenticationResultBuilder)5 LinkedHashMap (java.util.LinkedHashMap)4 RegisteredService (org.apereo.cas.services.RegisteredService)4