Skip to content

Commit

Permalink
write a line into test.file
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Dec 19, 2023
1 parent d256f0c commit 9db21d5
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/spring/csf8693a30-9e0e-11ee-85e6-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.huifer.full.shiro.service;

import com.github.huifer.full.shiro.entity.ShiroDept;
import com.github.huifer.full.shiro.model.req.dept.DeptCreateParam;

public interface DeptService {

boolean create(DeptCreateParam param);

boolean update(DeptCreateParam param, int id);

boolean delete(int id);

ShiroDept byId(int id);
}
15 changes: 15 additions & 0 deletions docs/spring/csf8a2b68e-9e0e-11ee-85e6-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.huifer.full.shiro.service;

import com.github.huifer.full.shiro.entity.ShiroApp;
import com.github.huifer.full.shiro.model.req.app.AppCreateParam;

public interface AppService {

boolean create(AppCreateParam param);

boolean update(AppCreateParam param, int id);

boolean delete(int id);

ShiroApp byId(int id);
}
25 changes: 25 additions & 0 deletions docs/spring/csf8dfe6da-9e0e-11ee-85e6-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.huifer.kafka.core.annot;

import com.huifer.kafka.core.bean.KafkaConsumerWithCore;
import com.huifer.kafka.core.bean.KafkaProducerWithCore;
import com.huifer.kafka.core.excephandler.ExceptionHandler;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class KafkaHandler {

private KafkaConsumerWithCore kafkaConsumer;
private KafkaProducerWithCore kafkaProducer;


private List<ExceptionHandler> exceptionHandlers;
private KafkaHandlerMeta kafkaHandlerMeta;
}
98 changes: 98 additions & 0 deletions docs/spring/csf92092b6-9e0e-11ee-85e6-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package dolores.oauthserver.service;

import dolores.oauthserver.config.OAuth2ClientProperties;
import dolores.oauthserver.config.OAuth2Properties;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableAuthorizationServer
public class GameAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

@Autowired
private OAuth2Properties oAuth2Properties;

@Autowired
private UserDetailsService userDetailsService;

@Autowired
private AuthenticationManager authenticationManager;

@Autowired
private TokenStore tokenStore;

@Autowired(required = false)
@Qualifier("jwtAccessTokenConverter")
private JwtAccessTokenConverter jwtAccessTokenConverter;

@Autowired(required = false)
@Qualifier("jwtTokenEnhancer")
private TokenEnhancer jwtTokenEnhancer;

@Autowired
private PasswordEncoder passwordEncoder;

public GameAuthorizationServerConfig() {
super();
}

@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.tokenKeyAccess("permitAll()");
security.checkTokenAccess("isAuthenticated()");
}

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
InMemoryClientDetailsServiceBuilder builder = clients.inMemory();

if (ArrayUtils.isNotEmpty(oAuth2Properties.getClients())) {
for (OAuth2ClientProperties config : oAuth2Properties.getClients()) {
builder.withClient(config.getClientId())
.secret(passwordEncoder.encode(config.getClientSecret()))
.accessTokenValiditySeconds(config.getAccessTokenValiditySeconds())
.refreshTokenValiditySeconds(60 * 60 * 24 * 15)
.authorizedGrantTypes("refresh_token", "password", "authorization_code")//OAuth2支持的验证模式
.redirectUris("http://www.ixx.com")
.scopes("all");
}
}
}

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.tokenStore(tokenStore)
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService);

if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) {
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
List<TokenEnhancer> enhancers = new ArrayList<>();
enhancers.add(jwtTokenEnhancer);
enhancers.add(jwtAccessTokenConverter);
tokenEnhancerChain.setTokenEnhancers(enhancers);
endpoints
.tokenEnhancer(tokenEnhancerChain)
.accessTokenConverter(jwtAccessTokenConverter);
}
}
}
110 changes: 110 additions & 0 deletions docs/spring/csf958a0e8-9e0e-11ee-85e6-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* Licensed 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.ibatis.submitted.global_variables_defaults;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Property;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.parsing.PropertyParser;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.type.JdbcType;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.Reader;
import java.util.Properties;

class CustomizationTest {

@Test
void applyDefaultValueWhenCustomizeDefaultValueSeparator() throws IOException {

Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty(PropertyParser.KEY_DEFAULT_VALUE_SEPARATOR, "?:");

Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config-custom-separator.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(CustomDefaultValueSeparatorMapper.class);

SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(CustomDefaultValueSeparatorMapper.class.getName()));

Assertions.assertThat(configuration.getJdbcTypeForNull()).isEqualTo(JdbcType.NULL);
Assertions.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl())
.isEqualTo("jdbc:hsqldb:mem:global_variables_defaults");
Assertions.assertThat(configuration.getDatabaseId()).isEqualTo("hsql");
Assertions.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"))
.isEqualTo("default");
Assertions.assertThat(cache.getName()).isEqualTo("default");

try (SqlSession sqlSession = factory.openSession()) {
CustomDefaultValueSeparatorMapper mapper = sqlSession.getMapper(CustomDefaultValueSeparatorMapper.class);
Assertions.assertThat(mapper.selectValue(null)).isEqualTo("default");
}

}

@Test
void applyPropertyValueWhenCustomizeDefaultValueSeparator() throws IOException {

Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty(PropertyParser.KEY_DEFAULT_VALUE_SEPARATOR, "?:");
props.setProperty("settings:jdbcTypeForNull", JdbcType.CHAR.name());
props.setProperty("db:name", "global_variables_defaults_custom");
props.setProperty("productName:hsql", "Hsql");
props.setProperty("objectFactory:name", "customObjectFactory");
props.setProperty("cache:name", "customCache");

Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config-custom-separator.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(CustomDefaultValueSeparatorMapper.class);

SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(CustomDefaultValueSeparatorMapper.class.getName()));

Assertions.assertThat(configuration.getJdbcTypeForNull()).isEqualTo(JdbcType.CHAR);
Assertions.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl())
.isEqualTo("jdbc:hsqldb:mem:global_variables_defaults_custom");
Assertions.assertThat(configuration.getDatabaseId()).isNull();
Assertions.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"))
.isEqualTo("customObjectFactory");
Assertions.assertThat(cache.getName()).isEqualTo("customCache");

try (SqlSession sqlSession = factory.openSession()) {
CustomDefaultValueSeparatorMapper mapper = sqlSession.getMapper(CustomDefaultValueSeparatorMapper.class);
Assertions.assertThat(mapper.selectValue("3333")).isEqualTo("3333");
}

}

@CacheNamespace(implementation = SupportClasses.CustomCache.class, properties = {
@Property(name = "name", value = "${cache:name?:default}")
})
private interface CustomDefaultValueSeparatorMapper {
@Select("SELECT '${val != null ? val : 'default'}' FROM INFORMATION_SCHEMA.SYSTEM_USERS")
String selectValue(@Param("val") String val);
}

}
Loading

0 comments on commit 9db21d5

Please sign in to comment.