Skip to content

Commit

Permalink
Merge pull request Azure#8 from WindowsAzure/dev
Browse files Browse the repository at this point in the history
forward integration from WindowsAzure/dev to gcheng/dev
  • Loading branch information
Albert Cheng committed Sep 17, 2012
2 parents d2b0190 + cc5b520 commit 87d3da5
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.project
target
node_modules
.settings

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
package com.microsoft.windowsazure.services.media;

import com.microsoft.windowsazure.services.core.Builder;
import com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor;
import com.microsoft.windowsazure.services.media.implementation.MediaRestProxy;
import com.microsoft.windowsazure.services.media.implementation.OAuthContract;
import com.microsoft.windowsazure.services.media.implementation.OAuthFilter;
import com.microsoft.windowsazure.services.media.implementation.OAuthRestProxy;
import com.microsoft.windowsazure.services.media.implementation.OAuthTokenManager;
import com.microsoft.windowsazure.services.media.implementation.RedirectFilter;
import com.microsoft.windowsazure.services.media.implementation.ResourceLocationManager;

public class Exports implements Builder.Exports {

Expand All @@ -27,9 +31,14 @@ public class Exports implements Builder.Exports {
*/
@Override
public void register(Builder.Registry registry) {
registry.add(MediaContract.class, MediaExceptionProcessor.class);
registry.add(MediaExceptionProcessor.class);
registry.add(MediaRestProxy.class);
registry.add(OAuthContract.class, OAuthRestProxy.class);
registry.add(OAuthTokenManager.class);
registry.add(OAuthFilter.class);
registry.add(ResourceLocationManager.class);
registry.add(RedirectFilter.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.microsoft.windowsazure.services.core.Configuration;

/**
* Provides functionality to create a service bus configuration.
* Provides functionality to create a media services configuration.
*
*/
public class MediaConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2011 Microsoft Corporation
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-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 com.microsoft.windowsazure.services.media;

import com.microsoft.windowsazure.services.core.FilterableService;

/**
*
* Defines the methods available for Windows Azure Media Services
*
*/
public interface MediaContract extends FilterableService<MediaContract> {

// Will fill in as we implement the various Media Services entities

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright 2011 Microsoft Corporation
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-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 com.microsoft.windowsazure.services.media;

import com.microsoft.windowsazure.services.core.Configuration;

/**
*
* Access media services functionality. This class cannot
* be instantiated.
*
*/
public class MediaService {

private MediaService() {
}

/**
* Creates an instance of the <code>MediaServicesContract</code> API.
*
*/
public static MediaContract create() {
return Configuration.getInstance().create(MediaContract.class);
}

/**
* Creates an instance of the <code>MediaServicesContract</code> API using the specified configuration.
*
* @param config
* A <code>Configuration</code> object that represents the configuration for the service bus service.
*
*/
public static MediaContract create(Configuration config) {
return config.create(MediaContract.class);
}

/**
* Creates an instance of the <code>MediaServicesContract</code> API.
*
*/
public static MediaContract create(String profile) {
return Configuration.getInstance().create(profile, MediaContract.class);
}

/**
* Creates an instance of the <code>MediaServicesContract</code> API using the specified configuration.
*
* @param config
* A <code>Configuration</code> object that represents the configuration for the service bus service.
*
*/
public static MediaContract create(String profile, Configuration config) {
return config.create(profile, MediaContract.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright 2011 Microsoft Corporation
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-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 com.microsoft.windowsazure.services.media.implementation;

import javax.inject.Inject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory;
import com.microsoft.windowsazure.services.media.MediaContract;

/**
* Wrapper implementation of <code>MediaServicesContract</code> that
* translates exceptions into ServiceExceptions.
*
*/
public class MediaExceptionProcessor implements MediaContract {

private final MediaContract next;
static Log log = LogFactory.getLog(MediaContract.class);

public MediaExceptionProcessor(MediaContract next) {
this.next = next;
}

@Inject
public MediaExceptionProcessor(MediaRestProxy next) {
this.next = next;
}

@Override
public MediaContract withFilter(ServiceFilter filter) {
return new MediaExceptionProcessor(next.withFilter(filter));
}

private ServiceException processCatch(ServiceException e) {
log.warn(e.getMessage(), e.getCause());
return ServiceExceptionFactory.process("MediaServices", e);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright 2011 Microsoft Corporation
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-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 com.microsoft.windowsazure.services.media.implementation;

import java.util.Arrays;

import javax.inject.Inject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

public class MediaRestProxy implements MediaContract {

private Client channel;
static Log log = LogFactory.getLog(MediaContract.class);

ServiceFilter[] filters;

@Inject
public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) {
this.channel = channel;
this.filters = new ServiceFilter[0];
channel.addFilter(redirectFilter);
channel.addFilter(authFilter);
}

public MediaRestProxy(Client channel, ServiceFilter[] filters) {
this.channel = channel;
this.filters = filters;
}

@Override
public MediaContract withFilter(ServiceFilter filter) {
ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1);
newFilters[filters.length] = filter;
return new MediaRestProxy(channel, newFilters);
}

public Client getChannel() {
return channel;
}

public void setChannel(Client channel) {
this.channel = channel;
}

private WebResource getResource(String entityName) {
WebResource resource = getChannel().resource(entityName);
for (ServiceFilter filter : filters) {
resource.addFilter(new ClientFilterAdapter(filter));
}
return resource;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import java.net.URISyntaxException;
import java.util.Date;

import javax.inject.Named;
import javax.management.timer.Timer;

import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.core.utils.DateFactory;
import com.microsoft.windowsazure.services.media.MediaConfiguration;

/**
* An OAuth token manager class.
Expand Down Expand Up @@ -59,8 +61,11 @@ public class OAuthTokenManager {
* A <code>String</code> object instance that represents the client secret.
*
*/
public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory, URI acsBaseUri, String clientId,
String clientSecret, String scope) {
public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory,
@Named(MediaConfiguration.OAUTH_URI) URI acsBaseUri,
@Named(MediaConfiguration.OAUTH_CLIENT_ID) String clientId,
@Named(MediaConfiguration.OAUTH_CLIENT_SECRET) String clientSecret,
@Named(MediaConfiguration.OAUTH_SCOPE) String scope) {
this.contract = contract;
this.dateFactory = dateFactory;
this.acsBaseUri = acsBaseUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
import java.net.URI;
import java.net.URISyntaxException;

import javax.inject.Named;
import javax.ws.rs.core.UriBuilder;

import com.microsoft.windowsazure.services.media.MediaConfiguration;

public class ResourceLocationManager {
private URI baseURI;

public ResourceLocationManager(String baseUri) throws URISyntaxException {
public ResourceLocationManager(@Named(MediaConfiguration.URI) String baseUri) throws URISyntaxException {
this.baseURI = new URI(baseUri);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright 2011 Microsoft Corporation
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-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 com.microsoft.windowsazure.services.media.models;

import java.util.EnumSet;

/**
* Permissions available to an access policy
*
*/
public enum AccessPolicyPermission {
NONE(0), READ(1), WRITE(2), DELETE(4), LIST(8);

private int flagValue;

private AccessPolicyPermission(int value) {
flagValue = value;
}

/**
* Get the flag bit value associated with this permission
*
* @return The integer permission value
*/
public int getFlagValue() {
return flagValue;
}

/**
* Given an integer representing the permissions as a bit vector,
* convert it into an <code>EnumSet&lt;AccessPolicyPermission&gt;</code> object containing the correct permissions
* *
*
* @param bits
* The bit vector of permissions
* @return The set of permissions in an <code>EnumSet</code> object.
*/
public static EnumSet<AccessPolicyPermission> permissionsFromBits(int bits) {
EnumSet<AccessPolicyPermission> perms = EnumSet.of(AccessPolicyPermission.NONE);

for (AccessPolicyPermission p : AccessPolicyPermission.values()) {
if ((bits & p.getFlagValue()) != 0) {
perms.remove(AccessPolicyPermission.NONE);
perms.add(p);
}
}

return perms;
}

/**
* Convert an <code>EnumSet</code> containing permissions into the
* corresponding integer bit vector to be passed to Media services.
*
* @param perms
* The permissions
* @return The bit vector to go out over the wire.
*/
public static int bitsFromPermissions(EnumSet<AccessPolicyPermission> perms) {
int result = 0;
for (AccessPolicyPermission p : perms) {
result |= p.getFlagValue();
}

return result;
}
}
Loading

0 comments on commit 87d3da5

Please sign in to comment.