List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:org.overlord.sramp.repository.jcr.modeshape.ModeshapeRepository.java
/** * @see org.overlord.sramp.repository.jcr.JCRRepository#doStartup() *///from ww w.j a v a2 s .c o m @Override protected void doStartup() throws RepositoryException { URL configUrl = null; try { configUrl = getModeshapeConfigurationUrl(); } catch (Exception e) { log.error(e.getMessage(), e); } //Using the Modeshape Service if (configUrl == null) { String srampJndiLocation = sramp.getConfigProperty(SrampConstants.SRAMP_CONFIG_JCR_REPO_JNDI, S_RAMP_JNDI); log.info(Messages.i18n.format("CONNECT_TO_MS", srampJndiLocation)); //$NON-NLS-1$ try { InitialContext context = new InitialContext(); repository = (javax.jcr.Repository) context.lookup(srampJndiLocation); } catch (NamingException e) { throw new RepositoryException(e.getMessage(), e); } if (repository == null) { throw new RepositoryException(Messages.i18n.format("JNDI_BINDING_NOT_FOUND", srampJndiLocation)); //$NON-NLS-1$ } } //Using Modeshape embedded else { log.info(Messages.i18n.format("STARTING_MS")); //$NON-NLS-1$ try { Map<String, String> parameters = new HashMap<String, String>(); RepositoryConfiguration config = RepositoryConfiguration.read(configUrl); Problems problems = config.validate(); if (problems.hasErrors()) { throw new RepositoryException(problems.toString()); } parameters.put("org.modeshape.jcr.URL", configUrl.toExternalForm()); //$NON-NLS-1$ Set<RepositoryFactory> services = ServiceRegistryUtil.getServices(RepositoryFactory.class); if (services.isEmpty()) throw new RepositoryException(Messages.i18n.format("FAILED_TO_CREATE_JCR_REPO")); //$NON-NLS-1$ for (RepositoryFactory factory : services) { theFactory = factory; repository = factory.getRepository(parameters); if (repository != null) break; } } catch (RepositoryException e) { throw e; } catch (Exception e) { throw new RepositoryException(e); } finally { if (this.tempConfigDir != null && this.tempConfigDir.isDirectory()) { FileUtils.deleteQuietly(tempConfigDir); } } } configureNodeTypes(); }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testAllAuthMethod() throws Exception { log.debug("+++ testAllAuthMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.allAuthMethod(info);/*from w w w . j a v a 2 s .c o m*/ bean.remove(); }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testUserMethod() throws Exception { log.debug("+++ testUserMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.userMethod(info);/*from w w w. ja v a 2 s. c o m*/ bean.remove(); }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testGroupMemberMethod() throws Exception { log.debug("+++ testGroupMemberMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.groupMemberMethod(info);/* www.j a v a2 s. c o m*/ bean.remove(); }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testRunAsMethod() throws Exception { log.debug("+++ testRunAsMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.runAsMethod(info);/* w w w .j a v a2 s . c om*/ bean.remove(); }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
/** Access an unchecked method with a valid login that calls the same method on another bean using a run-as role./*w w w . j a v a2 s . com*/ @throws Exception */ public void testPublicMethod() throws Exception { log.debug("+++ testPublicMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.publicMethod(info); bean.remove(); }
From source file:org.nuxeo.ecm.core.management.jtajca.internal.DefaultConnectionMonitor.java
protected AbstractConnectionManager lookup(String repositoryName) { ConnectionManager cm = NuxeoContainer.getConnectionManager(repositoryName); if (cm == null) { // try setup through NuxeoConnectionManagerFactory try {/*from www.j ava 2 s.com*/ InitialContext ic = new InitialContext(); cm = (ConnectionManager) ic.lookup(NUXEO_CONNECTION_MANAGER_PREFIX + repositoryName); } catch (NamingException cause) { throw new RuntimeException("Cannot lookup connection manager", cause); } } if (!(cm instanceof NuxeoContainer.ConnectionManagerWrapper)) { throw new RuntimeException("Nuxeo container not installed"); } try { Field f = NuxeoContainer.ConnectionManagerWrapper.class.getDeclaredField("cm"); f.setAccessible(true); return (AbstractConnectionManager) f.get(cm); } catch (Exception cause) { throw new RuntimeException("Cannot access to geronimo connection manager", cause); } }
From source file:org.tolven.gatekeeper.bean.LdapBean.java
private LdapRealmContext getLdapRealmContext(String realm) { try {//from ww w . j ava 2 s .co m InitialContext ictx = new InitialContext(); TolvenContext tolvenContext = (TolvenContext) ictx.lookup("tolvenContext"); return (LdapRealmContext) tolvenContext.getRealmContext(realm); } catch (Exception ex) { throw new RuntimeException("Could not get LdapRealmContext", ex); } }
From source file:it.doqui.index.ecmengine.client.backoffice.EcmEngineBackofficeDirectDelegateImpl.java
@Override protected EcmEngineBackofficeBusinessInterface createBackofficeService() throws Throwable { Properties properties = new Properties(); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] BEGIN "); rb = ResourceBundle.getBundle(ECMENGINE_BKO_PROPERTIES_FILE); /*//from w w w .j a va2 s .c o m * Caricamento della porta delegata del backoffice. */ try { this.log.debug( "[" + getClass().getSimpleName() + "::createBackofficeService] P-Delegata di backoffice."); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] context factory vale : " + rb.getString(ECMENGINE_BKO_CONTEXT_FACTORY)); properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_BKO_CONTEXT_FACTORY)); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] url to connect vale : " + rb.getString(ECMENGINE_BKO_URL_TO_CONNECT)); properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_BKO_URL_TO_CONNECT)); /* Controllo che la property cluster partition sia valorizzata per capire se * sto lavorando in una configurazione in cluster oppure no */ String clusterPartition = rb.getString(ECMENGINE_BKO_CLUSTER_PARTITION); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] clusterPartition vale : " + clusterPartition); if (clusterPartition != null && clusterPartition.length() > 0) { properties.put("jnp.partitionName", clusterPartition); this.log.debug( "[" + getClass().getSimpleName() + "::createBackofficeService] disable discovery vale : " + rb.getString(ECMENGINE_BKO_DISABLE_DISCOVERY)); properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_BKO_DISABLE_DISCOVERY)); } // Get an initial context InitialContext jndiContext = new InitialContext(properties); log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] context istanziato"); // Get a reference to the Bean Object ref = jndiContext.lookup(ECMENGINE_BKO_JNDI_NAME); // Get a reference from this to the Bean's Home interface EcmEngineBackofficeHome home = (EcmEngineBackofficeHome) PortableRemoteObject.narrow(ref, EcmEngineBackofficeHome.class); // Create an Adder object from the Home interface return home.create(); } catch (Throwable e) { this.log.error("[" + getClass().getSimpleName() + "::createBackofficeService] " + "Impossibile istanziare la P-Delegata di backoffice: " + e.getMessage()); throw e; } finally { this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] END "); } }
From source file:org.apache.ws.scout.transport.RMITransport.java
/** * Sends an element and returns an element. *//*from w w w . j av a 2 s .c o m*/ public Element send(Element request, URI endpointURI) throws TransportException { Element response = null; if (log.isDebugEnabled()) { log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request)); log.debug("Calling " + endpointURI + " using rmi"); } try { String host = endpointURI.getHost(); int port = endpointURI.getPort(); String scheme = endpointURI.getScheme(); String service = endpointURI.getPath(); String className = endpointURI.getQuery(); String methodName = endpointURI.getFragment(); Properties env = new Properties(); //It be a lot nicer if this is configured through properties, but for now //I'd like to keep the changes localized, so this seems pretty reasonable. String factoryInitial = SecurityActions.getProperty("java.naming.factory.initial"); if (factoryInitial == null) factoryInitial = "org.jnp.interfaces.NamingContextFactory"; String factoryURLPkgs = SecurityActions.getProperty("java.naming.factory.url.pkgs"); if (factoryURLPkgs == null) factoryURLPkgs = "org.jboss.naming"; env.setProperty("java.naming.factory.initial", factoryInitial); env.setProperty("java.naming.factory.url.pkgs", factoryURLPkgs); env.setProperty("java.naming.provider.url", scheme + "://" + host + ":" + port); log.debug("Initial Context using env=" + env.toString()); InitialContext context = new InitialContext(env); log.debug("Calling service=" + service + ", Class = " + className + ", Method=" + methodName); //Looking up the object (i.e. Publish) Object requestHandler = context.lookup(service); //Loading up the stub Class<?> c = Class.forName(className); //Getting a handle to method we want to call (i.e. publish.publish(Element element)) Method method = c.getMethod(methodName, Element.class); //Calling that method Node node = (Node) method.invoke(requestHandler, request); //The result is in the first element if (node.getFirstChild() != null) { response = (Element) node.getFirstChild(); } } catch (Exception ex) { throw new TransportException(ex); } if (log.isDebugEnabled()) { log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response)); } return response; }