Laravel:创建作曲家包的最佳位置

时间:2016-02-25 09:56:53

标签: laravel github composer-php

我要创建我的第一个基于laravel的作曲家包。还安装了github for windows。 laravel位于:

@Configuration
public class SecurityConfig {

    @Configuration
    @Order(4)
    @EnableWebSecurity
    protected static class WebSecurityConfig extends WebSecurityConfigurerAdapter {

        @Value("${baseUrl}")
        private String baseUrl;

        @Autowired
        private DataSource dataSource;

        @Resource
        private PasswordEncoder passwordEncoder;

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            JdbcUserDetailsManagerConfigurer<AuthenticationManagerBuilder> jdbcUserDetail = new JdbcUserDetailsManagerConfigurer<AuthenticationManagerBuilder>();
            jdbcUserDetail.dataSource(dataSource);
            jdbcUserDetail.passwordEncoder(passwordEncoder);
            jdbcUserDetail.authoritiesByUsernameQuery(
                    "select a.username, r.role_name from account a, role r, account_role ar where a.id = ar.account_id and r.id = ar.role_id and a.username = ?");
            jdbcUserDetail.usersByUsernameQuery(
                    "select a.username, a.password, a.enabled, a.email from account a where a.username = ?");
            auth.apply(jdbcUserDetail);
        }

        @Bean(name = "authenticationManager")
        @Override
        public AuthenticationManager authenticationManagerBean() throws Exception {
            return super.authenticationManagerBean();
        }

        @Override
        public void configure(WebSecurity webSecurity) throws Exception {
            webSecurity
                .ignoring()
                    .antMatchers("/resources/**", "/swagger/**", "/copyright*", "/api-docs/**")
                    .antMatchers(HttpMethod.POST, "/api/**/account")
                .and()
                    .debug(false);
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {

            http.requiresChannel().anyRequest().requiresSecure();

            // @formatter:off
            http
                .authorizeRequests()
                    .anyRequest().hasRole("USER")
                    .and()
                // TODO put CSRF protection back into this endpoint
                .csrf()
                    .requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize")).disable()
                     ;
            // @formatter:on
        }

    }

    @Configuration
    @EnableResourceServer
    protected static class ResourceServerConfig extends ResourceServerConfigurerAdapter {

        @Autowired
        private ResourceServerTokenServices tokenServices;

        @Autowired
        private OAuth2AccessDeniedHandler oAuth2AccessDeniedHandler;

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.tokenServices(tokenServices);
            resources.resourceId("My resource");
        }

        @Override
        public void configure(HttpSecurity http) throws Exception {

            // @formatter:off
            http.requiresChannel().anyRequest().requiresSecure();

            // API calls
            http
                .requestMatchers()
                    .antMatchers("/api/**", "/whatever")
                .and()
                    .authorizeRequests()
                    .anyRequest()
                    .access("#oauth2.hasScope('blah') and (hasRole('ROLE_USER'))");

            // @formatter:on
        }

    }

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

        @Autowired
        private AuthenticationManager authenticationManager;

        @Autowired
        private RedisConnectionFactory redisConnectionFactory;

        @Bean
        public TokenStore tokenStore() {
            return new RedisTokenStore(redisConnectionFactory);
        }

        @Bean
        public UserApprovalHandler userApprovalHandler() throws Exception {
            RedrumUserApprovalHandler handler = new RedrumUserApprovalHandler();
            handler.setApprovalStore(approvalStore());
            handler.setClientDetailsService(clientDetailsService());
            handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService()));
            handler.setUseApprovalStore(true);
            return handler;
        }

        @Bean
        public ApprovalStore approvalStore() {
            TokenApprovalStore store = new TokenApprovalStore();
            store.setTokenStore(tokenStore());
            return store;
        }

        @Primary
        @Bean
        public DefaultTokenServices tokenServices() throws Exception {
            final DefaultTokenServices tokenServices = new DefaultTokenServices();
            tokenServices.setAccessTokenValiditySeconds(6000);
            tokenServices.setClientDetailsService(clientDetailsService());
            tokenServices.setTokenEnhancer(new RedrumTokenEnhancer());
            tokenServices.setSupportRefreshToken(true);
            tokenServices.setTokenStore(tokenStore());
            return tokenServices;
        }

        @Bean
        public ClientDetailsService clientDetailsService() throws Exception {
            ClientDetailsServiceConfiguration serviceConfig = new ClientDetailsServiceConfiguration();

            serviceConfig.clientDetailsServiceConfigurer().inMemory()
                .withClient("xyz")
                .secret("...................")
                .authorizedGrantTypes("password", "authorization_code", "refresh_token", "client_credentials")
                .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
                .scopes("blah")
                ;

            return serviceConfig.clientDetailsService();
        }

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints
                .authenticationManager(authenticationManager)
                .tokenServices(tokenServices())
                .userApprovalHandler(userApprovalHandler());
        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients
                .withClientDetails(clientDetailsService());
        }

        @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
            oauthServer
                .realm("zzz/clients")
                .allowFormAuthenticationForClients();
        }

    }

}

因为我需要在开发期间使用laravel测试我的包(检查关系路径,错误调试)哪里是创建包根文件夹的最佳位置?

1 个答案:

答案 0 :(得分:1)

此处没有默认位置。让我们说你的软件包叫做HelloWorld,而不是把你的软件包放在这里:

E:\xampp\htdocs\pnu\packages\Alex\Helloworld

然后将其添加到您的composer文件(根目录中的composer.json):

"autoload": {
    "psr-4": {
        "Alex\\Helloworld\\": "packages/Alex/Helloworld/src"
    }
},

您可以在此处详细了解https://laracasts.com/discuss/channels/tips/developing-your-packages-in-laravel-5