यह करने का यह सबसे आसान तरीका है। समूह प्राधिकरणों के साथ-साथ उपयोगकर्ता प्राधिकरणों की अनुमति देता है।
-- Postgres syntax
create table users (
user_id serial primary key,
enabled boolean not null default true,
password text not null,
username citext not null unique
);
create index on users (username);
create table groups (
group_id serial primary key,
name citext not null unique
);
create table authorities (
authority_id serial primary key,
authority citext not null unique
);
create table user_authorities (
user_id int references users,
authority_id int references authorities,
primary key (user_id, authority_id)
);
create table group_users (
group_id int references groups,
user_id int referenecs users,
primary key (group_id, user_id)
);
create table group_authorities (
group_id int references groups,
authority_id int references authorities,
primary key (group_id, authority_id)
);
फिर META-INF/applicationContext-security.xml
<beans:bean class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" id="passwordEncoder" />
<authentication-manager>
<authentication-provider>
<jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="select username, password, enabled from users where username=?"
authorities-by-username-query="select users.username, authorities.authority from users join user_authorities using(user_id) join authorities using(authority_id) where users.username=?"
group-authorities-by-username-query="select groups.id, groups.name, authorities.authority from users join group_users using(user_id) join groups using(group_id) join group_authorities using(group_id) join authorities using(authority_id) where users.username=?"
/>
<password-encoder ref="passwordEncoder" />
</authentication-provider>
</authentication-manager>
सब जो यहाँ आने के लिए
स्रोत
2013-07-14 23:10:35
में, वहाँ एक लेख जो वास्तव में मेरी समस्या का हल है। कृपया [इस] (http://slackspace.de/articles/roles-permissions-with-spring-security-3/) – flash
पर एक नज़र डालें, मैंने उस लेख को पढ़ा और मैं इसे लागू करने की कोशिश कर रहा हूं। क्या आप कृपया मुझे बताएंगे कि आपने SpringSecurityDaoImpl क्लास को कैसे कार्यान्वित किया? @PreAuthorize मेरे यूआरएल को बिल्कुल प्रभावित नहीं करता है! मैंने बिल्कुल उस लेख में सामग्री की तरह किया है। – sina
@sina आपको 'SpringSecurityDaoImpl' को लागू करने की आवश्यकता नहीं है, उदाहरण के लिए बस 'JdbcDaoImpl' को बढ़ाएं। गिटूब पर उदाहरण कोड को देखना सुनिश्चित करें, जिसे लेख में संदर्भित किया गया है। – flash