Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn shiro

[Shiro] Cấu hình autowire lớp DAO trong shiro Realm khi sử dụng với Spring framework

1. Vấn đề: Trong các shiro realm thường tương tác với CSDL thông qua các class DAO để lấy thông tin người dùng phục vụ xử lý chứng thực. Tuy nhiên do các Realm class của Shiro thường được khởi tạo trước sau đó mới đến các lớp Component của Spring framework nên các DAO khai báo trong realm class không thể sử dụng anotation autowire của Spring (null). 2. Cách xử lý B1 : Khai báo class DAO vào file shiro.ini userRealmDao = com.viettel.smartparking.model.dao.UserRealmDao B2 : Khai báo DAO như là một thuộc tính của Realm class trong shiro.ini jdbcRealm = com.viettel.smartparking.shiro.realm.ShiroRealm jdbcRealm.credentialsMatcher = $credMatcher jdbcRealm.userRealmDao = $userRealmDao B3 : Khai báo lớp DAO trong Realm class private UserRealmDao userRealmDao

[Shiro][Spring-MVC] Apache Shiro with Spring framework, Java config and WebApplicationInitializer

Recently I was adding  Apache Shiro  security framework to Spring based web application which is using Java config and doesn't have xml configuration at all, not even web.xml Apache Shiro documentation is mostly using xml examples so it took some time to put it all together in Java config based application. Central part of Shiro security is  a realm. Here is how official Shiro documentation defines realms: " A Realm is a component that can access application-specific security data such as users, roles, and permissions. The Realm translates this application-specific data into a format that Shiro understands so Shiro can in turn provide a single easy-to-understand  Subject  programming API no matter how many data sources exist or how application-specific your data might be ." Shiro comes with number of out-of-the-box Realm  implementations that connects directly to database, to LDAP, etc, but in this example we will use custom Realm implementation since