public static JaxbRole fromRole(Role role) { if (role instanceof JaxbRole) return (JaxbRole) role; JaxbOrganization org = JaxbOrganization.fromOrganization(role.getOrganization()); return new JaxbRole(role.getName(), org, role.getDescription(), role.getType()); }
/** * Constructs an organization from an organization * * @param org * the organization */ public static JaxbOrganization fromOrganization(Organization org) { if (org instanceof JaxbOrganization) return (JaxbOrganization) org; return new JaxbOrganization(org.getId(), org.getName(), org.getServers(), org.getAdminRole(), org.getAnonymousRole(), org.getProperties()); }
/** * Create the global anonymous user with the given organization. * * @param org * the organization * @return the global anonymous user */ public static User createAnonymousUser(Organization org) { JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(org); return new JaxbUser(GLOBAL_ANONYMOUS_USERNAME, null, jaxbOrganization, new JaxbRole( jaxbOrganization.getAnonymousRole(), jaxbOrganization)); }
/** Get a user of a certain organization by its ID. */ public static Option<User> getUserOfOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId) { final Organization prevOrg = sec.getOrganization(); try { final Organization org = orgDir.getOrganization(orgId); sec.setOrganization(org); return option(userDir.loadUser(userId)); } catch (NotFoundException e) { return none(); } finally { sec.setOrganization(prevOrg); } }
/** * Create a system user for the given organization with global and organization local admin role. Get the * <code>systemUserName</code> from the global config where it is stored under {@link #PROPERTY_KEY_SYS_USER}. In an * OSGi environment this is typically done calling * <code>componentContext.getBundleContext().getProperty(PROPERTY_KEY_SYS_USER)</code>. * * @see #createSystemUser(org.osgi.service.component.ComponentContext, org.opencastproject.security.api.Organization) */ public static User createSystemUser(String systemUserName, Organization org) { JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(org); return new JaxbUser(systemUserName, null, jaxbOrganization, new JaxbRole(GLOBAL_ADMIN_ROLE, jaxbOrganization), new JaxbRole(org.getAdminRole(), jaxbOrganization)); }
public static JaxbGroup fromGroup(Group group) { JaxbOrganization organization = JaxbOrganization.fromOrganization(group.getOrganization()); Set<JaxbRole> roles = new HashSet<JaxbRole>(); for (Role role : group.getRoles()) { if (role instanceof JaxbRole) { roles.add((JaxbRole) role); } else { roles.add(JaxbRole.fromRole(role)); } } return new JaxbGroup(group.getGroupId(), organization, group.getName(), group.getDescription(), roles, group.getMembers()); }
@Override public JaxbRole apply(String role, Organization organization) { return new JaxbRole(role, JaxbOrganization.fromOrganization(organization)); } };
/** * {@inheritDoc} * * @see org.opencastproject.security.api.UserProvider#getOrganization() */ @Override public String getOrganization() { return organization.getId(); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (!(obj instanceof Role)) return false; Role other = (Role) obj; return name.equals(other.getName()) && organization.equals(other.getOrganization()); }
/** * Sets the workflow's organization. * * @param organization * the organization */ public void setOrganization(Organization organization) { if (organization == null) this.organization = null; else this.organization = JaxbOrganization.fromOrganization(organization); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (!(obj instanceof Group)) return false; Group other = (Group) obj; return groupId.equals(other.getGroupId()) && organization.equals(other.getOrganization()); }
/** * Closes any http connections kept open by this http response. */ protected void closeConnection(HttpResponse response) { if (response != null) client.close(response); }
@Override public JaxbUser marshal(User user) throws Exception { if (user == null) return null; if (user instanceof JaxbUser) return (JaxbUser) user; return JaxbUser.fromUser(user); }
/** * Constructs an UnauthorizedException for the specified user's attempt to take a specified action. * * @param user * the current user * @param action * the action attempted */ public UnauthorizedException(User user, String action) { super(formatMessage(user, action, null)); }
@Override public String apply(AccessControlList acl) { return toJsonSilent(acl); } };
@Override public AccessControlList apply(String s) { return parseAclSilent(s); } };
@Override public Boolean apply(Object action) { return isAuthorized(acl, user, org, action); } };
@Override public String toString() { return this.getValue(); }
/** * {@inheritDoc} * * @see org.opencastproject.security.api.UserProvider#getOrganization() */ @Override public String getOrganization() { return organization.getId(); }
@Override public JaxbOrganization marshal(Organization org) throws Exception { if (org == null) return null; if (org instanceof JaxbOrganization) return (JaxbOrganization) org; return JaxbOrganization.fromOrganization(org); }