This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-xing-api.git
commit 43cb3c04fee4938b355303ff93ce2fc7d58eaeed Author: Oliver Lietz <[email protected]> AuthorDate: Fri Jul 4 15:43:38 2014 +0000 SLING-3731 SLING-3732 add Sling Authentication XING API, Sling Authentication XING OAuth and Sling Authentication XING Login git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1607877 13f79535-47bb-0310-9956-ffa450edef68 --- README.md | 4 + pom.xml | 124 +++++++++++++++++++++ .../auth/xing/api/AbstractXingUserManager.java | 108 ++++++++++++++++++ .../org/apache/sling/auth/xing/api/XingUser.java | 44 ++++++++ .../sling/auth/xing/api/XingUserManager.java | 39 +++++++ .../apache/sling/auth/xing/api/package-info.java | 20 ++++ .../apache/sling/auth/xing/api/users/Users.java | 36 ++++++ .../sling/auth/xing/api/users/package-info.java | 20 ++++ 8 files changed, 395 insertions(+) diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f543b9 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Apache Sling Authentication XING API +==================================== + +shared API bundle for Authentication XING Login and Authentication XING Oauth diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b17d254 --- /dev/null +++ b/pom.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>19</version> + <relativePath>../../../parent/pom.xml</relativePath> + </parent> + + <artifactId>org.apache.sling.auth.xing.api</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>bundle</packaging> + + <name>Apache Sling Authentication XING API</name> + <description>Apache Sling Authentication XING API</description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <sling.java.version>6</sling.java.version> + </properties> + + <dependencies> + <!-- javax --> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + <scope>provided</scope> + </dependency> + <!-- Apache Commons --> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + <scope>test</scope> + </dependency> + <!-- Apache Sling --> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.7.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.api</artifactId> + <version>2.2.0</version> + <scope>provided</scope> + </dependency> + <!-- Apache Jackrabbit --> + <dependency> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-api</artifactId> + <version>2.0.0</version> + <scope>provided</scope> + </dependency> + <!-- bndlib --> + <dependency> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bndlib</artifactId> + <version>2.3.0</version> + <scope>provided</scope> + </dependency> + <!-- Gson --> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.2.4</version> + <scope>test</scope> + </dependency> + <!-- logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.7</version> + <scope>provided</scope> + </dependency> + <!-- testing --> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.8.8</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-Category>sling</Bundle-Category> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/src/main/java/org/apache/sling/auth/xing/api/AbstractXingUserManager.java b/src/main/java/org/apache/sling/auth/xing/api/AbstractXingUserManager.java new file mode 100644 index 0000000..7c18efe --- /dev/null +++ b/src/main/java/org/apache/sling/auth/xing/api/AbstractXingUserManager.java @@ -0,0 +1,108 @@ +/* + * 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.sling.auth.xing.api; + +import javax.jcr.Credentials; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; + +import org.apache.jackrabbit.api.JackrabbitSession; +import org.apache.jackrabbit.api.security.user.Authorizable; +import org.apache.jackrabbit.api.security.user.User; +import org.apache.jackrabbit.api.security.user.UserManager; +import org.apache.sling.jcr.api.SlingRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AbstractXingUserManager implements XingUserManager { + + protected boolean autoCreateUser; + + protected boolean autoUpdateUser; + + protected Session session; + + public static final boolean DEFAULT_AUTO_CREATE_USER = true; + + public static final boolean DEFAULT_AUTO_UPDATE_USER = false; + + private final Logger logger = LoggerFactory.getLogger(AbstractXingUserManager.class); + + protected abstract SlingRepository getSlingRepository(); + + @Override + public boolean autoCreate() { + return autoCreateUser; + } + + @Override + public boolean autoUpdate() { + return autoUpdateUser; + } + + @Override + public User getUser(final Credentials credentials) { + if (credentials instanceof SimpleCredentials) { + final SimpleCredentials simpleCredentials = (SimpleCredentials) credentials; + final String userId = simpleCredentials.getUserID(); + return getUser(userId); + } + return null; + } + + protected User getUser(final String userId) { + logger.info("getting user with id '{}'", userId); + try { + final Session session = getSession(); + final UserManager userManager = getUserManager(session); + final Authorizable authorizable = userManager.getAuthorizable(userId); + if (authorizable != null) { + if (authorizable instanceof User) { + final User user = (User) authorizable; + logger.debug("user for id '{}' found", userId); + return user; + } else { + logger.debug("found authorizable with id '{}' is not an user", authorizable.getID()); + } + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + return null; + } + + protected synchronized Session getSession() throws RepositoryException { + if (session == null || !session.isLive()) { + session = getSlingRepository().loginService(null, null); + } + return session; + } + + protected UserManager getUserManager(final Session session) throws RepositoryException { + if (session instanceof JackrabbitSession) { + final JackrabbitSession jackrabbitSession = (JackrabbitSession) session; + return jackrabbitSession.getUserManager(); + } else { + logger.error("Cannot get UserManager from session: not a Jackrabbit session"); + return null; + } + } + +} diff --git a/src/main/java/org/apache/sling/auth/xing/api/XingUser.java b/src/main/java/org/apache/sling/auth/xing/api/XingUser.java new file mode 100644 index 0000000..1edf5b1 --- /dev/null +++ b/src/main/java/org/apache/sling/auth/xing/api/XingUser.java @@ -0,0 +1,44 @@ +/* + * 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.sling.auth.xing.api; + +public class XingUser { + + private String id; + + private String firstName; + + private String lastName; + + public XingUser() { + } + + public String getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + +} diff --git a/src/main/java/org/apache/sling/auth/xing/api/XingUserManager.java b/src/main/java/org/apache/sling/auth/xing/api/XingUserManager.java new file mode 100644 index 0000000..b1e339f --- /dev/null +++ b/src/main/java/org/apache/sling/auth/xing/api/XingUserManager.java @@ -0,0 +1,39 @@ +/* + * 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.sling.auth.xing.api; + +import javax.jcr.Credentials; + +import aQute.bnd.annotation.ProviderType; +import org.apache.jackrabbit.api.security.user.User; + +@ProviderType +public interface XingUserManager { + + boolean autoCreate(); + + boolean autoUpdate(); + + User getUser(Credentials credentials); + + User createUser(Credentials credentials); + + User updateUser(Credentials credentials); + +} diff --git a/src/main/java/org/apache/sling/auth/xing/api/package-info.java b/src/main/java/org/apache/sling/auth/xing/api/package-info.java new file mode 100644 index 0000000..45538f6 --- /dev/null +++ b/src/main/java/org/apache/sling/auth/xing/api/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ [email protected]("0.0.1") +package org.apache.sling.auth.xing.api; diff --git a/src/main/java/org/apache/sling/auth/xing/api/users/Users.java b/src/main/java/org/apache/sling/auth/xing/api/users/Users.java new file mode 100644 index 0000000..6afbe55 --- /dev/null +++ b/src/main/java/org/apache/sling/auth/xing/api/users/Users.java @@ -0,0 +1,36 @@ +/* + * 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.sling.auth.xing.api.users; + +import java.util.List; + +import org.apache.sling.auth.xing.api.XingUser; + +public class Users { + + private List<XingUser> users; + + public Users() { + } + + public List<XingUser> getUsers() { + return users; + } + +} diff --git a/src/main/java/org/apache/sling/auth/xing/api/users/package-info.java b/src/main/java/org/apache/sling/auth/xing/api/users/package-info.java new file mode 100644 index 0000000..90c15a7 --- /dev/null +++ b/src/main/java/org/apache/sling/auth/xing/api/users/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ [email protected]("0.0.1") +package org.apache.sling.auth.xing.api.users; -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
