本文整理汇总了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;
}