Skip to content

Commit

Permalink
For 830
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron-boom committed Oct 12, 2021
1 parent de32429 commit 57ac6c4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
Expand Up @@ -17,6 +17,8 @@

package org.apache.dubbo.admin;

import org.apache.dubbo.admin.utils.SpringBeanUtils;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
Expand All @@ -28,6 +30,6 @@
public class DubboAdminApplication {

public static void main(String[] args) {
SpringApplication.run(DubboAdminApplication.class, args);
SpringBeanUtils.applicationContext = SpringApplication.run(DubboAdminApplication.class, args);
}
}
Expand Up @@ -21,19 +21,18 @@
import org.apache.dubbo.admin.authentication.InterceptorAuthentication;
import org.apache.dubbo.admin.interceptor.AuthInterceptor;
import org.apache.dubbo.admin.utils.JwtTokenUtil;
import org.apache.dubbo.admin.utils.SpringBeanUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;


public class DefaultPreHandle implements InterceptorAuthentication {
@Autowired
private JwtTokenUtil jwtTokenUtil;

private JwtTokenUtil jwtTokenUtil = SpringBeanUtils.getBean(JwtTokenUtil.class);

@Override
public boolean authentication(HttpServletRequest request, HttpServletResponse response, Object handler) {
Expand Down
Expand Up @@ -56,6 +56,8 @@ public String login(HttpServletRequest httpServletRequest, HttpServletResponse r
if (iterator != null && !iterator.hasNext()) {
if (StringUtils.isBlank(rootUserName) || (rootUserName.equals(userName) && rootUserPassword.equals(password))) {
return jwtTokenUtil.generateToken(userName);
} else {
flag = false;
}
}
while (iterator.hasNext()) {
Expand Down
@@ -0,0 +1,41 @@
/*
* 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.apache.dubbo.admin.utils;

import org.springframework.context.ApplicationContext;


/**
* get spring bean tool class.
*/
public class SpringBeanUtils {
/**
* spring applicationContext
*/
public static ApplicationContext applicationContext;

/**
* get spring bean
*
* @return spring bean
* @param c
*/
public static <T> T getBean(Class<T> c){
return applicationContext.getBean(c);
}
}

0 comments on commit 57ac6c4

Please sign in to comment.