You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by sb...@apache.org on 2012/07/24 03:32:29 UTC
[1/20] git commit: Moved DefaultIdentity
Updated Branches:
refs/heads/master c32050e08 -> c6959e7c3
Moved DefaultIdentity
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/c6959e7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/c6959e7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/c6959e7c
Branch: refs/heads/master
Commit: c6959e7c3cdf4243897024548fc412ca68c7b805
Parents: 7ff2047
Author: Shane Bryzak <sb...@gmail.com>
Authored: Tue Jul 24 11:19:28 2012 +1000
Committer: Shane Bryzak <sb...@gmail.com>
Committed: Tue Jul 24 11:19:28 2012 +1000
----------------------------------------------------------------------
.../deltaspike/security/impl/DefaultIdentity.java | 34 +--
.../impl/authentication/DefaultIdentity.java | 224 ---------------
2 files changed, 5 insertions(+), 253 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/c6959e7c/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/DefaultIdentity.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/DefaultIdentity.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/DefaultIdentity.java
index a791b94..dc725a5 100644
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/DefaultIdentity.java
+++ b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/DefaultIdentity.java
@@ -20,15 +20,13 @@ package org.apache.deltaspike.security.impl;
import java.io.Serializable;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Named;
+
import org.apache.deltaspike.core.util.ExceptionUtils;
import org.apache.deltaspike.security.api.Identity;
-<<<<<<< HEAD
-<<<<<<< HEAD
-=======
-import org.apache.deltaspike.security.api.User;
->>>>>>> added missing files
-=======
->>>>>>> added ACL permission storage annotations, copied reflections utils from Solder (to be merged with DS core later), minor fixes
import org.apache.deltaspike.security.api.authentication.AuthenticationException;
import org.apache.deltaspike.security.api.authentication.UnexpectedCredentialException;
import org.apache.deltaspike.security.api.authentication.event.AlreadyLoggedInEvent;
@@ -38,26 +36,12 @@ import org.apache.deltaspike.security.api.authentication.event.PostAuthenticateE
import org.apache.deltaspike.security.api.authentication.event.PostLoggedOutEvent;
import org.apache.deltaspike.security.api.authentication.event.PreAuthenticateEvent;
import org.apache.deltaspike.security.api.authentication.event.PreLoggedOutEvent;
-<<<<<<< HEAD
-<<<<<<< HEAD
-import org.apache.deltaspike.security.api.credential.LoginCredentials;
-import org.apache.deltaspike.security.api.idm.User;
-=======
-import org.apache.deltaspike.security.api.credential.LoginCredential;
->>>>>>> added missing files
-=======
import org.apache.deltaspike.security.api.credential.LoginCredentials;
import org.apache.deltaspike.security.api.idm.User;
->>>>>>> added ACL permission storage annotations, copied reflections utils from Solder (to be merged with DS core later), minor fixes
import org.apache.deltaspike.security.spi.authentication.Authenticator;
import org.apache.deltaspike.security.spi.authentication.Authenticator.AuthenticationStatus;
import org.apache.deltaspike.security.spi.authentication.AuthenticatorSelector;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-import javax.inject.Named;
-
/**
* Default Identity implementation
*/
@@ -78,15 +62,7 @@ public class DefaultIdentity implements Identity
@Inject
@SuppressWarnings("NonSerializableFieldInSerializableClass")
-<<<<<<< HEAD
-<<<<<<< HEAD
- private LoginCredentials loginCredential;
-=======
- private LoginCredential loginCredential;
->>>>>>> added missing files
-=======
private LoginCredentials loginCredential;
->>>>>>> added ACL permission storage annotations, copied reflections utils from Solder (to be merged with DS core later), minor fixes
/**
* Flag indicating whether we are currently authenticating
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/c6959e7c/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authentication/DefaultIdentity.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authentication/DefaultIdentity.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authentication/DefaultIdentity.java
deleted file mode 100644
index d70b24c..0000000
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authentication/DefaultIdentity.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * 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.deltaspike.security.impl.authentication;
-
-import org.apache.deltaspike.core.util.ExceptionUtils;
-import org.apache.deltaspike.security.api.Identity;
-import org.apache.deltaspike.security.api.User;
-import org.apache.deltaspike.security.api.authentication.AuthenticationException;
-import org.apache.deltaspike.security.api.authentication.UnexpectedCredentialException;
-import org.apache.deltaspike.security.api.authentication.event.AlreadyLoggedInEvent;
-import org.apache.deltaspike.security.api.authentication.event.LoggedInEvent;
-import org.apache.deltaspike.security.api.authentication.event.LoginFailedEvent;
-import org.apache.deltaspike.security.api.authentication.event.PostAuthenticateEvent;
-import org.apache.deltaspike.security.api.authentication.event.PostLoggedOutEvent;
-import org.apache.deltaspike.security.api.authentication.event.PreAuthenticateEvent;
-import org.apache.deltaspike.security.api.authentication.event.PreLoggedOutEvent;
-import org.apache.deltaspike.security.api.credential.LoginCredential;
-import org.apache.deltaspike.security.spi.authentication.Authenticator;
-import org.apache.deltaspike.security.spi.authentication.Authenticator.AuthenticationStatus;
-import org.apache.deltaspike.security.spi.authentication.AuthenticatorSelector;
-
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-
-/**
- * Default Identity implementation
- */
-@SuppressWarnings("UnusedDeclaration")
-@SessionScoped
-public class DefaultIdentity implements Identity
-{
- private static final long serialVersionUID = 3696702275353144429L;
-
- @Inject
- @SuppressWarnings("NonSerializableFieldInSerializableClass")
- private AuthenticatorSelector authenticatorSelector;
-
- @Inject
- @SuppressWarnings("NonSerializableFieldInSerializableClass")
- private BeanManager beanManager;
-
- @Inject
- @SuppressWarnings("NonSerializableFieldInSerializableClass")
- private LoginCredential loginCredential;
-
- /**
- * Flag indicating whether we are currently authenticating
- */
- private boolean authenticating;
-
- private User user;
-
- public boolean isLoggedIn()
- {
- // If there is a user set, then the user is logged in.
- return user != null;
- }
-
- @Override
- public User getUser()
- {
- return user;
- }
-
- @Override
- public AuthenticationResult login()
- {
- try
- {
- if (isLoggedIn())
- {
- if (isAuthenticationRequestWithDifferentUserId())
- {
- throw new UnexpectedCredentialException("active user: " + user.getId() +
- " provided credentials: " + loginCredential.getUserId());
- }
-
- beanManager.fireEvent(new AlreadyLoggedInEvent());
- return AuthenticationResult.SUCCESS;
- }
-
- boolean success = authenticate();
-
- if (success)
- {
- beanManager.fireEvent(new LoggedInEvent()); //X TODO beanManager.fireEvent(new LoggedInEvent(user));
- return AuthenticationResult.SUCCESS;
- }
-
- beanManager.fireEvent(new LoginFailedEvent(null));
- return AuthenticationResult.FAILED;
- }
- catch (Exception e)
- {
- //X TODO discuss special handling of UnexpectedCredentialException
- beanManager.fireEvent(new LoginFailedEvent(e));
-
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException)e;
- }
-
- ExceptionUtils.throwAsRuntimeException(e);
- //Attention: the following line is just for the compiler (and analysis tools) - it won't get executed
- throw new IllegalStateException(e);
- }
- }
-
- private boolean isAuthenticationRequestWithDifferentUserId()
- {
- return isLoggedIn() && loginCredential.getUserId() != null &&
- !loginCredential.getUserId().equals(user.getId());
- }
-
- protected boolean authenticate() throws AuthenticationException
- {
- if (authenticating)
- {
- authenticating = false; //X TODO discuss it
- throw new IllegalStateException("Authentication already in progress.");
- }
-
- try
- {
- authenticating = true;
-
- beanManager.fireEvent(new PreAuthenticateEvent());
-
- Authenticator activeAuthenticator = authenticatorSelector.getSelectedAuthenticator();
-
- activeAuthenticator.authenticate();
-
- if (activeAuthenticator.getStatus() == null)
- {
- throw new AuthenticationException("Authenticator must return a valid authentication status");
- }
-
- if (activeAuthenticator.getStatus() == AuthenticationStatus.SUCCESS)
- {
- postAuthenticate(activeAuthenticator);
- user = activeAuthenticator.getUser();
- return true;
- }
- }
- catch (Exception ex)
- {
- if (ex instanceof AuthenticationException)
- {
- throw (AuthenticationException) ex;
- }
- else
- {
- throw new AuthenticationException("Authentication failed.", ex);
- }
- }
- finally
- {
- authenticating = false;
- }
- return false;
- }
-
- protected void postAuthenticate(Authenticator activeAuthenticator)
- {
- activeAuthenticator.postAuthenticate();
-
- if (!activeAuthenticator.getStatus().equals(AuthenticationStatus.SUCCESS))
- {
- return;
- }
-
- beanManager.fireEvent(new PostAuthenticateEvent());
- }
-
- @Override
- public void logout()
- {
- logout(true);
- }
-
- protected void logout(boolean invalidateLoginCredential)
- {
- if (isLoggedIn())
- {
- beanManager.fireEvent(new PreLoggedOutEvent(user));
-
- PostLoggedOutEvent postLoggedOutEvent = new PostLoggedOutEvent(user);
-
- unAuthenticate(invalidateLoginCredential);
-
- beanManager.fireEvent(postLoggedOutEvent);
- }
- }
-
- /**
- * Resets all security state and loginCredential
- */
- private void unAuthenticate(boolean invalidateLoginCredential)
- {
- user = null;
-
- if (invalidateLoginCredential)
- {
- loginCredential.invalidate();
- }
- }
-}