小编Mih*_*sek的帖子

发布到 Nexus 上的私有 NPM 存储库时出现身份验证错误

发布到托管在我的私有 Nexus 上的私有 npm 注册表时,我遇到了身份验证问题。

我的 Nexus 设置是我有npm-proxynpm-registry(托管 npm with allowRepublish=false)、npm-snapshots(托管 npm with allowRepublish=true)和npm-public(与所有其他三个存储库分组)。

由于我正在开发一个库,我使用的是我的快照存储库,所以我可以不断地重新部署相同的版本(类似于 Maven 世界中的快照)。

在我的库项目中,我在package.json 中设置了这个选项

"publishConfig": {
    "registry": "https://my.nexus.com/repository/npm-snapshots/"
}
Run Code Online (Sandbox Code Playgroud)

接下来,我创建了包含以下内容的.npmrc文件:

registry=https://my.nexus.com/repository/npm-public/
_auth=RVhBTVBMRQ==
Run Code Online (Sandbox Code Playgroud)

有了这个设置,我可以毫无问题地发布项目。但是,让我烦恼的是,我的密码(只是 base64 编码)存储在文件中,应该提交,但由于其中的凭据,我无法提交。

我试图改为登录 npm 注册表并从 .npmrc 中删除了 auth 行 npm adduser --registry=https://my.nexus.com/repository/npm-snapshots --always-auth

我得到了回应 Logged in as myusername on https://my.nexus.com/repository/npm-snapshots.

但是,当我尝试运行时,npm publish我得到:

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository …
Run Code Online (Sandbox Code Playgroud)

nexus node.js npm

29
推荐指数
4
解决办法
6万
查看次数

SpringBoot JPA Hibernate:创建名为“entityManagerFactory”的 bean 时出错

我正在尝试设置一个 Spring Boot 应用程序,它使用 SpringBoot Security 来验证存储在我的 MySQL 数据库中的用户。我遵循了一些关于如何制作的教程,但是,当我尝试使用 maven 运行应用程序时,出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-boot

7
推荐指数
2
解决办法
3万
查看次数

使用带有 Spring Boot 和 Angular 5 的 httponly cookie 的 JWT 身份验证

所以,我正在开发一个需要身份验证的Angular 5应用程序。Angular 应用程序正在从Spring Boot API检索数据。对于身份验证,我将电子邮件和密码发送到 API,如果正确,则将 JWT 令牌发回给我。我读过在 localStorage 中存储令牌不是一个好主意,因为它可以通过 javascript 访问,因此容易受到攻击。因此,我想将 JWT 存储到带有httponly安全标志的cookie 中。

但是,问题是因为 Angular 应用程序和 Spring Boot 应用程序运行在不同的来源上,因此从 Spring 收到的响应无法设置 cookie。

我想知道如何在登录成功时实现这一点,我的 API 为可能存在于另一个域上的 angular 应用程序设置 cookie。

这是我的身份验证资源:

@PostMapping("/login")
    public ResponseEntity<LoginResponse> loginUser(@RequestBody LoginRequest request, HttpServletResponse res) {
        LoginResponse response = new LoginResponse("this_is_my_token");
        Cookie cookie = new Cookie("token", "this_is_my_token");
        cookie.setPath("/");
        cookie.setSecure(true);
        cookie.setHttpOnly(true);
        res.setHeader("Access-Control-Allow-Credentials", "true");
        res.addCookie(cookie);
        return ResponseEntity.ok().body(response);
    }
Run Code Online (Sandbox Code Playgroud)

我还配置了 CORS 过滤器:

@Bean
    public WebMvcConfigurer cors() {
        return new WebMvcConfigurer() {
            @Override …
Run Code Online (Sandbox Code Playgroud)

java spring jwt spring-boot angular

7
推荐指数
0
解决办法
5284
查看次数

Spring Boot JPA 使用查询填充实体字段

我正在我的应用程序中构建一个菜单,因此我创建了实体 MenuItem,它代表我的菜单中的一项。这可以是文件或目录。

但是,我想知道一个目录是否有子目录,因为如果没有,我不想显示它。我也不希望对这么多的子项进行硬编码,因为这意味着我每次添加内容时都必须更新该值。

我想知道的是,是否有一种方法可以使用查询而不是持久值来映射属性。

这是我的 MenuItem.java 文件:

@Entity
@Table(name = "menu_item")
public class MenuItem {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column
    private long parent;

    @Column
    private String name;

    @Column
    private long num_of_childs;

    @Enumerated(EnumType.STRING)
    @Column
    private MenuItemType type;

    @ManyToOne
    @JoinColumn(name = "file_id")
    private FileItem file;

    /* getters and setters... */
}
Run Code Online (Sandbox Code Playgroud)

我想要的是这样的:

@Column
@Transient
@Query("SELECT COUNT(i) as num_of_childs FROM MenuItem i WHERE parent = i.id")
private long num_of_childs;
Run Code Online (Sandbox Code Playgroud)

甚至可以做这样的事情吗?

java spring jpa spring-data-jpa spring-boot

6
推荐指数
1
解决办法
6991
查看次数

Spring boot 在登录页面上请求 X509 证书

我正在编写一个Spring Boot应用程序,在登录页面上,应该提示用户提供他的X509 证书(使用我的自签名 CA 生成)。如果用户未能提供证书,则会显示另一个错误页面。如果用户提供了正确的证书,我想向他显示一个登录页面,其中预填了他的电子邮件(从证书中读取)并等待密码输入。唯一受影响的路径应该是需要证书的/admin/login,所有其他路径都应该完全不安全。

到目前为止我发现的是这个程序:

  1. 生成适当的证书
  2. 生成jks文件
  3. 配置tomcat请求证书
  4. 配置 Spring Boot 安全性
  5. 在加载登录页面之前,请求证书,解析它,检查其中数据的有效性(通用名称,...)
  6. 显示登录页面
  7. 检查登录数据,如果没问题,做我的事情

我在第3-5点遇到问题,因为我找到的所有教程都不是我正在寻找的解决方案。

另外,稍后这个 Spring Boot 项目将在 Apache 的虚拟主机后面运行,所以我想我需要 Apache 来请求证书,然后将其转发到 Spring Boot 服务器。

我需要一些起点来学习如何实现这一点。


一些上下文:我正在构建一个 Angular 6(用于后端的 Spring Boot)应用程序,其中我有两种类型的角色:用户和管理员。用户将仅使用用户名和密码通过普通(Angular)页面登录。管理员必须通过提供证书登录,然后使用在证书和密码中写入的用户名登录 - 这将在 Spring Boot 使用 Thymeleaf 模板引擎提供的单独页面上完成。我想实现的是,当用户通过身份验证时,我生成 JWT 令牌并将其保存到 cookie,它将用于所有未来的请求(在 JWT 的有效性期间)。唯一的问题是我不知道如何连接所有这些东西

java apache ssl spring angular

6
推荐指数
0
解决办法
1185
查看次数

ContentDialog showAsync()给出错误:没有getAwaiter的定义

我正在构建一个UWP应用程序(C#),点击按钮,我想验证输入.如果验证失败,我想显示一条消息,说明输入错误.这是我应该处理的功能:

private async void AddContact_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
    DBHelper db = new DBHelper();
    if(i_name.Text != "" && i_phone.Text != "") {
        db.insertPerson(new Person(i_name.Text, i_phone.Text));
        Frame.Navigate(typeof(MainPage));
    } else {
        ContentDialog msg = new ContentDialog() {
            Title = "Empty input!",
            Content = "Please fill both fields!",
            CloseButtonText = "OK"
        };
        await msg.ShowAsync();
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当输入最后一部分(等待msg.showAsync())时,它会以红色下划线(在VS中).构建器读取以下错误:

错误CS4036'IAsyncOperation '不包含'GetAwaiter'的定义,并且没有扩展方法'GetAwaiter'接受类型'IAsyncOperation'的第一个参数(你是否缺少'System'的using指令?) testniStudioApp d:. ..\SecondPage.xaml.cs 43有效

现在我尝试将此调用分配给变量(因为我看到有人解决了类似的问题),但它仍然没有奏效.然后我尝试清除这里所述的NuGet缓存和重建项目,但这些解决方案都没有奏效.

我很难理解它对我的要求.关于如何显示消息的每个教程都以大致相同的方式编写,因此我无法理解可能出现的问题.

c# async-await uwp

4
推荐指数
1
解决办法
669
查看次数

带有 i18n(国际化)和 thymeleaf 的 Spring Boot

我正在尝试让 i18n 与我的 Spring Boot 应用程序一起使用,该应用程序使用 thymeleaf 作为模板引擎。

我遵循了一些教程,它向我展示了如何定义消息源和语言环境解析器,所以我制作了这个配置类:

@Configuration
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource msgSrc = new ReloadableResourceBundleMessageSource();
        msgSrc.setBasename("i18n/messages");
        msgSrc.setDefaultEncoding("UTF-8");
        return msgSrc;
    }

    @Bean
    public LocaleResolver localeResolver() {
        CookieLocaleResolver resolver = new CookieLocaleResolver();
        resolver.setDefaultLocale(new Locale("en"));
        resolver.setCookieName("myI18N_cookie");
        return resolver;
    }

    @Override
    public void addInterceptors(InterceptorRegistry reg) {
        LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
        interceptor.setParamName("locale");
        reg.addInterceptor(interceptor);
    }

}
Run Code Online (Sandbox Code Playgroud)

然后,在我的资源文件夹(src/main/resources)中,我创建了文件夹i18n并在里面放置了messages.propertiesmessages_sl.properties

里面定义了first.greeting = Hello World!

这是我的百里香模板:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc internationalization thymeleaf

4
推荐指数
1
解决办法
5126
查看次数

为了将我的域名切换到HTTPS,我是否需要更改Apache或我的Node.js应用程序?

我有一个在我的域上运行的Web应用程序.首先我有常规HTTP站点,它在我的服务器上的端口8082上运行,而Apache服务器(使用虚拟主机)将请求从端口80重定向到localhost:8082.

现在我获得了一个SSL证书,我试图在我的网站上安装.我在Node中创建了一个HTTPS服务器,并且https://localhost:8082一切正常.

但后来我尝试通过HTTPS提供我的域名.我尝试编辑我的虚拟主机文件以使用证书,但我认为我没有正确编写它.此外,我试图让它将HTTP重定向到HTTPS,但它没有用.

我该怎么办?我应该在Node中运行HTTP或HTTPS服务器,我应该在Apache虚拟主机配置中添加什么?

这是我的虚拟主机文件:

<VirtualHost *:80>
        ServerName www.domain.com
        Redirect permanent / https://www.domain.com
</VirtualHost>

<VirtualHost *:443>

        ServerName domain.com
        ServerAlias www.domain.com

        SSLEngine On
        SSLProxyEngine On
        SSLCertificateFile "/home/USERNAME/Projects/NODEAPP/chained.pem"
        SSLCertificateKeyFile "/home/USERNAME/Projects/NODEAPP/domain.key"

        ProxyPreserveHost On
        ProxyRequests off

        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>

        <Location />
                ProxyPass http://localhost:8082/

                ProxyPassReverse http://localhost:8082/
        </Location>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

apache ssl reverse-proxy node.js

-1
推荐指数
1
解决办法
203
查看次数