OAUTH2: решение об авторизации Страница не появляется после успешного входа в систему - PullRequest
0 голосов
/ 18 мая 2018

Я пишу OAUTH-аутентификацию на основе форм для получения кода авторизации. Предполагалось, что у него будет «Страница решения об авторизации» после того, как сервер ресурсов попросит владельца ресурса аутентифицировать себя и предоставить полномочия для обмена данными.

Ниже приведены настройки на стороне сервера

Сервер авторизации

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
     @Bean
        public BCryptPasswordEncoder passwordEncoder() {
            return new BCryptPasswordEncoder();
        }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory().withClient("javainuse").secret("{noop}secret").authorizedGrantTypes("authorization_code")
            .scopes("read").authorities("CLIENT");
    }
}

WebSecurity Configurer

@Configuration
@EnableWebSecurity
public class EmployeeSecurityConfiguration extends WebSecurityConfigurerAdapter {

     @Bean
        @Override
        public AuthenticationManager authenticationManager() throws Exception {

            return super.authenticationManager();
        }

     @Autowired
     private BCryptPasswordEncoder  passwordEncoder;



    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/user/getEmployeesList")
            .hasAnyRole("ADMIN").anyRequest().authenticated().and().formLogin()
            .permitAll().and().logout().permitAll();

        http.csrf().disable();
    }

    @Override
    public void configure(AuthenticationManagerBuilder authenticationMgr) throws Exception {
        authenticationMgr.inMemoryAuthentication().withUser("admin").password(passwordEncoder.encode("admin"))
            .authorities("ROLE_ADMIN");
    }


}

Ниже представлен клиентбоковые конфиги

Контроллер

@Controller
public class EmployeeController {

    @RequestMapping(value = "/getEmployees", method = RequestMethod.GET)
    public ModelAndView getEmployeeInfo() {
        return new ModelAndView("getEmployees");
    }

    @RequestMapping(value = "/showEmployees", method = RequestMethod.GET)
    public String getEmployeeInfo1() {
        return "showEmployees";
    }
}

getEmployees.jsp

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Employee</title>
</head>
<body>
    <h3 style="color: red;">Add New Employee</h3>

    <div id="addEmployee">
        <form:form action="http://localhost:8081/oauth/authorize"
            method="post" modelAttribute="emp">
            <p>
                <label>Enter Employee Id</label>
                 <input type="text" name="response_type" value="code" /> 
                 <input type="text" name="client_id" value="javainuse" />
                 <input type="text" name="redirect_uri" value="http://localhost:8090/showEmployees" />
                 <input type="text" name="scope" value="read" /> 
                 <input type="SUBMIT" value="Get Employee info" />
        </form:form>
    </div>
</body>
</html>

После предоставления данных для входа в систему при входе в систему

enter image description here

я предоставил детали, после того как он должен был предоставить мне подсказку на http://localhost:8081/oauth/authorize

enter image description here

этодавая мне информацию в журналах

INFO AuthorizationEndpoint : Handling OAuth2 error: error="invalid_request", error_description="At least one redirect_uri must be registered with the client."

любая помощь очень ценится, не знаю, где я делаю неправильно.Я использую Spring Boot 2.0.2.RELEASE.

Ответы [ 2 ]

0 голосов
/ 10 августа 2019

добавление URL перенаправления в ClientDetailsServiceConfigurer будет работать.

0 голосов
/ 01 ноября 2018

Значение redirect_uri http://localhost:8090/showEmployees, которое дается во входном теге, также необходимо сопоставить в приведенной выше конфигурации сервера авторизации, поэтому

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory().withClient("javainuse").secret("secret").authorizedGrantTypes("authorization_code")
        .scopes("read").authorities("CLIENT").redirectUris("http://localhost:8090/showEmployees");
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...