org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory Java Examples
The following examples show how to use
org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSecurityConfig.java From Mastering-Microservices-with-Java-Third-Edition with MIT License | 5 votes |
@Bean @Autowired public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore) { TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler(); handler.setTokenStore(tokenStore); handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService)); handler.setClientDetailsService(clientDetailsService); return handler; }
Example #2
Source File: OAuthRestController.java From spring-oauth-server with GNU General Public License v2.0 | 5 votes |
@Override public void afterPropertiesSet() throws Exception { Assert.state(clientDetailsService != null, "ClientDetailsService must be provided"); Assert.state(authenticationManager != null, "AuthenticationManager must be provided"); oAuth2RequestFactory = new DefaultOAuth2RequestFactory(clientDetailsService); }
Example #3
Source File: OpenIdOAuth2Configuration.java From cola with MIT License | 5 votes |
@Bean @ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class}) public OpenIdTokenGranter openIdTokenGranter(AuthenticationManager authenticationManager, AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService) { return new OpenIdTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService)); }
Example #4
Source File: AcOAuth2Configuration.java From cola with MIT License | 5 votes |
@Bean @ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class}) public AcTokenGranter acTokenGranter(AuthenticationManager authenticationManager, AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService) { return new AcTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService)); }
Example #5
Source File: SmsOAuth2Configuration.java From cola with MIT License | 5 votes |
@Bean @ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class}) public SmsTokenGranter smsTokenGranter(AuthenticationManager authenticationManager, AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService) { return new SmsTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService)); }
Example #6
Source File: OAuth2SecurityConfiguration.java From openapi-generator with Apache License 2.0 | 5 votes |
@Bean @Autowired public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore){ TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler(); handler.setTokenStore(tokenStore); handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService)); handler.setClientDetailsService(clientDetailsService); return handler; }
Example #7
Source File: OAuth2SecurityConfiguration.java From swagger-aem with Apache License 2.0 | 5 votes |
@Bean @Autowired public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore){ TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler(); handler.setTokenStore(tokenStore); handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService)); handler.setClientDetailsService(clientDetailsService); return handler; }
Example #8
Source File: OAuth2Configuration.java From oauth2lab with MIT License | 5 votes |
@Bean public TokenGranter tokenGranter() { DefaultOAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService()); AuthorizationCodeServices codeServices = authorizationCodeServices(); AuthorizationServerTokenServices tokenServices = tokenServices(); List<TokenGranter> tokenGranters = Arrays.asList( new AuthorizationCodeTokenGranter(tokenServices, codeServices, clientDetailsService(), requestFactory), new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService(), requestFactory), new ImplicitTokenGranter(tokenServices, clientDetailsService(), requestFactory)); return new CompositeTokenGranter(tokenGranters); }
Example #9
Source File: OAuthConfiguration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { DefaultOAuth2RequestFactory factory = new DefaultOAuth2RequestFactory(clientDetailsService); factory.setCheckUserScopes(true); endpoints .requestFactory(factory); }
Example #10
Source File: OAuth2Configuration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Bean public TokenGranter tokenGranter() { DefaultOAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService()); AuthorizationCodeServices codeServices = authorizationCodeServices(); AuthorizationServerTokenServices tokenServices = tokenServices(); List<TokenGranter> tokenGranters = Arrays.asList( new CustomAuthCodeTokenGranter(tokenServices, codeServices, clientDetailsService(), requestFactory), new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService(), requestFactory), new ImplicitTokenGranter(tokenServices, clientDetailsService(), requestFactory)); return new CompositeTokenGranter(tokenGranters); }
Example #11
Source File: LoginController.java From microservices-event-sourcing with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/login", method = RequestMethod.POST) public String login(HttpServletRequest request, HttpServletResponse response, Model model) { HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response); httpSessionSecurityContextRepository.loadContext(holder); try { // 使用提供的证书认证用户 List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"); Authentication auth = new UsernamePasswordAuthenticationToken(request.getParameter("username"), request.getParameter("password"), authorities); SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(auth)); // 认证用户 if(!auth.isAuthenticated()) throw new CredentialException("用户不能够被认证"); } catch (Exception ex) { // 用户不能够被认证,重定向回登录页 logger.info(ex); return "login"; } // 从会话得到默认保存的请求 DefaultSavedRequest defaultSavedRequest = (DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST"); // 为令牌请求生成认证参数Map Map<String, String> authParams = getAuthParameters(defaultSavedRequest); AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clientDetailsService).createAuthorizationRequest(authParams); authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN")); model.addAttribute("authorizationRequest", authRequest); httpSessionSecurityContextRepository.saveContext(SecurityContextHolder.getContext(), holder.getRequest(), holder.getResponse()); return "authorize"; }
Example #12
Source File: OAuth2SecurityConfiguration.java From swaggy-jenkins with MIT License | 5 votes |
@Bean @Autowired public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore){ TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler(); handler.setTokenStore(tokenStore); handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService)); handler.setClientDetailsService(clientDetailsService); return handler; }
Example #13
Source File: OAuth2ServerConfiguration.java From spring-oauth-server with GNU General Public License v2.0 | 4 votes |
@Bean public OAuth2RequestFactory oAuth2RequestFactory() { return new DefaultOAuth2RequestFactory(clientDetailsService); }
Example #14
Source File: OAuth2AuthorizationServerConfig.java From osiam with MIT License | 4 votes |
@Bean public OAuth2RequestFactory oAuth2RequestFactory() { return new DefaultOAuth2RequestFactory(osiamClientDetailsService); }
Example #15
Source File: LoginController.java From spring-cloud-event-sourcing-example with GNU General Public License v3.0 | 4 votes |
@RequestMapping(value = "/login", method = RequestMethod.POST) public String login(HttpServletRequest request, HttpServletResponse response, Model model) { HttpRequestResponseHolder responseHolder = new HttpRequestResponseHolder(request, response); sessionRepository.loadContext(responseHolder); try { // Authenticate the user with the supplied credentials List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"); Authentication auth = new UsernamePasswordAuthenticationToken(request.getParameter("username"), request.getParameter("password"), authorities); SecurityContextHolder.getContext() .setAuthentication(authenticationManager.authenticate(auth)); // Authenticate the user if(!authenticationManager.authenticate(auth).isAuthenticated()) throw new CredentialException("User could not be authenticated"); } catch (Exception ex) { // The user couldn't be authenticated, redirect back to login ex.printStackTrace(); return "login"; } // Get the default saved request from session DefaultSavedRequest defaultSavedRequest = ((DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST")); // Generate an authorization parameter map for the token request Map<String, String> authParams = getAuthParameters(defaultSavedRequest); // Create the authorization request and put it in the view model AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clients).createAuthorizationRequest(authParams); authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN")); sessionRepository.saveContext(SecurityContextHolder.getContext(), responseHolder.getRequest(), responseHolder.getResponse()); model.addAttribute("authorizationRequest", authRequest); // Return the token authorization view return "authorize"; }
Example #16
Source File: LoginController.java From cloud-native-microservice-strangler-example with GNU General Public License v3.0 | 4 votes |
@RequestMapping(value = "/login", method = RequestMethod.POST) public String login(HttpServletRequest request, HttpServletResponse response, Model model) { HttpRequestResponseHolder responseHolder = new HttpRequestResponseHolder(request, response); sessionRepository.loadContext(responseHolder); try { // Authenticate the user with the supplied credentials List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"); Authentication auth = new UsernamePasswordAuthenticationToken(request.getParameter("username"), request.getParameter("password"), authorities); SecurityContextHolder.getContext() .setAuthentication(authenticationManager.authenticate(auth)); // Authenticate the user if(!authenticationManager.authenticate(auth).isAuthenticated()) throw new CredentialException("User could not be authenticated"); } catch (Exception ex) { // The user couldn't be authenticated, redirect back to login ex.printStackTrace(); return "login"; } // Get the default saved request from session DefaultSavedRequest defaultSavedRequest = ((DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST")); // Generate an authorization parameter map for the token request Map<String, String> authParams = getAuthParameters(defaultSavedRequest); // Create the authorization request and put it in the view model AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clients).createAuthorizationRequest(authParams); authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN")); sessionRepository.saveContext(SecurityContextHolder.getContext(), responseHolder.getRequest(), responseHolder.getResponse()); model.addAttribute("authorizationRequest", authRequest); // Return the token authorization view return "authorize"; }
Example #17
Source File: OAuth2Config.java From spring-cloud-gray with Apache License 2.0 | 4 votes |
@Bean public OAuth2RequestFactory requestFactory(ClientDetailsService clientDetailsService) { return new DefaultOAuth2RequestFactory(clientDetailsService); }
Example #18
Source File: ApiBootAuthorizationServerConfiguration.java From api-boot with Apache License 2.0 | 4 votes |
private OAuth2RequestFactory requestFactory() { return new DefaultOAuth2RequestFactory(clientDetailsService); }
Example #19
Source File: FebsAuthorizationServerConfigure.java From FEBS-Cloud with Apache License 2.0 | 4 votes |
@Bean public DefaultOAuth2RequestFactory oAuth2RequestFactory() { return new DefaultOAuth2RequestFactory(redisClientDetailsService); }
Example #20
Source File: ApiBootAuthorizationServerConfiguration.java From beihu-boot with Apache License 2.0 | 4 votes |
private OAuth2RequestFactory requestFactory() { return new DefaultOAuth2RequestFactory(clientDetailsService); }