我正在尝试将 spring oauth2(基于 Java 的配置而不是引导)与 angular 6 集成,
我的 WebSecurityConfigurerAdapter.java 文件是:
package com.novowash.authentication;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.approval.ApprovalStore;
import org.springframework.security.oauth2.provider.approval.TokenApprovalStore;
import org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
NovoAuthenticationProvider novoAuthenticationProvider;
@Autowired
UserDetailsServiceImpl userDetailsServiceImpl;
@Autowired
private PasswordEncoder userPasswordEncoder;
@Autowired
@Qualifier("dataSource") …Run Code Online (Sandbox Code Playgroud) 我已经解决了hackerrank Sock Merchant问题但是我想降低代码的复杂性(我不确定这是否可能)。
约翰在一家服装店工作。他有一大堆袜子,必须按颜色搭配出售。给定一个代表每只袜子颜色的整数数组,确定有多少双袜子颜色匹配。
例如,有n=7 只袜子的颜色为ar= [1,2,1,2,1,3,2]。有一对颜色 1和一对颜色2。剩下三只奇怪的袜子,每种颜色一只。对数为 2。
功能说明
在下面的编辑器中完成 sockMerchant 功能。它必须返回一个整数,表示可用的匹配袜子对的数量。
sockMerchant 具有以下参数:
n:堆中袜子的数量
ar:每只袜子的颜色
输入格式
第一行包含一个整数n,表示在ar 中的袜子数量。第二行包含n 个以空格分隔的整数,用于描述堆中袜子的颜色ar[i]。
约束
1 <= n <= 100
1 <= ar[i] <= 100 其中 0 <= i < n
输出格式
返回 John 可以出售的匹配袜子的总数。
样本输入
9
10 20 20 10 10 30 50 10 20
Run Code Online (Sandbox Code Playgroud)
样本输出
3
Run Code Online (Sandbox Code Playgroud)
我的解决方案:
package com.hackerrank.test;
public class Solution {
public …Run Code Online (Sandbox Code Playgroud)