小编mas*_*asa的帖子

如何配置Spring Security以发送'X-CSRF-TOKEN'?

问题是让CSRF令牌在Spring Security和Angular之间运行.

用于Angular的Spring Security CSRF令牌拦截器似乎应该可以完成这项工作,但是来自服务器的HEAD响应中没有"X-CSRF-TOKEN".

我目前很小的实现在GitHub(Tag v.1.0)中可用,如果知道该主题的人能快速查看代码,我会非常感激,问题应该很容易发现.

根据文档,我的印象是CSRF应该已经自动启用,但似乎并非如此.

我正在使用Spring Boot并且更喜欢基于注释的配置而不是XML,如果需要以不同方式配置某些内容.

使Spring Security能够对抗Angular的任何其他方法?

spring csrf spring-security angularjs spring-boot

11
推荐指数
1
解决办法
2万
查看次数

通过Java配置禁用Spring Security?

我有一个Java应用程序,通过Java配置使用Spring Security.

在编译中打开/关闭整个Spring Security的最简单方法是什么?

因此,像这样的,但对于不使用XML的配置.

编辑:

应用@Profile后,我的代码如下:

@Configuration
@Profile("SecurityOn")
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
Run Code Online (Sandbox Code Playgroud)

问题是如果未激活配置文件"SecurityOn",Spring Security将使用某些默认配置.相反,在这种情况下如何完全关闭Spring Security?

java spring spring-security

5
推荐指数
2
解决办法
4138
查看次数

Git pull 在工作树上失败:不是 git 存储库(或任何父目录)

有一个 Git 存储库proj.git,克隆到proj1proj2proj1没有工作树,proj2有工作树。

目标:更新a.txtproj1将更改更新到 中的工作树proj2

问题:git pull失败proj2并显示错误消息:

fatal: Not a git repository (or any of the parent directories): .git
Run Code Online (Sandbox Code Playgroud)

重现问题:

创建proj.gitproj1

$ git init --bare proj.git
$ git clone proj.git proj1
$ cd proj1
- edit a.txt: v1
$ git add .
$ git commit -m "v1"
$ git push -u origin master
Run Code Online (Sandbox Code Playgroud)

使用工作树创建proj2: …

git

5
推荐指数
1
解决办法
6404
查看次数

Querydsl/MySQL上的Count(*)(星号)?

最初的功能MySQL查询,列出所有列出标签的所有提供商:

SELECT * FROM provider
  INNER JOIN provider_tag
  ON provider_tag.provider_id = provider.id AND provider_tag.tag_id in (1, 2)
  GROUP BY (provider.id)
  HAVING COUNT(*) = 2
Run Code Online (Sandbox Code Playgroud)

在Querydsl中转换为MySQLQuery非常简单......

MySQLQuery query = new MySQLQuery(conn, dialect);

List<Integer> tagIds = ...;

query.from(provider)
    .innerJoin(provider_tag)
    .on(providerTag.providerId.eq(provider.id), providerTag.tagId.in(tagIds))
    .groupBy(provider.id)
    .having(???);
Run Code Online (Sandbox Code Playgroud)

......除了条件having.

如何添加COUNT(*)到查询?

在蒂莫的第一次修正提案后编辑:

所以,查询看起来像这样:

SearchResults<Tuple> result = query.from(provider)
    .innerJoin(providerTag)
    .on(providerTag.providerId.eq(provider.id), providerTag.tagId.in(tagIds))
    .groupBy(provider.id)
    .having(Wildcard.count.eq((long) tagIds.size()))
    .listResults(
        provider.id,
        provider.name);
Run Code Online (Sandbox Code Playgroud)

但是,Illegal operation on empty result set如果结果集为空,则会导致SQLException .

我的其他返回空结果集的查询不会导致异常,所以我想我不应该捕获异常,但是有一个问题需要修复?

生成的MySQL工作正常(返回0行),所以问题不存在.

编辑2:

问题在于groupBy().如果应用问题中 …

java mysql querydsl

3
推荐指数
1
解决办法
1340
查看次数

如何在Visual Studio中调试时查看ViewBag内容?

一个非常基本的问题:在 Visual Studio 中调试 ASP.NET MVC 控制器时如何轻松查看 ViewBag 的内容?

作为解决方法,我使用临时变量:

string tmp = ViewBag.MyData;

所以,问题是ViewBag.MyData直接观看很难,tmp也很容易。

c# asp.net-mvc visual-studio razor

2
推荐指数
1
解决办法
6979
查看次数

如何通过 .net 上的多重身份验证使 OAuth2 适用于 Azure Active Directory?

我们在 Azure Active Directory 上使用OAuth 2.0 身份验证代码授权来对我们的 Web 应用程序中的用户进行身份验证。

这没有问题,但现在 AD 维护人员想要部署多因素身份验证。我们当前的 OAuth 实现与此不符。

这是我们的代码:

public static ActionResult LogOn()
{
    string authorizationUrl = string.Format(
        "https://login.windows.net/{0}/oauth2/authorize?api-version=1.0&response_type=code&response_mode=query&client_id={1}&scope={2}&redirect_uri={3}",
        HttpUtility.UrlEncode(azureActiveDirectoryTenant),
        HttpUtility.UrlEncode(azureActiveDirectoryClientId),
        HttpUtility.UrlEncode("https://graph.microsoft.com/v1.0/me/"),
        HttpUtility.UrlEncode(azureActiveDirectoryCodeRedirectURL) // refers to Code() below
    );

    return new RedirectResult(authorizationUrl, false);
}

public async Task<ActionResult> Code(string code = null, string state = "", string error = null, string error_description = null)
{
    if (String.IsNullOrEmpty(error))
    {
        if (String.IsNullOrWhiteSpace(code))
        {
            return LogOn();
        }
        AuthenticationContext ctx = new AuthenticationContext("https://login.microsoftonline.com/" + azureActiveDirectoryTenant);
        ClientCredential clcred …
Run Code Online (Sandbox Code Playgroud)

.net oauth oauth-2.0 azure-active-directory

2
推荐指数
1
解决办法
2036
查看次数