O2OA使用手册
第1章 功能简介及概述
第6章 平台部署与配置
  • 6.1 安装部署-在Windows系统中部署O2OA开发平台
  • 6.2 安装部署-在Linux系统中部署O2OA开发平台
  • 6.3 安装部署-在宝塔/PHPStudy中部署O2OA开发平台
  • 6.4 安装部署-O2OA开发平台之HTTP端口规划
  • 6.5 安装部署-平台服务器版本升级操作说明
  • 6.6 安装部署-私有化部署服务器架构推荐
  • 6.7 安装部署-O2OA开发平台集群部署配置及操作说明
  • 6.8 安装部署-在线部署自定义应用的WAR包和JAR包
  • 6.9 服务器配置与管理-​O2OA主要配置文件说明
  • 6.10 服务器配置与管理-服务器端口冲突和端口修改
  • 6.11 服务器配置与管理-如何修改服务器内存占用率?
  • 6.12 服务器配置与管理-如何访问和操作H2内置数据库
  • 6.13 服务器配置与管理-​如何在O2OA中使用MySQL数据库?
  • 6.14 服务器配置与管理-如何修改平台支持的数据库驱动包
  • 6.15 服务器配置与管理-O2OA使用openGauss(华为高斯数据库)配置
  • 6.16 服务器配置与管理-O2OA开发平台平台数据库配置信息样例
  • 6.17 服务器配置与管理-配置O2OA服务器连接O2云
  • 6.18 服务器配置与管理-O2OA实现服务器随操作系统自动启动
  • 6.19 服务器配置与管理-文件存储服务器配置
  • 6.20 服务器配置与管理-工作日节假日配置
  • 6.21 服务器配置与管理-为平台增加全文检索功能
  • 6.22 服务器配置与管理-消息提醒配置说明
  • 6.23 服务器配置与管理-自定义消息提醒
  • 6.24 服务器配置与管理-定制消息通知的内容
  • 6.25 服务器配置与管理-消息通知过滤
  • 6.26 服务器配置与管理-为待办创建配置邮件通知
  • 6.27 服务器配置与管理-待办待阅数据的查询操作和管理
  • 6.28 服务器配置与管理-​自动执行平台数据的备份与恢复
  • 6.29 服务器配置与管理-数据导出导入与系统数据备份
  • 6.30 ​服务器配置与管理-定期自动执行数据备份与恢复
  • 6.31 系统安全-O2OA作为认证中心实现基于OAUTH2单点认证
  • 6.32 系统安全-O2OA基于Nginx的SSL跳转、转发配置
  • 6.33 O2OA(翱途)开发平台如何基于nginx上下文分发的方式快速集群部署
  • 6.34 系统安全-访问日志相关配置
  • 6.35 系统架构-平台集群化部署之基于Nginx端口分发机制实现集群部署
  • 6.36 系统安全-审计日志相关配置
  • 6.37 系统安全-平台日志文件说明
  • 6.38 系统架构-基于nginx快速集群部署-上下文分发
  • 6.39 系统安全-O2OA日志输出设置log4j2.xml
  • 6.40 系统安全-用户密码初始化规则的设定
  • 6.41 系统安全-启用HTTPS(百度云版)
  • 6.42 系统安全-启用HTTPS(腾讯云版)
  • 6.43 系统安全-自签名SSL证书验证HTTPS功能
  • 6.44 系统安全-登录密码RSA加密
  • 6.45 系统安全-用户登录IP限制
  • 6.46 系统安全-在用户登录过程中启用图形验证码
  • 6.47 系统安全-平台部署之使用非root用户运行服务
  • 6.48 系统安全-O2Server启用国密加密设置
  • 6.49 系统安全-日志应用使用说明
  • 6.50 系统安全-用户重置密码操作
  • 6.51 系统安全-超级管理员(xadmin)密码修改
  • 6.52 系统安全-使用Web端运行服务器管理命令
  • 6.53 系统安全-o2server无法正常显示验证码解决办法
  • 6.54 O2OA(翱途)开发平台前端安全配置建议(一)
  • 第16章 开发知识及常见问题
  • 16.1 如何替换登录页面二维码中默认的logo图标
  • 16.2 O2OA(翱途)流程引擎中如何修改,定制流程的流转记录
  • 16.3 mysql数据库备份
  • 16.4 domain不正确的时候如何强制设置成正确的
  • 16.5 配置文件中使用密文存储密码
  • 16.6 常见问题-连接MySQL出现 Public Key Retrieval is not allowed 的错误
  • 16.7 常见问题-查看表结构
  • 16.8 常见问题-7.2及以上版本开启web代理后请求中没有正确使用web端口问题解决方式
  • 16.9 linux环境libreoffice安装及使用
  • 16.10 在O2OA中使用网络会议(二):Openmeetings与O2OA认证配置
  • 16.11 在O2OA中使用网络会议(一):Openmeetings-5.1.0亲手安装整理 Step-By-Step
  • 16.12 藕粉社区问答系列1
  • 16.13 藕粉社区问答系列2
  • 16.14 藕粉社区问答系列3
  • 16.15 快速入门-平台相关资料汇总
  • 16.16 快速入门-服务器总体介绍汇总
  • 16.17 快速入门-流程表单载入基础数据
  • 16.18 快速入门-常用表单脚本样例汇总
  • 16.19 快速入门-自定义表数据分页样例
  • 16.20 OEM白标-如何修改平台中的Logo图标和文字
  • 16.21 云服务器-阿里云ECS服务器的端口启用
  • 16.22 开发知识-React篇:在O2OA平台框架中使用React
  • 16.23 开发知识-React篇:在O2OA门户页面中使用React
  • 16.24 开发知识-Vue篇:在Vue应用中集成O2OA
  • 16.25 开发知识-Vue篇:使用Vue-CLI开发O2应用
  • 16.26 开发知识-Vue篇:在O2门户页面中使用Vue
  • 16.27 平台中使用Druid数据库连接及监控
  • 16.28 开发知识-在PAAS平台上部署O2OA开发平台
  • 16.29 开发知识-如何使用Tomcat架设webdav服务器
  • 16.30 开发知识-单个端口模式的Nginx和系统配置
  • 16.31 开发知识-Linux非root用户如何使用80端口启动O2OA
  • 16.32 开发知识-O2OA平台启用Eruda进行移动端调试
  • 16.33 开发知识-神通数据库安装
  • 16.34 开发知识-人大金仓数据安装
  • 16.35 开发知识-中标麒麟安装达梦数据库(DM8)
  • 16.36 开发知识-中标麒麟安装人大金仓详细步骤
  • 16.37 开发知识-使用VNC连接中标麒麟V7操作系统
  • 16.38 开发知识-鲲鹏(ARM)麒麟操作系统如何替换yum源?
  • 16.39 开发知识-数据优化知识点
  • 16.40 水印安全-附件水印|加密|文档格式转换图片|PDF
  • 16.41 消息队列-配置activeMQ、kafka消息队列
  • 16.42 常见问题-数据导出或者导入时发生OOM异常
  • 16.43 常见问题-如何让用户在首次登录时,必须对初始密码进行修改
  • 16.44 常见问题-如何在模块部署中控制模块的访问权限
  • 16.45 常见问题-如何在平台中开发Ftp文件上传文件的服务?
  • 16.46 常见问题-如何使用服务管理调用WebService
  • 16.47 常见问题-如何使用脚本调用外部服务
  • 16.48 常见问题-如何使用脚本控制流程自动流转
  • 16.49 常见问题-如何通过脚本调用系统内服务
  • 16.50 常见问题-接口代码疑惑解答汇总
  • 16.51 常见问题:Maven编译o2server错误: Java Heap Space
  • 16.52 常见问题-集群配置后启动报错:NullPointerException
  • 16.53 常见问题-服务器错误:can not decrypt token
  • 16.54 常见问题-IOS移动办公无法收到验证码
  • 16.55 常见问题-服务器和日志时间相差12小时的问题
  • 16.56 常见问题-为什么127.0.0.1可以访问但其他IP无法访问
  • 16.57 藕粉社区问答系列4
  • 16.58 开发知识-React篇:在React应用中集成O2OA

  • 服务集成-发送用户账号密码进行登录认证

    时间:2022-08-03   

    O2OA提供多种SSO单点认证方式,比如约定密钥,OAuth2,SMAP等等。本文主要演示如何发送用户账号密码进行登录认证

    此示例演示如何使用java发送Http请求来登录o2server,获取登录认证xtoken信息

    完整代码示例:

    使用账号密码发送请求登录


    package net.o2oa.demos;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.URL;
    import java.net.URLConnection;
    import org.apache.commons.codec.binary.StringUtils;
    import org.json.JSONObject;
    /**
     * 此示例演示如何使用java发送Http请求来登录o2server,获取登录认证xtoken信息 
     * @author O2OA
     */
    public class Demo_LoginToServer {
            
        	static final String URL_LOGIN = "/x_organization_assemble_authentication/jaxrs/authentication";
        
            public static void main(String[] args) {
                String applicationServer = "127.0.0.1";
                Integer applicationPort = 20020;
                String userName = "张三";
                String password = "o2oa@2022";
                try {
                    LoginResult result = login(applicationServer, applicationPort, userName, password);
                    if (StringUtils.equals("success", result.getType())) {
                        System.out.println("xtoken=" + result.getToken());
                    } else {
                        System.out.println("message:" + result.getMessage());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            
        //服务地址:http://127.0.0.1:20020/x_organization_assemble_authentication/jaxrs/authentication
        // {"credential":"xadmin","password":"o2oa@2022"}
        /**
             * 使用登录认证的接口进行服务器登录,获取xtoken信息
             * @param applicationServer  127.0.0.1
             * @param applicationPort     20020
             * @param userName             张三
             * @param password              o2oa@2022
             * @return
             * @throws Exception
             */
        public static LoginResult login(String applicationServer, Integer applicationPort, String userName, String password) throws Exception {
            //参数
            String loginUrl = "http://" + applicationServer + ":" + applicationPort + URL_LOGIN;
            String loginParams = String.format("{'credential':'%s','password':'%s'}", userName, password);
            String responseData = sendPost(loginUrl, loginParams);
            JSONObject result = new JSONObject(responseData);
            String type = result.getString("type");
            if (StringUtils.equals("success", type)) {
            	//登录成功
                JSONObject data = result.getJSONObject("data");
                String token = data.getString("token");
            	return new LoginResult("success", token, "登录成功!");
            } else {
            	//登录失败
            	return new LoginResult("error", null, "用户不存在或者密码错误!");
            }
        }
        /**
          	* 发送POST请求     
            * 	 
            * @param url  地址	 
            * @param param   传入的数据	 
            * @return
        	*/
        public static String sendPost(String url, String param) {
                PrintWriter out = null;
                BufferedReader in = null;
                String result = "";
            try {
                URL realUrl = new URL(url);
                URLConnection conn = realUrl.openConnection();
                conn.setRequestProperty("accept", "*/*");
                conn.setRequestProperty("connection", "Keep-Alive");
                conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
                conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                conn.setDoOutput(true);
                conn.setDoInput(true);
                out = new PrintWriter(conn.getOutputStream());
                out.print(param);
                out.flush();
                in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String line;
                
                while ((line = in.readLine()) != null) {
                    result += line;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (out != null) {
                        out.close();
                    }
                    if (in != null) {
                        in.close();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
        	}
        	return result;
        }
    }


    LoginResult.java

    public static class LoginResult {
        
        private String type;
        private String token;
        private String message;
        
        public LoginResult(String type, String token, String message) {
            super();
            this.type = type;
            this.token = token;
            this.message = message;
        }
        
        public String getType() {
       		return type;
        }
        
        public void setType(String type) {
        	this.type = type;
        }
        
        public String getToken() {
        	return token;
        }
        
        public void setToken(String token) {
        	this.token = token;
        }
        
        public String getMessage() {
        	return message;
        }
        
        public void setMessage(String message) {
        	this.message = message;
        }
    }

    成功响应结果JSON:

    {
      "type": "success",
      "data": {
        "tokenType": "manager",
        "token": "HeEoZIVgPjQAuhSAF5z5qKCO-_-iWowwEIdiuKMfurQ",
        "roleList": [
        "Manager",
        "OrganizationManager",
        "MeetingManager",
        "ProcessPlatformManager"
        ],
        "id": "xadmin",
        "name": "xadmin",
        "employee": "xadmin",
        "distinguishedName": "xadmin@o2oa@P",
        "mail": "xadmin@o2oa.net",
        "weixin": "",
        "qq": "",
        "mobile": ""
      },
      "message": "",
      "date": "2019-10-19 14:15:17",
      "spent": 18,
      "size": -1,
      "count": 0,
      "position": 0
    }

    失败响应结果JSON:

    {
      "readyState": 4,
      "responseText": "{"type": "error","message": "用户不存在或者密码错误.","date": "2019-10-19 14:34:34","spent": 9,  "size": -1,  "count": 0,  "position": 0,   "prompt":"com.x.organization.assemble.authentication.jaxrs.authentication.ExceptionPersonNotExistOrInvalidPassword"  }",
      "responseJSON": {
      "type": "error",
      "message": "用户不存在或者密码错误.",
      "date": "2019-10-19 14:34:34",
      "spent": 9,
      "size": -1,
      "count": 0,
      "position": 0,
      "prompt": "com.x.organization.assemble.authentication.jaxrs.authentication.ExceptionPersonNotExistOrInvalidPassword"
      },
      "status": 500,
      "statusText": "Internal Server Error"
    }

    pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>net.o2oa.demos</groupId>
      <artifactId>test_start_process_demo</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>jar</packaging>
      <name>test_start_process_demo</name>
      <url>http://maven.apache.org</url>
      <properties>
      	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <dependencies>        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.5.10</version>
        </dependency>        
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore-nio -->
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpcore-nio</artifactId>
          <version>4.4.12</version>
        </dependency>        
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpcore</artifactId>
          <version>4.4.12</version>
        </dependency>        
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpmime</artifactId>
          <version>4.5.10</version>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-lang3</artifactId>
          <version>3.9</version>
        </dependency>
        <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.8.5</version>
        </dependency>        
        <!-- https://mvnrepository.com/artifact/org.json/json -->
        <dependency>
          <groupId>org.json</groupId>
          <artifactId>json</artifactId>
          <version>20190722</version>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>