本文整理匯總了Java中org.apache.shiro.subject.SimplePrincipalCollection.add方法的典型用法代碼示例。如果您正苦於以下問題:Java SimplePrincipalCollection.add方法的具體用法?Java SimplePrincipalCollection.add怎麽用?Java SimplePrincipalCollection.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.subject.SimplePrincipalCollection
的用法示例。
在下文中一共展示了SimplePrincipalCollection.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPrincipals
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Override
public PrincipalCollection getPrincipals() {
RealmSecurityManager manager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
SimplePrincipalCollection ret = new SimplePrincipalCollection();
for (Realm realm : manager.getRealms()) {
/*
if (realm instanceof ProfileRealm) {
String email = token.getEmail();
if (((ProfileRealm) realm).accountExists(email)) {
ret.add(email, realm.getName());
}
}
*/
}
ret.add(token.getEmail(), bearerTokenAuthenticatingRealm.getName());
return ret;
}
示例2: add
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Override
protected void add(SimpleAccount account) {
String username = (String)account.getPrincipals().getPrimaryPrincipal();
// Let's add some additional principals for testing
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
principalCollection.addAll(account.getPrincipals());
principalCollection.add(counter.getAndIncrement(), "integerRealm");
TestObjPrincipal objPrinc = new TestObjPrincipal(username.toUpperCase()+" "+username.toUpperCase());
principalCollection.add(objPrinc, "objRealm");
account.setPrincipals(principalCollection);
super.add(account); //To change body of generated methods, choose Tools | Templates.
}
示例3: doGetAuthorizationInfo
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// 根據用戶名查找角色,請根據需求實現
String username = (String) principals.getPrimaryPrincipal();
User user = userService.findByName(username);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) principals;
principalCollection.clear();
principalCollection.add(user, getName());
RolePermission rolePermission = user.new RolePermission();
authorizationInfo.setRoles(rolePermission.getRoleSet());
authorizationInfo.setStringPermissions(rolePermission.getPermissionSet());
return authorizationInfo;
}
示例4: doCredentialsMatch
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
JsonWebToken jsonWebToken = (JsonWebToken) token;
JWTVerifier verifier = new JWTVerifier(secret, audience);
try {
Map<String, Object> map = verifier.verify(jsonWebToken.getToken());
SimpleAuthenticationInfo authenticationInfo = (SimpleAuthenticationInfo) info;
String realmName = authenticationInfo.getPrincipals().getRealmNames().iterator().next();
SimplePrincipalCollection principals = new SimplePrincipalCollection();
principals.add(map.get("iss"), realmName);
authenticationInfo.setPrincipals(principals);
return true;
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | SignatureException
| IOException | JWTVerifyException e) {
log.debug(e.getMessage());
return false;
}
}
示例5: createAuthenticationInfo
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
/**
* Method description
*
*
* @param token
* @param result
*
* @return
*/
private AuthenticationInfo createAuthenticationInfo(PublicKeyToken token,
AuthenticationResult result) {
User user = result.getUser();
Collection<String> groups = authenticate(result);
SimplePrincipalCollection collection = new SimplePrincipalCollection();
/*
* the first (primary) principal should be a unique identifier
*/
collection.add(user.getId(), NAME);
collection.add(user, NAME);
collection.add(new GroupNames(groups), NAME);
return new SimpleAuthenticationInfo(collection, token.getPublicKey());
}
示例6: createAuthenticationInfo
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
/**
* Method description
*
*
* @param token
* @param result
*
* @return
*/
private AuthenticationInfo createAuthenticationInfo(
UsernamePasswordToken token, AuthenticationResult result) {
User user = result.getUser();
Collection<String> groups = authenticate(
new String(token.getPassword()), result);
SimplePrincipalCollection collection = new SimplePrincipalCollection();
/*
* the first (primary) principal should be a unique identifier
*/
collection.add(user.getId(), NAME);
collection.add(user, NAME);
collection.add(new GroupNames(groups), NAME);
return new SimpleAuthenticationInfo(collection, token.getPassword());
}
示例7: RLCMSAuthenticationInfo
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
public RLCMSAuthenticationInfo(String realmName, List<Map<String, Object>> permissions, Object credentials){
this.credentials = credentials;
SimplePrincipalCollection spc = new SimplePrincipalCollection();
for(Map<String, Object> map : permissions){
spc.add(map.get("permission"), realmName);
}
this.principalCollection = spc;
}
示例8: mockCurrentUser
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
public static void mockCurrentUser(User user, boolean isSuperAdmin) {
Subject subject = Mockito.mock(Subject.class);
Mockito.when(subject.isAuthenticated()).thenReturn(true);
Mockito.when(subject.getPrincipal()).thenReturn(user.getUsername());
SimplePrincipalCollection principals = new SimplePrincipalCollection(user.getUsername(), "root");
principals.add(user, "root");
Mockito.when(subject.getPrincipals()).thenReturn(principals);
Mockito.when(subject.hasRole(ADMIN)).thenReturn(isSuperAdmin);
bindSubject(subject);
}
示例9: ClothoAccount
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
public ClothoAccount(String username, String password){
this(username);
authcInfo = new SimpleAuthenticationInfo();
SimplePrincipalCollection principals = new SimplePrincipalCollection();
principals.add(username, "clotho");
authcInfo.setPrincipals(principals);
setPassword(password);
}
示例10: getsUserRoles
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Test @MongoData("/principals.json")
public void getsUserRoles() {
SimplePrincipalCollection principals=new SimplePrincipalCollection();
principals.add("sample-principal-user","fooRealm");
AuthorizationInfo info=realm.doGetAuthorizationInfo(principals);
assertEqualsNoOrder(info.getRoles().toArray(),new String[] {"role:user"});
}
開發者ID:TensorWrench,項目名稱:shiro-mongodb-realm,代碼行數:8,代碼來源:MongoUserPasswordRealmAuthorizationTest.java
示例11: getsAdminRoles
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Test @MongoData("/principals.json")
public void getsAdminRoles() {
SimplePrincipalCollection principals=new SimplePrincipalCollection();
principals.add("sample-principal-admin","fooRealm");
AuthorizationInfo info=realm.doGetAuthorizationInfo(principals);
assertEqualsNoOrder(info.getRoles().toArray(),new String[] {"role:user","role:admin"});
}
開發者ID:TensorWrench,項目名稱:shiro-mongodb-realm,代碼行數:8,代碼來源:MongoUserPasswordRealmAuthorizationTest.java
示例12: add
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Override
protected void add(SimpleAccount account) {
String username = (String) account.getPrincipals().getPrimaryPrincipal();
// Let's add some additional principals for testing
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
principalCollection.addAll(account.getPrincipals());
principalCollection.add(counter.getAndIncrement(), "integerRealm");
TestObjPrincipal objPrinc = new TestObjPrincipal(username.toUpperCase() + " " + username.toUpperCase());
principalCollection.add(objPrinc, "objRealm");
account.setPrincipals(principalCollection);
super.add(account);
}
示例13: unmarshal
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
/**
*{@inheritDoc}}
*/
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext uc) {
SimplePrincipalCollection pc = new SimplePrincipalCollection();
User user = null;
reader.moveDown(); //principals
while (reader.hasMoreChildren()) {
reader.moveDown();
String realm = reader.getAttribute("realm");
pc.add(reader.getValue(), realm);
// reader.getAttribute("primary"); // ???
reader.moveUp();
}
reader.moveUp(); //end principals
reader.moveDown(); // credentials
user = new User(pc, reader.getValue(), Freedomotic.INJECTOR.getInstance(Auth.class));
reader.moveUp(); // end credentials
reader.moveDown(); //salt
user.setCredentialsSalt(ByteSource.Util.bytes(Base64.decode(reader.getValue())));
reader.moveUp();
reader.moveDown();
while (reader.hasMoreChildren()) {
reader.moveDown();
user.addRole(reader.getAttribute("name"));
reader.moveUp();
}
reader.moveUp();
reader.moveDown(); //properties
while (reader.hasMoreChildren()) {
reader.moveDown();
user.setProperty(reader.getAttribute("name"), reader.getAttribute("value"));
reader.moveUp();
}
reader.moveUp();
return user;
}
示例14: removeUserCache
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
/**
* 清除用戶緩存
* @param loginName
*/
public void removeUserCache(String loginName){
SimplePrincipalCollection principals = new SimplePrincipalCollection();
principals.add(loginName, super.getName());
super.clearCachedAuthenticationInfo(principals);
}
示例15: getPrincipals
import org.apache.shiro.subject.SimplePrincipalCollection; //導入方法依賴的package包/類
@Override
public PrincipalCollection getPrincipals() {
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
principalCollection.add(user.getUsername(), "JPA");
return principalCollection;
}