mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-06-14 11:31:47 +08:00
init
This commit is contained in:
7
maxkey-protocols/maxkey-protocol-extendapi/.classpath
Normal file
7
maxkey-protocols/maxkey-protocol-extendapi/.classpath
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
41
maxkey-protocols/maxkey-protocol-extendapi/.project
Normal file
41
maxkey-protocols/maxkey-protocol-extendapi/.project
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>maxkey-protocol-extendapi</name>
|
||||
<comment>Project maxkey-protocol-extendapi created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,11 @@
|
||||
build.commands=org.eclipse.jdt.core.javabuilder
|
||||
connection.arguments=
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.java.home=null
|
||||
connection.jvm.arguments=
|
||||
connection.project.dir=../..
|
||||
containers=org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7/
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature
|
||||
project.path=\:maxkey-protocols\:maxkey-protocol-extendapi
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="maxkey-protocol-extendapi">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="java"/>
|
||||
<fixed facet="jst.utility"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
</faceted-project>
|
||||
@@ -0,0 +1,2 @@
|
||||
boot.validation.initialized=true
|
||||
eclipse.preferences.version=1
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
25
maxkey-protocols/maxkey-protocol-extendapi/build.gradle
Normal file
25
maxkey-protocols/maxkey-protocol-extendapi/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
description = "maxkey-protocol-extendapi"
|
||||
|
||||
|
||||
dependencies {
|
||||
//local jars
|
||||
compile fileTree(dir: '../maxkey-lib/spring/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/spring-security/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/apache/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/db/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/tiles/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/common/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/opensaml/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/xml/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/json/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/log/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/java/', include: '*.jar')
|
||||
compile fileTree(dir: '../maxkey-lib/other/', include: '*.jar')
|
||||
|
||||
compile project(":maxkey-core")
|
||||
compile project(":maxkey-dao")
|
||||
compile project(":maxkey-jose-jwt")
|
||||
compile project(":maxkey-client-sdk")
|
||||
compile project(":maxkey-protocols:maxkey-protocol-authorize")
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
Manifest-Version: 1.0
|
||||
Implementation-Title: maxkey-protocol-extendapi
|
||||
Implementation-Version: 3.0.0.RELEASE
|
||||
Implementation-Date: 2019-03-05T21:26:16.770+08:00[GMT+08:00]
|
||||
Created-By: com.connsec.maxkey
|
||||
Implementation-Vendor: http://www.connsec.com
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.maxkey.authz.exapi.endpoint;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.BOOLEAN;
|
||||
import org.maxkey.domain.Accounts;
|
||||
import org.maxkey.domain.apps.Applications;
|
||||
import org.maxkey.util.Instance;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
final static Logger _logger = LoggerFactory.getLogger(ExtendApiAuthorizeEndpoint.class);
|
||||
|
||||
@RequestMapping("/authz/api/{id}")
|
||||
public ModelAndView authorize(HttpServletRequest request,@PathVariable("id") String id){
|
||||
|
||||
Applications apps=getApp(id);
|
||||
_logger.debug(""+apps);
|
||||
|
||||
if(BOOLEAN.isTrue(apps.getIsAdapter())){
|
||||
Accounts appUser=getAppAccounts(apps);
|
||||
|
||||
if(appUser == null){
|
||||
return generateInitCredentialModelAndView(id,"/authorize/api/"+id);
|
||||
}
|
||||
|
||||
ModelAndView modelAndView=new ModelAndView();
|
||||
|
||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
|
||||
|
||||
apps.setAppUser(appUser);
|
||||
|
||||
modelAndView=adapter.authorize(
|
||||
WebContext.getUserInfo(),
|
||||
apps,
|
||||
appUser.getRelatedUsername()+"."+appUser.getRelatedPassword(),
|
||||
modelAndView);
|
||||
return modelAndView;
|
||||
}else{
|
||||
String redirec_uri=getApp(id).getLoginUrl();
|
||||
return WebContext.redirect(redirec_uri);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.maxkey.authz.exapi.endpoint.adapter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.client.oauth.OAuthClient;
|
||||
import org.maxkey.client.oauth.model.Token;
|
||||
import org.maxkey.client.utils.JsonUtils;
|
||||
import org.maxkey.domain.ExtraAttrs;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.domain.apps.Applications;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
public class ExtendApiQQExmailDefaultAdapter extends AbstractAuthorizeAdapter {
|
||||
final static Logger _logger = LoggerFactory.getLogger(ExtendApiQQExmailDefaultAdapter.class);
|
||||
static String login_url_template="https://exmail.qq.com/cgi-bin/login?fun=bizopenssologin&method=bizauth&agent=%s&user=%s&ticket=%s";
|
||||
static String token_uri="https://exmail.qq.com/cgi-bin/token";
|
||||
static String authkey_uri="http://openapi.exmail.qq.com:12211/openapi/mail/authkey";
|
||||
|
||||
@Override
|
||||
public String generateInfo(UserInfo userInfo,Object app) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String data, String algorithmKey, String algorithm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
Applications details=(Applications)app;
|
||||
//extraAttrs from Applications
|
||||
ExtraAttrs extraAttrs=null;
|
||||
if(details.getIsExtendAttr()==1){
|
||||
extraAttrs=new ExtraAttrs(details.getExtendAttr());
|
||||
}
|
||||
OAuthClient tokenRestClient=new OAuthClient(token_uri);
|
||||
tokenRestClient.addParameter("grant_type", "client_credentials");
|
||||
tokenRestClient.addBasicAuthorization(details.getPrincipal(), details.getCredentials());
|
||||
Token token =tokenRestClient.requestAccessToken();
|
||||
_logger.debug(""+token);
|
||||
|
||||
OAuthClient authkeyRestClient=new OAuthClient(authkey_uri);
|
||||
authkeyRestClient.addBearerAuthorization(token.getAccess_token());
|
||||
authkeyRestClient.addParameter("Alias", details.getAppUser().getRelatedUsername());
|
||||
|
||||
HashMap<String, String> authKey=JsonUtils.gson2Object(authkeyRestClient.execute().getBody(), HashMap.class);
|
||||
_logger.debug("authKey : "+authKey);
|
||||
|
||||
String redirec_uri=String.format(login_url_template,details.getPrincipal(),details.getAppUser().getRelatedUsername(),authKey.get("auth_key"));
|
||||
_logger.debug("redirec_uri : "+redirec_uri);
|
||||
return WebContext.redirect(redirec_uri);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user