Spring custom centralized authorization server (oauth) - Error authenticating and customizing












0














I'm green to both spring and OAuth, which makes this an exciting problem for me to be stuck on!



From what I gather, what I need to do is create a centralized authorization server with oauth and open ID.



We have a central database of users and we want all of our applications to make a call to the authorization server, login in, automatically approve (since the only traffic should be from our servers) and redirect them based on the URI they pass.



Ideally, we would give them the authorization token and the ID token (open ID) so they have information on the user logged in.



So I am working on setting up a Spring boot application where it acts just as the authorization server. So far, I see the login page - but every single login attempt ends with the following error:



Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.


Here is what I have so far for that server:



SpringBootServletInitializer (application initializer) - com.company



@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

public static void main(String args) {
SpringApplication.run(Application.class, args);
}
}


AuthorizationServerConfigurerAdapter(auth server) - com.company.config



@Configuration
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("my_client")
.secret("my_secret")
.autoApprove(true)
.authorizedGrantTypes("authorization_code", "refresh_token", "password")
.scopes("openid")
.accessTokenValiditySeconds(600);
}
}


WebSecurityConfigurerAdapter(security) - com.company.config



@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()

.withUser("user").password("password")
.roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()

.and()

.httpBasic().disable()
.anonymous().disable()
.authorizeRequests().anyRequest().authenticated();

// disabled basic auth and configured to use dafault Spring Security form login.
}
}


So questions:




  1. What is that error and why am I seeing it?

  2. How do I customize the login page I am seeing? I'm desperately looking around in Spring documentation and I'm lost/overwhelmed. I don't have anything in the resources folder outside of the property file I have.










share|improve this question






















  • You may enable verbose logging by setting the following in application.properties to see the exact error. logging.level.org.springframework.security=DEBUG
    – Tuhin Kanti Sharma
    Nov 20 at 20:42










  • Will add - thank you!
    – StaticMaine
    Nov 20 at 20:50
















0














I'm green to both spring and OAuth, which makes this an exciting problem for me to be stuck on!



From what I gather, what I need to do is create a centralized authorization server with oauth and open ID.



We have a central database of users and we want all of our applications to make a call to the authorization server, login in, automatically approve (since the only traffic should be from our servers) and redirect them based on the URI they pass.



Ideally, we would give them the authorization token and the ID token (open ID) so they have information on the user logged in.



So I am working on setting up a Spring boot application where it acts just as the authorization server. So far, I see the login page - but every single login attempt ends with the following error:



Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.


Here is what I have so far for that server:



SpringBootServletInitializer (application initializer) - com.company



@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

public static void main(String args) {
SpringApplication.run(Application.class, args);
}
}


AuthorizationServerConfigurerAdapter(auth server) - com.company.config



@Configuration
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("my_client")
.secret("my_secret")
.autoApprove(true)
.authorizedGrantTypes("authorization_code", "refresh_token", "password")
.scopes("openid")
.accessTokenValiditySeconds(600);
}
}


WebSecurityConfigurerAdapter(security) - com.company.config



@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()

.withUser("user").password("password")
.roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()

.and()

.httpBasic().disable()
.anonymous().disable()
.authorizeRequests().anyRequest().authenticated();

// disabled basic auth and configured to use dafault Spring Security form login.
}
}


So questions:




  1. What is that error and why am I seeing it?

  2. How do I customize the login page I am seeing? I'm desperately looking around in Spring documentation and I'm lost/overwhelmed. I don't have anything in the resources folder outside of the property file I have.










share|improve this question






















  • You may enable verbose logging by setting the following in application.properties to see the exact error. logging.level.org.springframework.security=DEBUG
    – Tuhin Kanti Sharma
    Nov 20 at 20:42










  • Will add - thank you!
    – StaticMaine
    Nov 20 at 20:50














0












0








0







I'm green to both spring and OAuth, which makes this an exciting problem for me to be stuck on!



From what I gather, what I need to do is create a centralized authorization server with oauth and open ID.



We have a central database of users and we want all of our applications to make a call to the authorization server, login in, automatically approve (since the only traffic should be from our servers) and redirect them based on the URI they pass.



Ideally, we would give them the authorization token and the ID token (open ID) so they have information on the user logged in.



So I am working on setting up a Spring boot application where it acts just as the authorization server. So far, I see the login page - but every single login attempt ends with the following error:



Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.


Here is what I have so far for that server:



SpringBootServletInitializer (application initializer) - com.company



@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

public static void main(String args) {
SpringApplication.run(Application.class, args);
}
}


AuthorizationServerConfigurerAdapter(auth server) - com.company.config



@Configuration
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("my_client")
.secret("my_secret")
.autoApprove(true)
.authorizedGrantTypes("authorization_code", "refresh_token", "password")
.scopes("openid")
.accessTokenValiditySeconds(600);
}
}


WebSecurityConfigurerAdapter(security) - com.company.config



@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()

.withUser("user").password("password")
.roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()

.and()

.httpBasic().disable()
.anonymous().disable()
.authorizeRequests().anyRequest().authenticated();

// disabled basic auth and configured to use dafault Spring Security form login.
}
}


So questions:




  1. What is that error and why am I seeing it?

  2. How do I customize the login page I am seeing? I'm desperately looking around in Spring documentation and I'm lost/overwhelmed. I don't have anything in the resources folder outside of the property file I have.










share|improve this question













I'm green to both spring and OAuth, which makes this an exciting problem for me to be stuck on!



From what I gather, what I need to do is create a centralized authorization server with oauth and open ID.



We have a central database of users and we want all of our applications to make a call to the authorization server, login in, automatically approve (since the only traffic should be from our servers) and redirect them based on the URI they pass.



Ideally, we would give them the authorization token and the ID token (open ID) so they have information on the user logged in.



So I am working on setting up a Spring boot application where it acts just as the authorization server. So far, I see the login page - but every single login attempt ends with the following error:



Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.


Here is what I have so far for that server:



SpringBootServletInitializer (application initializer) - com.company



@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

public static void main(String args) {
SpringApplication.run(Application.class, args);
}
}


AuthorizationServerConfigurerAdapter(auth server) - com.company.config



@Configuration
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("my_client")
.secret("my_secret")
.autoApprove(true)
.authorizedGrantTypes("authorization_code", "refresh_token", "password")
.scopes("openid")
.accessTokenValiditySeconds(600);
}
}


WebSecurityConfigurerAdapter(security) - com.company.config



@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()

.withUser("user").password("password")
.roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()

.and()

.httpBasic().disable()
.anonymous().disable()
.authorizeRequests().anyRequest().authenticated();

// disabled basic auth and configured to use dafault Spring Security form login.
}
}


So questions:




  1. What is that error and why am I seeing it?

  2. How do I customize the login page I am seeing? I'm desperately looking around in Spring documentation and I'm lost/overwhelmed. I don't have anything in the resources folder outside of the property file I have.







spring spring-security spring-security-oauth2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 20:07









StaticMaine

175




175












  • You may enable verbose logging by setting the following in application.properties to see the exact error. logging.level.org.springframework.security=DEBUG
    – Tuhin Kanti Sharma
    Nov 20 at 20:42










  • Will add - thank you!
    – StaticMaine
    Nov 20 at 20:50


















  • You may enable verbose logging by setting the following in application.properties to see the exact error. logging.level.org.springframework.security=DEBUG
    – Tuhin Kanti Sharma
    Nov 20 at 20:42










  • Will add - thank you!
    – StaticMaine
    Nov 20 at 20:50
















You may enable verbose logging by setting the following in application.properties to see the exact error. logging.level.org.springframework.security=DEBUG
– Tuhin Kanti Sharma
Nov 20 at 20:42




You may enable verbose logging by setting the following in application.properties to see the exact error. logging.level.org.springframework.security=DEBUG
– Tuhin Kanti Sharma
Nov 20 at 20:42












Will add - thank you!
– StaticMaine
Nov 20 at 20:50




Will add - thank you!
– StaticMaine
Nov 20 at 20:50












1 Answer
1






active

oldest

votes


















1














the error it's from spring being enable to map to an error page, that's because there is an Exception.



you can specify your own login page as follow:



       .formLogin()
.loginPage("/login.html") //your custom login page
.defaultSuccessUrl("/homepage.html", true) //welcome page after login success
.failureUrl("/login.html?error=true") // when AccessDenied happens





share|improve this answer





















  • So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
    – StaticMaine
    Nov 20 at 21:09










  • Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
    – StaticMaine
    Nov 21 at 18:40











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400762%2fspring-custom-centralized-authorization-server-oauth-error-authenticating-an%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














the error it's from spring being enable to map to an error page, that's because there is an Exception.



you can specify your own login page as follow:



       .formLogin()
.loginPage("/login.html") //your custom login page
.defaultSuccessUrl("/homepage.html", true) //welcome page after login success
.failureUrl("/login.html?error=true") // when AccessDenied happens





share|improve this answer





















  • So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
    – StaticMaine
    Nov 20 at 21:09










  • Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
    – StaticMaine
    Nov 21 at 18:40
















1














the error it's from spring being enable to map to an error page, that's because there is an Exception.



you can specify your own login page as follow:



       .formLogin()
.loginPage("/login.html") //your custom login page
.defaultSuccessUrl("/homepage.html", true) //welcome page after login success
.failureUrl("/login.html?error=true") // when AccessDenied happens





share|improve this answer





















  • So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
    – StaticMaine
    Nov 20 at 21:09










  • Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
    – StaticMaine
    Nov 21 at 18:40














1












1








1






the error it's from spring being enable to map to an error page, that's because there is an Exception.



you can specify your own login page as follow:



       .formLogin()
.loginPage("/login.html") //your custom login page
.defaultSuccessUrl("/homepage.html", true) //welcome page after login success
.failureUrl("/login.html?error=true") // when AccessDenied happens





share|improve this answer












the error it's from spring being enable to map to an error page, that's because there is an Exception.



you can specify your own login page as follow:



       .formLogin()
.loginPage("/login.html") //your custom login page
.defaultSuccessUrl("/homepage.html", true) //welcome page after login success
.failureUrl("/login.html?error=true") // when AccessDenied happens






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 20:50









slimane

60914




60914












  • So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
    – StaticMaine
    Nov 20 at 21:09










  • Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
    – StaticMaine
    Nov 21 at 18:40


















  • So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
    – StaticMaine
    Nov 20 at 21:09










  • Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
    – StaticMaine
    Nov 21 at 18:40
















So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
– StaticMaine
Nov 20 at 21:09




So question about oauth and the flow with Spring. Ideally, I want the success URL to be whatever the redirect URI is. How do I pass that and configure that in my formLogin Spring configuration? Thank you for help - I see how this makes sense and am trying it now
– StaticMaine
Nov 20 at 21:09












Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
– StaticMaine
Nov 21 at 18:40




Modified that a tiny bit by adding a request path to /login in a controller I added, added the login page to the resources and all set. Thank you!
– StaticMaine
Nov 21 at 18:40


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400762%2fspring-custom-centralized-authorization-server-oauth-error-authenticating-an%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'