Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.jee.api.cassandra.util;
 
Update the cached role information in tokens associated with a particular person. Maintaining a cached version of a users role information in the token table decreases the number of round trips to the database, one query can be used to both validate a token, and get information about a users access privileges.
	public static void updatePersonTokenRoleString(Session sUUID personUuid) {
		PreparedStatement p = s.prepare("select uid from session_token where person_uuid=?");
		PreparedStatement t = s.prepare("update session_token set roles=? where uid=?");
		String roles = null;
		for(Row r : s.execute(p.bind(personUuid))) {
			if(roles == null) {
				roles = personTokenRoleString(spersonUuid);
			}
			s.execute(t.bind(rolesr.getString(0)));
		}
	}
	public static String personTokenRoleString(Session sUUID personUuid) {
		StringBuffer roleString = new StringBuffer();
		PreparedStatement p = s.prepare("select role, resource, uid from role where person_uuid=? allow filtering");
		for(Row r : s.execute(p.bind(personUuid))) {
			if(roleString.length() > 0) {
				roleString.append("|");
			}
			if(!r.getString(1).equals("#")) {
				roleString.append(r.getString(0));
				roleString.append(":");
				roleString.append(r.getString(1));
				roleString.append(":");
				roleString.append(r.getString(2));
else {
				roleString.append(r.getString(0));
			}
		}
		return roleString.toString();
	}
New to GrepCode? Check out our FAQ X