Search in sources :

Example 6 with IdProviders

use of com.enonic.xp.security.IdProviders in project xp by enonic.

the class LoginHandlerTest method testLoginNoIdProviders.

@Test
public void testLoginNoIdProviders() {
    final IdProviders idProviders = IdProviders.from(IdProvider.create().displayName("system").key(IdProviderKey.from("system")).build());
    final AuthenticationInfo authInfo = TestDataFixtures.createAuthenticationInfo();
    Mockito.when(this.securityService.authenticate(Mockito.any())).thenReturn(authInfo);
    Mockito.when(this.securityService.getIdProviders()).thenReturn(idProviders);
    runFunction("/test/login-test.js", "loginNoIdProvider");
    final Session session = ContextAccessor.current().getLocalScope().getSession();
    final AuthenticationInfo sessionAuthInfo = session.getAttribute(AuthenticationInfo.class);
    assertEquals(authInfo, sessionAuthInfo);
}
Also used : IdProviders(com.enonic.xp.security.IdProviders) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Session(com.enonic.xp.session.Session) Test(org.junit.jupiter.api.Test)

Example 7 with IdProviders

use of com.enonic.xp.security.IdProviders in project xp by enonic.

the class LoginHandlerTest method testExamples.

@Test
public void testExamples() {
    final AuthenticationInfo authInfo = TestDataFixtures.createAuthenticationInfo();
    final IdProviders idProviders = IdProviders.from(IdProvider.create().displayName("system").key(IdProviderKey.from("system")).build());
    Mockito.when(this.securityService.authenticate(Mockito.any())).thenReturn(authInfo);
    Mockito.when(this.securityService.getIdProviders()).thenReturn(idProviders);
    runScript("/lib/xp/examples/auth/login.js");
}
Also used : IdProviders(com.enonic.xp.security.IdProviders) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 8 with IdProviders

use of com.enonic.xp.security.IdProviders 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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IdProviders(com.enonic.xp.security.IdProviders) SecurityService(com.enonic.xp.security.SecurityService) FilterChain(javax.servlet.FilterChain) IdProvider(com.enonic.xp.security.IdProvider) IdProviderKey(com.enonic.xp.security.IdProviderKey) HttpServletResponse(javax.servlet.http.HttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdProviders (com.enonic.xp.security.IdProviders)8 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)6 Test (org.junit.jupiter.api.Test)6 IdProvider (com.enonic.xp.security.IdProvider)3 Session (com.enonic.xp.session.Session)2 IdProviderDescriptor (com.enonic.xp.idprovider.IdProviderDescriptor)1 IdProviderKey (com.enonic.xp.security.IdProviderKey)1 SecurityService (com.enonic.xp.security.SecurityService)1 EmailPasswordAuthToken (com.enonic.xp.security.auth.EmailPasswordAuthToken)1 VerifiedEmailAuthToken (com.enonic.xp.security.auth.VerifiedEmailAuthToken)1 VerifiedUsernameAuthToken (com.enonic.xp.security.auth.VerifiedUsernameAuthToken)1 SessionMock (com.enonic.xp.session.SessionMock)1 FilterChain (javax.servlet.FilterChain)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1