@Transactional(rollbackForClassName = "java.lang.Exception") @RequestMapping( value = "updateAccount", params = {"delete"}, method = RequestMethod.POST) public ModelAndView deleteAccount(@Valid User user, HttpServletRequest request) throws IllegalRequestException { Integer authUserId = userCookieGenerator.getUserId(request); if (!authUserId.equals(user.getId())) throw new IllegalRequestException(); userProfileMapper.deleteProfile(authUserId); userMasterMapper.deleteUser(authUserId); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(authUserId.toString()); Connection connection = connectionRepository.findPrimaryConnection(Facebook.class); if (connection != null) connectionRepository.removeConnection(connection.getKey()); connection = connectionRepository.findPrimaryConnection(Twitter.class); if (connection != null) connectionRepository.removeConnection(connection.getKey()); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("forward:logout"); return modelAndView; }
private boolean userNotFound(String userId) { // doesn't bother checking a local user database: simply checks if the userId is connected to // Facebook return connectionRepository .createConnectionRepository(userId) .findPrimaryConnection(Twitter.class) != null; }
private void handleSignOut(HttpServletRequest request, HttpServletResponse response) { if (SecurityContext.userSignedIn() && request.getServletPath().startsWith("/signout")) { connectionRepository .createConnectionRepository(SecurityContext.getCurrentUser().getId()) .removeConnections("twitter"); userCookieGenerator.removeCookie(response); SecurityContext.remove(); } }
@Test public void test() { logger.debug("Running '{}'...", name.getMethodName()); con = usersConnectionRepository.createConnectionRepository("GeraldXv"); Connection<Twitter> twitter = con.findPrimaryConnection(Twitter.class); twitterApi = twitter.getApi(); Connection<Google> google = con.findPrimaryConnection(Google.class); googleApi = google.getApi(); System.out.println(twitterApi.friendOperations().getFriends().get(0).getName()); // System.out.println(googleApi.personOperations().getPerson("110377639084744464746").get); }
public LinkedIn getApi() { if (logger.isDebugEnabled()) { logger.debug("Getting API binding instance for Facebook"); } Connection<LinkedIn> connection = usersConnectionRepository .createConnectionRepository(userIdSource.getUserId()) .findPrimaryConnection(LinkedIn.class); if (logger.isDebugEnabled() && connection == null) { logger.debug("No current connection; Returning default FacebookTemplate instance."); } return connection != null ? connection.getApi() : null; }
@ApiOperation( value = "SNS 기반 로그인", produces = "application/json", response = EmptyJsonResponse.class) @RequestMapping(value = "/login/social/{providerId}", method = RequestMethod.POST) public EmptyJsonResponse loginSocialUser( @PathVariable String providerId, @Valid @RequestBody LoginSocialUserForm form, NativeWebRequest request) { CommonConst.ACCOUNT_TYPE convertProviderId = CommonConst.ACCOUNT_TYPE.valueOf(providerId.toUpperCase()); AccessGrant accessGrant = new AccessGrant(form.getAccessToken()); Connection<?> connection = null; switch (convertProviderId) { case FACEBOOK: connection = facebookConnectionFactory.createConnection(accessGrant); break; case DAUM: connection = daumConnectionFactory.createConnection(accessGrant); break; } assert connection != null; ConnectionKey connectionKey = connection.getKey(); Set<String> userIds = usersConnectionRepository.findUserIdsConnectedTo( providerId, new HashSet<>(Collections.singletonList(connectionKey.getProviderUserId()))); User existUser = userService.findOneByProviderIdAndProviderUserId( convertProviderId, connectionKey.getProviderUserId()); // 로그인 처리. if (!userIds.isEmpty()) { userService.signInSocialUser(existUser); return EmptyJsonResponse.newInstance(); } // SNS 신규 가입. ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(connection); sessionStrategy.setAttribute(request, ProviderSignInAttempt.SESSION_ATTRIBUTE, signInAttempt); throw new ServiceException(ServiceError.NOT_REGISTER_WITH_SNS); }
@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); }
@Before public void setup() { MockitoAnnotations.initMocks(this); doNothing() .when(mockMailService) .sendSocialRegistrationValidationEmail(anyObject(), anyString()); doNothing().when(mockConnectionRepository).addConnection(anyObject()); when(mockUsersConnectionRepository.createConnectionRepository(anyString())) .thenReturn(mockConnectionRepository); socialService = new SocialService(); ReflectionTestUtils.setField(socialService, "authorityRepository", authorityRepository); ReflectionTestUtils.setField(socialService, "passwordEncoder", passwordEncoder); ReflectionTestUtils.setField(socialService, "mailService", mockMailService); ReflectionTestUtils.setField(socialService, "userRepository", userRepository); ReflectionTestUtils.setField( socialService, "usersConnectionRepository", mockUsersConnectionRepository); }
@Transactional(rollbackForClassName = "java.lang.Exception") @RequestMapping(value = "updateSocial", method = RequestMethod.GET) public ModelAndView updateSocial(HttpServletRequest request) throws IllegalRequestException { Integer authUserId = userCookieGenerator.getUserId(request); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(authUserId.toString()); boolean facebookConnected = ((connectionRepository.findPrimaryConnection(Facebook.class)) != null); boolean twitterConnected = ((connectionRepository.findPrimaryConnection(Twitter.class)) != null); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("facebookConnected", facebookConnected); modelAndView.addObject("twitterConnected", twitterConnected); modelAndView.setViewName("user/editSocial"); return modelAndView; }
@Transactional(rollbackForClassName = "java.lang.Exception") @RequestMapping(value = "disconnect", method = RequestMethod.POST) public ModelAndView disconnect(HttpServletRequest request) throws IllegalRequestException { Integer authUserId = userCookieGenerator.getUserId(request); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(authUserId.toString()); if (request.getParameter("disconnectFacebook") != null) { Connection connection = connectionRepository.findPrimaryConnection(Facebook.class); if (connection != null) connectionRepository.removeConnection(connection.getKey()); } if (request.getParameter("disconnectTwitter") != null) { Connection connection = connectionRepository.findPrimaryConnection(Twitter.class); if (connection != null) connectionRepository.removeConnection(connection.getKey()); } ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("activeTab", "social"); modelAndView.addObject("updated", true); modelAndView.setViewName("user/edit"); return modelAndView; }
private void createSocialConnection(String login, Connection<?> connection) { ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(login); connectionRepository.addConnection(connection); }
private boolean userNotFound(String userId) { return myConnectionRepository .createConnectionRepository(userId) .findPrimaryConnection(Facebook.class) != null; }