我正在使用 Spring web security,下面的代码限制了除资源和 app.html 等列出的页面之外的所有页面
如何更改此设置以允许除我特别指定的页面之外的所有页面?
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http .authorizeRequests()
.antMatchers("/resources/**", "/registration", "/app.html").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
}
}
Run Code Online (Sandbox Code Playgroud)
我从这里得到了代码:https : //spring.io/blog/2013/07/03/spring-security-java-config-preview-web-security/ 但我看不到我的问题的答案。
谢谢
如何迅速在这样的完成处理程序中引发错误:
let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: {
(data, response, error) in
do {
//something
completion(result)
} catch let jsonError {
throw CustomError.myerror //THIS DOESN'T WORK
}
})
task.resume()
Run Code Online (Sandbox Code Playgroud)
因为错误是
从类型为((_,_,_)的throwing函数将->()无效转换为非抛出函数类型为'(Data ?, URLResponse ?, Error?)-> Void'
我一直在阅读reduce,并且发现有3个参数版本,基本上可以执行map reduce,如下所示:
String[] strarr = {"abc", "defg", "vwxyz"};
System.out.println(Arrays.stream(strarr).reduce(0, (l, s) -> l + s.length(), (s1, s2) -> s1 + s2));
Run Code Online (Sandbox Code Playgroud)
但是,我看不出带有reduce的mapToInt的优势。
System.out.println(Arrays.stream(strarr).mapToInt(s -> s.length()).reduce(0, (s1, s2) -> s1 + s2));
Run Code Online (Sandbox Code Playgroud)
两者都给出正确的答案12,并且似乎并行工作良好。
一个比另一个好吗?如果是,为什么?
我正在尝试计算在“对象列表”中的字段中看到一个Int的次数。
这是我的代码
TreeMap<Integer, Double> ratings = new TreeMap();
ArrayList<Establishment> establishments = new ArrayList<>();
double one = 0;
double two = 0;
double three = 0;
double five = 0;
for (Establishment e : establishments) {
if (e.getRating() == 1) {
one++;
}
if (e.getRating() == 2) {
two++;
}
if (e.getRating() == 3) {
three++;
}
if (e.getRating() == 5) {
five++;
}
}
ratings.put(1, (one / establishments.size()) * 100);
ratings.put(2, (two / establishments.size()) * 100);
ratings.put(3, (three / establishments.size()) …Run Code Online (Sandbox Code Playgroud) 我一直在
Cross-thread operation not valid: Control 'keyholderTxt' accessed from a thread other than the thread it was created on.
Run Code Online (Sandbox Code Playgroud)
关于项目中各种表单的各种控件,我已经用Google搜索并发现很多关于如何从各种线程访问内容的响应,但据我所知,我没有在我的项目中使用任何其他线程,并且更改代码中数百个可能的位置将是无法管理的.
它从来没有发生过,只是因为我添加了似乎无关的各种代码.我提供了一个我在下面得到错误的地方样本,但它已经在解决方案的很多地方发生了.
keyholderTxt.Text = "Keyholders Currently In:\r\n \r\n Nibley 1: + keyholders";
Run Code Online (Sandbox Code Playgroud)
或者这是一个更好的例子,因为你可以看到从表单加载到错误发生的所有事情:
private void Identification_Load(object sender, System.EventArgs e)
{
_Timer.Interval = 1000;
_Timer.Tick += new EventHandler(_Timer_Tick);
_Timer.Start();
txtIdentify.Text = string.Empty;
rightIndex = null;
SendMessage(Action.SendMessage, "Place your finger on the reader.");
if (!_sender.OpenReader())
{
this.Close();
}
if (!_sender.StartCaptureAsync(this.OnCaptured))
{
this.Close();
}
}
void _Timer_Tick(object sender, EventArgs e)
{
this.theTime.Text = DateTime.Now.ToString(); …Run Code Online (Sandbox Code Playgroud) 我有这个基本的 python3 服务器,但不知道如何提供目录。
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
print(self.path)
if self.path == '/up':
self.send_response(200)
self.end_headers()
self.wfile.write(b'Going Up')
if self.path == '/down':
self.send_response(200)
self.end_headers()
self.wfile.write(B'Going Down')
httpd = socketserver.TCPServer(("", PORT), SimpleHTTPRequestHandler)
print("Server started on ", PORT)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)
如果不是上面的自定义类,我只是简单地传入Handler = http.server.SimpleHTTPRequestHandlerTCPServer():,默认功能是提供一个目录,但我想提供该目录并在上面的两个 GET 上提供功能。
例如,如果有人要访问 localhost:8080/index.html,我希望将该文件提供给他们
我正在尝试设置NavigationView. 我正在尝试ZStack使用下面的代码添加一个(部分来自 SwiftUI 教程)。然而它永远是白色的,除非我NavigationView...用Spacer()
var body: some View {
ZStack
{
NavigationView {
List {
Toggle(isOn: $userData.showFavoritesOnly) {
Text("Favourites")
}
ForEach(userData.landmarks) { landmark in
if !self.userData.showFavoritesOnly || landmark.isFavorite {
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
}
}
.navigationBarTitle(Text("Landmarks"), displayMode: .large)
}
}.background(Color.blue.edgesIgnoringSafeArea(.all))
}
Run Code Online (Sandbox Code Playgroud)
我可以设置单个列表项的颜色,但我希望整个背景显示为蓝色
我使用了故事书网站上示例中的一些代码,具体来说:
export const Primary = Primary.decorators = [(Story) => <div style={{ margin: '3em' }}><Story/></div>]
Run Code Online (Sandbox Code Playgroud)
然而,即使这是打字稿示例,它也没有指定 Story 的类型,并且除非它有类型,否则我的 linter 将不会通过。我应该为故事使用什么类型?
Story: any
Run Code Online (Sandbox Code Playgroud)
也不会通过。
参考: https: //storybook.js.org/docs/react/writing-stories/decorators
我刚开始通过Java进行android开发(我之前只使用过phonegap).
我用一个简单的表单文本字段和发送按钮创建了我的第一个hello world项目,它不会运行.
我的错误日志如下:
12-06 20:31:11.482: E/AndroidRuntime(32656): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thesurvivor2299/com.example.thesurvivor2299.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-06 20:31:11.482: E/AndroidRuntime(32656): Caused by: android.view.InflateException:
Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-06 22:32:31.304: W/ResourceType(804): Failure getting entry for 0x7f0201f2 (t=1 e=498) in package 0 (error -2147483647)
12-06 22:32:31.305: W/ResourceType(804): Failure getting entry for 0x7f0201f3 (t=1 e=499) in package 0 (error -2147483647)
12-06 22:32:31.305: W/ResourceType(804): Failure getting entry for 0x7f0201f4 (t=1 e=500) in package …Run Code Online (Sandbox Code Playgroud) 这个 HTML:
<li value="16-May-2017" data-reactid=".0.1.0.0.1.2.2.$16">16test</li>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下 React.js 代码检索 的值:
selectDate(event) {
event.preventDefault();
console.log(event.target.value);
if(this.state.whichDate == 0) {
this.state.selectedToDate = event.target.value
this.state.whichDate = 1
} else {
this.state.selectedFromDate = event.target.value
this.state.whichDate = 0
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我将“16”打印到控制台而不是“16-May-2017”。
我认为它可能会在标签之间打印文本,但它不能像我在那里进行测试一样查看......也许它在值中的连字符后没有打印任何内容?
以下SQL查询导致错误:
INSERT INTO members.signIns
(employeeid, date, timeIn, timeOut, timeIn2, timeOut2, timeIn3, timeOut3, timeIn4, timeOut4)
VALUES (1, 2012-08-10, 21-28, 21-28, 21-28, 21-28, 21-28, 21-28, 21-28, 21-28);
Run Code Online (Sandbox Code Playgroud)
错误:INSERT命令被拒绝用户'waycov_scanlock'@'66.40.52.44'表'signIns'
我的托管提供商说它与此代码有关,而不是设置问题