Permalink
Browse files

Moving non oauth controllers into separate repository and removing de…

…pendency on spring-social-web-non-oauth-extension
  • Loading branch information...
1 parent 1871d86 commit 24d16a46359572f94b9d9f35819f9b1b2890e868 @michaellavelle committed Oct 20, 2011
View
@@ -13,11 +13,6 @@
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.0.0.RELEASE</version>
-</dependency>
- <dependency>
- <groupId>org.socialsignin</groupId>
- <artifactId>spring-social-web-non-oauth-extension</artifactId>
- <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
@@ -1,121 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.lastfm.connect.web;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.inject.Inject;
-
-import org.springframework.social.connect.Connection;
-import org.springframework.social.connect.ConnectionFactory;
-import org.springframework.social.connect.ConnectionFactoryLocator;
-import org.springframework.social.connect.ConnectionRepository;
-import org.springframework.social.connect.web.ExtensibleConnectController;
-import org.springframework.social.lastfm.connect.LastFmConnectionFactory;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.context.request.NativeWebRequest;
-import org.springframework.web.servlet.view.RedirectView;
-
-/**
- * @author Michael Lavelle
- */
-public class LastFmConnectController extends ExtensibleConnectController {
-
- private final LastFmConnectSupport lastFmWebSupport = new LastFmConnectSupport();
-
- @Inject
- public LastFmConnectController(
- ConnectionFactoryLocator connectionFactoryLocator,
- ConnectionRepository connectionRepository) {
- super(connectionFactoryLocator, connectionRepository);
- }
-
- /**
- * Configures the base secure URL for the application this controller is
- * being used in e.g. <code>https://myapp.com</code>. Defaults to null. If
- * specified, will be used to generate OAuth callback URLs. If not
- * specified, OAuth callback URLs are generated from web request info. You
- * may wish to set this property if requests into your application flow
- * through a proxy to your application server. In this case, the request URI
- * may contain a scheme, host, and/or port value that points to an internal
- * server not appropriate for an external callback URL. If you have this
- * problem, you can set this property to the base external URL for your
- * application and it will be used to construct the callback URL instead.
- *
- * @param applicationUrl
- * the application URL value
- */
- public void setApplicationUrl(String applicationUrl) {
- try {
- lastFmWebSupport.setApplicationUrl(new URL(applicationUrl));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Process the authorization callback from the LastFm service provider.
- * Called after the user authorizes the connection, generally done by having
- * he or she click "Allow" in their web browser at the provider's site. On
- * authorization verification, connects the user's local account to the
- * account they hold at the service provider.
- */
- @RequestMapping(value = "/{providerId}", method = RequestMethod.GET, params = {
- "!code", "!oauth_token" })
- public RedirectView lastFmCallback(@PathVariable String providerId,
- @RequestParam("token") String token, NativeWebRequest request) {
- LastFmConnectionFactory connectionFactory = (LastFmConnectionFactory) connectionFactoryLocator
- .getConnectionFactory(providerId);
- Connection<?> connection = lastFmWebSupport.completeConnection(
- connectionFactory, request);
- addConnection(connection, connectionFactory, request);
- return connectionStatusRedirect(providerId);
- }
-
- /**
- * Process a connect form submission by commencing the process of
- * establishing a connection to the provider on behalf of the member. For
- * OAuth1, fetches a new request token from the provider, temporarily stores
- * it in the session, then redirects the member to the provider's site for
- * authorization. For OAuth2, redirects the user to the provider's site for
- * authorization.
- */
- @Override
- @RequestMapping(value = "/{providerId}", method = RequestMethod.POST)
- public RedirectView connect(@PathVariable String providerId,
- NativeWebRequest request) {
-
- ConnectionFactory<?> connectionFactory = connectionFactoryLocator
- .getConnectionFactory(providerId);
- MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
- preConnect(connectionFactory, parameters, request);
- if (connectionFactory instanceof LastFmConnectionFactory) {
- return new RedirectView(lastFmWebSupport.buildAuthUrl(
- (LastFmConnectionFactory) connectionFactory, request,
- parameters));
- } else {
- return super.connect(providerId, request);
- }
-
- }
-
-}
@@ -1,113 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.lastfm.connect.web;
-
-import java.net.URL;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.springframework.social.connect.Connection;
-import org.springframework.social.lastfm.auth.LastFmAccessGrant;
-import org.springframework.social.lastfm.auth.LastFmAuthOperations;
-import org.springframework.social.lastfm.auth.LastFmAuthParameters;
-import org.springframework.social.lastfm.connect.LastFmConnectionFactory;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.context.request.NativeWebRequest;
-
-/**
- * Provides common LastFm connect support and utilities for Java web/servlet
- * environments. Used by {@link LastFmProviderSignInController}.
- *
- * @author Michael Lavelle
- */
-public class LastFmConnectSupport {
-
- private URL applicationUrl;
-
- /**
- * Configures the base secure URL for the application this controller is
- * being used in e.g. <code>https://myapp.com</code>. Defaults to null. If
- * specified, will be used to generate OAuth callback URLs. If not
- * specified, LastFm callback URLs are generated from
- * {@link HttpServletRequest HttpServletRequests}. You may wish to set this
- * property if requests into your application flow through a proxy to your
- * application server. In this case, the HttpServletRequest URI may contain
- * a scheme, host, and/or port value that points to an internal server not
- * appropriate for an external callback URL. If you have this problem, you
- * can set this property to the base external URL for your application and
- * it will be used to construct the callback URL instead.
- *
- * @param applicationUrl
- * the application URL value
- */
- public void setApplicationUrl(URL applicationUrl) {
- this.applicationUrl = applicationUrl;
- }
-
- /**
- * Complete the connection to the OAuth2 provider.
- *
- * @param connectionFactory
- * the LastFmConnectionFactory
- * @param request
- * the current web request
- * @return a new connection to the service provider
- */
- public Connection<?> completeConnection(
- LastFmConnectionFactory connectionFactory, NativeWebRequest request) {
- String code = request.getParameter("token");
- LastFmAccessGrant accessGrant = connectionFactory
- .getLastFmAuthOperations().exchangeForAccess(code, null);
- return connectionFactory.createConnection(accessGrant);
- }
-
- public String buildAuthUrl(LastFmConnectionFactory connectionFactory,
- NativeWebRequest request,
- MultiValueMap<String, String> additionalParameters) {
- LastFmAuthOperations oauthOperations = connectionFactory
- .getLastFmAuthOperations();
- LastFmAuthParameters parameters = getLastFmAuthParameters(request,
- additionalParameters);
-
- return oauthOperations.buildAuthorizeUrl(parameters);
- }
-
- private LastFmAuthParameters getLastFmAuthParameters(
- NativeWebRequest request,
- MultiValueMap<String, String> additionalParameters) {
- LastFmAuthParameters parameters = new LastFmAuthParameters(
- additionalParameters);
- parameters.setRedirectUri(callbackUrl(request));
-
- return parameters;
- }
-
- private String callbackUrl(NativeWebRequest request) {
- HttpServletRequest nativeRequest = request
- .getNativeRequest(HttpServletRequest.class);
- if (applicationUrl != null) {
- return applicationUrl + connectPath(nativeRequest);
- } else {
- return nativeRequest.getRequestURL().toString();
- }
- }
-
- private String connectPath(HttpServletRequest request) {
- String pathInfo = request.getPathInfo();
- return request.getServletPath() + (pathInfo != null ? pathInfo : "");
- }
-
-}
@@ -1,120 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.lastfm.connect.web;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.inject.Inject;
-
-import org.springframework.social.connect.Connection;
-import org.springframework.social.connect.ConnectionFactory;
-import org.springframework.social.connect.ConnectionFactoryLocator;
-import org.springframework.social.connect.UsersConnectionRepository;
-import org.springframework.social.connect.web.ExtensibleProviderSignInController;
-import org.springframework.social.connect.web.SignInAdapter;
-import org.springframework.social.lastfm.connect.LastFmConnectionFactory;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.context.request.NativeWebRequest;
-import org.springframework.web.servlet.View;
-import org.springframework.web.servlet.view.RedirectView;
-
-/**
- * Spring MVC Controller for handling the LastFm user sign-in flow. We cannot
- * use the existing ProviderSignInController, as LastFm's Auth scheme is neither
- * OAuth1 or OAuth2.
- * <ul>
- * <li>POST /signin/{providerId} - Initiate user sign-in with {providerId}.</li>
- * <li>GET /signin/{providerId}?oauth_token&oauth_verifier||code - Receive
- * {providerId} authentication callback and establish the connection.</li>
- * </ul>
- *
- * @author Michael Lavelle
- */
-public class LastFmSignInController extends ExtensibleProviderSignInController {
-
- private final LastFmConnectSupport lastFmWebSupport = new LastFmConnectSupport();
-
- @Inject
- public LastFmSignInController(
- ConnectionFactoryLocator connectionFactoryLocator,
- UsersConnectionRepository usersConnectionRepository,
- SignInAdapter signInAdapter) {
- super(connectionFactoryLocator, usersConnectionRepository,
- signInAdapter);
- }
-
- @RequestMapping(value = "/{providerId}", method = RequestMethod.GET, params = {
- "!code", "!oauth_token" })
- public View lastFmAuthCallback(@PathVariable String providerId,
- @RequestParam("token") String token, NativeWebRequest request) {
- LastFmConnectionFactory connectionFactory = (LastFmConnectionFactory) connectionFactoryLocator
- .getConnectionFactory(providerId);
- Connection<?> connection = lastFmWebSupport.completeConnection(
- connectionFactory, request);
- return handleSignIn(connection, request);
- }
-
- /**
- * Configures the base secure URL for the application this controller is
- * being used in e.g. <code>https://myapp.com</code>. Defaults to null. If
- * specified, will be used to generate OAuth callback URLs. If not
- * specified, OAuth callback URLs are generated from web request info. You
- * may wish to set this property if requests into your application flow
- * through a proxy to your application server. In this case, the request URI
- * may contain a scheme, host, and/or port value that points to an internal
- * server not appropriate for an external callback URL. If you have this
- * problem, you can set this property to the base external URL for your
- * application and it will be used to construct the callback URL instead.
- *
- * @param applicationUrl
- * the application URL value
- */
- public void setApplicationUrl(String applicationUrl) {
- try {
- lastFmWebSupport.setApplicationUrl(new URL(applicationUrl));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Process a sign-in form submission by commencing the process of
- * establishing a connection to the provider on behalf of the user. For
- * OAuth1, fetches a new request token from the provider, temporarily stores
- * it in the session, then redirects the user to the provider's site for
- * authentication authorization. For OAuth2, redirects the user to the
- * provider's site for authentication authorization.
- */
- @RequestMapping(value = "/{providerId}", method = RequestMethod.POST)
- public RedirectView signIn(@PathVariable String providerId,
- NativeWebRequest request) {
-
- ConnectionFactory<?> connectionFactory = connectionFactoryLocator
- .getConnectionFactory(providerId);
- if (connectionFactory instanceof LastFmConnectionFactory) {
- return new RedirectView(lastFmWebSupport.buildAuthUrl(
- (LastFmConnectionFactory) connectionFactory, request, null));
- } else {
- return super.signIn(providerId, request);
-
- }
- }
-
-}

0 comments on commit 24d16a4

Please sign in to comment.