我试图~/public_html/dev使用http auth basic 保护目录,但为了使其安全,我想在ssl上运行它.
.htaccess如果请求URI /dev以及开始工作,则以下文件的中间部分将切换为https .
该文件的最后一部分也可以正常工作,但与https重定向无法正常工作.
我基本上希望能够键入http://www.example.com/dev/some_sub_dir/并重定向到https://www.example.com/dev/some_sub_dir/并提示输入http auth用户名和密码.
目前发生的情况是,如果我去,http://www.example.com/dev/some_sub_dir/我会通过端口80提示输入用户名和密码,然后立即通过端口443再次提示.因此,我的凭据被发送两次,一次是明文,一次加密.使整个https url重写有点无意义.
这样做的原因是我无法意外地通过http提交我的用户/传递; https将始终用于访问该/dev目录.
该.htaccess是在~/public_html/dev目录中.
# Rewrite Rules for example.com
RewriteEngine On
RewriteBase /
# force /dev over https
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^/dev
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# do auth
AuthType Basic
AuthName "dev"
AuthUserFile /home/matt/public_html/dev/.htpasswd
Require valid-user apache .htaccess mod-rewrite url-rewriting http-authentication
我试图使用HTTP从IP摄像头获取图像.相机需要HTTP基本身份验证,因此我必须添加相应的请求标头:
URL url = new URL("http://myipcam/snapshot.jpg");
URLConnection uc = url.openConnection();
uc.setRequestProperty("Authorization",
"Basic " + new String(Base64.encode("user:pass".getBytes())));
// outputs "null"
System.out.println(uc.getRequestProperty("Authorization"));
Run Code Online (Sandbox Code Playgroud)
我稍后将url对象传递给ImageIO.read(),并且,正如您所猜测的,我正在获取HTTP 401 Unauthorized,尽管user并且pass是正确的.
我究竟做错了什么?
我也试过了new URL("http://user:pass@myipcam/snapshot.jpg"),但这也行不通.
我有一个Spring MVC REST服务,启用了Spring Security(3.2.5.RELEASE).当我打开@EnableWebMvcSecurity时,会在http:// localhost:8080/login为我自动生成一个登录表单.如果我使用此表单登录,一切正常.
当我尝试通过直接发送POST请求登录时,会发生此问题.在我的帖子请求中,我提供了用户名和密码.我还包括http标头'X-CSRF-TOKEN',对于标头值,我使用我看到的JSESSIONID已在cookie中生成.但是,当我发送此POST请求时,我得到以下结果:
HTTP Status 403 - Invalid CSRF Token '29F5E49EFE8D758D4903C0491D56433E'
was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我提供了错误的令牌价值吗?这是什么JSESSIONID?如果我没有为此标题输入值,或者一起省略标题,则会告诉我"找到空的CSRF标记".
以下是我的Spring Security配置:
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/secure/**").authenticated()
.and()
.formLogin()
.usernameParameter("username")
.passwordParameter("password")
.and()
.logout()
.and()
.httpBasic()
.and()
.csrf();
}
}
Run Code Online (Sandbox Code Playgroud)
我真的很感激任何帮助!提前致谢!
我在我的工作中写了很多GreaseMonkey脚本,它会自动登录我们这里的内部网站.除了我们的时间表应用程序(使用HTTP身份验证)之外,我已经设法为几乎每个站点编写脚本.
有没有办法可以使用GreaseMonkey自动登录我这个网站?
编辑:我知道浏览器中的商店密码功能,但是我的脚本更进一步,检查我是否在加载时(通过遍历HTML)登录到站点,然后将帖子提交到登录页面.这消除了必须加载站点,进入登录页面,输入我的凭据,然后点击提交的步骤
javascript authentication greasemonkey http http-authentication
我想在DocumentRoot中创建一个.htaccess文件,以便该目录受密码保护.
但密码文件,我想通过使用DocumentRoot的相对路径来指定.
所以,如果我在另一个系统中检查代码,它就会按原样运行.密码文件将是我的源代码管理的一部分.
如何从.htaccess文件访问DocumentRoot的父目录?
我已经搜索了许多处理过这个HttpRetryException问题的人的地方,但我找到的所有问题都遇到了一些名为CXF的apache服务,我没有使用它.我使用的是java.net.HttpURLConnection.我创建一个连接,使用setRequestProperty进行"授权",获取输出流,写入一堆字节,然后尝试读取回复输入流.大部分时间都有效,但有时我会得到上面提到的例外.我无法避免流式传输,因为有时我需要编写比存储在内存中更大的文件,无论如何,我发现搜索的大部分结果都表明这不是真正的问题.他们通常提供解决方案,bindingProvider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
bindingProvider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
我不使用cxf或任何其他包装器通过HttpURLConnection,并且没有服务或绑定提供程序来引用.使用setRequestProperty设置的用户名和密码在大多数情况下都可以正常进行身份验证.我希望我能说出可靠地复制错误所需的特定前提条件,但到目前为止它已被击中或未命中.
我有一个ad-hoc iPad应用程序分发服务器设置,允许用户通过Safari下载每晚构建的iPad应用程序,我在服务器上设置了基本HTTP身份验证.
当用户单击链接以下载应用程序时,其外观如下所示:
itms-services://?action=download-manifest&url=http%3A%2F%2F<url>
Run Code Online (Sandbox Code Playgroud)
Safari正在提示用户每次都输入凭据.有没有办法让它缓存凭据,就像普通http://页面一样?
我熟悉使用Jersey创建RESTful webservice服务器和客户端,但由于类加载问题,我试图将Jersey客户端转换为CXF.我相信我想使用以HTTP为中心的客户端,但我们不使用Spring.我们需要使用基本的HTTP身份验证.的用户指南具有本实施例中:
WebClient client = WebClient.create("http:books", "username", "password", "classpath:/config/https.xml");
Run Code Online (Sandbox Code Playgroud)
第一个参数不是URI字符串.它是Spring使用的格式吗?这个方法只能用于使用Spring创建WebClient吗?
执行身份验证的另一种方法是添加标头字符串:
String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility.encode("user:password".getBytes());
webClient.header("Authorization", authorizationHeader);
Run Code Online (Sandbox Code Playgroud)
我猜这"user:password"应该用真实的价值观代替,但我会很感激确认.
如何使用Volley库为API 进行Http身份验证?
我尝试了以下代码....它抛出运行时异常和空指针异常.请提供建议
String url = "Site url";
String host = "hostName";
int port = 80;
String userName = "username";
String password = "Password";
DefaultHttpClient client = new DefaultHttpClient();
AuthScope authscope = new AuthScope(host, port);
Credentials credentials = new UsernamePasswordCredentials(userName, password);
client.getCredentialsProvider().setCredentials(authscope, credentials);
HttpClientStack stack = new HttpClientStack(client);
RequestQueue queue = Volley.newRequestQueue(VolleyActivity.this, stack);
Run Code Online (Sandbox Code Playgroud) android http-authentication android-networking android-volley
我有一个HTTP Basic Auth的API.如果未经过身份验证的用户发送HTTP请求,则服务器将返回401状态代码和WWW-Authenticate标头.浏览器显示标准登录表单.是否可以显示我的HTML登录表单而不是标准浏览器的登录表单?
java ×3
.htaccess ×2
apache ×2
javascript ×2
rest ×2
android ×1
client ×1
cxf ×1
greasemonkey ×1
http ×1
http-headers ×1
ipad ×1
mod-rewrite ×1
safari ×1
spring ×1
spring-mvc ×1
url ×1