Hello-
Am trying to do a mini application that integrates dropbox with a web app. Trying to follow the tutorial for integrating oAuth for dropbox authentication. Application is always coming back with an error that says AccessTokenRequiredException: No OAuth security context has been established. Unable to access resource.. System is able to authenticate against Dropbox infra, but after that when it is trying to access the files/folders REST URL, am getting the above exception. I was hoping someone can take a look @ my code and point out what is that am doing wrong with the integration. Thanks in advance. Here are the files am using.
Security and spring config file code base.
Here is my web.xml fileCode:<beans:bean id="sucRate" class="com.company.dropbox.MultiTenantLogoutSuccessHandler"/> <http auto-config='true' use-expressions="true" access-denied-page="/login/login"> <intercept-url pattern="/services/**" access="hasRole('ROLE_USER')"/> <intercept-url pattern="/login/index" access="hasRole('ROLE_USER')"/> <intercept-url pattern="/services/upload" access="hasRole('ROLE_USER')"/> <intercept-url pattern="/login/login" access="permitAll"/> <!--Line below will redirect page if there are errors in the submit.--> <form-login login-page="/login/login" default-target-url="/" authentication-failure-url="/login/login?error=true"/> <!--See note for the sucRate definition. We are invalidating session data.--> <logout success-handler-ref="sucRate" invalidate-session="true"/> </http> <authentication-manager> <authentication-provider> <user-service> <user authorities="ROLE_USER" name="guest" password="guest"/> </user-service> </authentication-provider> </authentication-manager> <oauth:consumer resource-details-service-ref="resourceDetails" requireAuthenticated="true"> <oauth:url pattern="/services/dropBoxAccountInfo" resources="dropbox"/> </oauth:consumer> <oauth:resource-details-service id="resourceDetails"> <oauth:resource id="dropbox" key="t" secret="t" request-token-url="http://api.getdropbox.com/0/oauth/request_token" user-authorization-url="https://www.dropbox.com/0/oauth/authorize?oauth_callback=http://localhost:8080" access-token-url="http://api.getdropbox.com/0/oauth/access_token" request-token-method="GET" access-token-method="GET"> <oauth:addtionalParameter name="oauth_callback" value="http://localhost:8080/"/> </oauth:resource> </oauth:resource-details-service> <bean id="dropBoxService" class="com.company.dropbox.DropBoxServiceImpl"> <property name="dropBoxAccountURL" value="https://api.dropbox.com/0/account/info"/> <property name="dropBoxRestTemplate"> <bean class="org.springframework.security.oauth.consumer.OAuthRestTemplate"> <constructor-arg ref="dropbox"/> </bean> </property> </bean>
Here is the code for controllerCode:<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/main-security.xml,classpath:spring-config.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/login/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
Here is the code for serviceImplCode:@Autowired private DropBoxService dropBoxService; @RequestMapping(value = "/trisunkdropBoxAccountInfo", method = RequestMethod.GET) protected String returnDropBoxAccountInfo() { try { dropBoxService.getAccountInfo(null); } catch (Exception e) { e.printStackTrace(); } return "upload"; }
Code:public class DropBoxServiceImpl implements DropBoxService { private String dropBoxAccountURL; private OAuthRestTemplate dropBoxRestTemplate; public void setDropBoxAccountURL(String dropBoxAccountURL) { this.dropBoxAccountURL = dropBoxAccountURL; } public void setDropBoxRestTemplate(OAuthRestTemplate dropBoxRestTemplate) { this.dropBoxRestTemplate = dropBoxRestTemplate; } public String getDropBoxAccountURL() { return dropBoxAccountURL; } public OAuthRestTemplate getDropBoxRestTemplate() { return dropBoxRestTemplate; } public void getAccountInfo(List params) throws DropboxException { try { Object ject = dropBoxRestTemplate.getForObject ("http://localhost:8080/services/dropBoxAccountInfo", String.class); ject.getClass(); } catch (Exception e) { throw new IllegalStateException(e); } } }


Reply With Quote
