Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samples do not function for multiple reasons #410

Closed
stewartadam opened this issue Apr 3, 2018 · 10 comments
Closed

Samples do not function for multiple reasons #410

stewartadam opened this issue Apr 3, 2018 · 10 comments
Assignees

Comments

@stewartadam
Copy link

  1. Version is required on Maven <dependency> snippets

  2. @EnableOAuth2Sso is missing (now requires new Maven dependency):

    			<groupId>org.springframework.security.oauth.boot</groupId>
    			<artifactId>spring-security-oauth2-autoconfigure</artifactId>
    			<version>2.0.0.RELEASE</version>
    		</dependency>
    
  3. Attempting to access a protected URL results in exception org.springframework.security.oauth2.client.resource.UserRedirectRequiredException: A redirect is required to get the users approval

    Debugging info:

    ...
    2018-04-03 12:16:05.274  INFO 41754 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@1706a5c9, org.springframework.security.web.context.SecurityContextPersistenceFilter@31da3d60, org.springframework.security.web.header.HeaderWriterFilter@468be356, org.springframework.security.web.csrf.CsrfFilter@6a0cbc6f, org.springframework.security.web.authentication.logout.LogoutFilter@4b869331, org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter@64412d34, com.microsoft.azure.spring.autoconfigure.aad.AADAuthenticationFilter@221ca7c, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@65ec8b24, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5e8c34a0, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@4d178d55, org.springframework.security.web.session.SessionManagementFilter@4df39a88, org.springframework.security.web.access.ExceptionTranslationFilter@58e85c6f, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@35178483]
    ...
    org.springframework.security.oauth2.client.resource.UserRedirectRequiredException: A redirect is required to get the users approval
    	at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.getRedirectForAuthorization(AuthorizationCodeAccessTokenProvider.java:359) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
    	at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.obtainAccessToken(AuthorizationCodeAccessTokenProvider.java:205) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
    	at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
    	at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
    	at org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter.attemptAuthentication(OAuth2ClientAuthenticationProcessingFilter.java:105) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-5.0.3.RELEASE.jar:5.0.3.RELEASE]
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.0.3.RELEASE.jar:5.0.3.RELEASE]
    	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-5.0.3.RELEASE.jar:5.0.3.RELEASE]
    ...
    

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@bill-blackmon
Copy link

This example is broken. Please see item #3 and post solution. stewartadams hints, while useful, do not solve the problem. Nor do the 'See also:' items above. These issues have been opened for an entire month with no resolution. You need to keep up!

@tschn
Copy link

tschn commented May 15, 2018

any idea on when this example will be fixed?

@rmcmurray
Copy link
Contributor

@tschn - we are working on that article now; we should have an update soon.

@stewartadam
Copy link
Author

stewartadam commented May 15, 2018

FWIW, if you're looking for something that works with Spring 5, I published my own sample here:
https://github.com/stewartadam/azuread-springsecurity5-oauth2-kickstart

It uses the built-in OAuth 2 support for Spring Security for Spring 5 instead of the add-on spring-security-oauth2 package, which is no longer compatible with Spring 5.

@jason279
Copy link

@brunoborges any updating for the issue? Still get the "A redirect is required to get the users approval" exception. Is there anyone can help to fix it?
Thanks!!

@rmcmurray
Copy link
Contributor

@jason279 - I am experiencing the same issue that you are seeing, and we are currently looking into that.

However, for now you can use the example azure-active-directory-spring-boot-sample application as a starting point for building an application; that sample has been tested and it works as expected.

@jason279
Copy link

OK. Thanks @rmcmurray .

@rmcmurray
Copy link
Contributor

@stewartadam, @jason279, and @tschn - we've made changes the the Spring starter which resolve the issues that you were seeing, and we've updated the article accordingly:

https://docs.microsoft.com/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory

Thanks!

@GauravWable
Copy link

GauravWable commented Jul 2, 2018

Error in import (HelloController.java):
The import org.springframework.security.access.prepost.PreAuthorize cannot be resolved

@PreAuthorize cannot be resolved to a type

And
(WebSecurityConfig.java)
The type org.springframework.security.authentication.AuthenticationManager cannot be resolved. It is indirectly referenced from required .class files

These .class files are present under dependencies but there are errors in import.
Maven Dependencies > spring-security-core-5.0.6.RELEASE.jar

Please help to resolve these errors. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants