From b086f57f56bf0eb9dab9cf321a0f69aaaae84347 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 May 2012 08:37:45 +0200 Subject: Initial Maven Conversion --- source/com/c2kernel/lookup/AgentPath.java | 154 ------------------------------ 1 file changed, 154 deletions(-) delete mode 100644 source/com/c2kernel/lookup/AgentPath.java (limited to 'source/com/c2kernel/lookup/AgentPath.java') diff --git a/source/com/c2kernel/lookup/AgentPath.java b/source/com/c2kernel/lookup/AgentPath.java deleted file mode 100644 index 5ff6988..0000000 --- a/source/com/c2kernel/lookup/AgentPath.java +++ /dev/null @@ -1,154 +0,0 @@ -/************************************************************************** - * EntityPath.java - * - * $Revision: 1.12 $ - * $Date: 2005/10/13 08:15:00 $ - * - * Copyright (C) 2001 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ - -package com.c2kernel.lookup; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.apache.xerces.impl.dv.util.Base64; - -import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; -import com.c2kernel.process.Gateway; -import com.novell.ldap.LDAPAttribute; -import com.novell.ldap.LDAPAttributeSet; -import com.novell.ldap.LDAPEntry; - - -/** -* Extends Path to enforce SystemKey structure and support int form -* -* @version $Revision: 1.12 $ $Date: 2005/10/13 08:15:00 $ -* @author $Author: abranson $ -**/ -public class AgentPath extends EntityPath -{ - - private String mAgentName=null; - private String mPassword=null; - - public AgentPath(int syskey, String agentName) - throws InvalidAgentPathException,InvalidEntityPathException - { - super(syskey); - if (agentName!=null && agentName.length()>0) - setAgentName(agentName); - else - throw new InvalidAgentPathException(); - } - - public AgentPath(int syskey) - throws InvalidEntityPathException - { - super(syskey); - } - - public AgentPath(EntityPath entity) { - super(); - try { - setSysKey(entity.getSysKey()); - } catch (InvalidEntityPathException ex) { - //won't happen as the entity path was valid - } - } - - public void setAgentName(String agentID) - { - mAgentName = agentID; - } - - public String getAgentName() - { - if (mAgentName==null) - { - try { - LDAPEntry agentEntry = LDAPLookupUtils.getEntry(Gateway.getLDAPLookup().getConnection(), this.getDN() + mLocalPath); - mAgentName = LDAPLookupUtils.getFirstAttributeValue(agentEntry,"uid"); - } catch (ObjectNotFoundException e) { - mAgentName = ""; - } - } - return mAgentName; - } - - public RolePath[] getRoles() - { - return Gateway.getLDAPLookup().getRoleManager().getRoles(this); - } - - public boolean hasRole(RolePath role) { - return Gateway.getLDAPLookup().getRoleManager().hasRole(this, role); - } - - public boolean hasRole(String role) { - try { - return hasRole(Gateway.getLDAPLookup().getRoleManager().getRolePath(role)); - } catch (ObjectNotFoundException ex) { - return false; - } - } - - public void setPassword(String passwd) - { - mPassword = passwd; - } - - public String getPassword() - { - return mPassword; - } - - @Override - public String dump() { - return super.dump()+ - "\n agentID="+ - mAgentName; - } - - static String generateUserPassword(String pass, String algo) throws NoSuchAlgorithmException { - MessageDigest sha = MessageDigest.getInstance(algo); - sha.reset(); - sha.update(pass.getBytes()); - byte hash[] = sha.digest(); - StringBuffer digest = new StringBuffer("{").append(algo).append("}"); - digest.append(Base64.encode(hash)); - return digest.toString(); - } - - @Override - public LDAPAttributeSet createAttributeSet() throws ObjectCannotBeUpdated - { - LDAPAttributeSet attrs = new LDAPAttributeSet(); - attrs.add(new LDAPAttribute("objectclass","cristalagent")); - attrs.add(new LDAPAttribute("intsyskey",Integer.toString(mSysKey))); - attrs.add(new LDAPAttribute("cn", getPath()[getPath().length-1])); - if (mIOR != null) - attrs.add(new LDAPAttribute("ior", Gateway.getORB().object_to_string(mIOR))); - - if (mAgentName!=null && mAgentName.length()>0) - attrs.add(new LDAPAttribute("uid",mAgentName)); - else - throw new ObjectCannotBeUpdated("Cannot create agent. No userId specified", ""); - - if (mPassword!=null && mPassword.length()>0) - try { - attrs.add(new LDAPAttribute("userPassword",generateUserPassword(mPassword, "SHA"))); - } catch (NoSuchAlgorithmException ex) { - throw new ObjectCannotBeUpdated("Cryptographic libraries for password hashing not found.", ""); - } - else - throw new ObjectCannotBeUpdated("Cannot create agent. No password given", ""); - - return attrs; - } - -} - -- cgit v1.2.3