summaryrefslogtreecommitdiffstats
path: root/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 06:27:21 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 06:27:21 +0000
commitaf2857365e659d99dda12bee356681ab7b789822 (patch)
tree8ae162fb541c1f5dabecf91f46bee0ba7d428f71 /sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
parent911069d0f429934349fa7b72160c864716fb011c (diff)
Adding user services and integrating with the store application
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829708 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java b/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
new file mode 100644
index 0000000000..bb449b22d3
--- /dev/null
+++ b/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.tuscany.sca.cloud.user.impl;
+
+import org.apache.tuscany.sca.cloud.user.User;
+import org.apache.tuscany.sca.cloud.user.UserContext;
+import org.apache.tuscany.sca.cloud.user.UserService;
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+import com.google.appengine.api.users.UserServiceFactory;
+
+@Service(UserService.class)
+@Scope("COMPOSITE")
+public class GoogleUserService implements UserService {
+ private com.google.appengine.api.users.UserService googleUerService;
+
+ @Init
+ public void init() {
+ googleUerService = UserServiceFactory.getUserService();
+ }
+
+
+ public User getCurrentUser() {
+ return fromGoogleUser(googleUerService.getCurrentUser());
+ }
+
+ public boolean isUserAdmin() {
+ //FIXME handle via roles from tuscany user api
+ throw new UnsupportedOperationException("Not supported yet");
+ }
+
+ public boolean isUserLoggedIn() {
+ return googleUerService.isUserLoggedIn();
+ }
+
+ public UserContext getUserContext(String destinationURL, String authDomain) {
+ return new UserContext (getCurrentUser(),
+ isUserLoggedIn(),
+ createLoginURL(destinationURL, authDomain),
+ createLogoutURL(destinationURL, authDomain));
+ }
+
+ public String createLoginURL(String destinationURL, String authDomain) {
+ if(authDomain != null && authDomain.length() > 0) {
+ return googleUerService.createLoginURL(destinationURL, authDomain);
+ } else {
+ return googleUerService.createLoginURL(destinationURL);
+ }
+ }
+
+ public String createLogoutURL(String destinationURL, String authDomain) {
+ if(authDomain != null && authDomain.length() > 0) {
+ return googleUerService.createLogoutURL(destinationURL, authDomain);
+ } else {
+ return googleUerService.createLogoutURL(destinationURL);
+ }
+ }
+
+ private static User fromGoogleUser(com.google.appengine.api.users.User googleUser) {
+ if(googleUser != null) {
+ return new User(googleUser.getUserId(), googleUser.getNickname(), googleUser.getEmail());
+ }
+
+ return new User(null, null, null);
+ }
+
+
+}