use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.
the class CentralAuthenticationServiceImplWithMockitoTests method getService.
private static Service getService(final String name) {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, name);
return new WebApplicationServiceFactory().createService(request);
}
use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.
the class TicketsResourceTests method setUp.
@Before
public void setUp() throws Exception {
final AuthenticationManager mgmr = mock(AuthenticationManager.class);
when(mgmr.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
when(ticketSupport.getAuthenticationFrom(anyString())).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
this.ticketsResourceUnderTest = new TicketsResource(new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(mgmr), new DefaultPrincipalElectionStrategy()), new DefaultCredentialFactory(), ticketSupport, new WebApplicationServiceFactory(), casMock);
this.mockMvc = MockMvcBuilders.standaloneSetup(this.ticketsResourceUnderTest).defaultRequest(get("/").contextPath("/cas").contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.
the class ManageRegisteredServicesMultiActionControllerTests method verifyCustomComponents.
@Test
public void verifyCustomComponents() throws Exception {
// override the RegisteredServiceMapper
this.registeredServiceFactory = new DefaultRegisteredServiceFactory(new DefaultAccessStrategyMapper(), policyMapper, new DefaultProxyPolicyMapper(), new CustomRegisteredServiceMapper(), new DefaultUsernameAttributeProviderMapper(), Collections.emptyList());
this.controller = new ManageRegisteredServicesMultiActionController(this.servicesManager, this.registeredServiceFactory, new WebApplicationServiceFactory(), "https://cas.example.org");
final RegexRegisteredService r = new RegexRegisteredService();
r.setId(1200);
r.setName(NAME);
r.setDescription(UNIQUE_DESCRIPTION);
r.setServiceId("test");
r.setEvaluationOrder(2);
this.servicesManager.save(r);
final MockHttpServletResponse response = new MockHttpServletResponse();
final ModelAndView mv = this.controller.manage(response);
assertTrue(mv.getModel().containsKey("defaultServiceUrl"));
assertTrue(mv.getModel().containsKey("status"));
this.controller.getServices(response);
final String content = response.getContentAsString();
assertTrue(content.contains(SERVICES));
assertTrue(content.contains(UNIQUE_DESCRIPTION));
assertTrue(content.contains("customComponent1"));
assertTrue(content.contains("key2"));
}
use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.
the class OAuthWebApplicationServiceTests method verifySerializeACompletePrincipalToJson.
@Test
public void verifySerializeACompletePrincipalToJson() throws IOException {
final AbstractRegisteredService service = new OAuthRegisteredService();
service.setName("checkCloning");
service.setServiceId("testId");
service.setTheme("theme");
service.setDescription("description");
final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
final WebApplicationService serviceWritten = factory.createService(service.getServiceId());
MAPPER.writeValue(JSON_FILE, serviceWritten);
final WebApplicationService serviceRead = MAPPER.readValue(JSON_FILE, WebApplicationService.class);
assertEquals(serviceWritten, serviceRead);
}
use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.
the class OAuth20AccessTokenControllerTests method verifyClientExpiredCode.
@Test
public void verifyClientExpiredCode() throws Exception {
final RegisteredService registeredService = getRegisteredService(REDIRECT_URI, CLIENT_SECRET);
servicesManager.save(registeredService);
final Map<String, Object> map = new HashMap<>();
map.put(NAME, VALUE);
final List<String> list = Arrays.asList(VALUE, VALUE);
map.put(NAME2, list);
final Principal principal = CoreAuthenticationTestUtils.getPrincipal(ID, map);
final Authentication authentication = getAuthentication(principal);
final DefaultOAuthCodeFactory expiringOAuthCodeFactory = new DefaultOAuthCodeFactory(new AlwaysExpiresExpirationPolicy());
final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
final Service service = factory.createService(registeredService.getServiceId());
final OAuthCode code = expiringOAuthCodeFactory.create(service, authentication);
oAuth20AccessTokenController.getTicketRegistry().addTicket(code);
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.getId());
mockRequest.setParameter(OAuthConstants.GRANT_TYPE, OAuth20GrantTypes.AUTHORIZATION_CODE.name().toLowerCase());
servicesManager.save(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
oAuth20AccessTokenController.handleRequestInternal(mockRequest, mockResponse);
assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
assertEquals(ERROR_EQUALS + OAuthConstants.INVALID_GRANT, mockResponse.getContentAsString());
}
Aggregations