当前位置: 首页>>代码示例>>Java>>正文


Java Clients类代码示例

本文整理汇总了Java中org.pac4j.core.client.Clients的典型用法代码示例。如果您正苦于以下问题:Java Clients类的具体用法?Java Clients怎么用?Java Clients使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Clients类属于org.pac4j.core.client包,在下文中一共展示了Clients类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyStartAuthentication

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void verifyStartAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
    mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
    mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);

    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE,
            org.jasig.cas.services.TestUtils.getService(MY_SERVICE));

    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET);
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final ClientAction action = new ClientAction();
    action.setCentralAuthenticationService(mock(CentralAuthenticationService.class));
    action.setClients(clients);

    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final Map<String, String> urls = (Map<String, String>) flowScope.get(ClientAction.PAC4J_URLS);
    assertTrue((urls.get("Facebook"))
            .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F"
                    + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state="));
    assertEquals(MY_LOGIN_URL + '?' + Clients.DEFAULT_CLIENT_NAME_PARAMETER
            + "=TwitterClient&needs_client_redirection=true", urls.get("Twitter"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:39,代码来源:ClientActionTests.java

示例2: checkUnautorizedProtocol

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void checkUnautorizedProtocol() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "IndirectBasicAuthClient");

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient();
    final Clients clients = new Clients(MY_LOGIN_URL, basicAuthClient);
    final ClientAction action = new ClientAction();
    action.setCentralAuthenticationService(mock(CentralAuthenticationService.class));
    action.setClients(clients);

    try {
        action.execute(mockRequestContext);
        fail("Should fail as the HTTP protocol is not authorized");
    } catch (final TechnicalException e) {
        assertEquals("Only CAS, OAuth, OpenID and SAML protocols are supported: " + basicAuthClient, e.getMessage());
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:25,代码来源:ClientActionTests.java

示例3: setUp

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Before
public void setUp() {
    this.fbClient = new MockFacebookClient();
    final Clients clients = new Clients(CALLBACK_URL, fbClient);
    this.handler = new ClientAuthenticationHandler();
    this.handler.setClients(clients);
    final Credentials credentials = new OAuthCredentials(null, MockFacebookClient.CLIENT_NAME);
    this.clientCredential = new ClientCredential(credentials);
    ExternalContextHolder.setExternalContext(mock(ServletExternalContext.class));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:11,代码来源:ClientAuthenticationHandlerTests.java

示例4: testCallback

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testCallback() throws Exception {
    final String originalSessionId = request.getSession().getId();
    request.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    final CommonProfile profile = new CommonProfile();
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    call();
    final HttpSession session = request.getSession();
    final String newSessionId = session.getId();
    final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
    assertTrue(profiles.containsValue(profile));
    assertEquals(1, profiles.size());
    assertNotEquals(newSessionId, originalSessionId);
    assertEquals(302, response.getStatus());
    assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:18,代码来源:J2ERenewSessionCallbackLogicTests.java

示例5: testCallbackWithOriginallyRequestedUrl

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testCallbackWithOriginallyRequestedUrl() throws Exception {
    HttpSession session = request.getSession();
    final String originalSessionId = session.getId();
    session.setAttribute(Pac4jConstants.REQUESTED_URL, PAC4J_URL);
    request.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    final CommonProfile profile = new CommonProfile();
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    call();
    session = request.getSession();
    final String newSessionId = session.getId();
    final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
    assertTrue(profiles.containsValue(profile));
    assertEquals(1, profiles.size());
    assertNotEquals(newSessionId, originalSessionId);
    assertEquals(302, response.getStatus());
    assertEquals(PAC4J_URL, response.getRedirectedUrl());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:20,代码来源:J2ERenewSessionCallbackLogicTests.java

示例6: testCallback

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testCallback(final TestContext testContext) throws Exception {
    final TestProfile expectedProfile = TestProfile.from(TEST_CREDENTIALS);
    when(webContext.getRequestParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER)).thenReturn(NAME);
    final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = clientsWithOneIndirectClient();
    when(config.getClients()).thenReturn(clients);
    asyncCallbackLogic = new DefaultAsyncCallbackLogic<>(false, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> future = asyncCallbackLogic.perform(webContext, null);
    final CompletableFuture<Map<String, TestProfile>> profilesFuture = future.thenAccept(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(302));
        assertThat(responseHeaders.get(LOCATION_HEADER), is(Pac4jConstants.DEFAULT_URL_VALUE));
        verify(sessionStore, never()).renewSession(any(AsyncWebContext.class));
    }).thenCompose((Void v) ->  webContext.getSessionStore().get(webContext, Pac4jConstants.USER_PROFILES));

    assertSuccessfulEvaluation(profilesFuture, profiles -> {
        assertThat(profiles.containsValue(expectedProfile), is(true));
        assertThat(profiles.size(), is(1));
    }, async);

}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:23,代码来源:DefaultAsyncCallbackLogicTest.java

示例7: testNotAuthenticatedButMatcher

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testNotAuthenticatedButMatcher(final TestContext testContext) throws Exception {
    final AsyncClient<TestCredentials, TestProfile> client = getMockIndirectClient(NAME);
    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, client);
    when(config.getClients()).thenReturn(clients);
    final Map<String, AsyncMatcher> matchers = new HashMap<>();
    matchers.put(NAME, AsyncMatcher.fromNonBlocking(context -> false));
    when(config.getMatchers()).thenReturn(matchers);
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, null, null, NAME);

    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(-1));
        verify(accessGrantedAdapter, times(1)).adapt(webContext);
    }), async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:19,代码来源:DefaultAsyncSecurityLogicTest.java

示例8: testAlreadyAuthenticatedAndAuthorized

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testAlreadyAuthenticatedAndAuthorized(final TestContext testContext) throws Exception {
    final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME);
    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient);
    when(config.getClients()).thenReturn(clients);
    final String authorizers = NAME;
    addSingleAuthorizerToConfig((context, prof) -> prof.get(0).getId().equals(GOOD_USERNAME));
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> result = simulatePreviousAuthenticationSuccess()
        .thenCompose(v -> asyncSecurityLogic.perform(webContext, accessGrantedAdapter, null, authorizers, null));
    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(-1));
        verify(accessGrantedAdapter, times(1)).adapt(webContext);
    }), async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:18,代码来源:DefaultAsyncSecurityLogicTest.java

示例9: testAlreadyAuthenticatedNotAuthorized

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test(timeout = 1000)
public void testAlreadyAuthenticatedNotAuthorized(final TestContext testContext) throws Exception {
    simulatePreviousAuthenticationSuccess();
    final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME);
    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient);
    when(config.getClients()).thenReturn(clients);
    final String authorizers = NAME;
    addSingleAuthorizerToConfig((context, prof) -> prof.get(0).getId().equals(BAD_USERNAME));
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> result = simulatePreviousAuthenticationSuccess()
            .thenCompose(v -> asyncSecurityLogic.perform(webContext, accessGrantedAdapter, null, authorizers, null));

    exception.expect(CompletionException.class);
    exception.expectCause(allOf(IsInstanceOf.instanceOf(HttpAction.class),
            hasProperty("message", is("forbidden")),
            hasProperty("code", is(403))));
    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(403));
        verify(accessGrantedAdapter, times(0)).adapt(webContext);
    }), async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:24,代码来源:DefaultAsyncSecurityLogicTest.java

示例10: testAuthorizerThrowsRequiresHttpAction

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test(timeout = 1000)
public void testAuthorizerThrowsRequiresHttpAction(final TestContext testContext) throws Exception {
    simulatePreviousAuthenticationSuccess();
    final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME);
    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient);
    when(config.getClients()).thenReturn(clients);
    final String authorizers = NAME;
    addSingleAuthorizerToConfig((context, prof) -> { throw HttpAction.status("bad request", 400, context); });
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> result = simulatePreviousAuthenticationSuccess()
            .thenCompose(v -> asyncSecurityLogic.perform(webContext, accessGrantedAdapter, null, authorizers, null));
    exception.expect(CompletionException.class);
    exception.expectCause(allOf(IsInstanceOf.instanceOf(HttpAction.class),
            hasProperty("message", is("bad request")),
            hasProperty("code", is(400))));
    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(400));
        verify(accessGrantedAdapter, times(0)).adapt(webContext);
    }), async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:23,代码来源:DefaultAsyncSecurityLogicTest.java

示例11: testDirectClientThrowsRequiresHttpAction

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testDirectClientThrowsRequiresHttpAction(final TestContext testContext) throws Exception {
    final AsyncClient directClient = getMockDirectClient(NAME, TEST_CREDENTIALS);
    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, directClient);
    when(config.getClients()).thenReturn(clients);
    final String clientNames = NAME;
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
    when(directClient.getCredentials(eq(webContext))).thenReturn(delayedException(250,
            (() -> HttpAction.status("bad request", 400, webContext))));
    final Async async = testContext.async();
    final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
    exception.expect(CompletionException.class);
    exception.expectCause(allOf(IsInstanceOf.instanceOf(HttpAction.class),
            hasProperty("message", is("bad request")),
            hasProperty("code", is(400))));

    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        assertThat(status.get(), is(400));
        verify(accessGrantedAdapter, times(0)).adapt(webContext);
    }), async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:23,代码来源:DefaultAsyncSecurityLogicTest.java

示例12: testDoubleDirectClientChooseBadDirectClient

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testDoubleDirectClientChooseBadDirectClient(final TestContext testContext) throws Exception {
    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = doubleDirectClients();
    when(config.getClients()).thenReturn(clients);
    final String clientNames = NAME;
    when(webContext.getRequestParameter(eq(Clients.DEFAULT_CLIENT_NAME_PARAMETER))).thenReturn(VALUE);
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, true, config, httpActionAdapter);
    final Async async = testContext.async();

    exception.expect(CompletionException.class);
    exception.expectCause(allOf(IsInstanceOf.instanceOf(TechnicalException.class),
            hasProperty("message", is("Client not allowed: " + VALUE))));
    final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        verify(accessGrantedAdapter, times(0)).adapt(webContext);
    }), async);

}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:20,代码来源:DefaultAsyncSecurityLogicTest.java

示例13: testDoubleIndirectClientOneChosen

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testDoubleIndirectClientOneChosen(final TestContext testContext) throws Exception {

    final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME, PAC4J_URL);
    final AsyncClient<TestCredentials, TestProfile> indirectClient2 = getMockIndirectClient(VALUE, PAC4J_BASE_URL);

    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient, indirectClient2);

    when(config.getClients()).thenReturn(clients);
    final String clientNames = NAME + "," + VALUE;
    when(webContext.getRequestParameter(eq(Clients.DEFAULT_CLIENT_NAME_PARAMETER))).thenReturn(VALUE);
    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);
    final Async async = testContext.async();
    final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
    assertRedirectionTo(async, result, PAC4J_BASE_URL);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:17,代码来源:DefaultAsyncSecurityLogicTest.java

示例14: testDoubleIndirectClientBadOneChosen

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testDoubleIndirectClientBadOneChosen(final TestContext testContext) throws Exception {
    final AsyncClient<TestCredentials, TestProfile> indirectClient = getMockIndirectClient(NAME, PAC4J_URL);
    final AsyncClient<TestCredentials, TestProfile> indirectClient2 = getMockIndirectClient(VALUE, PAC4J_BASE_URL);

    final Clients<AsyncClient<? extends Credentials, ? extends CommonProfile>, AsyncAuthorizationGenerator<CommonProfile>> clients = new Clients<>(CALLBACK_URL, indirectClient, indirectClient2);

    when(config.getClients()).thenReturn(clients);
    final String clientNames = NAME;
    when(webContext.getRequestParameter(eq(Clients.DEFAULT_CLIENT_NAME_PARAMETER))).thenReturn(VALUE);

    asyncSecurityLogic = new DefaultAsyncSecurityLogic<>(true, false, config, httpActionAdapter);

    final Async async = testContext.async();

    exception.expect(CompletionException.class);
    exception.expectCause(allOf(IsInstanceOf.instanceOf(TechnicalException.class),
            hasProperty("message", is("Client not allowed: " + VALUE))));
    final CompletableFuture<Object> result = asyncSecurityLogic.perform(webContext, accessGrantedAdapter, clientNames, null, null);
    assertSuccessfulEvaluation(result, ExceptionSoftener.softenConsumer(o -> {
        assertThat(o, is(nullValue()));
        verify(accessGrantedAdapter, times(0)).adapt(webContext);
    }), async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:25,代码来源:DefaultAsyncSecurityLogicTest.java

示例15: testLogoutPerformed

import org.pac4j.core.client.Clients; //导入依赖的package包/类
@Test
public void testLogoutPerformed(final TestContext testContext) {
    final Map<String, TestProfile> profiles = new HashMap<>();
    profiles.put(NAME, TestProfile.from(TEST_CREDENTIALS));
    final Clients<AsyncClient<? extends Credentials, ? extends TestProfile>, AsyncAuthorizationGenerator<TestProfile>> clients = new Clients<>();
    when(config.getClients()).thenReturn(clients);
    final Async async = testContext.async();
    asyncLogoutLogic = new DefaultAsyncLogoutLogic<>(config, httpActionAdapter, null, null, true, false, false);
    final CompletableFuture<Object> resultFuture = addProfilesToContext(profiles)
            .thenCompose(v -> asyncLogoutLogic.perform(webContext));

    assertSuccessfulEvaluation(assertProfilesCount(resultFuture, 0), o -> {
        assertThat(buffer.toString(), is(""));
        assertThat(status.get(), is(200));
    }, async);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:17,代码来源:DefaultAsyncLogoutLogicTest.java


注:本文中的org.pac4j.core.client.Clients类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。