当前位置: 首页>>代码示例>>Java>>正文


Java SimplePrincipalCollection.add方法代码示例

本文整理汇总了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;
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:18,代码来源:BearerAuthenticationInfo.java

示例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.
   }
 
开发者ID:usydapeng,项目名称:thymeleaf3-shiro,代码行数:17,代码来源:TestIniRealm.java

示例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;
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:18,代码来源:StatelessRealm.java

示例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;
    }
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:19,代码来源:JsonWebTokenCredentialsMatcher.java

示例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());
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:26,代码来源:ScmPublicKeyRealm.java

示例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());
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:27,代码来源:ScmPasswordRealm.java

示例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;
}
 
开发者ID:luozhengjie,项目名称:RLCMS,代码行数:9,代码来源:RLCMSAuthenticationInfo.java

示例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);
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:11,代码来源:ShiroTestUtils.java

示例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);
}
 
开发者ID:CIDARLAB,项目名称:clotho3crud,代码行数:11,代码来源:ClothoAccount.java

示例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);
}
 
开发者ID:theborakompanioni,项目名称:thymeleaf-extras-shiro,代码行数:16,代码来源:TestIniRealm.java

示例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;
}
 
开发者ID:freedomotic,项目名称:freedomotic,代码行数:39,代码来源:UserConverter.java

示例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);
}
 
开发者ID:TomChen001,项目名称:xmanager,代码行数:10,代码来源:ShiroDbRealm.java

示例15: getPrincipals

import org.apache.shiro.subject.SimplePrincipalCollection; //导入方法依赖的package包/类
@Override
public PrincipalCollection getPrincipals() {
    SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
    principalCollection.add(user.getUsername(), "JPA");
    return principalCollection;
}
 
开发者ID:felixhusse,项目名称:bookery,代码行数:7,代码来源:AppUserAuthenticationInfo.java


注:本文中的org.apache.shiro.subject.SimplePrincipalCollection.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。