User: danch
Date: 02/02/22 11:24:03
Modified: jetty/src/main/org/jboss/jetty Tag: Branch_2_4
JBossUserRealm.java
Log:
beautified and back-ported the fix for the 'not serializable' problem from the 3.0
main
Revision Changes Path
No revision
No revision
1.2.2.5 +136 -159 contrib/jetty/src/main/org/jboss/jetty/Attic/JBossUserRealm.java
Index: JBossUserRealm.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/Attic/JBossUserRealm.java,v
retrieving revision 1.2.2.4
retrieving revision 1.2.2.5
diff -u -r1.2.2.4 -r1.2.2.5
--- JBossUserRealm.java 2 Dec 2001 02:08:53 -0000 1.2.2.4
+++ JBossUserRealm.java 22 Feb 2002 19:24:03 -0000 1.2.2.5
@@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
-// $Id: JBossUserRealm.java,v 1.2.2.4 2001/12/02 02:08:53 starksm Exp $
+// $Id: JBossUserRealm.java,v 1.2.2.5 2002/02/22 19:24:03 danch Exp $
package org.jboss.jetty;
@@ -26,165 +26,142 @@
/** An implementation of UserRealm that integrates with the JBossSX
* security manager associted with the web application.
* @author [EMAIL PROTECTED]
- * @version $Revision: 1.2.2.4 $
+ * @version $Revision: 1.2.2.5 $
+ *
+ * <p><b>Revisions:</b>
+ *
+ * <p><b>20020220 danch:</b>
+ * <ul>
+ * <li> beautified 8^})</li>
+ * <li> Back-port '... not Serializable ' fix by Anatoly Akkerman
+ * </ul>
*/
-public class JBossUserRealm
- implements UserRealm
-{
- private Category _log;
- private String _realmName;
- private AuthenticationManager _securityMgr;
- private RealmMapping _realmMapping;
- private HashMap _users = new HashMap();
-
- class User
- extends SimplePrincipal
- implements UserPrincipal
- {
- User(String name)
- {
- super(name);
- _log.info("Security- created JBossUserRealm::User: "+name);
- }
-
- public boolean
- equals(Object o)
- {
- if (o==this)
- return true;
-
- if (o==null)
- return false;
-
- if (getClass()!=o.getClass())
- return false;
-
- String myName =this.getName();
- String yourName=((User)o).getName();
-
- if (myName==null && yourName==null)
- return true;
-
- if (myName!=null && myName.equals(yourName))
- return true;
-
- return false;
- }
-
- public boolean
- authenticate(String password, HttpRequest request)
- {
- boolean authenticated = false;
- String userName = this.getName(); // needs disambiguation
-
- // Get the JBoss security manager from the ENC context
- if(_securityMgr!=null &&_securityMgr.isValid(this, password))
- {
- authenticated = true;
- _log.info("Security- User: "+userName+" is authenticated");
- SecurityAssociation.setPrincipal(this);
- SecurityAssociation.setCredential(password.toCharArray());
- }
- else
- {
- _log.warn("Security- User: "+userName+" is NOT authenticated");
- }
-
- return authenticated;
- }
-
- public boolean
- isUserInRole(String role)
- {
- boolean isUserInRole = false;
- String userName = this.getName();
-
- // Get the JBoss security manager from the ENC context
- SimplePrincipal rolePrincipal = new SimplePrincipal(role);
- Set requiredRoles = Collections.singleton(rolePrincipal);
- if(_realmMapping.doesUserHaveRole(this, requiredRoles))
- {
- isUserInRole = true;
- _log.info("Security- User: "+userName+" is in Role: "+role);
- }
- else
- {
- _log.warn("Security- User: "+userName+" is NOT in Role: "+role);
- }
-
- return isUserInRole;
- }
-
- public UserRealm
- getUserRealm()
- {
- return JBossUserRealm.this;
- }
- }
-
- public
- JBossUserRealm(Category log, String realmName)
- {
- _log = log;
- _realmName = realmName;
- _log.info("Security- created JBossUserRealm: "+_realmName);
- }
-
- public String
- getName()
- {
- return _realmName;
- }
-
- /**
- * @deprecated
- */
- public UserPrincipal
- getUser(String userName, HttpRequest request)
- {
- return getUser(userName);
- }
-
- //----------------------------------------
-
- private synchronized User
- ensureUser(String userName)
- {
- User user = (User)_users.get(userName);
-
- if (user==null)
- {
- user=new User(userName);
- _users.put(userName, user);
- }
-
- return user;
- }
-
- public UserPrincipal
- getUser(String userName)
- {
- if (_securityMgr==null)
- {
- try
- {
- // do we really have to do this every time - is it expensive ? TODO
- InitialContext iniCtx = new InitialContext();
- // do we need the 'java:comp/env' prefix ? TODO
- _securityMgr = (AuthenticationManager)
iniCtx.lookup("java:comp/env/security/securityMgr");
- _realmMapping = (RealmMapping)
iniCtx.lookup("java:comp/env/security/realmMapping");
- }
- catch (NamingException e)
- {
- _log.error("Security- Could not create initial Context", e);
- }
- }
-
- _log.info("Security- User: "+userName);
-
- return ensureUser(userName);
- }
+public class JBossUserRealm implements UserRealm {
+ private Category _log;
+ private String _realmName;
+ private AuthenticationManager _securityMgr;
+ private RealmMapping _realmMapping;
+ private HashMap _users = new HashMap();
- //----------------------------------------
+ class User extends SimplePrincipal implements UserPrincipal {
+ User(String name) {
+ super(name);
+ _log.info("Security- created JBossUserRealm::User: "+name);
+ }
+
+ public boolean equals(Object o) {
+ if (o == this)
+ return true;
+
+ if (o == null)
+ return false;
+
+ if (getClass() != o.getClass())
+ return false;
+
+ String myName = this.getName();
+ String yourName = ((User) o).getName();
+
+ if (myName == null && yourName == null)
+ return true;
+
+ if (myName != null && myName.equals(yourName))
+ return true;
+
+ return false;
+ }
+
+ public boolean authenticate(String password, HttpRequest request) {
+ boolean authenticated = false;
+ String userName = this.getName(); // needs disambiguation
+
+ // Get the JBoss security manager from the ENC context
+ if (_securityMgr != null && _securityMgr.isValid(this, password)) {
+ authenticated = true;
+ _log.info("Security- User: "+userName + " is authenticated");
+ // work around the fact that we are not serialisable - thanks Anatoly
+ // SecurityAssociation.setPrincipal(this);
+ SecurityAssociation.setPrincipal(new SimplePrincipal(userName));
+ SecurityAssociation.setCredential(password.toCharArray());
+ } else {
+ _log.warn("Security- User: "+userName + " is NOT authenticated");
+ }
+
+ return authenticated;
+ }
+
+ public boolean isUserInRole(String role) {
+ boolean isUserInRole = false;
+ String userName = this.getName();
+
+ // Get the JBoss security manager from the ENC context
+ SimplePrincipal rolePrincipal = new SimplePrincipal(role);
+ Set requiredRoles = Collections.singleton(rolePrincipal);
+ if (_realmMapping.doesUserHaveRole(this, requiredRoles)) {
+ isUserInRole = true;
+ _log.info("Security- User: "+userName + " is in Role: "+role);
+ } else {
+ _log.warn("Security- User: "+userName + " is NOT in Role: "+
+ role);
+ }
+
+ return isUserInRole;
+ }
+
+ public UserRealm getUserRealm() {
+ return JBossUserRealm.this;
+ }
+ }
+
+ public JBossUserRealm(Category log, String realmName) {
+ _log = log;
+ _realmName = realmName;
+ _log.info("Security- created JBossUserRealm: "+_realmName);
+ }
+
+ public String getName() {
+ return _realmName;
+ }
+
+ /**
+ * @deprecated
+ */
+ public UserPrincipal getUser(String userName, HttpRequest request) {
+ return getUser(userName);
+ }
+
+ //----------------------------------------
+
+ private synchronized User ensureUser(String userName) {
+ User user = (User)_users.get(userName);
+
+ if (user == null) {
+ user = new User(userName);
+ _users.put(userName, user);
+ }
+
+ return user;
+ }
+
+ public UserPrincipal getUser(String userName) {
+ if (_securityMgr == null) {
+ try {
+ // do we really have to do this every time - is it expensive ? TODO
+ InitialContext iniCtx = new InitialContext();
+ // do we need the 'java:comp/env' prefix ? TODO
+ _securityMgr = (AuthenticationManager)
iniCtx.lookup("java:comp/env/security/securityMgr");
+ _realmMapping = (RealmMapping)
iniCtx.lookup("java:comp/env/security/realmMapping");
+ } catch (NamingException e) {
+ _log.error("Security- Could not create initial Context", e);
+ }
+ }
+
+ _log.info("Security- User: "+userName);
+
+ return ensureUser(userName);
+ }
+
+ //----------------------------------------
}
+
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development