/** * INTERNAL: * Clone the login. * This also clones the platform as it is internal to the login. */ public Object clone() { DatasourceLogin clone = null; try { clone = (DatasourceLogin)super.clone(); } catch (Exception exception) { // should not happen...do nothing } if (getConnector() != null) { clone.setConnector((Connector)getConnector().clone()); } clone.setDatasourcePlatform((Platform)getDatasourcePlatform().clone()); clone.setProperties((Properties)properties.clone()); return clone; }
/** * ADVANCED: * Create a new login for the given platform. */ public DatasourceLogin(Platform databasePlatform) { this.platform = databasePlatform; this.dontUseExternalConnectionPooling(); this.dontUseExternalTransactionController(); this.properties = new NonSynchronizedProperties(4); this.properties.put("user", ""); this.isEncryptedPasswordSet = false; this.securableObjectHolder = new SecurableObjectHolder(); }
/** * PUBLIC: * The properties are additional, driver-specific, connection information * to be passed to the driver.<p> * NOTE: Do not set the password directly by getting the properties and * setting the "password" property directly. Use the method DatabaseLogin.setPassword(String). */ public Object getProperty(String name) { return getProperties().get(name); }
/** * ADVANCED: * Set the database platform to be custom platform. */ public void usePlatform(Platform platform) { if (getDatasourcePlatform() != null) { getDatasourcePlatform().copyInto(platform); } setPlatform(platform); }
/** * INTERNAL: * Connect to the datasource, and return the driver level connection object. */ @Override public Object connectToDatasource(Accessor accessor, Session session) throws DatabaseException { return getConnector().connect(prepareProperties(properties), session); }
Class platformClass = m_classLoader.loadClass(platformClassName); if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ login.usePlatform((DatasourcePlatform)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(platformClass))); }else{ login.usePlatform((DatasourcePlatform)PrivilegedAccessHelper.newInstanceFromClass(platformClass)); login.setTableQualifier(tableQualifier); login.setUserName(loginConfig.getUsername()); login.setEncryptionClassName(loginConfig.getEncryptionClass()); login.setEncryptedPassword(loginConfig.getEncryptedPassword()); login.setUsesExternalConnectionPooling(loginConfig.getExternalConnectionPooling()); login.setUsesExternalTransactionController(loginConfig.getExternalTransactionController()); if (loginConfig.getSequencingConfig().getDefaultSequenceConfig() != null) { Sequence sequence = buildSequence(loginConfig.getSequencingConfig().getDefaultSequenceConfig()); login.setDefaultSequence(sequence); login.addSequence(sequence); login.getProperties().put(propertyConfig.getName(), propertyConfig.getValue());
login.setPlatformClassName(eclipselinkPlatform, this.persistenceUnitInfo.getClassLoader()); if (login.getDatasourcePlatform() instanceof EISPlatform) { isEIS = true; EISLogin newLogin = new EISLogin(); newLogin.setDatasourcePlatform(login.getDatasourcePlatform()); this.session.setDatasourceLogin(newLogin); if (this.session.isServerSession()) { login.setConnector((Connector)connectorValue); } else if (connectorValue instanceof String) { Class cls = null; login.setConnector(connector); ((EISConnectionSpec)login.getConnector()).setConnectionSpecObject(connectorValue); ((EISConnectionSpec)login.getConnector()).setName((String)factoryValue); } else if (factoryValue != null) { ((EISConnectionSpec)login.getConnector()).setConnectionFactoryObject(factoryValue); String property = (String)entry.getKey(); Object value = entry.getValue(); login.setProperty(property, value); String password = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_PASSWORD, m, this.session); if(user != null) { login.setUserName(user);
if (login.shouldUseExternalTransactionController() && isDefaultConnectorRequired) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("entity_manager_properties_conflict_default_connector_vs_external_transaction_controller", new Object[] {})); String dataSourceName = null; if (isJNDIConnectorRequired) { if (login.shouldUseExternalTransactionController()) { if (isPropertyToBeAdded(jtaDataSource, jtaDataSourceName)) { dataSource = jtaDataSource; Boolean isNewUserRequired = isPropertyValueToBeUpdated(login.getUserName(), user); if (login.getConnector() instanceof DefaultConnector) { oldDefaultConnector = (DefaultConnector) login.getConnector(); if (login.getConnector() instanceof JNDIConnector) { oldJNDIConnector = (JNDIConnector) login.getConnector(); newLogin = login.clone(); newPolicy.setLogin(newLogin); newLogin.setProperty("user", user); } else { newLogin.getProperties().remove("user"); newLogin.setProperty("password", password); } else { newLogin.getProperties().remove("password"); newLogin.setConnector(new DefaultConnector());
/** * PUBLIC: * Print all of the connection information. */ public String toString() { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); writer.write(Helper.getShortClassName(getClass())); writer.println("("); writer.println("\t" + ToStringLocalization.buildMessage("platform", (Object[])null) + "=> " + getDatasourcePlatform()); if (!shouldUseExternalConnectionPooling()) { writer.println("\t" + ToStringLocalization.buildMessage("user_name", (Object[])null) + "=> \"" + getUserName() + "\""); } writer.print("\t"); getConnector().toString(writer); writer.write(")"); return stringWriter.toString(); }
/** * INTERNAL: * Return the name of the database platform class. */ public String getPlatformClassName() { return getDatasourcePlatform().getClass().getName(); } /**
/** * Set the password. */ public void setPassword(String password) { if (password != null) { // PERF: Do not encrypt empty string. if (password == "") { setProperty("password", ""); } else { // first call to get will initialize the securable object // Bug 4117441 - Secure programming practices, store password in char[] String encryptedPassword = getSecurableObjectHolder().getSecurableObject().encryptPassword(password); setProperty("password", encryptedPassword.toCharArray()); } } else { // is null so remove the property removeProperty("password"); } }
@Override public void customize(Session session) throws Exception { DatasourceLogin login = session.getLogin(); login.setConnector(new ProfilingConnector(login.getConnector())); if (session instanceof ServerSession) { ServerSession serverSession = (ServerSession) session; ConnectionPool pool = serverSession.getReadConnectionPool(); if (pool != null) { Login poolLogin = pool.getLogin(); if (poolLogin instanceof DatasourceLogin) { login = (DatasourceLogin) poolLogin; login.setConnector(new ProfilingConnector(login.getConnector())); } } } } }
Sequence defaultSequence = ((DatasourceLogin)datasourceLogin).getDefaultSequenceToWrite(); if (defaultSequence != null) { method.addLine(""); method.addLine(setDefaultOrAddSequenceString(defaultSequence, true)); Map sequences = ((DatasourceLogin)datasourceLogin).getSequencesToWrite(); if ((sequences != null) && !sequences.isEmpty()) { if (!addedSequencingHeader) {
login.setDefaultSequence(sequences.get(MetadataProject.DEFAULT_AUTO_GENERATOR)); login.addSequence(sequence); } else { String seqName;
if (sequenceDataSource != null) { DatasourceLogin login = this.session.getLogin().clone(); login.dontUseExternalTransactionController(); JNDIConnector jndiConnector = new JNDIConnector(sequenceDataSource); login.setConnector(jndiConnector); serverSession.getSequencingControl().setLogin(login);
/** * Sets the encryption class name */ public void setEncryptionClassName(String encryptionClassName) { getSecurableObjectHolder().setEncryptionClassName(encryptionClassName); }
/** * In cases where there is no data source, we will use properties to configure the login for * our session. This method gets those properties and sets them on the login. */ protected void updateLoginDefaultConnector(DatasourceLogin login, Map m){ //Login info might be already set with sessions.xml and could be overridden by session customizer after this //If login has default connector then JDBC properties update(override) the login info if ((login.getConnector() instanceof DefaultConnector)) { DatabaseLogin dbLogin = (DatabaseLogin)login; // Note: This call does not checked the stored persistenceUnitInfo or extended properties because // the map passed into this method should represent the full set of properties we expect to process String jdbcDriver = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_DRIVER, m, session); String connectionString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_URL, m, session); if(connectionString != null) { dbLogin.setConnectionString(connectionString); } if(jdbcDriver != null) { dbLogin.setDriverClassName(jdbcDriver); } } }
Class platformClass = m_classLoader.loadClass(platformClassName); if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ login.usePlatform((DatasourcePlatform)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(platformClass))); }else{ login.usePlatform((DatasourcePlatform)PrivilegedAccessHelper.newInstanceFromClass(platformClass)); login.setTableQualifier(tableQualifier); login.setUserName(loginConfig.getUsername()); login.setEncryptionClassName(loginConfig.getEncryptionClass()); login.setEncryptedPassword(loginConfig.getEncryptedPassword()); login.setUsesExternalConnectionPooling(loginConfig.getExternalConnectionPooling()); login.setUsesExternalTransactionController(loginConfig.getExternalTransactionController()); if (loginConfig.getSequencingConfig().getDefaultSequenceConfig() != null) { Sequence sequence = buildSequence(loginConfig.getSequencingConfig().getDefaultSequenceConfig()); login.setDefaultSequence(sequence); login.addSequence(sequence); login.getProperties().put(propertyConfig.getName(), propertyConfig.getValue());
/** * PUBLIC: * Print all of the connection information. */ public String toString() { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); writer.write(Helper.getShortClassName(getClass())); writer.println("("); writer.println("\t" + ToStringLocalization.buildMessage("platform", (Object[])null) + "=> " + getDatasourcePlatform()); if (!shouldUseExternalConnectionPooling()) { writer.println("\t" + ToStringLocalization.buildMessage("user_name", (Object[])null) + "=> \"" + getUserName() + "\""); } writer.print("\t"); getConnector().toString(writer); writer.write(")"); return stringWriter.toString(); }
/** * INTERNAL: * Return the name of the database platform class. */ public String getPlatformClassName() { return getDatasourcePlatform().getClass().getName(); } /**