Search in sources :

Example 1 with Session

use of lotus.domino.Session in project org.openntf.xsp.jakartaee by OpenNTF.

the class PostInstallFactory method getServices.

@Override
public HttpService[] getServices(LCDEnvironment env) {
    System.out.println("postinstall start");
    try {
        Session session = NotesFactory.createSession();
        try {
            for (String nsfName : NSFS) {
                Database database = session.getDatabase("", nsfName);
                if (database == null || !database.isOpen()) {
                    throw new RuntimeException("Could not find " + nsfName);
                }
                ACL acl = database.getACL();
                ACLEntry anon = acl.getEntry("Anonymous");
                if (anon == null) {
                    anon = acl.createACLEntry("Anonymous", ACL.LEVEL_AUTHOR);
                } else {
                    anon.setLevel(ACL.LEVEL_AUTHOR);
                }
                ACLEntry admin = acl.createACLEntry("CN=Jakarta EE Test/O=OpenNTFTest", ACL.LEVEL_MANAGER);
                try {
                    admin.enableRole("[Admin]");
                } catch (NotesException e) {
                // Failing here is fine, in case the NSF doesn't have the role
                }
                acl.save();
                database.getView("Persons");
                session.sendConsoleCommand("", "load updall " + nsfName);
            }
            session.sendConsoleCommand("", "tell http osgi diag");
        } finally {
            session.recycle();
        }
    } catch (NotesException e) {
        e.printStackTrace();
    } finally {
        System.out.println("Done with postinstall");
    }
    return new HttpService[0];
}
Also used : NotesException(lotus.domino.NotesException) ACLEntry(lotus.domino.ACLEntry) HttpService(com.ibm.designer.runtime.domino.adapter.HttpService) Database(lotus.domino.Database) ACL(lotus.domino.ACL) Session(lotus.domino.Session)

Example 2 with Session

use of lotus.domino.Session in project org.openntf.nsfodp by OpenNTF.

the class DeployNSFTask method run.

@Override
public void run() {
    try {
        Session session = NotesFactory.createSession();
        try {
            String server, filePath;
            // $NON-NLS-1$
            int bangIndex = destPath.indexOf("!!");
            if (bangIndex > -1) {
                server = destPath.substring(0, bangIndex);
                filePath = destPath.substring(bangIndex + 2);
            } else {
                // $NON-NLS-1$
                server = "";
                filePath = destPath;
            }
            Database dest = session.getDatabase(server, filePath, true);
            if (dest.isOpen() && !replaceDesign) {
                throw new IllegalStateException(MessageFormat.format(Messages.DeployNSFTask_dbExists, destPath));
            }
            if (dest.isOpen()) {
                // Then do a replace design
                ReplaceDesignTaskLocal task = new ReplaceDesignTaskLocal(filePath, nsfFile, new NullProgressMonitor());
                DominoThreadFactory.getExecutor().submit(task).get();
            } else {
                // $NON-NLS-1$
                Database source = session.getDatabase("", nsfFile.toAbsolutePath().toString());
                dest = source.createFromTemplate(server, filePath, false);
            }
            if (this.signDatabase) {
                AdministrationProcess adminp = session.createAdministrationProcess(server);
                adminp.signDatabaseWithServerID(server, filePath);
                // $NON-NLS-1$
                session.sendConsoleCommand(server, "tell adminp p im");
            }
        } finally {
            session.recycle();
        }
    } catch (NotesException | ExecutionException | InterruptedException ne) {
        throw new RuntimeException(Messages.DeployNSFTask_exceptionDeploying, ne);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NotesException(lotus.domino.NotesException) Database(lotus.domino.Database) AdministrationProcess(lotus.domino.AdministrationProcess) ExecutionException(java.util.concurrent.ExecutionException) Session(lotus.domino.Session)

Example 3 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class AdminNSFProxyConfigProvider method createConfiguration.

@SuppressWarnings("unchecked")
@Override
public ReverseProxyConfig createConfiguration() {
    ReverseProxyConfig result = new ReverseProxyConfig();
    RuntimeConfigurationProvider runtimeConfig = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
    result.dominoHostName = runtimeConfig.getDominoHostName();
    result.dominoHttpPort = runtimeConfig.getDominoPort();
    result.dominoHttps = runtimeConfig.isDominoHttps();
    try {
        DominoThreadFactory.getExecutor().submit(() -> {
            try {
                Session session = NotesFactory.createSession();
                try {
                    Database adminNsf = AdminNSFUtil.getAdminDatabase(session);
                    Document config = AdminNSFUtil.getConfigurationDocument(adminNsf);
                    // Load the main config
                    boolean connectorHeaders = runtimeConfig.isUseDominoConnectorHeaders();
                    readConfigurationDocument(result, config, connectorHeaders);
                    if (!result.isGlobalEnabled()) {
                        return;
                    }
                    Collection<String> namesList = AdminNSFUtil.getCurrentServerNamesList();
                    // Look for proxy-enabled webapps
                    View targetsView = adminNsf.getView(VIEW_REVERSEPROXYTARGETS);
                    targetsView.setAutoUpdate(false);
                    targetsView.refresh();
                    ViewNavigator nav = targetsView.createViewNav();
                    nav.setEntryOptions(ViewNavigator.VN_ENTRYOPT_NOCOUNTDATA);
                    ViewEntry entry = nav.getFirst();
                    while (entry != null) {
                        Vector<?> columnValues = entry.getColumnValues();
                        List<String> dominoServers;
                        Object dominoServersObj = columnValues.get(4);
                        if (dominoServersObj instanceof String) {
                            dominoServers = Arrays.asList((String) dominoServersObj);
                        } else {
                            dominoServers = (List<String>) dominoServersObj;
                        }
                        boolean shouldRun = AdminNSFUtil.isNamesListMatch(namesList, dominoServers);
                        if (shouldRun) {
                            // Format: http://localhost:80
                            String baseUri = (String) columnValues.get(1);
                            // $NON-NLS-1$
                            boolean useXForwardedFor = "Y".equals(columnValues.get(2));
                            // $NON-NLS-1$
                            boolean useWsHeaders = "Y".equals(columnValues.get(3));
                            // Now read the children to build targets
                            ViewEntry childEntry = nav.getChild(entry);
                            while (childEntry != null) {
                                Vector<?> childValues = childEntry.getColumnValues();
                                // Format: foo
                                String contextPath = (String) childValues.get(0);
                                // $NON-NLS-1$
                                URI uri = URI.create(baseUri + "/" + contextPath);
                                ReverseProxyTarget target = new ReverseProxyTarget(uri, useXForwardedFor, useWsHeaders);
                                result.addTarget(contextPath, target);
                                childEntry.recycle(childValues);
                                ViewEntry tempChild = childEntry;
                                childEntry = nav.getNextSibling(childEntry);
                                tempChild.recycle();
                            }
                        }
                        entry.recycle(columnValues);
                        ViewEntry tempEntry = entry;
                        entry = nav.getNextSibling(entry);
                        tempEntry.recycle();
                    }
                } finally {
                    session.recycle();
                }
                return;
            } catch (Throwable e) {
                e.printStackTrace(OpenLibertyLog.instance.out);
                throw new RuntimeException(e);
            }
        }).get();
        if (result.isGlobalEnabled()) {
            // Determine the local server port from the server doc
            DominoThreadFactory.getExecutor().submit(() -> {
                try {
                    Session session = NotesFactory.createSession();
                    try {
                        String serverName = session.getUserName();
                        // $NON-NLS-1$ //$NON-NLS-2$
                        Database names = session.getDatabase("", "names.nsf");
                        // $NON-NLS-1$
                        View servers = names.getView("$Servers");
                        Document serverDoc = servers.getDocumentByKey(serverName);
                        // Mirror Domino's maximum entity size
                        // $NON-NLS-1$
                        long maxEntitySize = serverDoc.getItemValueInteger("HTTP_MaxContentLength");
                        if (maxEntitySize == 0) {
                            maxEntitySize = Long.MAX_VALUE;
                        }
                        result.maxEntitySize = maxEntitySize;
                    } finally {
                        session.recycle();
                    }
                } catch (Exception e) {
                    e.printStackTrace(OpenLibertyLog.instance.out);
                    throw new RuntimeException(e);
                }
            }).get();
        }
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace(OpenLibertyLog.instance.out);
        throw new RuntimeException(e);
    }
    return result;
}
Also used : ReverseProxyTarget(org.openntf.openliberty.domino.reverseproxy.ReverseProxyTarget) ViewNavigator(lotus.domino.ViewNavigator) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) Document(lotus.domino.Document) View(lotus.domino.View) URI(java.net.URI) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NotesException(lotus.domino.NotesException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) ReverseProxyConfig(org.openntf.openliberty.domino.reverseproxy.ReverseProxyConfig) ViewEntry(lotus.domino.ViewEntry) Database(lotus.domino.Database) Collection(java.util.Collection) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Vector(java.util.Vector) Session(lotus.domino.Session)

Example 4 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class IdentityServlet method checkPassword.

private String checkPassword(String userSecurityName, String password) throws NotesException, IOException {
    Session session = NotesFactory.createSession();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        Database names = session.getDatabase("", "names.nsf");
        Document tempDoc = names.createDocument();
        // $NON-NLS-1$
        tempDoc.replaceItemValue("Username", userSecurityName);
        // $NON-NLS-1$
        tempDoc.replaceItemValue("Password", password);
        // $NON-NLS-1$
        session.evaluate(" @SetField('HashPassword'; @NameLookup([NoCache]:[Exhaustive]; Username; 'HTTPPassword')[1]) ", tempDoc);
        // TODO look up against other password variants, or find real way to do this
        // $NON-NLS-1$
        List<?> result = session.evaluate(" @VerifyPassword(Password; HashPassword) ", tempDoc);
        if (!result.isEmpty() && Double.valueOf(1).equals(result.get(0))) {
            // $NON-NLS-1$
            return (String) session.evaluate(" @NameLookup([NoCache]:[Exhaustive]; Username; 'FullName') ", tempDoc).get(0);
        } else {
            // $NON-NLS-1$
            return "";
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    } finally {
        session.recycle();
    }
}
Also used : Database(lotus.domino.Database) Document(lotus.domino.Document) Session(lotus.domino.Session)

Example 5 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class IdentityServlet method getUniqueGroupIds.

@SuppressWarnings("unchecked")
private String getUniqueGroupIds(String uniqueUserId) throws NotesException {
    Session session = NotesFactory.createSession();
    try {
        DominoServer server = new DominoServer(session.getUserName());
        String name = getUserSecurityName(uniqueUserId);
        List<String> names = new ArrayList<>((Collection<String>) server.getNamesList(name));
        // $NON-NLS-1$
        int starIndex = names.indexOf("*");
        if (starIndex > -1) {
            // Everything at and after this point should be a group or
            // pseudo-group (e.g. "*/O=SomeOrg")
            names = names.subList(starIndex, names.size());
        }
        // $NON-NLS-1$
        return String.join("\n", names);
    } finally {
        session.recycle();
    }
}
Also used : DominoServer(lotus.notes.addins.DominoServer) ArrayList(java.util.ArrayList) Session(lotus.domino.Session)

Aggregations

Session (lotus.domino.Session)24 Database (lotus.domino.Database)18 Document (lotus.domino.Document)12 NotesException (lotus.domino.NotesException)8 View (lotus.domino.View)4 ViewEntry (lotus.domino.ViewEntry)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 ExecutionException (java.util.concurrent.ExecutionException)2 DateTime (lotus.domino.DateTime)2 DocumentCollection (lotus.domino.DocumentCollection)2 Name (lotus.domino.Name)2 NoteCollection (lotus.domino.NoteCollection)2 ViewNavigator (lotus.domino.ViewNavigator)2 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesSession (com.ibm.designer.domino.napi.NotesSession)1 HttpService (com.ibm.designer.runtime.domino.adapter.HttpService)1 ModuleClassLoader (com.ibm.domino.xsp.module.nsf.ModuleClassLoader)1 Sort (jakarta.nosql.Sort)1