[jboss-svn-commits] JBL Code SVN: r18302 - in labs/jbosslabs/labs-3.0-build: core/core-api/src/main/java/org/jboss/labs/auth/custom and 9 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 4 10:51:32 EST 2008
Author: szimano
Date: 2008-02-04 10:51:32 -0500 (Mon, 04 Feb 2008)
New Revision: 18302
Added:
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDHandler.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/LabsException.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/admin/
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserRoleException.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/RoleExistsException.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/service/
Removed:
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/LabsException.java
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/admin/
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/auth/
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/service/
Modified:
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/RoleBinderService.java
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java
labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDProvider.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/core/model/auth/User.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchRoleForUserException.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserException.java
labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/UserExistsException.java
labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java
labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/CustomIDService.java
labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/CustomIDServiceImpl.java
labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/RoleBinderServiceImpl.java
labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java
labs/jbosslabs/labs-3.0-build/services/events-service/src/main/java/org/jboss/labs/events/service/impl/EventsServiceBean.java
labs/jbosslabs/labs-3.0-build/views/foo-view/src/main/java/org/jboss/labs/MyServlet.java
Log:
excpetion in core-model, authorization user service implementation, custom id service, JBLAB-901
Modified: labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/RoleBinderService.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/RoleBinderService.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/RoleBinderService.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -27,6 +27,7 @@
import org.jboss.labs.auth.custom.CustomIDProvider;
import org.jboss.labs.core.model.auth.ServiceRole;
import org.jboss.labs.core.model.auth.UserRole;
+import org.jboss.labs.exception.auth.NoSuchUserRoleException;
/**
* Class that allows exposing role list for a service.
@@ -74,7 +75,7 @@
* Project id
*/
public <E extends Enum<E>> void bindRolesWithProject(E serviceRole,
- UserRole role, String projectId);
+ UserRole role, String projectId) throws NoSuchUserRoleException;
/**
* Binds given service role with a user role for a given custom id.
@@ -91,7 +92,7 @@
* @see org.jboss.labs.auth.custom.CustomIDProvider
*/
public <E extends Enum<E>> void bindRolesWithId(E serviceRole,
- UserRole role, String customId);
+ UserRole role, String customId) throws NoSuchUserRoleException;
/**
* Binds service role to a user role globally. This means that members of
@@ -105,7 +106,8 @@
* @param role
* User role
*/
- public <E extends Enum<E>> void bindRolesGlobal(E serviceRole, UserRole role);
+ public <E extends Enum<E>> void bindRolesGlobal(E serviceRole, UserRole role)
+ throws NoSuchUserRoleException;
/**
* Grants superrole in a project to a user. User with a superrole can
Modified: labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/UserService.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -28,7 +28,9 @@
import org.jboss.labs.core.model.auth.User;
import org.jboss.labs.core.model.auth.UserRole;
import org.jboss.labs.exception.auth.NoSuchRoleForUserException;
+import org.jboss.labs.exception.auth.NoSuchUserRoleException;
import org.jboss.labs.exception.auth.NoSuchUserException;
+import org.jboss.labs.exception.auth.RoleExistsException;
import org.jboss.labs.exception.auth.UserExistsException;
public interface UserService {
@@ -52,7 +54,7 @@
* @return Set of user roles if there are any or empty set if there are no
* user roles for a user
*/
- public Set<UserRole> getRolesForUser(Principal user);
+ public Set<UserRole> getRolesForUser(Principal user) throws NoSuchUserException;
/**
* Returns set of user roles for a user by a login.
@@ -62,17 +64,17 @@
* @return Set of user roles if there are any or empty set if there are no
* user roles for a user
*/
- public Set<UserRole> getRolesForUser(String login);
+ public Set<UserRole> getRolesForUser(String login) throws NoSuchUserException;
/**
- * Binds user role to a user.
+ * Binds user role to a user. If role doesn't exists it will be created.
*
* @param user
* User
* @param role
* User role
*/
- public void bindRoleToUser(Principal user, UserRole role);
+ public void bindRoleToUser(Principal user, UserRole role) throws NoSuchUserException;
/**
* Removes user role from a user
@@ -81,11 +83,11 @@
* User
* @param role
* Role
- * @throws NoSuchRoleForUserException
+ * @throws NoSuchUserRoleForUserException
* When given user doesn't have the given role.
*/
public void removeRoleFromUser(Principal user, UserRole role)
- throws NoSuchRoleForUserException;
+ throws NoSuchUserException, NoSuchRoleForUserException;
/**
* Stores new user in the database.
@@ -95,5 +97,17 @@
* @throws UserExistsException
* when user already exists
*/
- public void createNewUser(User user) throws UserExistsException;
+ public void addNewUser(User user) throws UserExistsException;
+
+ /** Adds new user role.
+ * @param role User role to add
+ * @throws RoleExistsException If role exists
+ */
+ public void addUserRole(UserRole role) throws RoleExistsException;
+
+ /** Removes user role.
+ * @param role User role to remove.
+ * @throws NoSuchUserRoleException If role doesn't exist
+ */
+ public void removeUserRole(UserRole role) throws NoSuchUserRoleException;
}
Added: labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDHandler.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDHandler.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDHandler.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -0,0 +1,44 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ *
+ * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+ * Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+/**
+ *
+ */
+package org.jboss.labs.auth.custom;
+
+import java.util.Set;
+
+import org.jboss.labs.core.model.auth.CustomID;
+
+/**
+ * @author tomaszszymanski
+ *
+ */
+public interface CustomIDHandler {
+
+ /**
+ * @param newIds
+ */
+ public void addCustomIDs(CustomIDProvider provider, Set<CustomID> newIds);
+
+ public void removeCustomIDs(CustomIDProvider provider, Set<CustomID> ids);
+}
Modified: labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDProvider.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDProvider.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/auth/custom/CustomIDProvider.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -22,6 +22,7 @@
*/
package org.jboss.labs.auth.custom;
+import java.util.HashSet;
import java.util.Set;
import org.jboss.labs.core.model.auth.CustomID;
@@ -32,26 +33,102 @@
* @author tomaszszymanski
*
*/
-public interface CustomIDProvider {
+/**
+ * @author tomaszszymanski
+ *
+ */
+public abstract class CustomIDProvider {
+
+ private Set<CustomIDHandler> handlers = new HashSet<CustomIDHandler>();
+
/**
* @return Returns set of customIDs available in this project
*/
- public Set<CustomID> getCustomIDs();
+ public abstract Set<CustomID> getCustomIDs();
/**
- * Gives authorization service set of new IDs.
+ * Gives authorization service set of new IDs. Do not override this method.
+ * It executes appropriate methods on custom id handler. If you need to add
+ * some logic here, please override newCustomIDsOps - it get's executed
+ * before executing handler methods.
*
* @param newIds
* New IDs available in in current service.
*/
- public void addCustomIDs(Set<CustomID> newIds);
+ public final void addCustomIDs(Set<CustomID> newIds) {
+ // execute method that user can place same logic to
+ addCustomIDsOps(newIds);
+
+ for (CustomIDHandler handler : handlers) {
+ handler.addCustomIDs(this, newIds);
+ }
+ }
+
/**
+ * Way to add some logic to addCustomIDs.
+ *
+ * @param newIds
+ * Passed Id's.
+ */
+ protected void addCustomIDsOps(Set<CustomID> newIds) {
+ // by default it does nothing
+ }
+
+ /**
* Tells authorization service to remove set of IDs. This won't remove role
* bindings for this ID but will make them unavailable for adding new roles.
*
* @param ids
* IDs that are no longer available.
*/
- public void removeCustomIDs(Set<CustomID> ids);
+ public final void removeCustomIDs(Set<CustomID> ids) {
+ // execute logic method
+ removeCustomIDsOps(ids);
+
+ for (CustomIDHandler handler : handlers) {
+ handler.removeCustomIDs(this, ids);
+ }
+ }
+
+ /**
+ * Way to add some logic to removeCustomIDs.
+ *
+ * @param ids
+ * Passed Id's
+ */
+ protected void removeCustomIDsOps(Set<CustomID> ids) {
+ // by default it does nothing
+ }
+
+ /**
+ * Adds a handler that's executed when addCustomIDs is executed.
+ *
+ * @param handler
+ */
+ public void addHandler(CustomIDHandler handler) {
+ handlers.add(handler);
+ }
+
+ /**
+ * Removes a handler that's executed when addCustomIDs is executed.
+ *
+ * @param handler
+ */
+ public void removeHandler(CustomIDHandler handler) {
+ handlers.remove(handler);
+ }
+
+ /**
+ * If this method returns true - customIDs will be buffered and the designer
+ * has to execute addCustomIDs every time new ID is created. If it returns
+ * false, getCustomIDs will be executed every time.
+ *
+ * Default is TRUE.
+ *
+ * @return True if buffered, false otherwise
+ */
+ public boolean isBuffered() {
+ return true;
+ }
}
Deleted: labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/LabsException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/LabsException.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/LabsException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -1,44 +0,0 @@
-/*
- * JBoss Labs. http://labs.jboss.com/jbosslabs
- *
- * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
- * Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
- */
-package org.jboss.labs.exception;
-
-public class LabsException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public LabsException() {
- super();
- }
-
- public LabsException(String msg) {
- super(msg);
- }
-
- public LabsException(Throwable t) {
- super(t);
- }
-
-}
Modified: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/core/model/auth/User.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/core/model/auth/User.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/core/model/auth/User.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -24,33 +24,36 @@
import java.security.Principal;
import java.util.Set;
+import java.util.TreeSet;
import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Version;
+import org.jboss.labs.exception.auth.NoSuchRoleForUserException;
+
@Entity
public class User implements Principal {
- @Id
- @GeneratedValue
- private Integer id;
@Version
private Integer version;
- private String username;
+ @Id
private String name;
private String bio;
private String website;
private String pictureURL;
-
+
private String password;
-
+
@OneToMany
private Set<UserRole> userRoles;
+ public User(String username) {
+ this.name = username;
+ }
+
public String getName() {
return name;
}
@@ -62,15 +65,7 @@
public void setVersion(Integer version) {
this.version = version;
}
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
+
public String getBio() {
return bio;
}
@@ -95,10 +90,6 @@
this.pictureURL = pictureURL;
}
- public Integer getId() {
- return id;
- }
-
public void setName(String name) {
this.name = name;
}
@@ -119,4 +110,40 @@
this.password = password;
}
+ /**
+ * Adds role for a user
+ *
+ * @param role
+ * Role
+ */
+ public void addRole(UserRole role) {
+ if (userRoles == null) {
+ userRoles = new TreeSet<UserRole>();
+ }
+
+ userRoles.add(role);
+ }
+
+ /**
+ * Removes role from a user
+ *
+ * @param role
+ * Role to remove
+ * @throws NoSuchUserRoleForUserException
+ * when user doesn't have the role
+ */
+ public void removeRole(UserRole role) throws NoSuchRoleForUserException {
+ if (userRoles != null) {
+ if (userRoles.contains(role)) {
+ userRoles.remove(role);
+ } else {
+ throw new NoSuchRoleForUserException("User " + name
+ + " doesn't have role " + role.getId());
+ }
+ } else {
+ throw new NoSuchRoleForUserException("User " + name
+ + " doesn't have any roles attached");
+ }
+ }
+
}
Copied: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/LabsException.java (from rev 18298, labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/LabsException.java)
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/LabsException.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/LabsException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -0,0 +1,44 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ *
+ * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+ * Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+package org.jboss.labs.exception;
+
+public class LabsException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public LabsException() {
+ super();
+ }
+
+ public LabsException(String msg) {
+ super(msg);
+ }
+
+ public LabsException(Throwable t) {
+ super(t);
+ }
+
+}
Copied: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/admin (from rev 18298, labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/admin)
Copied: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth (from rev 18298, labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/auth)
Modified: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchRoleForUserException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/auth/NoSuchRoleForUserException.java 2008-02-04 12:44:29 UTC (rev 18298)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchRoleForUserException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -27,6 +27,13 @@
public class NoSuchRoleForUserException extends LabsException {
/**
+ * @param string
+ */
+ public NoSuchRoleForUserException(String string) {
+ super(string);
+ }
+
+ /**
*
*/
private static final long serialVersionUID = 1L;
Modified: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/auth/NoSuchUserException.java 2008-02-04 12:44:29 UTC (rev 18298)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -27,6 +27,13 @@
public class NoSuchUserException extends LabsException {
/**
+ * @param string
+ */
+ public NoSuchUserException(String string) {
+ super(string);
+ }
+
+ /**
*
*/
private static final long serialVersionUID = 1L;
Added: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserRoleException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserRoleException.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/NoSuchUserRoleException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -0,0 +1,48 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ *
+ * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+ * Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+/**
+ *
+ */
+package org.jboss.labs.exception.auth;
+
+import org.jboss.labs.exception.LabsException;
+
+/**
+ * @author tomaszszymanski
+ *
+ */
+public class NoSuchUserRoleException extends LabsException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param string
+ */
+ public NoSuchUserRoleException(String string) {
+ super(string);
+ }
+
+}
Added: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/RoleExistsException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/RoleExistsException.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/RoleExistsException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -0,0 +1,48 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ *
+ * Copyright © 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+ * Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+/**
+ *
+ */
+package org.jboss.labs.exception.auth;
+
+import org.jboss.labs.exception.LabsException;
+
+/**
+ * @author tomaszszymanski
+ *
+ */
+public class RoleExistsException extends LabsException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param string
+ */
+ public RoleExistsException(String string) {
+ super(string);
+ }
+
+}
Modified: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/UserExistsException.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/auth/UserExistsException.java 2008-02-04 12:44:29 UTC (rev 18298)
+++ labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/auth/UserExistsException.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -33,4 +33,16 @@
*/
public class UserExistsException extends LabsException {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param string
+ */
+ public UserExistsException(String string) {
+ super(string);
+ }
+
}
Copied: labs/jbosslabs/labs-3.0-build/core/core-model/src/main/java/org/jboss/labs/exception/service (from rev 18298, labs/jbosslabs/labs-3.0-build/core/core-api/src/main/java/org/jboss/labs/exception/service)
Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/AuthHelper.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -45,4 +45,8 @@
throw new RuntimeException(e);
}
}
+
+ public static <E extends Enum<E>> String getServiceID(E serviceRole) {
+ return serviceRole.getDeclaringClass().getCanonicalName();
+ }
}
Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/CustomIDService.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/CustomIDService.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/CustomIDService.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -1,7 +1,12 @@
package org.jboss.labs.auth;
+import java.util.Set;
+
import org.jboss.labs.auth.custom.CustomIDProvider;
+import org.jboss.labs.core.model.auth.CustomID;
public interface CustomIDService{
public void registerCustomIDProvider(CustomIDProvider provider, String serviceID);
+
+ public Set<CustomID> getCustomIDs(String serviceID);
}
Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/CustomIDServiceImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/CustomIDServiceImpl.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/CustomIDServiceImpl.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -1,19 +1,83 @@
package org.jboss.labs.auth.impl;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import javax.ejb.Local;
+import org.apache.log4j.Logger;
import org.jboss.annotation.ejb.Service;
import org.jboss.labs.auth.CustomIDService;
+import org.jboss.labs.auth.custom.CustomIDHandler;
import org.jboss.labs.auth.custom.CustomIDProvider;
+import org.jboss.labs.core.model.auth.CustomID;
@Service
@Local
-public class CustomIDServiceImpl implements CustomIDService {
+public class CustomIDServiceImpl implements CustomIDService, CustomIDHandler {
+ private static final Logger log = Logger
+ .getLogger(CustomIDServiceImpl.class);
+
+ private Map<String, CustomIDProvider> providers = new HashMap<String, CustomIDProvider>();
+ private Map<CustomIDProvider, Set<CustomID>> customIDs = new HashMap<CustomIDProvider, Set<CustomID>>();
+
public void registerCustomIDProvider(CustomIDProvider provider,
String serviceID) {
- // TODO Auto-generated method stub
-
+ providers.put(serviceID, provider);
+ provider.addHandler(this);
+
+ if (provider.isBuffered()) {
+ customIDs.put(provider, new HashSet<CustomID>(provider
+ .getCustomIDs()));
+ }
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.labs.auth.custom.CustomIDHandler#addCustomIDs(java.util.Set)
+ */
+ public void addCustomIDs(CustomIDProvider provider, Set<CustomID> newIds) {
+ if (!provider.isBuffered()) {
+ log
+ .warn("You're using addCustomIDs method, even tho provider is not buffered ! Provider: "
+ + provider);
+ } else {
+ customIDs.get(provider).addAll(newIds);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.labs.auth.custom.CustomIDHandler#removeCustomIDs(java.util.Set)
+ */
+ public void removeCustomIDs(CustomIDProvider provider, Set<CustomID> ids) {
+ if (!provider.isBuffered()) {
+ log
+ .warn("You're using removeCustomIDs method, even tho provider is not buffered ! Provider: "
+ + provider);
+ } else {
+ customIDs.get(provider).removeAll(ids);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.labs.auth.CustomIDService#getCustomIDs(java.lang.String)
+ */
+ public Set<CustomID> getCustomIDs(String serviceID) {
+ CustomIDProvider provider = providers.get(serviceID);
+
+ if (provider.isBuffered()) {
+ return new HashSet<CustomID>(customIDs.get(provider));
+ } else {
+ return provider.getCustomIDs();
+ }
+ }
+
}
Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/RoleBinderServiceImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/RoleBinderServiceImpl.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/RoleBinderServiceImpl.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -34,6 +34,7 @@
import javax.persistence.PersistenceContext;
import org.apache.log4j.Logger;
+import org.jboss.labs.auth.AuthHelper;
import org.jboss.labs.auth.CustomIDService;
import org.jboss.labs.auth.RoleBinderService;
import org.jboss.labs.auth.custom.CustomIDProvider;
@@ -66,8 +67,7 @@
public <E extends Enum<E>> void bindRolesWithProject(E serviceRole,
UserRole role, String projectId) {
- // TODO Auto-generated method stub
-
+ ServiceRole sr = getServiceRole(serviceRole);
}
public <E extends Enum<E>> void exposeServiceRoles(E[] serviceRoleList) {
@@ -102,8 +102,9 @@
public <E extends Enum<E>> void exposeServiceRolesAndRegisterCustomIDProvider(
E[] serviceRoleList, CustomIDProvider provider) {
- // TODO Auto-generated method stub
+ exposeServiceRoles(serviceRoleList);
+ customIDService.registerCustomIDProvider(provider, AuthHelper.getServiceID(serviceRoleList[0]));
}
public <E extends Enum<E>> void bindRolesGlobal(E serviceRole, UserRole role) {
Modified: labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/services/credential/src/main/java/org/jboss/labs/auth/impl/UserServiceImpl.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -1,6 +1,3 @@
-package org.jboss.labs.auth.impl;
-
-import java.security.Principal;
/*
* JBoss Labs. http://labs.jboss.com/jbosslabs
*
@@ -23,6 +20,10 @@
* Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
* Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
*/
+
+package org.jboss.labs.auth.impl;
+
+import java.security.Principal;
import java.util.Set;
import javax.annotation.PostConstruct;
@@ -37,6 +38,9 @@
import org.jboss.labs.core.model.auth.User;
import org.jboss.labs.core.model.auth.UserRole;
import org.jboss.labs.exception.auth.NoSuchRoleForUserException;
+import org.jboss.labs.exception.auth.NoSuchUserRoleException;
+import org.jboss.labs.exception.auth.NoSuchUserException;
+import org.jboss.labs.exception.auth.RoleExistsException;
import org.jboss.labs.exception.auth.UserExistsException;
import org.josso.gateway.identity.service.ws.impl.SSOIdentityManager;
import org.josso.gateway.identity.service.ws.impl.SSOIdentityManagerServiceLocator;
@@ -45,7 +49,7 @@
@Local
public class UserServiceImpl implements UserService {
- @PersistenceContext(name="auth_model")
+ @PersistenceContext(name = "auth_model")
private EntityManager manager;
private SSOIdentityManager identityManager;
@@ -64,38 +68,117 @@
}
}
- public void bindRoleToUser(Principal user, UserRole role) {
- // TODO Auto-generated method stub
+ public void bindRoleToUser(Principal user, UserRole role)
+ throws NoSuchUserException {
+ User userEn = manager.find(User.class, user.getName());
+ if (userEn == null) {
+ throw new NoSuchUserException("User " + user.getName()
+ + " doesn't exist");
+ }
+
+ UserRole roleEn = manager.find(UserRole.class, role.getId());
+
+ if (roleEn == null) {
+ manager.persist(role);
+ roleEn = role;
+ }
+
+ userEn.addRole(roleEn);
+
+ manager.merge(userEn);
}
- public Set<UserRole> getRolesForUser(Principal user) {
- // TODO Auto-generated method stub
- return null;
+ public Set<UserRole> getRolesForUser(Principal user)
+ throws NoSuchUserException {
+ return getRolesForUser(user.getName());
}
- public Set<UserRole> getRolesForUser(String login) {
- // TODO Auto-generated method stub
- return null;
+ public Set<UserRole> getRolesForUser(String login)
+ throws NoSuchUserException {
+ User u = getUser(login);
+
+ return u.getUserRoles();
}
- public User getUserByLogin(String login)
- throws org.jboss.labs.exception.auth.NoSuchUserException {
- // TODO Auto-generated method stub
- return null;
+ public User getUserByLogin(String login) throws NoSuchUserException {
+ return getUser(login);
}
public void removeRoleFromUser(Principal user, UserRole role)
- throws NoSuchRoleForUserException {
- // TODO Auto-generated method stub
+ throws NoSuchRoleForUserException, NoSuchUserException {
+ User u = getUser(user);
+ u.removeRole(role);
+
+ manager.merge(u);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.jboss.labs.auth.UserService#createNewUser(org.jboss.labs.core.model.auth.User)
*/
- public void createNewUser(User user) throws UserExistsException {
+ public void addNewUser(User user) throws UserExistsException {
+ try {
+ // check if user exists
+ getUser(user);
+
+ throw new UserExistsException("User " + user.getName()
+ + " already exists");
+ } catch (NoSuchUserException e) {
+ }
+
+ manager.persist(user);
+ }
+
+ private User getUser(Principal user) throws NoSuchUserException {
+ return getUser(user.getName());
+ }
+
+ private User getUser(String login) throws NoSuchUserException {
+ User userEn = manager.find(User.class, login);
+
+ if (userEn == null) {
+ throw new NoSuchUserException("User " + login + " doesn't exist");
+ }
+
+ return userEn;
+ }
+
+ private UserRole getUserRole(UserRole role) throws NoSuchUserRoleException {
+ return getUserRole(role.getId());
+ }
+
+ private UserRole getUserRole(String roleID) throws NoSuchUserRoleException {
+ UserRole roleEn = manager.find(UserRole.class, roleID);
+ if (roleEn == null) {
+ throw new NoSuchUserRoleException("Role "+roleID + "doesn't exist");
+ }
+
+ return roleEn;
}
+ /* (non-Javadoc)
+ * @see org.jboss.labs.auth.UserService#addUserRole(org.jboss.labs.core.model.auth.UserRole)
+ */
+ public void addUserRole(UserRole role) throws RoleExistsException {
+ try {
+ getUserRole(role);
+ throw new RoleExistsException("Role "+role.getId()+" already exist");
+ } catch (NoSuchUserRoleException e) {
+ }
+
+ manager.persist(role);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.labs.auth.UserService#removeUserRole(org.jboss.labs.core.model.auth.UserRole)
+ */
+ public void removeUserRole(UserRole role) throws NoSuchUserRoleException {
+ UserRole roleEn = getUserRole(role);
+
+ manager.remove(roleEn);
+ }
}
Modified: labs/jbosslabs/labs-3.0-build/services/events-service/src/main/java/org/jboss/labs/events/service/impl/EventsServiceBean.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/services/events-service/src/main/java/org/jboss/labs/events/service/impl/EventsServiceBean.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/services/events-service/src/main/java/org/jboss/labs/events/service/impl/EventsServiceBean.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -32,6 +32,7 @@
import org.jboss.labs.events.service.EventListenersStorageServiceRemote;
import org.jboss.labs.events.service.EventsService;
+
/**
* @author <a href="mailto:rkozmik at redhat.com">Ryszard Kozmik</a>
*/
Modified: labs/jbosslabs/labs-3.0-build/views/foo-view/src/main/java/org/jboss/labs/MyServlet.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/foo-view/src/main/java/org/jboss/labs/MyServlet.java 2008-02-04 14:18:40 UTC (rev 18301)
+++ labs/jbosslabs/labs-3.0-build/views/foo-view/src/main/java/org/jboss/labs/MyServlet.java 2008-02-04 15:51:32 UTC (rev 18302)
@@ -25,6 +25,7 @@
import com.google.inject.Inject;
import org.apache.log4j.Logger;
import org.jboss.labs.auth.UserService;
+import org.jboss.labs.exception.auth.NoSuchUserException;
import org.jboss.labs.foo.FooService;
import org.jboss.labs.servlet.LabsHttpServlet;
@@ -61,7 +62,12 @@
+ "<br/>");
}
- userService.bindRoleToUser(null, null);
+ try {
+ userService.bindRoleToUser(null, null);
+ } catch (NoSuchUserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
resp.getWriter().println(
"Foo says: " + "Foo[" + fooService.sayFoo().id
More information about the jboss-svn-commits
mailing list