Skip to content

Commit

Permalink
remove ctrip profile (#3920)
Browse files Browse the repository at this point in the history
* update org content.

* Update CHANGES.md

* fix code style.

* fix code style.

* fix code style.
  • Loading branch information
JaredTan95 authored Aug 29, 2021
1 parent fea6325 commit 9f072d8
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 1,761 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Apollo 1.10.0
* [Fix issue that the $ symbol is not used when reading shell variables](https://github.com/ctripcorp/apollo/pull/3890)
* [Bump xstream from 1.4.17 to 1.4.18](https://github.com/apolloconfig/apollo/pull/3916)
* [switch apollo.config-service log from warning to info level](https://github.com/ctripcorp/apollo/pull/3884)
* [remove ctrip profile](https://github.com/ctripcorp/apollo/pull/3920)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)

Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Type;
import java.util.*;

@Component
public class PortalConfig extends RefreshableConfig {

Expand Down Expand Up @@ -80,7 +83,7 @@ public List<Env> portalSupportedEnvs() {
public Map<String, String> getMetaServers() {
final String key = "apollo.portal.meta.servers";
String jsonContent = getValue(key);
if(null == jsonContent) {
if (null == jsonContent) {
return Collections.emptyMap();
}

Expand Down Expand Up @@ -263,72 +266,6 @@ public String getAdminServiceAccessTokens() {
return getValue("admin-service.access.tokens");
}

/***
* The following configurations are used in ctrip profile
**/

public int appId() {
return getIntProperty("ctrip.appid", 0);
}

//send code & template id. apply from ewatch
public String sendCode() {
return getValue("ctrip.email.send.code");
}

public int templateId() {
return getIntProperty("ctrip.email.template.id", 0);
}

//email retention time in email server queue.TimeUnit: hour
public int survivalDuration() {
return getIntProperty("ctrip.email.survival.duration", 5);
}

public boolean isSendEmailAsync() {
return getBooleanProperty("email.send.async", true);
}

public String portalServerName() {
return getValue("serverName");
}

public String casServerLoginUrl() {
return getValue("casServerLoginUrl");
}

public String casServerUrlPrefix() {
return getValue("casServerUrlPrefix");
}

public String credisServiceUrl() {
return getValue("credisServiceUrl");
}

public String userServiceUrl() {
return getValue("userService.url");
}

public String userServiceAccessToken() {
return getValue("userService.accessToken");
}

public String soaServerAddress() {
return getValue("soa.server.address");
}

public String cloggingUrl() {
return getValue("clogging.server.url");
}

public String cloggingPort() {
return getValue("clogging.server.port");
}

public String hermesServerAddress() {
return getValue("hermes.server.address");
}

public String[] webHookUrls() {
return getArrayProperty("config.release.webhook.service.url", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@
* limitations under the License.
*
*/

package com.ctrip.framework.apollo.portal.spi.configuration;

import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.repository.UserRepository;
import com.ctrip.framework.apollo.portal.spi.LogoutHandler;
import com.ctrip.framework.apollo.portal.spi.SsoHeartbeatHandler;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripLogoutHandler;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripSsoHeartbeatHandler;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripUserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripUserService;
import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultLogoutHandler;
import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultSsoHeartbeatHandler;
import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserInfoHolder;
Expand All @@ -44,13 +40,12 @@
import com.ctrip.framework.apollo.portal.spi.springsecurity.ApolloPasswordEncoderFactory;
import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserService;
import com.google.common.collect.Maps;
import java.util.Collections;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
Expand All @@ -75,160 +70,13 @@
import org.springframework.security.provisioning.JdbcUserDetailsManager;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;

import javax.servlet.Filter;
import javax.sql.DataSource;
import java.util.Collections;
import java.util.EventListener;
import java.util.Map;

@Configuration
public class AuthConfiguration {

private static final String[] BY_PASS_URLS = {"/prometheus/**", "/metrics/**", "/openapi/**",
"/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**", "/i18n/**", "/prefix-path",
"/health"};

/**
* spring.profiles.active = ctrip
*/
@Configuration
@Profile("ctrip")
static class CtripAuthAutoConfiguration {

private final PortalConfig portalConfig;

public CtripAuthAutoConfiguration(final PortalConfig portalConfig) {
this.portalConfig = portalConfig;
}

@Bean
public ServletListenerRegistrationBean redisAppSettingListner() {
ServletListenerRegistrationBean redisAppSettingListener = new ServletListenerRegistrationBean();
redisAppSettingListener
.setListener(listener("org.jasig.cas.client.credis.CRedisAppSettingListner"));
return redisAppSettingListener;
}

@Bean
public ServletListenerRegistrationBean singleSignOutHttpSessionListener() {
ServletListenerRegistrationBean singleSignOutHttpSessionListener = new ServletListenerRegistrationBean();
singleSignOutHttpSessionListener
.setListener(listener("org.jasig.cas.client.session.SingleSignOutHttpSessionListener"));
return singleSignOutHttpSessionListener;
}

@Bean
public FilterRegistrationBean casFilter() {
FilterRegistrationBean singleSignOutFilter = new FilterRegistrationBean();
singleSignOutFilter.setFilter(filter("org.jasig.cas.client.session.SingleSignOutFilter"));
singleSignOutFilter.addUrlPatterns("/*");
singleSignOutFilter.setOrder(1);
return singleSignOutFilter;
}

@Bean
public FilterRegistrationBean authenticationFilter() {
FilterRegistrationBean casFilter = new FilterRegistrationBean();

Map<String, String> filterInitParam = Maps.newHashMap();
filterInitParam.put("redisClusterName", "casClientPrincipal");
filterInitParam.put("serverName", portalConfig.portalServerName());
filterInitParam.put("casServerLoginUrl", portalConfig.casServerLoginUrl());
//we don't want to use session to store login information, since we will be deployed to a cluster, not a single instance
filterInitParam.put("useSession", "false");
filterInitParam.put("/openapi.*", "exclude");

casFilter.setInitParameters(filterInitParam);
casFilter
.setFilter(filter("com.ctrip.framework.apollo.sso.filter.ApolloAuthenticationFilter"));
casFilter.addUrlPatterns("/*");
casFilter.setOrder(2);

return casFilter;
}

@Bean
public FilterRegistrationBean casValidationFilter() {
FilterRegistrationBean casValidationFilter = new FilterRegistrationBean();
Map<String, String> filterInitParam = Maps.newHashMap();
filterInitParam.put("casServerUrlPrefix", portalConfig.casServerUrlPrefix());
filterInitParam.put("serverName", portalConfig.portalServerName());
filterInitParam.put("encoding", "UTF-8");
//we don't want to use session to store login information, since we will be deployed to a cluster, not a single instance
filterInitParam.put("useSession", "false");
filterInitParam.put("useRedis", "true");
filterInitParam.put("redisClusterName", "casClientPrincipal");

casValidationFilter
.setFilter(
filter("org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter"));
casValidationFilter.setInitParameters(filterInitParam);
casValidationFilter.addUrlPatterns("/*");
casValidationFilter.setOrder(3);

return casValidationFilter;
}

@Bean
public FilterRegistrationBean assertionHolder() {
FilterRegistrationBean assertionHolderFilter = new FilterRegistrationBean();

Map<String, String> filterInitParam = Maps.newHashMap();
filterInitParam.put("/openapi.*", "exclude");

assertionHolderFilter.setInitParameters(filterInitParam);

assertionHolderFilter.setFilter(
filter("com.ctrip.framework.apollo.sso.filter.ApolloAssertionThreadLocalFilter"));
assertionHolderFilter.addUrlPatterns("/*");
assertionHolderFilter.setOrder(4);

return assertionHolderFilter;
}

@Bean
public CtripUserInfoHolder ctripUserInfoHolder() {
return new CtripUserInfoHolder();
}

@Bean
public CtripLogoutHandler logoutHandler() {
return new CtripLogoutHandler();
}

private Filter filter(String className) {
Class clazz = null;
try {
clazz = Class.forName(className);
Object obj = clazz.newInstance();
return (Filter) obj;
} catch (Exception e) {
throw new RuntimeException("instance filter fail", e);
}
}

private EventListener listener(String className) {
Class clazz = null;
try {
clazz = Class.forName(className);
Object obj = clazz.newInstance();
return (EventListener) obj;
} catch (Exception e) {
throw new RuntimeException("instance listener fail", e);
}
}

@Bean
public UserService ctripUserService(PortalConfig portalConfig) {
return new CtripUserService(portalConfig);
}

@Bean
public SsoHeartbeatHandler ctripSsoHeartbeatHandler() {
return new CtripSsoHeartbeatHandler();
}
}

/**
* spring.profiles.active = auth
*/
Expand Down Expand Up @@ -398,7 +246,7 @@ static class SpringSecurityLDAPConfigurer extends WebSecurityConfigurerAdapter {

public SpringSecurityLDAPConfigurer(final LdapProperties ldapProperties,
final LdapContextSource ldapContextSource,
final LdapExtendProperties ldapExtendProperties) {
final LdapExtendProperties ldapExtendProperties) {
this.ldapProperties = ldapProperties;
this.ldapContextSource = ldapContextSource;
this.ldapExtendProperties = ldapExtendProperties;
Expand All @@ -409,7 +257,8 @@ public FilterBasedLdapUserSearch userSearch() {
if (ldapExtendProperties.getGroup() == null || StringUtils
.isBlank(ldapExtendProperties.getGroup().getGroupSearch())) {
FilterBasedLdapUserSearch filterBasedLdapUserSearch = new FilterBasedLdapUserSearch("",
ldapProperties.getSearchFilter(), ldapContextSource);
ldapProperties.getSearchFilter(), ldapContextSource
);
filterBasedLdapUserSearch.setSearchSubtree(true);
return filterBasedLdapUserSearch;
}
Expand All @@ -418,7 +267,8 @@ public FilterBasedLdapUserSearch userSearch() {
ldapProperties.getBase(), ldapProperties.getSearchFilter(), ldapExtendProperties.getGroup().getGroupBase(),
ldapContextSource, ldapExtendProperties.getGroup().getGroupSearch(),
ldapExtendProperties.getMapping().getRdnKey(),
ldapExtendProperties.getGroup().getGroupMembership(),ldapExtendProperties.getMapping().getLoginId());
ldapExtendProperties.getGroup().getGroupMembership(), ldapExtendProperties.getMapping().getLoginId()
);
filterLdapByGroupUserSearch.setSearchSubtree(true);
return filterLdapByGroupUserSearch;
}
Expand All @@ -445,9 +295,9 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(BY_PASS_URLS).permitAll()
.antMatchers("/**").authenticated();
http.formLogin().loginPage("/signin").defaultSuccessUrl("/", true).permitAll().failureUrl("/signin?#/error").and()
.httpBasic();
.httpBasic();
http.logout().logoutUrl("/user/logout").invalidateHttpSession(true).clearAuthentication(true)
.logoutSuccessUrl("/signin?#/logout");
.logoutSuccessUrl("/signin?#/logout");
http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/signin"));
}

Expand Down
Loading

0 comments on commit 9f072d8

Please sign in to comment.