问题:如何在spring boot中配置.htaccess?
angularjs提供html5Mode,这使您的应用程序使用基于pushstate的URL而不是hashtags.但是,这需要服务器端支持,因为生成的URL也需要正确呈现.
如果您在Apache服务器上运行角度应用程序,则可以在.htaccess文件中轻松添加此规则.
# Apache .htaccess
# angularjs pushstate (history) support:
# See http://www.josscrowcroft.com/2012/code/htaccess-for-html5-history-pushstate-url-routing/
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !.*\.(css¦js|html|png) #Add extra extensions needed.
RewriteRule (.*) index.html [L]
</ifModule>
Run Code Online (Sandbox Code Playgroud) 据我所知,Spring Boot有一个内置的Tomcat服务器(或Jetty),可以促进快速开发.但是,当您因为流量增加而需要扩展应用程序时,您会怎么做?
我正在尝试在Spring-Boot中为我的控制器编写错误处理程序,以便捕获大多数可能的错误(Spring,sql等).到目前为止,我能够通过Null获得JSON响应,但是我无法将任何数据放入其中.当我尝试收到错误消息时,我只收到一个空白页面.
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
@RestController
public class BasicErrorController implements ErrorController {
private static final String ERROR_PATH = "/error";
@RequestMapping(value=ERROR_PATH)
@ExceptionHandler(value = {NoSuchRequestHandlingMethodException.class, SQLException.class, IOException.class, RuntimeException.class, Exception.class})
public ErrorBody defaultErrorHandler(HttpServletRequest request, Exception e) {
ErrorBody eBody = new ErrorBody();
eBody.setMessage(e.getCause().getMessage());
return eBody;
}
}
Run Code Online (Sandbox Code Playgroud)
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ErrorBody {
private String dateTime;
private String exception;
private String url;
private String message;
}
Run Code Online (Sandbox Code Playgroud) 我想在登录过程中添加用户ip验证.如果用户的IP地址不在数据库中,则应用程序应拒绝身份验证.
问题:鉴于下面的设置,结果是auth.authenticationProvider()没有替换默认的DaoAuthenticationProvider,而是将UserIpAuthenticationProvider添加为列表中的第一个AuthenticationProvider.
在用户名/密码组合不正确的情况下,框架最终调用UserDetailsService.loadUserByUsername()两次,一次来自UserIpAuthenticationProvider,另一次来自内部DaoAuthenticationProvider,它抛出最终的BadCredentialsException().
问题:是否有任何可以在Spring Boot中设置的设置,以便Spring Security不会添加它自己的内部实例DaoAuthenticationProvider,而只使用我的UserIpAuthenticationProvider,它已经拥有所有必要的功能(可能通过某种方式替换AuthenticationManagerBuilder能够覆盖userDetailsService()方法?).
public <T extends UserDetailsService> DaoAuthenticationConfigurer<AuthenticationManagerBuilder,T> userDetailsService(
T userDetailsService) throws Exception {
this.defaultUserDetailsService = userDetailsService;
return apply(new DaoAuthenticationConfigurer<AuthenticationManagerBuilder,T>(userDetailsService));
}
Run Code Online (Sandbox Code Playgroud)
配置:根据我的理解,UserDetailsService应该提供有关用户的所有必要详细信息,以便AuthenticationProvider可以决定身份验证是否成功.
由于从数据库加载了所有必要的信息,因此扩展DaoAuthenticationProvider并在覆盖additionalAuthenticationChecks()方法中添加额外的验证似乎很自然(白名单中的IP列表在数据库中,因此它们作为用户对象的一部分加载IpAwareUser).
@Named
@Component
class UserIpAuthenticationProvider extends DaoAuthenticationProvider {
@Inject
public UserIpAuthenticationProvider(UserDetailsService userDetailsService)
{
...
}
@SuppressWarnings("deprecation")
protected void additionalAuthenticationChecks(UserDetails userDetails,
UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
super.additionalAuthenticationChecks(userDetails, authentication);
WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
IpAwareUser ipAwareUser = (IpAwareUser) userDetails;
if (!ipAwareUser.isAllowedIp(details.getRemoteAddress()))
{
throw new DisabledException("Login restricted from ip: " + details.getRemoteAddress());
}
}
} …Run Code Online (Sandbox Code Playgroud) 如何将.bin文件写入软盘/虚拟软盘/软盘映像的第一个扇区?
我正在尝试启动一个简单的512字节引导加载程序.各地的大小都说"512字节",所以我应该已经很好了.
附加信息:
引导程序只显示一个字符串,我正在学习简单的汇编.一些工作是在Windows中完成的,一些是在Ubuntu 14.04(Trusty Tahr)中完成的(如果这很重要).
即使它具有引导加载程序标志,它也无法启动.
我正在尝试制作自己的自定义操作系统,我需要一些代码帮助.这是我的bootloader.asm:
[ORG 0x7c00]
start:
cli
xor ax, ax
mov ds, ax
mov ss, ax
mov es, ax
mov [BOOT_DRIVE], dl
mov bp, 0x8000
mov sp, bp
mov bx, 0x9000
mov dh, 5
mov dl, [BOOT_DRIVE]
call load_kernel
call enable_A20
call graphics_mode
lgdt [gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp CODE_SEG:init_pm
[bits 32]
init_pm:
mov ax, DATA_SEG
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000 …Run Code Online (Sandbox Code Playgroud) 我用AT&T语法编写了一个程序,用于GNU汇编程序:
.data
format: .ascii "%d\n"
.text
.global main
main:
mov $format, %rbx
mov (%rbx), %rdi
mov $1, %rsi
call printf
ret
Run Code Online (Sandbox Code Playgroud)
我使用GCC来组装和链接:
gcc -o main main.s
我用这个命令运行它:
./主要
当我运行程序时,我得到一个seg错误.通过使用gdb,它说printf没有找到.我试过".extern printf",但是没有用.有人建议我应该printf在RET之前存储堆栈指针并在RET之前恢复,我该怎么做?
我是学习OS开发的新手.从我读过的书中,它说启动加载器会将第一个MBR复制到0x7c00,然后从实模式开始.
并且,示例从16位汇编代码开始.但是,当我查看今天的linux内核时,arch/x86/boot有'header.S'和'boot.h',但实际代码是在main.c中实现的.
这似乎对"不编写汇编"很有用.但是,这是如何在Linux中专门完成的?我可以粗略地想象可能有特殊gcc选项和链接策略,但我看不到细节.
据我所知,gcc内联汇编中使用的约束告诉gcc输入和输出变量必须(或必须),以便生成有效的汇编.正如精细手册所说,"对操作数放置的限制".
这是一个教程中特定的工作示例.
static inline uint8_t inb(uint16_t port)
{
uint8_t ret;
asm volatile ( "inb %1, %0"
: "=a"(ret)
: "Nd"(port) );
return ret;
}
Run Code Online (Sandbox Code Playgroud)
inb是AT&T语法 - 代表IN从I/O端口接收一个字节的i386 指令.
以下是本指令的规格,取自i386手册.需要注意的是端口号,从去0x0000到0xFFFF.
IN AL,imm8 // Input byte from immediate port into AL
IN AX,imm8 // Input word from immediate port into AX
IN EAX,imm8 // Input dword from immediate port into EAX
IN AL,DX // Input byte from port DX into AL
IN AX,DX …Run Code Online (Sandbox Code Playgroud) 我处于以当前权限级别(CPL = 0)运行的32位保护模式.我试图通过将EFLAGS.VM(位17)标志设置为1(和IOPL为0)并对我的16位实模式代码执行FAR JMP来进入v8086模式.我使用当前的标志PUSHF; 将EFLAGS.VM(第17位)设置为1; 将EFLAGS.IOPL(第22位和第23位)设置为0; 设置新的EFLAGS POPF.这个代码看起来像:
bits 32
cli
[snip]
pushf ; Get current EFLAGS
pop eax
or eax, 1<<EFLAGS_VM_BIT ; Set VM flag to enter v8086 mode
and eax, ~(3<<EFLAGS_IOPL_BITS)
; Set IOPL to 0
; IF flag already 0 because of earlier CLI
push eax
popf ; Reload new flags
jmp CODE32_SEL:v86_mode_entry
; Far JMP to v8086 entry point
; v8086 code entry point
bits 16
v86_mode_entry:
hlt ; Halt should double fault …Run Code Online (Sandbox Code Playgroud) assembly ×5
osdev ×4
spring ×4
spring-boot ×4
bootloader ×3
x86 ×3
gcc ×2
spring-mvc ×2
x86-64 ×2
.htaccess ×1
apache ×1
bios ×1
c ×1
floppy ×1
g++ ×1
java ×1
kernel ×1
linux ×1
linux-kernel ×1
nasm ×1
scalability ×1
security ×1
tomcat ×1
x86-16 ×1