我有以下场景.我正在使用JPA,Spring:
@Autowired
SampleService service;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void PerformLogic(LogicData data) throws SIASFaultMessage
{
SampleObject so = createSampleObject();
try{
.//do some logic to persist things in data
.
.
persistData(data);
.
.
.
updateSampleObject(so);
}
catch(Exception){
updateSampleObject(so);
throw new SIASFaultMessage();
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public createSampleObject()
{
SampleObject so = new SampleObject();
.
.//initialize so
.
service.persist(so);
return so;
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public updateSampleObject(SampleObject so)
{
service.persist(so);
return so;
}
Run Code Online (Sandbox Code Playgroud)
当一切正常时,数据会毫无问题地保存在数据库中.但是,当抛出异常时,我需要方法updateSampleObject(so)将信息保存在数据库中.这不是正在发生的事情.如果抛出异常,方法updateSampleObject也会回滚,这不是我需要的.我需要这两个方法( …
我目前正在使用这个例子
在Azure AD中使用OAuth检查客户端凭据流.从理论上讲,这个例子可行.客户端应用程序成功与服务器App通信,首先从Azure AD令牌URL获取OAuth令牌.没有问题.但是,我正在尝试使用Postman检查客户端凭据流,但我无法使其工作.
在邮递员中,我应该提供访问令牌URL,客户端ID和客户端密钥,授权类型设置为客户端凭据.使用与https://github.com/Azure-Samples/active-directory-dotnet-daemon中的Microsoft示例提供的示例中相同的参数,在尝试访问Web服务时收到401响应.我认为主要原因是因为在邮递员中,我无法输入我想要访问的资源,因此收到的令牌不会"链接"到任何资源,这就是为什么授权在Web服务器中失败的原因?这可能是原因吗?如果这是原因,那么我应该在服务器中做什么,因为,不知何故,似乎Postman的要求应该是客户端凭据流中的有效要求(我的意思是,根据OAuth2客户端凭据,不应该给出任何资源)流,对吗?
这是从Microsoft示例下载的示例中的Starup类的代码
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"]
});
}
Run Code Online (Sandbox Code Playgroud)
ConfigurationManager.AppSettings ["ida:Tenant"]是我的Azure AD帐户,而 ConfigurationManager.AppSettings ["ida:Audience"]是我需要访问的受保护资源.这两个值都是必需的.如果我没有提供受众,我在.net web api初始化中收到错误.
.net authentication oauth-2.0 asp.net-web-api azure-active-directory
我有一个同时生成JSON和XML响应的ASP.NET Core Service。但是,我只想限制一个动作接受的媒体类型,因此Swagger只能将application / json列为有效的响应内容类型。如何在ASP.Net Core中实现此目标?
请考虑我正在使用ASP.Net Core(ASP.NET MVC 6),而不是ASP.NET WebAPI。
更新
好的,所以我将答案添加为同一问题的一部分。感谢@Helen,我能够在ASP.Net Core(ASP.Net MVC 6)中添加所需的类来实现此目的。答案基于此答案,但已修改为使用ASP.NET Core类。
步骤1.创建一个自定义操作过滤器属性,以便管道对禁止的内容类型做出反应:
/// <summary>
/// SwaggerResponseContentTypeAttribute
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class SwaggerResponseContentTypeAttribute : ActionFilterAttribute
{
/// <summary>
/// SwaggerResponseContentTypeAttribute
/// </summary>
/// <param name="responseType"></param>
public SwaggerResponseContentTypeAttribute(string responseType)
{
ResponseType = responseType;
}
/// <summary>
/// Response Content Type
/// </summary>
public string ResponseType { get; private set; }
/// <summary>
/// Remove all other Response Content Types
/// …
Run Code Online (Sandbox Code Playgroud) 我有一个本地 git 仓库,我需要更新它。然而,在线回购远远领先于我的本地副本。我的连接速度非常慢。当我使用git pull -v --progress 时,我开始看到进度,但过了一会儿,我收到了这个错误:
efrror: RPC failed: result = 18, HTTP code = 200 | 5.00 KiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Run Code Online (Sandbox Code Playgroud)
这是由于我的连接速度很慢。我需要知道是否有办法获得,比如在我的本地仓库之前的第一次提交,看看我是否可以一次更新我的本地仓库。
重要提示:我想知道是否有办法在我的本地副本之前提取 # 次提交,而不是特定的提交。
发布请求后,API 将响应正文作为字符串返回
响应体看起来像
{ UniqueID = 93243434,birthGender = M,birthDate = 11/1/2018 5:51:18 PM,familyNames = James,givenNames = Test }
当我尝试使用以下代码设置环境变量时
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("currentUniqueId", data.UniqueId);
Run Code Online (Sandbox Code Playgroud)
我在测试结果中收到以下错误
错误消息:评估测试脚本时出错:JSONError: Unexpected token 'U' at 1:3 { UniqueID = 93243434,birthGender = M,birthDate = 11/1/2018 5:51:18 PM, family ^
我的目标是我需要提取值 93243434 并分配给环境变量。
我有一个类结构,我需要一个BaseModel
和很多ChildModels
. 像这样的东西
// BaseModel type
import { Injectable } from '@angular/core';
@Injectable()
export class BaseModel {
constructor() {
}
public _instanceUrl(): string {
return '';
};
public url(): string {
return 'BASE_URL_' + this._instanceUrl();
};
}
Run Code Online (Sandbox Code Playgroud)
// ChildModel type
import { BaseModel } from './base-model';
import { Injectable } from '@angular/core';
@Injectable()
export class ChildModel extends BaseModel {
constructor() {
super();
}
public _instanceUrl(): string {
return "CHILD_URL";
}
}
Run Code Online (Sandbox Code Playgroud)
// BaseService type
import { Injectable} …
Run Code Online (Sandbox Code Playgroud) 我很难告诉Visual Studio Online忽略某些我不想在VSO构建过程中运行的测试。我的测试库中有一组测试,我不希望它们在在线构建过程中运行。这些测试可能要花费极长的时间才能完成,因此我不希望它们成为将在构建阶段执行的测试的一部分,因此,构建代理会花费尽可能少的时间来完成构建。因此,我可以用NUnit类别标记这些测试
/// <summary>
/// This is a long running test
/// </summary>
[Test]
[Category("LongRunningTest")]
public void ObtainsTourInformationTest() {
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试任务定义的部分记录。我读过某个地方可以为此目的使用“ 测试”过滤条件,但是我还没有弄清楚。
我正在使用以下NUnit软件包
<package id="NUnit.Runners" version="2.6.4" />
<package id="NUnit" version="2.6.4"/>
<package id="NUnitTestAdapter" version="2.0.0" />
Run Code Online (Sandbox Code Playgroud)
因此,基本上,我需要知道的是如何致电Visual Studio在线测试任务以忽略标有NUnit类别属性的测试。
我正在寻找帮助,找到一个RegEx,要求正好9个数字,但连续阻止任何超过4个重复的数字.如果输入多于或少于9个字符,则应该失败.
例子是:
我试过以下没有运气:
/^(?!.*(\d)\1{5})(\d{9})*$/
Run Code Online (Sandbox Code Playgroud) 我在Spring中托管了Apache CXF服务.我正在使用WSS4J拦截器来验证用户名/密码安全性以访问服务器.验证工作正常,如果我从SoapUI发送错误的凭据我不能按预期使用该服务.如果我发送正确的凭据,服务没有问题.这是我在spring上下文文件中的配置.
<bean id="myPasswordCallback" class="cu.datys.sias.custom.ServerPasswordCallback"/>
<jaxws:endpoint id="siasEndpoint"
implementor="#siasImpl"
address="/sias">
<jaxws:features>
<!-- Soporte WS-Addressing -->
<!--<wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing" addressingRequired="true" usingAddressingAdvisory="true" allowDuplicates="true"/>-->
</jaxws:features>
<jaxws:inInterceptors>
<bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordText" />
<entry key="passwordCallbackRef"
value-ref="myPasswordCallback" />
</map>
</constructor-arg>
</bean>
</jaxws:inInterceptors>
</jaxws:endpoint>
Run Code Online (Sandbox Code Playgroud)
现在我需要能够在我的服务方法中访问我的经过身份验证的用户,如下所示:
@WebResult(name = "UpdatePatternResponse", targetNamespace = "http://test.com/schemas/xsd/myservice/", partName = "UpdatePatternResponse")
@WebMethod(operationName = "UpdatePattern", action = "UpdatePattern")
@Generated(value = "org.apache.cxf.tools.wsdlto.WSDLToJava", date = "2015-02-19T12:49:59.491-05:00")
public test.com.schemas.xsd.myservice.UpdatePatternResponse updatePattern(
@WebParam(partName = "UpdatePatternRequest", name = "UpdatePatternRequest", targetNamespace = "http://test.com/schemas/xsd/myservice/")
test.com.schemas.xsd.myservice.UpdatePatternRequest updatePatternRequest
) throws …
Run Code Online (Sandbox Code Playgroud) 我在 ASP .NET Core 2.1 应用程序中注销(注销)时收到以下错误
没有为“联合”方案注册注销身份验证处理程序。注册的注销方案有:WsFederation、Cookies。您是否忘记调用 AddAuthentication().AddCookies("Federation",...)
这是我的 Startup.cs 中的代码片段
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme =
CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultSignInScheme =
CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme =
WsFederationDefaults.AuthenticationScheme;
})
.AddWsFederation(options =>
{
options.Wtrealm = this._wtrealm;
options.MetadataAddress = this._metadataAddress;
})
.AddCookie();
}
Run Code Online (Sandbox Code Playgroud)
这是 SignOut 方法的代码
public IActionResult SignOut()
{
foreach (var key in this.HttpContext.Request.Cookies.Keys)
{
this.HttpContext.Response.Cookies.Delete(key);
// this.HttpContext.Response.Cookies.Append(key,
// string.Empty,
// new CookieOptions() {
// Expires = DateTime.Now.AddDays(-1)
// });
}
return this.SignOut(
new Microsoft.AspNetCore.Authentication.AuthenticationProperties
{
RedirectUri = this.GetReturnUrl()
},
CookieAuthenticationDefaults.AuthenticationScheme, …
Run Code Online (Sandbox Code Playgroud) .net ×2
asp.net-core ×2
c# ×2
java ×2
spring ×2
angular ×1
asp.net ×1
azure-devops ×1
bitbucket ×1
cxf ×1
fast-forward ×1
git ×1
hibernate ×1
javascript ×1
jpa ×1
media-type ×1
nunit ×1
oauth-2.0 ×1
postman ×1
pull ×1
regex ×1
swagger-ui ×1
tfsbuild ×1
transactions ×1
typescript ×1
unit-testing ×1
web-services ×1