org.pac4j.oauth.client.FacebookClient Java Examples
The following examples show how to use
org.pac4j.oauth.client.FacebookClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultConfigurationTest.java From dropwizard-pac4j with Apache License 2.0 | 6 votes |
@Test public void allOptionsClients() throws Exception { Pac4jFactory conf = getPac4jFactory("alloptions-pac4j.yaml"); Config config = conf.build(); assertThat(config).isExactlyInstanceOf(FakeConfig.class); final FakeConfig fakeConfig = (FakeConfig) config; assertThat(fakeConfig.getProperties().size()).isEqualTo(2); assertThat(config.getClients().getClients()).hasSize(2); Client client0 = config.getClients().getClients().get(0); assertThat(client0).isExactlyInstanceOf(FacebookClient.class); assertThat(((FacebookClient) client0).getKey()).isEqualTo("fbId"); Client client1 = config.getClients().getClients().get(1); assertThat(client1).isInstanceOf(DirectBasicAuthClient.class); assertThat(client1.getName()).isEqualTo("DirectBasicAuthClient"); assertThat(((DirectBasicAuthClient) client1).getAuthenticator()) .isNotNull() .isInstanceOf(SimpleTestUsernamePasswordAuthenticator.class); assertThat(config.getAuthorizers().size()).isEqualTo(1); assertThat(config.getMatchers().size()).isEqualTo(1); }
Example #2
Source File: DefaultConfigurationTest.java From dropwizard-pac4j with Apache License 2.0 | 6 votes |
@Test public void clientsAndProperties() throws Exception { Pac4jFactory conf = getPac4jFactory("clientsandproperties-pac4j.yaml"); Config config = conf.build(); assertThat(config.getClients().getClients()).hasSize(2); Client client0 = config.getClients().getClients().get(0); assertThat(client0).isExactlyInstanceOf(FacebookClient.class); assertThat(((FacebookClient) client0).getKey()).isEqualTo("fbId"); Client client1 = config.getClients().getClients().get(1); assertThat(client1).isInstanceOf(DirectBasicAuthClient.class); assertThat(client1.getName()).isEqualTo("DirectBasicAuthClient"); assertThat(((DirectBasicAuthClient) client1).getAuthenticator()) .isNotNull() .isInstanceOf(SimpleTestUsernamePasswordAuthenticator.class); assertThat(config.getAuthorizers().size()).isEqualTo(0); assertThat(config.getMatchers().size()).isEqualTo(0); }
Example #3
Source File: ClientActionTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyStartAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(ClientAction.THEME, MY_THEME); mockRequest.setParameter(ClientAction.LOCALE, MY_LOCALE); mockRequest.setParameter(ClientAction.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(ClientAction.SERVICE, new SimpleWebApplicationServiceImpl(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(mock(CentralAuthenticationService.class), clients); final Event event = action.execute(mockRequestContext); assertEquals("error", event.getId()); assertEquals(MY_THEME, mockSession.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockSession.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockSession.getAttribute(ClientAction.METHOD)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); assertTrue(((String) flowScope.get("FacebookClientUrl")) .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", flowScope.get("TwitterClientUrl")); }
Example #4
Source File: ClientActionTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyFinishAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient"); final MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute(ClientAction.THEME, MY_THEME); mockSession.setAttribute(ClientAction.LOCALE, MY_LOCALE); mockSession.setAttribute(ClientAction.METHOD, MY_METHOD); final Service service = new SimpleWebApplicationServiceImpl(MY_SERVICE); mockSession.setAttribute(ClientAction.SERVICE, service); mockRequest.setSession(mockSession); final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class); when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest); final MockRequestContext mockRequestContext = new MockRequestContext(); mockRequestContext.setExternalContext(servletExternalContext); final FacebookClient facebookClient = new MockFacebookClient(); final Clients clients = new Clients(MY_LOGIN_URL, facebookClient); final TicketGrantingTicket tgt = new TicketGrantingTicketImpl(TGT_ID, mock(Authentication.class), mock(ExpirationPolicy.class)); final CentralAuthenticationService casImpl = mock(CentralAuthenticationService.class); when(casImpl.createTicketGrantingTicket(any(Credential.class))).thenReturn(tgt); final ClientAction action = new ClientAction(casImpl, clients); final Event event = action.execute(mockRequestContext); assertEquals("success", event.getId()); assertEquals(MY_THEME, mockRequest.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockRequest.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockRequest.getAttribute(ClientAction.METHOD)); assertEquals(MY_SERVICE, mockRequest.getAttribute(ClientAction.SERVICE)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); final MutableAttributeMap requestScope = mockRequestContext.getRequestScope(); assertEquals(service, flowScope.get(ClientAction.SERVICE)); assertEquals(TGT_ID, flowScope.get(TGT_NAME)); assertEquals(TGT_ID, requestScope.get(TGT_NAME)); }
Example #5
Source File: ClientActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testStartAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(ClientAction.THEME, MY_THEME); mockRequest.setParameter(ClientAction.LOCALE, MY_LOCALE); mockRequest.setParameter(ClientAction.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(ClientAction.SERVICE, new SimpleWebApplicationServiceImpl(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(mock(CentralAuthenticationService.class), clients); final Event event = action.execute(mockRequestContext); assertEquals("error", event.getId()); assertEquals(MY_THEME, mockSession.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockSession.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockSession.getAttribute(ClientAction.METHOD)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); assertTrue(((String) flowScope.get("FacebookClientUrl")) .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", flowScope.get("TwitterClientUrl")); }
Example #6
Source File: ClientActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testFinishAuthentication() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient"); final MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute(ClientAction.THEME, MY_THEME); mockSession.setAttribute(ClientAction.LOCALE, MY_LOCALE); mockSession.setAttribute(ClientAction.METHOD, MY_METHOD); final Service service = new SimpleWebApplicationServiceImpl(MY_SERVICE); mockSession.setAttribute(ClientAction.SERVICE, service); mockRequest.setSession(mockSession); final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class); when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest); final MockRequestContext mockRequestContext = new MockRequestContext(); mockRequestContext.setExternalContext(servletExternalContext); final FacebookClient facebookClient = new MockFacebookClient(); final Clients clients = new Clients(MY_LOGIN_URL, facebookClient); final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients); final Event event = action.execute(mockRequestContext); assertEquals("success", event.getId()); assertEquals(MY_THEME, mockRequest.getAttribute(ClientAction.THEME)); assertEquals(MY_LOCALE, mockRequest.getAttribute(ClientAction.LOCALE)); assertEquals(MY_METHOD, mockRequest.getAttribute(ClientAction.METHOD)); final MutableAttributeMap flowScope = mockRequestContext.getFlowScope(); assertEquals(service, flowScope.get(ClientAction.SERVICE)); }
Example #7
Source File: DefaultConfigurationTest.java From dropwizard-pac4j with Apache License 2.0 | 5 votes |
@Test public void clientsProperties() throws Exception { Pac4jFactory conf = getPac4jFactory("clientsproperties-pac4j.yaml"); Config config = conf.build(); assertThat(config.getClients().getClients()).hasSize(1); Client client0 = config.getClients().getClients().get(0); assertThat(client0).isExactlyInstanceOf(FacebookClient.class); assertThat(((FacebookClient) client0).getKey()).isEqualTo("fbId"); assertThat(config.getAuthorizers().size()).isEqualTo(1); assertThat(config.getMatchers().size()).isEqualTo(0); }