Skip to content

Commit

Permalink
Adds logout to password grant sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dutra committed Apr 15, 2016
1 parent 0987769 commit 5cc8fb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.cloudfoundry.identity.samples.password;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.core.JsonParseException;
import org.apache.commons.codec.binary.Base64;
import org.cloudfoundry.identity.samples.oauth2.composite.CompositeAccessTokenProvider;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -18,10 +16,6 @@
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.token.AccessTokenProvider;
import org.springframework.security.oauth2.client.token.AccessTokenProviderChain;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider;
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider;
import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider;
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -38,6 +32,10 @@
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

@Configuration
@EnableAutoConfiguration
Expand Down Expand Up @@ -133,4 +131,11 @@ ResourceOwnerPasswordResourceDetails passwordGrantResourceDetails() {
public OAuth2RestTemplate passwordGrantRestTemplate() {
return new OAuth2RestTemplate(passwordGrantResourceDetails());
}


@RequestMapping(value="/logout", method = GET)
public String logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
this.oAuth2RestTemplate.getOAuth2ClientContext().setAccessToken(null);
return "redirect:/password";
}
}
7 changes: 7 additions & 0 deletions password/src/main/resources/templates/password_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ <h1>Password Grant Sample</h1>
<p>This is the ID Token:</p>
<pre th:text="${id_token}"></pre>

<h2>What do you want to do?</h2>
<ul>
<li>
<a href="/logout">Log out</a>
</li>
</ul>

</body>
</html>

0 comments on commit 5cc8fb5

Please sign in to comment.