use of com.enonic.xp.security.IdProvider in project xp by enonic.
the class SecurityServiceImplTest method testCreateIdProvider.
@Test
public void testCreateIdProvider() throws Exception {
runAsAdmin(() -> {
final PrincipalKey userKey = PrincipalKey.ofUser(SYSTEM, "User1");
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "group-a");
final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
final IdProviderAccessControlList permissions = IdProviderAccessControlList.of(IdProviderAccessControlEntry.create().principal(userKey).access(CREATE_USERS).build(), IdProviderAccessControlEntry.create().principal(groupKey1).access(ADMINISTRATOR).build(), IdProviderAccessControlEntry.create().principal(groupKey2).access(WRITE_USERS).build());
final CreateIdProviderParams createIdProvider = CreateIdProviderParams.create().key(IdProviderKey.from("enonic")).displayName("Enonic Id Provider").permissions(permissions).description("id provider description").build();
final IdProvider idProviderCreated = securityService.createIdProvider(createIdProvider);
assertNotNull(idProviderCreated);
assertEquals("enonic", idProviderCreated.getKey().toString());
assertEquals("Enonic Id Provider", idProviderCreated.getDisplayName());
assertEquals("id provider description", idProviderCreated.getDescription());
final IdProviderAccessControlList createdPermissions = securityService.getIdProviderPermissions(IdProviderKey.from("enonic"));
assertNotNull(idProviderCreated);
assertEquals(CREATE_USERS, createdPermissions.getEntry(userKey).getAccess());
assertEquals(ADMINISTRATOR, createdPermissions.getEntry(groupKey1).getAccess());
assertEquals(WRITE_USERS, createdPermissions.getEntry(groupKey2).getAccess());
});
}
use of com.enonic.xp.security.IdProvider in project xp by enonic.
the class GetIdProviderConfigHandlerTest method testExample.
@Test
public void testExample() {
final IdProvider idProvider = TestDataFixtures.getTestIdProvider();
this.portalRequest.setIdProvider(idProvider);
runScript("/lib/xp/examples/auth/getIdProviderConfig.js");
}
use of com.enonic.xp.security.IdProvider in project xp by enonic.
the class BasicAuthFilterTest method setup.
@BeforeEach
public void setup() {
this.request = Mockito.mock(HttpServletRequest.class);
this.response = Mockito.mock(HttpServletResponse.class);
this.chain = Mockito.mock(FilterChain.class);
this.securityService = Mockito.mock(SecurityService.class);
this.filter = new BasicAuthFilter();
this.filter.setSecurityService(this.securityService);
final IdProviderKey idProviderKey = IdProviderKey.from("store");
final IdProvider idProvider = IdProvider.create().key(idProviderKey).build();
final IdProviders idProviders = IdProviders.from(idProvider);
when(this.securityService.getIdProviders()).thenReturn(idProviders);
}
use of com.enonic.xp.security.IdProvider in project xp by enonic.
the class IdProviderControllerServiceImplTest method setup.
@BeforeEach
public void setup() throws Exception {
// Mocks the IdProviderDescriptorService
final IdProviderDescriptorService idProviderDescriptorService = Mockito.mock(IdProviderDescriptorService.class);
Mockito.when(idProviderDescriptorService.getDescriptor(ApplicationKey.from("myapplication"))).thenReturn(IdProviderDescriptor.create().key(ApplicationKey.from("myapplication")).build());
// Mocks the SecurityService
final SecurityService securityService = Mockito.mock(SecurityService.class);
final IdProvider emptyIdProvider = IdProvider.create().build();
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from("myapplication")).build();
final IdProvider idProvider = IdProvider.create().idProviderConfig(idProviderConfig).build();
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyidprovider"))).thenReturn(emptyIdProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myidprovider"))).thenReturn(idProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyuserstore"))).thenReturn(emptyIdProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myuserstore"))).thenReturn(idProvider);
// Mocks the PortalScriptService
final PortalScriptService portalScriptService = setupPortalScriptService();
// Creates IdProviderControllerScriptFactoryImpl
final IdProviderControllerScriptFactoryImpl idProviderControllerScriptFactory = new IdProviderControllerScriptFactoryImpl();
idProviderControllerScriptFactory.setScriptService(portalScriptService);
// Creates IdProviderControllerServiceImpl
idProviderControllerService = new IdProviderControllerServiceImpl();
idProviderControllerService.setIdProviderControllerScriptFactory(idProviderControllerScriptFactory);
idProviderControllerService.setIdProviderDescriptorService(idProviderDescriptorService);
idProviderControllerService.setSecurityService(securityService);
}
Aggregations