Spring custom centralized authorization server (oauth) - Error authenticating and customizing
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:
- What is that error and why am I seeing it?
- 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
add a comment |
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:
- What is that error and why am I seeing it?
- 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
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
add a comment |
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:
- What is that error and why am I seeing it?
- 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
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:
- What is that error and why am I seeing it?
- 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
spring spring-security spring-security-oauth2
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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