我是Authorization标头的新手,尝试使用JAX-RS服务创建授权(和身份验证)
我在javascript上的代码片段如下所示:
sUrl = getURL() + "/com.cabRoutePlanner.Login/Login";
var oHeaders = {};
oHeaders['Authorization'] = "Basic " + btoa(getUserName() + ":" + getPassword());
var request = {
headers : oHeaders,
requestUri : sUrl,
data: connectionData,
method : "POST"
};
OData.request(request, onSuccessForRegister, onRegError);
Run Code Online (Sandbox Code Playgroud)
现在,我想在JAX-RS服务中读取此授权标头,即我的Java Rest服务中的用户名和密码,并检查我的数据库.我感到困惑的是,我不知道如何使用此授权标头.如果有人能够在REST服务中向我展示该功能的声明,并且只是为了访问我的用户名和密码,那就太棒了.
我以某种方式编写了代码,有点直觉和Eclipse的大力帮助
@Path("/Log")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response log(HttpServletRequest req)throws JSONException
{
JSONObject returnObject = new JSONObject();
String authorization = req.getHeader("Authorization");
if (authorization != null && authorization.startsWith("Basic"))
{
//byte[] message = authorization.substring("Basic".length()).trim().getBytes();
String credentials = authorization.substring("Basic".length()).trim();
byte[] decoded = DatatypeConverter.parseBase64Binary(credentials); …Run Code Online (Sandbox Code Playgroud) 我正在使用spring boot命令行运行器应用程序,它挂在PostGIS方言中,下面的堆栈跟踪包含正在发生的事情.我无法理解出现了什么问题,我有hibernate-spatial查询.
2018-04-06 12:11:08.554 INFO 31495 --- [ main] replayer.Main : No active profile set, falling back to default profiles: default
2018-04-06 12:11:08.780 INFO 31495 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@39d9314d: startup date [Fri Apr 06 12:11:08 NZST 2018]; root of context hierarchy
2018-04-06 12:11:10.811 INFO 31495 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-04-06 12:11:11.149 INFO 31495 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$a0866479] is not eligible for getting …Run Code Online (Sandbox Code Playgroud) 我需要授予主用户(MasterUsername)访问pg_catalog的权限.
GRANT USAGE ON SCHEMA pg_catalog TO <master-user>;
Run Code Online (Sandbox Code Playgroud)
运行此操作时,我收到以下警告:警告:没有为"pg_catalog"授予任何权限.
基本上,我有一个自动化脚本,我在其中创建数据库,我设置搜索路径和:
SET search_path = <my-schema>, pg_catalog;
CREATE TYPE <type> AS (
id bigint,
name character varying);
Run Code Online (Sandbox Code Playgroud)
我得到以下错误
Caused by: org.postgresql.util.PSQLException: ERROR: permission denied for schema pg_catalog
Run Code Online (Sandbox Code Playgroud)
本质上,它不允许我创建类型,因为pg_type表存在于pg_catalog中.如何创建类型?
我不知道授予USAGE权利是否会有所帮助?如果有另一种解决方法,请告诉我.
错误如下所示.问题是,如下所示,这个XmlWebApplicationContext不需要发生,因为它再次注入了bean.怎么避免呢?
org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Initializing Spring root WebApplicationContext
Sep 08, 2015 12:40:44 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Sep 08, 2015 12:40:44 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue Sep 08 12:40:44 IST 2015]; root of context hierarchy
Sep 08, 2015 12:40:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/context/PersistenceManagerContext.xml]
Sep 08, 2015 12:40:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/context/ServiceApiContext.xml]
Sep 08, 2015 12:40:44 PM …Run Code Online (Sandbox Code Playgroud) 使用spring,我在通过java阅读我的yaml时遇到了问题.让我先说明代码
@Component
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "countries")
public class UserLimitReader {
private HashMap<String, Integer> orders;
private HashMap<String, Integer> requests;
public HashMap<String, Integer> getOrders() {
return orders;
}
public void setOrderRedeemableLimit(HashMap<String, Integer> orders)
{
this.orders= orders;
}
public HashMap<String, Integer> getRequests() {
return requests;
}
public void setMonthlyRedeemableLimit(HashMap<String, Integer> requests) {
this.requests= requests;
}
}
Run Code Online (Sandbox Code Playgroud)
我的yaml文件:
cassandra:
hosts: localhost:9142, 127.0.0.1:9142
keyspace: test
countries:
orders:
JPY: 1000
USD: 1000
requests:
JPY: 100000
USD: 100000
Run Code Online (Sandbox Code Playgroud)
spring context xml也有这个:
<bean id="yamlProperties"
class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
<property name="resources">
<value>classpath:config/application.yaml</value> …Run Code Online (Sandbox Code Playgroud) 我正在使用 wireMock,即使存根响应是 200 OK,我也得到了 500 Internal Server Error 的一致响应。
如果我调试,我会看到连接总是关闭的。知道可能出了什么问题吗?或者我做错了什么。
这是测试
public class MyControllerTest {
@Autowired
MyController myController;
String id1 = "id1";
String id2 = "id2";
Integer offset = 0;
Integer limit = 1;
int port = 8080;
protected WireMockServer wireMockServer;
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(port);
@Test
public void hosDriversHoursOfServiceGet() throws Exception {
stubFor(WireMock.get(urlEqualTo("/path/endPoint"))
.withQueryParam("id1", equalTo(id1))
.withQueryParam("id2", equalTo(id2))
.withQueryParam("limit", equalTo(limit.toString()))
.withQueryParam("offset", equalTo(offset.toString()))
.willReturn(aResponse().withStatus(200).withBody((getJsonString()))));
Response response = myController.hosDriversHoursOfServiceGet(driverId, 1, 1);
assertEquals(Integer.valueOf(1), response.getCount());
}
private String getJsonString() {
return "{\"count\":1}"; …Run Code Online (Sandbox Code Playgroud) 我有一份工作有很多这样的任务:
- name: main-job
serial: true
plan:
- aggregate:
- get: <git-resource>
passed: [previous-job]
trigger: true
- get: <git-resource-3>
- task: <task-1>
file: <git-resource>/<path>/<task-1-no-db>.yml
- task: <task-2>
tags: ['<specific-tag>']
file: <git-resource>/<path>/<task-1>.yml
params:
DATABASE_HOST: <file>
DATABASE: <my-db-1>
- task: <task-2>
tags: ['<specific-tag>']
file: <git-resource>/<path>/<task-1>.yml
params:
DATABASE_HOST: <file>
DATABASE: <my-db-1>
Run Code Online (Sandbox Code Playgroud)
我的问题是,我必须从字面上调用相同的工作,但不是 DATABASE params 是my-db-1,我希望它是my-db-2.
我能够做到这一点的唯一方法是拥有新工作并传递参数,从字面上复制整组行。我的工作太繁重,因为其中有太多任务,所以复制它虽然是显而易见的解决方案,我想知道是否有一种方法可以通过拥有多个管道和一个主要管道来重用DATABASE 的参数传递或有两个小作业,它们使用不同的参数调用此主要作业,如下所示:
- name: <call-main-job-with-db-1>
serial: true
plan:
- aggregate:
- get: <git-resource>
passed: [previous-job]
trigger: true
- task: <call-main-job-task>
params:
DATABASE_HOST: <file>
DATABASE: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Intellij 的 IBM Websphere 配置在 WAS 上部署 Ear。
我看到以下日志:
************ Start Display Current Environment ************
Log file started at: [11/11/20 8:41:45:679 NZDT]
************* End Display Current Environment *************
Nov 11, 2020 8:41:49 AM com.ibm.websphere.management.AdminClientFactory
WARNING: ADMC0046W: The system failed to load properties from com.ibm.SOAP.configURL: file:null/properties/soap.client.props
Nov 11, 2020 8:41:50 AM com.ibm.ws.management.connector.interop.JMXClassLoader
WARNING: Could not find tmx4jTransform.jar in null/etc/tmx4jTransform.jar - Interoperability to older versions of WebSphere is disabled
Nov 11, 2020 8:41:50 AM com.ibm.ws.ssl.config.SSLConfigManager
INFO: CWPKI0051I: The process has the …Run Code Online (Sandbox Code Playgroud) java ×5
spring ×2
amazon-rds ×1
concourse ×1
dictionary ×1
ear ×1
header ×1
jax-rs ×1
junit4 ×1
permissions ×1
postgis ×1
postgresql ×1
rds ×1
spring-boot ×1
spring-mvc ×1
websphere ×1
wiremock ×1
xml ×1
yaml ×1