當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。