Index: api/src/main/java/org/sakaiproject/authz/api/MemberWithRoleId.java =================================================================== --- api/src/main/java/org/sakaiproject/authz/api/MemberWithRoleId.java (revision 306447) +++ api/src/main/java/org/sakaiproject/authz/api/MemberWithRoleId.java (working copy) @@ -19,9 +19,9 @@ * **********************************************************************************/ -package org.sakaiproject.authz.impl; +package org.sakaiproject.authz.api; -import org.sakaiproject.authz.api.Member; +import java.io.Serializable; /** * An class used in the membership cache in RealmRoleGroupCache @@ -28,11 +28,16 @@ * The cache key is userId String, * and cache value is of MemberWithRoleId object, which contains information of roleId, provided, active * KNL-1037 + * + * Moved this to API (shared) so it can be serializable for distribution + * KNL-1184 * * @author zqian */ -class MemberWithRoleId -{ +public class MemberWithRoleId implements Serializable { + + static final long serialVersionUID = 1L; + protected String roleId = null; protected boolean provided = false; protected boolean active = true; @@ -79,4 +84,5 @@ { this.active = active; } -} \ No newline at end of file + +} Index: api/src/main/java/org/sakaiproject/authz/api/SimpleRole.java =================================================================== --- api/src/main/java/org/sakaiproject/authz/api/SimpleRole.java (revision 0) +++ api/src/main/java/org/sakaiproject/authz/api/SimpleRole.java (working copy) @@ -0,0 +1,84 @@ +/********************************************************************************** + * $URL$ + * $Id$ + *********************************************************************************** + * + * Copyright (c) 2014 Apereo Foundation + * + * Licensed under the Educational Community License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.opensource.org/licenses/ECL-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + **********************************************************************************/ + +package org.sakaiproject.authz.api; + +import java.io.Serializable; +import java.util.Set; + +/** + * SimpleRole is a class that allows BaseRole (Role) to be serializable for distribution + * This class should only have getters/setters and should be serializable. + * KNL-1184 + */ +public class SimpleRole implements Serializable { + + static final long serialVersionUID = 1L; + + private String id; + private Set locks; + private String description; + private boolean providerOnly; + private boolean active; + + public SimpleRole() { } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Set getLocks() { + return this.locks; + } + + public void setLocks(Set locks) { + this.locks = locks; + } + + public boolean isActive() { + return this.active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isProviderOnly() { + return this.providerOnly; + } + + public void setProviderOnly(boolean providerOnly) { + this.providerOnly = providerOnly; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} Property changes on: api/src/main/java/org/sakaiproject/authz/api/SimpleRole.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Date Revision Author HeadURL Id \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: api/src/main/java/org/sakaiproject/event/api/Event.java =================================================================== --- api/src/main/java/org/sakaiproject/event/api/Event.java (revision 306447) +++ api/src/main/java/org/sakaiproject/event/api/Event.java (working copy) @@ -21,6 +21,7 @@ package org.sakaiproject.event.api; +import java.io.Serializable; import java.util.Date; /** @@ -28,7 +29,7 @@ * Event represents a single significant activity by the end-user. *

*/ -public interface Event +public interface Event extends Serializable { /** * Access the event id string Index: api/src/main/java/org/sakaiproject/event/api/SimpleEvent.java =================================================================== --- api/src/main/java/org/sakaiproject/event/api/SimpleEvent.java (revision 0) +++ api/src/main/java/org/sakaiproject/event/api/SimpleEvent.java (working copy) @@ -0,0 +1,265 @@ +/********************************************************************************** + * $URL$ + * $Id$ + *********************************************************************************** + * + * Copyright (c) 2014 Apereo Foundation + * + * Licensed under the Educational Community License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.opensource.org/licenses/ECL-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + **********************************************************************************/ + +package org.sakaiproject.event.api; + +import java.util.Date; + +/** + * Allows Event object to be serializable for distribution + * KNL-1184 + */ +public class SimpleEvent implements Event { + + static final long serialVersionUID = 1L; + + /** + * Constructor + * + * Converts an Event object into a SimpleEvent object + * in order to be serializable for distribution + * + * @param event the event object + * @param serverId the server id this event originated from + */ + public SimpleEvent(Event event, String serverId) { + if (event == null) { + throw new IllegalArgumentException("The SimpleEvent event cannot be null."); + } + if (serverId == null) { + throw new IllegalArgumentException("The SimpleEvent serverId cannot be null."); + } + + setEvent(event.getEvent()); + setResource(event.getResource()); + setSessionId(event.getSessionId()); + setUserId(event.getUserId()); + setContext(event.getContext()); + setModify(event.getModify()); + setPriority(event.getPriority()); + setEventTime(event.getEventTime()); + setServerId(serverId); + } + + /** The Event's sequence number. */ + protected long seq = 0; + + /** The Event's id string. */ + protected String id = ""; + + /** The Event's resource reference string. */ + protected String resource = ""; + + /** The Event's context. May be null. */ + protected String context = null; + + /** The Event's session id string. May be null. */ + protected String session = null; + + /** The Event's user id string. May be null. */ + protected String user = null; + + /** The Event's modify flag (true if the event caused a resource modification). */ + protected boolean modify = false; + + /** The Event's notification priority. */ + protected int priority = NotificationService.NOTI_OPTIONAL; + + /** Event creation time. */ + protected Date time = null; + + /** Event server ID */ + protected String serverId = null; + + /** + * Access the event id string + * + * @return The event id string. + */ + public String getEvent() { + return id; + } + + /** + * Set the event id. + * + * @param id + * The event id string. + */ + public void setEvent(String id) { + this.id = (id != null) ? id : ""; + } + + /** + * Access the resource reference. + * + * @return The resource reference string. + */ + public String getResource() { + return resource; + } + + /** + * Set the resource id. + * + * @param id + * The resource id string. + */ + public void setResource(String id) { + resource = (id != null) ? id : ""; + } + + /** + * Access the resource reference. + * + * @return The resource reference string. + */ + public String getContext() { + return context; + } + + /** + * Set the resource reference + * + * @param context resource reference + */ + public void setContext(String context) { + this.context = context; + } + + /** + * Access the UsageSession id. If null, check for a User id. + * + * @return The UsageSession id string. + */ + public String getSessionId() { + return session; + } + + /** + * Set the session id. + * + * @param id + * The session id string. + */ + public void setSessionId(String id) { + session = ((id != null) && (id.length() > 0)) ? id : null; + } + + /** + * Access the User id. If null, check for a session id. + * + * @return The User id string. + */ + public String getUserId() { + return user; + } + + /** + * Set the user id. + * + * @param id + * The user id string. + */ + public void setUserId(String id) { + user = ((id != null) && (id.length() > 0)) ? id : null; + } + + /** + * Is this event one that caused a modify to the resource, or just an access. + * + * @return true if the event caused a modify to the resource, false if it was just an access. + */ + public boolean getModify() { + return modify; + } + + /** + * Set resource modify or access + * + * @param modify modified event + */ + public void setModify(boolean modify) { + this.modify = modify; + } + + /** + * Access the event's notification priority. + * + * @return The event's notification priority. + */ + public int getPriority() { + return priority; + } + + /** + * Set the event's notification priority + * + * @param priority level + */ + public void setPriority(int priority) { + this.priority = priority; + } + + /** + * Get the server's ID + * + * @return the server ID string + */ + public String getServerId() { + return serverId; + } + + /** + * Set the server ID string + * + * @param serverId id string + */ + public void setServerId(String serverId) { + this.serverId = serverId; + } + + /** + * Get the event's time + * + * @return the event date + */ + public Date getEventTime() { + return time; + } + + /** + * Set the event's date + * + * @param time date event occurred + */ + public void setEventTime(Date time) { + this.time = time; + } + + /** + * @return A representation of this event's values as a string. + */ + public String toString() { + return seq + ":" + getEvent() + "@" + getResource() + "[" + (getModify() ? "m" : "a") + ", " + getPriority() + "]"; + } + +} Property changes on: api/src/main/java/org/sakaiproject/event/api/SimpleEvent.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Date Revision Author HeadURL Id \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/BaseRole.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/BaseRole.java (revision 306447) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/BaseRole.java (working copy) @@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory; import org.sakaiproject.authz.api.AuthzGroup; import org.sakaiproject.authz.api.Role; +import org.sakaiproject.authz.api.SimpleRole; import org.sakaiproject.util.Xml; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -67,6 +68,22 @@ protected boolean m_active = false; /** + * creates a new BaseRole, based on a SimpleRole which was exported in a previous + * step, in order to support distributed cluster caching. BaseRole cannot be serialized by + * distributed caches because of ClassLoader issues. + * @param map + */ + public BaseRole(SimpleRole role) { + if (role != null) { + m_id = role.getId(); + m_locks = role.getLocks(); + m_description = role.getDescription(); + m_providerOnly = role.isProviderOnly(); + m_active = role.isActive(); + } + } + + /** * Construct. * * @param id @@ -327,6 +344,22 @@ return compare; } + + /** + * exports the contents of BaseRole to a primitive Map, which can be Serialized + * if necessary to support Terracotta cluster caching. BaseRole cannot be serialized by + * Terracotta because of classloader issues. + * @return + */ + public SimpleRole exportToSimpleRole() { + SimpleRole role = new SimpleRole(); + role.setId(m_id); + role.setLocks(m_locks); + role.setDescription(m_description); + role.setProviderOnly(m_providerOnly); + role.setActive(m_active); + return role; + } /** * {@inheritDoc} Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupService.java (revision 306447) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupService.java (working copy) @@ -40,11 +40,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.sakaiproject.authz.api.AuthzGroup; -import org.sakaiproject.authz.api.GroupFullException; -import org.sakaiproject.authz.api.Member; -import org.sakaiproject.authz.api.Role; -import org.sakaiproject.authz.api.GroupNotDefinedException; +import org.sakaiproject.authz.api.*; import org.sakaiproject.db.api.SqlReader; import org.sakaiproject.db.api.SqlService; import org.sakaiproject.entity.api.Entity; Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/MemberWithRoleId.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/MemberWithRoleId.java (revision 306447) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/MemberWithRoleId.java (working copy) @@ -1,82 +0,0 @@ -/********************************************************************************** - * $URL$ - * $Id$ - *********************************************************************************** - * - * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Sakai Foundation - * - * Licensed under the Educational Community License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.opensource.org/licenses/ECL-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - **********************************************************************************/ - -package org.sakaiproject.authz.impl; - -import org.sakaiproject.authz.api.Member; - -/** - * An class used in the membership cache in RealmRoleGroupCache - * The cache key is userId String, - * and cache value is of MemberWithRoleId object, which contains information of roleId, provided, active - * KNL-1037 - * - * @author zqian - */ -class MemberWithRoleId -{ - protected String roleId = null; - protected boolean provided = false; - protected boolean active = true; - - public MemberWithRoleId(String roleId, boolean active, boolean provided) - { - this.roleId = roleId; - this.active = active; - this.provided = provided; - } - - public MemberWithRoleId(Member m) - { - this.roleId = m.getRole() != null? m.getRole().getId():null; - this.active = m.isActive(); - this.provided = m.isProvided(); - } - - public String getRoleId() - { - return roleId; - } - - /** - * whether the member is provided or not - */ - public boolean isProvided() - { - return provided; - } - - /** - * whether the member is active or not - */ - public boolean isActive() - { - return active; - } - - /** - * set the active attribute - */ - public void setActive(boolean active) - { - this.active = active; - } -} \ No newline at end of file