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.sql.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 class PersonTokenRoleString {
	public static String personTokenRoleString(Connection cUUID personUuidthrows SQLException {
		StringBuffer roleString = new StringBuffer();
		PreparedStatement s = null;
		ResultSet r = null;
		try {
					"select role, resource, uid " +
					"from role " +
					"where assignee_uuid=? " +
					"union " +
					"select r.role, r.resource, r.uid " +
					"from group_member gm join role r on (gm.person_uuid=? and r.assignee_uuid=gm.group_uuid)");
			s.setString(1, personUuid.toString());
			s.setString(2, personUuid.toString());
			r = s.executeQuery();
			while(r.next()) {
				if(roleString.length() > 0) {
					roleString.append("|");
				}
				if(r.getString(2) != null && r.getString(2).length() > 0) {
					roleString.append(r.getString(1));
					roleString.append(":");
					roleString.append(r.getString(2));
					roleString.append(":");
					roleString.append(r.getString(3));
else {
					roleString.append(r.getString(1));
				}
			}
			r.close();
			r = null;
			s.close();
			s = null;
finally {
			if(r != null) { try { r.close(); } catch(SQLException e) {} }
			if(s != null) { try { s.close(); } catch(SQLException e) {} }
		}
		return roleString.toString();
	}
New to GrepCode? Check out our FAQ X