好吧标题说明了一切.有谁知道代码190,子代码490的含义是什么?(错误验证访问令牌:用户参加了一个阻塞,登录检查点)它不会出现在 官方Facebook开发人员的错误代码文档,而不是对非官方的wiki页面我的SO挖出.
有问题的令牌用于管理用户的粉丝页面(发布内容,更改标题图片等).对于大多数用户而言,这种错误不会发生,但对于某些用户而言,它将显示不知道差异可能在哪里.
导致错误的请求是POST pageId/feed.
我们正在使用Graph API 2.0版
如何在纯资源服务器上获取我的自定义ResponseEntityExceptionHandler或OAuth2ExceptionRenderer处理Spring安全性引发的异常?
我们实施了一个
@ControllerAdvice
@RestController
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Run Code Online (Sandbox Code Playgroud)
因此,只要资源服务器上出现错误,我们就希望它能够回答
{
"message": "...",
"type": "...",
"status": 400
}
Run Code Online (Sandbox Code Playgroud)
资源服务器使用application.properties设置:
security.oauth2.resource.userInfoUri: http://localhost:9999/auth/user
Run Code Online (Sandbox Code Playgroud)
对我们的auth服务器进行身份验证和授权请求.
但是,任何弹簧安全性错误都将始终绕过我们的异常处理程
@ExceptionHandler(InvalidTokenException.class)
public ResponseEntity<Map<String, Object>> handleInvalidTokenException(InvalidTokenException e) {
return createErrorResponseAndLog(e, 401);
}
Run Code Online (Sandbox Code Playgroud)
并生产
{
"timestamp": "2016-12-14T10:40:34.122Z",
"status": 403,
"error": "Forbidden",
"message": "Access Denied",
"path": "/api/templates/585004226f793042a094d3a9/schema"
}
Run Code Online (Sandbox Code Playgroud)
要么
{
"error": "invalid_token",
"error_description": "5d7e4ab5-4a88-4571-b4a4-042bce0a076b"
}
Run Code Online (Sandbox Code Playgroud)
那么如何配置资源服务器的安全性异常处理呢?我找到的只是如何通过实现自定义来自定义Auth服务器的示例OAuth2ExceptionRenderer.但我无法找到将其连接到资源服务器的安全链的位置.
我们唯一的配置/设置是这样的:
@SpringBootApplication
@Configuration
@ComponentScan(basePackages = {"our.packages"})
@EnableAutoConfiguration
@EnableResourceServer
Run Code Online (Sandbox Code Playgroud) 我正在尝试理解并实现我们的新REST服务器和现有客户端应用程序之间的客户端凭据流.我已经像这样设置了spring-security OAuth2 .根据我的理解,到目前为止,我的服务器现在应该支持以下请求:
$ curl -X -v -d 'client_id=the_client&client_secret=secret&grant_type=client_credentials' -X POST "http://localhost:9090/oauth/token"
Run Code Online (Sandbox Code Playgroud)
但我明白了
InsufficientAuthenticationException: There is no client authentication
Run Code Online (Sandbox Code Playgroud)
由引起的Principal是null这里(弹簧安全码):
@FrameworkEndpoint
@RequestMapping(value = "/oauth/token")
public class TokenEndpoint extends AbstractEndpoint {
@RequestMapping
public ResponseEntity<OAuth2AccessToken> getAccessToken(Principal principal,
@RequestParam("grant_type") String grantType, @RequestParam Map<String, String> parameters) {
if (!(principal instanceof Authentication)) {
throw new InsufficientAuthenticationException(
Run Code Online (Sandbox Code Playgroud)
所以看来,我需要先对服务器进行身份验证.但这不是我想要做的.我希望我的两台服务器使用共享密钥互相通信.OAuth提供程序服务器应根据请求向(受信任)客户端服务器提供访问令牌,以便客户端服务器可以使用该令牌访问服务器上的所有REST资源.这应该保护REST资源免受外部访问.
后来我想向第三方提供所选资源,并最终为服务器到服务器通信实现一些更细粒度的安全性.但是现在我需要保护REST服务器免受外部访问.
看起来我可能对整个客户端凭证流程或弹簧安全的应用有一些误解,因此任何澄清将非常感激.
我们使用Spring Security OAuth2保护我们的REST服务(用于服务器到服务器的通信,无需用户参与).但是,当尝试在浏览器中访问受保护资源时,它将显示:
<oauth>
<error_description>
An Authentication object was not found in the SecurityContext
</error_description>
<error>unauthorized</error>
</oauth>
Run Code Online (Sandbox Code Playgroud)
我们希望这是我们自己选择的自定义页面.有办法吗?
设置访问被拒绝页面将不起作用.首先,它需要定义我们没有的登录页面,因为这是一个纯粹的服务器到服务器通信.对于另一个,这个属性据说自从Spring 3.0以后就被弃用了.
无论如何..调试我的方式进入OAuth错误处理.并且发现响应似乎以某种方式通过我在错误页面上看到的信息得到了丰富.显然根本没有完成页面渲染,所以看起来没有要替换的错误页面..?!
至少我们想要隐藏我们使用OAuth的事实,如果我们不能拥有一个"真正的"页面,只显示一个基本的"拒绝"文本.所以也许我将不得不扩展spring安全处理程序或添加一个自定义过滤器修改响应?!
也许重定向到我们的错误页面?
谢谢!
编辑
我有一个包含UTF-8字符的.java文件.所以我告诉eclipse对其.java文件使用UTF-8编码.当试图通过Jenkins构建它时,它失败了
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
.../... unmappable character for encoding ASCII
Run Code Online (Sandbox Code Playgroud)
浏览到我的svn存储库时,我注意到特殊字符是使用奇怪的符号编码的.有没有办法将这些字符正确地存入我的存储库?我是否必须告诉我的svn存储库以某种方式使用UTF-8.或者我的subclipse插件..?
编辑
更新了我的问题,以帮助其他人找到问题.
我们有一个基于Oauth2的REST服务器(资源+授权),由spring-security + spring web + jersey为我们的REST资源.其中大部分工作都很顺利,但是当在带有错误凭据的用户名密码流中命中/ oauth/token时,我们不仅会获得400(因为规范是正确的),而是在响应中将整个堆栈跟踪作为JSON .我已经搜索和调试并摸索了,但无法找到罪魁祸首.这可能是一个弹簧安全设置吗?还是弹簧网?或者使用泽西匹配资源的servlet?
响应示例(缩写):
$ curl -X POST -v --data "grant_type=password&username=admin&password=wrong_password&client_id=my_client" http://localhost:9090/oauth/token
* ...
* Connected to localhost (::1) port 9090 (#0)
* ...
> POST /oauth/token HTTP/1.1
> ...
> Accept: */*
> ...
> Content-Type: application/x-www-form-urlencoded
>
* ...
< HTTP/1.1 400 Bad Request
< ...
< Content-Type: application/json;charset=UTF-8
< ...
<
* ...
curl: (56) Recv failure: Connection reset by peer
{
"cause": null,
"stackTrace": [{
"methodName": "getOAuth2Authentication",
"fileName": "ResourceOwnerPasswordTokenGranter.java",
"lineNumber": 62, …Run Code Online (Sandbox Code Playgroud) 我试图通过加入子查询来获得对groupBy的计数的平均值.不知道这是否是正确的方法,但除了mysema doc之外我无法解决任何关于子查询的问题.
场景:客户平均每件产品订单数量是多少?含义:客户订购产品.因此,客户多次(计数)订购了特定产品.客户为任何产品订购的平均订单数量是多少?
可能听起来有点假设,事实上它只是原型的一部分,但它让我想知道如何使用来自Mysema的花哨的QueryDSL来获取在子查询中创建的自定义列的引用.
在SQL中,您只需为count列指定一个别名,并使用第二个ID列进行连接.QueryDSL也有"as()"方法,但我不知道,如何检索该列加上我看不出它如何与其他人加入一个查询,因为query.list()只是获取一个列表但是对于某些加入接受它的原因.感觉不对...
这是我的代码:
JPQLQuery query = createJPQLQuery();
QOrdering qOrdering = QOrdering.ordering;
QProduct qProduct = QProduct.product;
QCustomer qCustomer = QCustomer.customer;
// how many of each product did a customer order?
HibernateSubQuery subQuery = new HibernateSubQuery();
subQuery.from(qOrdering).innerJoin(qOrdering.product,qProduct).innerJoin(qOrdering.customer, qCustomer);
subQuery.groupBy(qCustomer,qProduct).list(qCustomer.id,qProduct.id,qProduct.count());
// get the average number of orders per product for each customer
query.from(qCustomer);
query.innerJoin(subQuery.list(qCustomer.id,qOrdering.count().as("count_orders")));
query.groupBy(qCustomer.id);
return (List<Object[]>) query.list(qCustomer.firstname,subQuery.count_orders.avg());
Run Code Online (Sandbox Code Playgroud)
再说一次:我如何加入子查询?如何获得别名"count"列以进行更多聚合,例如avg(我的团队是正确的btw?)可能是因为我有其他一些错误,所以任何帮助表示赞赏!
谢谢!
编辑: 这是我希望看到QueryDSL产生的本机SQL:
Select avg(numOrders) as average, cust.lastname from
customer cust
inner join
(select count(o.product_id) as numOrders, c.id as cid, p.name …Run Code Online (Sandbox Code Playgroud) 我目前正在将spring-security集成到我们的新Web应用程序堆栈中.我们需要能够为用户或角色授予访问特定对象或特定类型的所有对象的权限.然而,在处理文档和示例时,我没有真正得到的一件事:
ACL是仅为单个对象的用户/角色授予权限还是为整个类型执行此操作?据我所知,它domain object意味着类型,但示例和教程似乎为特定对象分配权限.我只是困惑或者我可以两个都做?如果没有,我该怎么办?
谢谢!
我们使用OAuth2保护了我们的REST服务器,并为我们控制的多个客户端应用程序实现了客户端凭据授权类型.现在我们面临的决定是让令牌长期存在(即它们"永不"到期)或者让客户经常进行reAuthenticate(取决于刷新令牌到期).第一个意味着被捕获的令牌可以被恶意方使用,第二个意味着经常暴露客户机密,然后可以用来获取令牌.
哪个在资源服务器到客户端 - 服务器身份验证更安全?如果我们怀疑盗窃,令牌和客户机密密码都可能无效.显然所有通信都是通过https完成的.
目前我们认为客户端密钥比令牌更强大,因此对于这种双腿情况,长寿命令牌应该更好.(对于我们即将实施的任何三条腿授权类型,我们更喜欢用作用户会话的短期令牌).
谢谢你的想法!
我们对我们的控制器进行单元测试.我们已成功模拟对REST服务层的调用,并验证它确实是使用给定数据调用的.然而,现在我们想在我们的控制器中测试thenpromise 的执行会改变location.path:
控制器:
(function () {
app.controller('registerController', ['$scope', '$location', '$ourRestWrapper', function ($scope, $location, $ourRestWrapper) {
$scope.submitReg = function(){
// test will execute this
var promise = $ourRestWrapper.post('user/registration', $scope.register);
promise.then(function(response) {
console.log("success!"); // test never hits here
$location.path("/");
},
function(error) {
console.log("error!"); // test never hits here
$location.path("/error");
}
);
};
Run Code Online (Sandbox Code Playgroud)
$ourRestWrapper.post(url,data)只是包裹Restangular.all(url).post(data)..
我们的测试:
(function () {
describe("controller: registerController", function() {
var scope, location, restMock, controller, q, deferred;
beforeEach(module("ourModule"));
beforeEach(function() {
restMock = {
post: …Run Code Online (Sandbox Code Playgroud) java ×4
oauth-2.0 ×4
spring ×3
rest ×2
security ×2
2-legged ×1
access-token ×1
acl ×1
angularjs ×1
eclipse ×1
encoding ×1
facebook ×1
javascript ×1
jersey ×1
jpql ×1
mocking ×1
permissions ×1
promise ×1
querydsl ×1
spring-boot ×1
subquery ×1
svn ×1
unit-testing ×1
utf-8 ×1