Search in sources :

Example 1 with IdProviderDescriptor

use of com.enonic.xp.idprovider.IdProviderDescriptor in project xp by enonic.

the class IdProviderControllerServiceImpl method execute.

@Override
public PortalResponse execute(final IdProviderControllerExecutionParams params) throws IOException {
    final IdProviderKey idProviderKey = retrieveIdProviderKey(params);
    final IdProvider idProvider = retrieveIdProvider(idProviderKey);
    final IdProviderDescriptor idProviderDescriptor = retrieveIdProviderDescriptor(idProvider);
    if (idProviderDescriptor != null) {
        final IdProviderControllerScript idProviderControllerScript = idProviderControllerScriptFactory.fromScript(idProviderDescriptor.getResourceKey());
        final String functionName = params.getFunctionName();
        if (idProviderControllerScript.hasMethod(functionName)) {
            PortalRequest portalRequest = params.getPortalRequest();
            if (portalRequest == null) {
                portalRequest = new PortalRequestAdapter().adapt(params.getServletRequest());
            }
            portalRequest.setApplicationKey(idProviderDescriptor.getKey());
            portalRequest.setIdProvider(idProvider);
            final PortalResponse portalResponse = idProviderControllerScript.execute(functionName, portalRequest);
            if (portalResponse != null) {
                final HttpServletResponse response = params.getResponse();
                if (response != null) {
                    responseSerializationService.serialize(portalRequest, portalResponse, response);
                }
            }
            return portalResponse;
        }
    }
    return null;
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequestAdapter(com.enonic.xp.portal.impl.PortalRequestAdapter) IdProvider(com.enonic.xp.security.IdProvider) IdProviderDescriptor(com.enonic.xp.idprovider.IdProviderDescriptor) IdProviderKey(com.enonic.xp.security.IdProviderKey) HttpServletResponse(javax.servlet.http.HttpServletResponse) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 2 with IdProviderDescriptor

use of com.enonic.xp.idprovider.IdProviderDescriptor in project xp by enonic.

the class ApplicationInfoServiceImplTest method mockIdProviderApplication.

private void mockIdProviderApplication(final ApplicationKey applicationKey) {
    final IdProviderDescriptor idProviderDescriptor = IdProviderDescriptor.create().config(Form.create().build()).key(applicationKey).mode(IdProviderDescriptorMode.EXTERNAL).build();
    final IdProvider idProvider1 = IdProvider.create().displayName("idProvider1").key(IdProviderKey.from("idProvider1")).idProviderConfig(IdProviderConfig.create().applicationKey(applicationKey).config(new PropertyTree()).build()).build();
    final IdProvider idProvider2 = IdProvider.create().displayName("idProvider2").key(IdProviderKey.from("idProvider2" + "")).idProviderConfig(IdProviderConfig.create().applicationKey(applicationKey).config(new PropertyTree()).build()).build();
    Mockito.when(this.idProviderDescriptorService.getDescriptor(applicationKey)).thenReturn(idProviderDescriptor);
    Mockito.when(this.securityService.getIdProviders()).thenReturn(IdProviders.from(idProvider1, idProvider2));
}
Also used : IdProviderDescriptor(com.enonic.xp.idprovider.IdProviderDescriptor) IdProvider(com.enonic.xp.security.IdProvider) PropertyTree(com.enonic.xp.data.PropertyTree)

Example 3 with IdProviderDescriptor

use of com.enonic.xp.idprovider.IdProviderDescriptor in project xp by enonic.

the class ApplicationInfoServiceImplTest method testIdProviderApplication.

@Test
public void testIdProviderApplication() {
    mockIdProviderApplication(this.applicationKey);
    final IdProviderDescriptor idProviderDescriptor = this.service.getIdProviderDescriptor(this.applicationKey);
    assertNotNull(idProviderDescriptor);
    final IdProviders idProviders = this.service.getIdProviderReferences(this.applicationKey);
    assertEquals(idProviders.getSize(), 2);
}
Also used : IdProviders(com.enonic.xp.security.IdProviders) IdProviderDescriptor(com.enonic.xp.idprovider.IdProviderDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with IdProviderDescriptor

use of com.enonic.xp.idprovider.IdProviderDescriptor in project xp by enonic.

the class IdProviderDescriptorServiceTest method testGetDescriptor.

@Test
public void testGetDescriptor() throws Exception {
    final IdProviderDescriptor idProviderDescriptor = this.service.getDescriptor(ApplicationKey.from("myapp1"));
    assertNotNull(idProviderDescriptor);
    assertEquals(ApplicationKey.from("myapp1"), idProviderDescriptor.getKey());
    assertEquals(IdProviderDescriptorMode.MIXED, idProviderDescriptor.getMode());
    final Input titleInput = Input.create().name("title").label("Title").inputType(InputTypeName.TEXT_LINE).build();
    assertEquals(Form.create().addFormItem(titleInput).build(), idProviderDescriptor.getConfig());
}
Also used : Input(com.enonic.xp.form.Input) IdProviderDescriptor(com.enonic.xp.idprovider.IdProviderDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IdProviderDescriptor (com.enonic.xp.idprovider.IdProviderDescriptor)4 IdProvider (com.enonic.xp.security.IdProvider)2 Test (org.junit.jupiter.api.Test)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 Input (com.enonic.xp.form.Input)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 PortalRequestAdapter (com.enonic.xp.portal.impl.PortalRequestAdapter)1 IdProviderKey (com.enonic.xp.security.IdProviderKey)1 IdProviders (com.enonic.xp.security.IdProviders)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1