@SuppressWarnings("unchecked") @Test public void addConnection() { UsersConnectionRepository usersConnectionRepository = mock(UsersConnectionRepository.class); SocialAuthenticationFilter filter = new SocialAuthenticationFilter(null, null, usersConnectionRepository, null); SocialAuthenticationService<Object> authService = mock(SocialAuthenticationService.class); ConnectionRepository connectionRepository = mock(ConnectionRepository.class); ConnectionFactory<Object> connectionFactory = mock(MockConnectionFactory.class); MockHttpServletRequest request = new MockHttpServletRequest(); ConnectionData data = new ConnectionData("dummyprovider", "1234", null, null, null, null, null, null, null); String userId = "joe"; DummyConnection<Object> connection = DummyConnection.dummy(data.getProviderId(), userId); when(usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), set(data.getProviderUserId()))).thenReturn(empty(String.class)); when(usersConnectionRepository.createConnectionRepository(userId)).thenReturn(connectionRepository); when(authService.getConnectionCardinality()).thenReturn(ConnectionCardinality.ONE_TO_ONE); when(authService.getConnectionFactory()).thenReturn(connectionFactory); when(authService.getConnectionAddedRedirectUrl(request, connection)).thenReturn("/redirect"); when(connectionFactory.createConnection(data)).thenReturn(connection); Connection<?> addedConnection = filter.addConnection(authService, userId, data); assertNotNull(addedConnection); assertSame(connection, addedConnection); verify(connectionRepository).addConnection(connection); }
protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) { HashSet<String> userIdSet = new HashSet<String>(); userIdSet.add(data.getProviderUserId()); Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet); if (connectedUserIds.contains(userId)) { return null; } else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) { return null; } ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId); if (!authService.getConnectionCardinality().isMultiProviderUserId()) { List<Connection<?>> connections = repo.findConnections(data.getProviderId()); if (!connections.isEmpty()) { return null; } } Connection<?> connection = authService.getConnectionFactory().createConnection(data); connection.sync(); repo.addConnection(connection); return connection; }
SocialAuthenticationFilter extends AbstractAuthenticationProcessingFilter { protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) { HashSet<String> userIdSet = new HashSet<String>(); userIdSet.add(data.getProviderUserId()); Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet); if (connectedUserIds.contains(userId)) { return null; } else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) { return null; } ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId); if (!authService.getConnectionCardinality().isMultiProviderUserId()) { List<Connection<?>> connections = repo.findConnections(data.getProviderId()); if (!connections.isEmpty()) { return null; } } Connection<?> connection = authService.getConnectionFactory().createConnection(data); connection.sync(); repo.addConnection(connection); return connection; } }
SocialAuthenticationFilter extends AbstractAuthenticationProcessingFilter { protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) { HashSet<String> userIdSet = new HashSet<String>(); userIdSet.add(data.getProviderUserId()); Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet); if (connectedUserIds.contains(userId)) { return null; } else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) { return null; } ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId); if (!authService.getConnectionCardinality().isMultiProviderUserId()) { List<Connection<?>> connections = repo.findConnections(data.getProviderId()); if (!connections.isEmpty()) { return null; } } Connection<?> connection = authService.getConnectionFactory().createConnection(data); connection.sync(); repo.addConnection(connection); return connection; } SocialAuthenticationFilter(AuthenticationManager authManager, UserIdSource userIdSource, UsersConnectionRepository usersConnectionRepository, SocialAuthenticationServiceLocator authServiceLocator); }
SocialAuthenticationFilter extends AbstractAuthenticationProcessingFilter { protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) { HashSet<String> userIdSet = new HashSet<String>(); userIdSet.add(data.getProviderUserId()); Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet); if (connectedUserIds.contains(userId)) { return null; } else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) { return null; } ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId); if (!authService.getConnectionCardinality().isMultiProviderUserId()) { List<Connection<?>> connections = repo.findConnections(data.getProviderId()); if (!connections.isEmpty()) { return null; } } Connection<?> connection = authService.getConnectionFactory().createConnection(data); connection.sync(); repo.addConnection(connection); return connection; } SocialAuthenticationFilter(AuthenticationManager authManager, UserIdSource userIdSource, UsersConnectionRepository usersConnectionRepository, SocialAuthenticationServiceLocator authServiceLocator); void setSignupUrl(String signupUrl); void setConnectionAddedRedirectUrl(String connectionAddedRedirectUrl); void setConnectionAddingFailureRedirectUrl(String connectionAddingFailureRedirectUrl); void setUpdateConnections(boolean updateConnections); void setPostLoginUrl(String postLoginUrl); void setAlwaysUsePostLoginUrl(boolean alwaysUsePostLoginUrl); void setPostFailureUrl(String postFailureUrl); void setSessionStrategy(SessionStrategy sessionStrategy); UsersConnectionRepository getUsersConnectionRepository(); SocialAuthenticationServiceLocator getAuthServiceLocator(); Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response); @Override void setFilterProcessesUrl(String filterProcessesUrl); }
SocialAuthenticationFilter extends AbstractAuthenticationProcessingFilter { protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) { HashSet<String> userIdSet = new HashSet<String>(); userIdSet.add(data.getProviderUserId()); Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet); if (connectedUserIds.contains(userId)) { return null; } else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) { return null; } ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId); if (!authService.getConnectionCardinality().isMultiProviderUserId()) { List<Connection<?>> connections = repo.findConnections(data.getProviderId()); if (!connections.isEmpty()) { return null; } } Connection<?> connection = authService.getConnectionFactory().createConnection(data); connection.sync(); repo.addConnection(connection); return connection; } SocialAuthenticationFilter(AuthenticationManager authManager, UserIdSource userIdSource, UsersConnectionRepository usersConnectionRepository, SocialAuthenticationServiceLocator authServiceLocator); void setSignupUrl(String signupUrl); void setConnectionAddedRedirectUrl(String connectionAddedRedirectUrl); void setConnectionAddingFailureRedirectUrl(String connectionAddingFailureRedirectUrl); void setUpdateConnections(boolean updateConnections); void setPostLoginUrl(String postLoginUrl); void setAlwaysUsePostLoginUrl(boolean alwaysUsePostLoginUrl); void setPostFailureUrl(String postFailureUrl); void setSessionStrategy(SessionStrategy sessionStrategy); UsersConnectionRepository getUsersConnectionRepository(); SocialAuthenticationServiceLocator getAuthServiceLocator(); Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response); @Override void setFilterProcessesUrl(String filterProcessesUrl);  }