Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
172 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.casbin.shiro.entity; | ||
|
||
public class User { | ||
private String username; | ||
|
||
public User() { | ||
} | ||
|
||
public User(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021 The casbin Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.casbin.shiro.realm; | ||
|
||
import org.apache.shiro.authc.*; | ||
import org.apache.shiro.authz.AuthorizationInfo; | ||
import org.apache.shiro.authz.SimpleAuthorizationInfo; | ||
import org.apache.shiro.realm.AuthorizingRealm; | ||
import org.apache.shiro.subject.PrincipalCollection; | ||
import org.casbin.shiro.entity.*; | ||
|
||
public class UserRealm extends AuthorizingRealm { | ||
/** | ||
* Retrieves the AuthorizationInfo for the given principals from the underlying data store. When returning | ||
* an instance from this method, you might want to consider using an instance of | ||
* {@link SimpleAuthorizationInfo SimpleAuthorizationInfo}, as it is suitable in most cases. | ||
* | ||
* @param principals the primary identifying principals of the AuthorizationInfo that should be retrieved. | ||
* @return the AuthorizationInfo associated with this principals. | ||
* @see SimpleAuthorizationInfo | ||
*/ | ||
@Override | ||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { | ||
return new SimpleAuthorizationInfo(); | ||
} | ||
|
||
/** | ||
* Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for the given | ||
* authentication token. | ||
* <p/> | ||
* For most datasources, this means just 'pulling' authentication data for an associated subject/user and nothing | ||
* more and letting Shiro do the rest. But in some systems, this method could actually perform EIS specific | ||
* log-in logic in addition to just retrieving data - it is up to the Realm implementation. | ||
* <p/> | ||
* A {@code null} return value means that no account could be associated with the specified token. | ||
* | ||
* @param token the authentication token containing the user's principal and credentials. | ||
* @return an {@link AuthenticationInfo} object containing account data resulting from the | ||
* authentication ONLY if the lookup is successful (i.e. account exists and is valid, etc.) | ||
* @throws AuthenticationException if there is an error acquiring data or performing | ||
* realm-specific authentication logic for the specified <tt>token</tt> | ||
*/ | ||
@Override | ||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { | ||
UsernamePasswordToken upToken = (UsernamePasswordToken) token; | ||
String username = upToken.getUsername(); | ||
String password = new String(upToken.getPassword()); | ||
User user = new User(username); | ||
return new SimpleAuthenticationInfo(user, password, getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
shiro-casbin: | ||
modelPath: classpath:casbin/rbac_model.conf | ||
policyPath: classpath:casbin/rbac_policy.csv | ||
|
||
spring: | ||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:3306/casbin?serverTimezone=GMT%2B8 | ||
username: casbin_test | ||
password: TEST_casbin | ||
|
||
shiro-casbin: | ||
model-path: classpath:casbin/keymatch_model.conf | ||
policy-path: classpath:casbin/keymatch_policy.csv | ||
user-name-method-name: getUsername |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p, admin, /data/*, (GET|POST) | ||
p, common, /data/data1, GET | ||
g, alice, admin | ||
g, bob, common |
Oops, something went wrong.