Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dinky-admin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.dinky.DinkyVersion;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.dto.LoginSSODTO;
import org.dinky.data.dto.UserDTO;
import org.dinky.data.enums.Status;
import org.dinky.data.model.rbac.Tenant;
Expand All @@ -47,6 +48,12 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Objects;

/**
* AdminController
*
Expand Down Expand Up @@ -88,6 +95,42 @@ public Result<Void> outLogin() {
return Result.succeed(Status.SIGN_OUT_SUCCESS.getMessage());
}

/**
* user sso login
* @param ticket
*/
@GetMapping("/redirect/login/sso")
@SaIgnore
public void loginsso(@RequestParam("ticket") String ticket, HttpServletResponse response)
throws URISyntaxException, IOException {

log.info("ticket is {}", ticket);
LoginSSODTO loginSSODTO = new LoginSSODTO();
loginSSODTO.setTicket(ticket);
UserDTO user = userService.loginSSOUser(loginSSODTO);
if (Objects.nonNull(user)) {
log.info("sso user succ {}", user);

Cookie cookie = new Cookie("dinky-token", user.getTokenInfo().getTokenValue());
cookie.setPath("/");
response.addCookie(cookie);

Cookie cookieTen = new Cookie(
"tenantId", String.valueOf(user.getTenantList().get(0).getId()));
cookieTen.setPath("/");
response.addCookie(cookieTen);

Cookie cookieLan = new Cookie("language", "zh-CN");
cookieLan.setPath("/");
response.addCookie(cookieLan);

response.sendRedirect(user.getRedirectUri());
} else {
log.error("loginsso failed user {}", user);
response.sendRedirect(user.getRedirectUri());
}
}

/**
* get current user info
*
Expand Down
28 changes: 28 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/dto/LoginSSODTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dinky.data.dto;


import lombok.Data;

@Data
public class LoginSSODTO {
private String ticket;
}
6 changes: 6 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dinky.data.model.rbac.UserRole;

@Data
@NoArgsConstructor
Expand All @@ -45,6 +46,11 @@ public class UserDTO {
@ApiModelProperty(value = "roleList", required = true, dataType = "List<Role>", allowEmptyValue = false)
private List<Role> roleList;

@ApiModelProperty(value = "userRoleList", required = false, dataType = "List<UserRole>", allowEmptyValue = false)
private List<UserRole> userRoleList;

private String redirectUri;

@ApiModelProperty(value = "tenantList", required = true, dataType = "List<Tenant>", allowEmptyValue = false)
private List<Tenant> tenantList;

Expand Down
12 changes: 12 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.dinky.data.dto.AssignRoleDTO;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.dto.LoginSSODTO;
import org.dinky.data.dto.ModifyPasswordDTO;
import org.dinky.data.dto.UserDTO;
import org.dinky.data.model.rbac.Role;
Expand All @@ -31,6 +32,8 @@
import org.dinky.data.vo.UserVo;
import org.dinky.mybatis.service.ISuperService;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

/**
Expand Down Expand Up @@ -80,6 +83,15 @@ public interface UserService extends ISuperService<User> {
*/
Result<UserDTO> loginUser(LoginDTO loginDTO);



/**
*
* @param loginSSODTO
*/
UserDTO loginSSOUser(LoginSSODTO loginSSODTO) throws URISyntaxException, IOException;


/**
* get user by username
*
Expand Down
Loading