Search in sources :

Example 6 with ConsumerDetails

use of org.springframework.security.oauth.provider.ConsumerDetails in project spring-security-oauth by spring-projects.

the class FilterChainInitializationTests method testClientDetailsFromPropertyFile.

@Test
public void testClientDetailsFromPropertyFile() {
    ConsumerDetails consumer = clientDetailsService.loadConsumerByConsumerKey("my-client-key");
    assertNotNull(consumer);
    assertEquals("my-client-secret", ((SharedConsumerSecret) consumer.getSignatureSecret()).getConsumerSecret());
}
Also used : ConsumerDetails(org.springframework.security.oauth.provider.ConsumerDetails) Test(org.junit.Test)

Example 7 with ConsumerDetails

use of org.springframework.security.oauth.provider.ConsumerDetails in project spring-security-oauth by spring-projects.

the class AccessConfirmationController method getAccessConfirmation.

@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String token = request.getParameter("oauth_token");
    if (token == null) {
        throw new IllegalArgumentException("A request token to authorize must be provided.");
    }
    OAuthProviderToken providerToken = tokenServices.getToken(token);
    ConsumerDetails consumer = consumerDetailsService.loadConsumerByConsumerKey(providerToken.getConsumerKey());
    String callback = request.getParameter("oauth_callback");
    TreeMap<String, Object> model = new TreeMap<String, Object>();
    model.put("oauth_token", token);
    if (callback != null) {
        model.put("oauth_callback", callback);
    }
    model.put("consumer", consumer);
    return new ModelAndView("access_confirmation", model);
}
Also used : OAuthProviderToken(org.springframework.security.oauth.provider.token.OAuthProviderToken) ModelAndView(org.springframework.web.servlet.ModelAndView) TreeMap(java.util.TreeMap) ConsumerDetails(org.springframework.security.oauth.provider.ConsumerDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ConsumerDetails

use of org.springframework.security.oauth.provider.ConsumerDetails in project spring-security-oauth by spring-projects.

the class UnauthenticatedRequestTokenProcessingFilterTests method testOnValidSignature.

/**
	 * test onValidSignature
	 */
@Test
public void testOnValidSignature() throws Exception {
    final OAuthProviderToken authToken = mock(OAuthProviderToken.class);
    UnauthenticatedRequestTokenProcessingFilter filter = new UnauthenticatedRequestTokenProcessingFilter() {

        @Override
        protected OAuthProviderToken createOAuthToken(ConsumerAuthentication authentication) {
            return authToken;
        }
    };
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    ConsumerCredentials creds = new ConsumerCredentials("key", "sig", "meth", "base", "tok");
    ConsumerDetails consumerDetails = mock(ConsumerDetails.class);
    when(authToken.getConsumerKey()).thenReturn("chi");
    when(authToken.getValue()).thenReturn("tokvalue");
    when(authToken.getSecret()).thenReturn("shhhhhh");
    when(consumerDetails.getAuthorities()).thenReturn(new ArrayList<GrantedAuthority>());
    when(consumerDetails.getConsumerKey()).thenReturn("chi");
    response.setContentType("text/plain;charset=utf-8");
    StringWriter writer = new StringWriter();
    when(response.getWriter()).thenReturn(new PrintWriter(writer));
    response.flushBuffer();
    TreeMap<String, String> params = new TreeMap<String, String>();
    params.put(OAuthConsumerParameter.oauth_callback.toString(), "mycallback");
    ConsumerAuthentication authentication = new ConsumerAuthentication(consumerDetails, creds, params);
    authentication.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    filter.onValidSignature(request, response, filterChain);
    assertEquals("oauth_token=tokvalue&oauth_token_secret=shhhhhh&oauth_callback_confirmed=true", writer.toString());
    SecurityContextHolder.getContext().setAuthentication(null);
}
Also used : ConsumerCredentials(org.springframework.security.oauth.provider.ConsumerCredentials) FilterChain(javax.servlet.FilterChain) GrantedAuthority(org.springframework.security.core.GrantedAuthority) HttpServletResponse(javax.servlet.http.HttpServletResponse) TreeMap(java.util.TreeMap) UnauthenticatedRequestTokenProcessingFilter(org.springframework.security.oauth.provider.filter.UnauthenticatedRequestTokenProcessingFilter) HttpServletRequest(javax.servlet.http.HttpServletRequest) OAuthProviderToken(org.springframework.security.oauth.provider.token.OAuthProviderToken) StringWriter(java.io.StringWriter) ConsumerAuthentication(org.springframework.security.oauth.provider.ConsumerAuthentication) ConsumerDetails(org.springframework.security.oauth.provider.ConsumerDetails) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 9 with ConsumerDetails

use of org.springframework.security.oauth.provider.ConsumerDetails in project spring-security-oauth by spring-projects.

the class UnauthenticatedRequestTokenProcessingFilterTests method testCreateOAuthToken.

/**
	 * tests creating the oauth token.
	 */
@Test
public void testCreateOAuthToken() throws Exception {
    ConsumerDetails consumerDetails = mock(ConsumerDetails.class);
    ConsumerCredentials creds = new ConsumerCredentials("key", "sig", "meth", "base", "tok");
    OAuthProviderTokenServices tokenServices = mock(OAuthProviderTokenServices.class);
    OAuthAccessProviderToken token = mock(OAuthAccessProviderToken.class);
    UnauthenticatedRequestTokenProcessingFilter filter = new UnauthenticatedRequestTokenProcessingFilter();
    filter.setTokenServices(tokenServices);
    when(consumerDetails.getConsumerKey()).thenReturn("chi");
    when(consumerDetails.getAuthorities()).thenReturn(new ArrayList<GrantedAuthority>());
    when(tokenServices.createUnauthorizedRequestToken("chi", "callback")).thenReturn(token);
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put(OAuthConsumerParameter.oauth_callback.toString(), "callback");
    ConsumerAuthentication authentication = new ConsumerAuthentication(consumerDetails, creds, map);
    assertSame(token, filter.createOAuthToken(authentication));
}
Also used : UnauthenticatedRequestTokenProcessingFilter(org.springframework.security.oauth.provider.filter.UnauthenticatedRequestTokenProcessingFilter) OAuthProviderTokenServices(org.springframework.security.oauth.provider.token.OAuthProviderTokenServices) ConsumerCredentials(org.springframework.security.oauth.provider.ConsumerCredentials) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ConsumerAuthentication(org.springframework.security.oauth.provider.ConsumerAuthentication) OAuthAccessProviderToken(org.springframework.security.oauth.provider.token.OAuthAccessProviderToken) TreeMap(java.util.TreeMap) ConsumerDetails(org.springframework.security.oauth.provider.ConsumerDetails) Test(org.junit.Test)

Aggregations

ConsumerDetails (org.springframework.security.oauth.provider.ConsumerDetails)9 Test (org.junit.Test)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ConsumerAuthentication (org.springframework.security.oauth.provider.ConsumerAuthentication)5 FilterChain (javax.servlet.FilterChain)4 GrantedAuthority (org.springframework.security.core.GrantedAuthority)4 ConsumerCredentials (org.springframework.security.oauth.provider.ConsumerCredentials)4 TreeMap (java.util.TreeMap)3 InvalidOAuthParametersException (org.springframework.security.oauth.provider.InvalidOAuthParametersException)3 OAuthProviderToken (org.springframework.security.oauth.provider.token.OAuthProviderToken)3 HashMap (java.util.HashMap)2 Authentication (org.springframework.security.core.Authentication)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 UnauthenticatedRequestTokenProcessingFilter (org.springframework.security.oauth.provider.filter.UnauthenticatedRequestTokenProcessingFilter)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Map (java.util.Map)1 OAuthSignatureMethod (org.springframework.security.oauth.common.signature.OAuthSignatureMethod)1 SignatureSecret (org.springframework.security.oauth.common.signature.SignatureSecret)1