Android Studio v0.4.2 + PhoneGap v3.3.0-0.19.6

Android Studio v0.4.2 + PhoneGap v3.3.0-0.19.6 项目创建

  1. 安装Android Studio v0.4.2
  2. 安装Node.js(我的版本是v0.10.24 (x64))
  3. 安装Apache Ant(链接http://ant.apache.org):解压到相应目录,将Bin路径(如D:\Program Files (x86)\apache-ant-1.9.3\bin)添加到系统的Path环境变量。
  4. 在CMD命令下运行npm install -g phonegap,(参考链接http://phonegap.com/install/)
  5. 通过CMD进入相应目录,执行phonegap create AndroidPhoneGapTest,期间会进行环境检测,如果没有安装Apache Ant会提示,没有安装最新的Android SDK也会提示(我安装时提示安装SDK19),成功执行时如下图:
  6. 打开Android Studio,依次选择File-New Project,如下图,Package name中的XXXX可以替换成你公司的名字,剩下的保持默认一路Next:

  7. 将E:\AndroidPhoneGapTest\platforms\android\CordovaLib\src\com下的squareup目录复制到工程目录D:\android\AndroidPhoneGapTest\app\src\main\java\com下;
  8. 将E:\AndroidPhoneGapTest\platforms\android\CordovaLib\src下的org目录复制到工程目录D:\android\AndroidPhoneGapTest\app\src\main\java下;
  9. 将E:\AndroidPhoneGapTest\platforms\android\下的assets目录复制到工程目录D:\android\AndroidPhoneGapTest\app\src\main下;
  10. 将E:\AndroidPhoneGapTest\platforms\android\res下的xml目录复制到工程目录D:\android\AndroidPhoneGapTest\app\src\main\res下;
  11. 修改D:\android\AndroidPhoneGapTest\app\src\main\java\com\XXXX\app\MainActivity.java
  12. 修改前:

  13. 修改后

  14. 运行

参考:http://www.cnblogs.com/xjfhnsd/p/3488080.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要添加以下Maven依赖项: ```xml <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-authorization-server</artifactId> <version>0.4.2</version> </dependency> ``` 然后,你可以创建一个配置类来配置OAuth2授权服务器: ```java @Configuration @RequiredArgsConstructor @EnableAuthorizationServer public class OAuth2AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { private final PasswordEncoder passwordEncoder; private final AuthenticationManager authenticationManager; @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory() .withClient("my-client") .secret(passwordEncoder.encode("my-secret")) .authorizedGrantTypes("password", "refresh_token") .scopes("read", "write") .accessTokenValiditySeconds(3600) .refreshTokenValiditySeconds(86400); } @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints.authenticationManager(authenticationManager); } } ``` 在上面的示例中,我们使用`@EnableAuthorizationServer`注解来启用授权服务器。我们还配置了一个`PasswordEncoder`和一个`AuthenticationManager`,并实现了`configure(ClientDetailsServiceConfigurer)`和`configure(AuthorizationServerEndpointsConfigurer)`方法来配置客户端详细信息和授权服务器的端点。 `configure(ClientDetailsServiceConfigurer)`方法中,我们使用`inMemory`方法配置一个内存中的客户端详细信息存储。我们创建了一个名为`my-client`的客户端,并使用`password`和`refresh_token`授权类型进行授权。我们还为客户端配置了`read`和`write`范围,并设置了访问令牌和刷新令牌的过期时间。 `configure(AuthorizationServerEndpointsConfigurer)`方法中,我们将`AuthenticationManager`传递给`endpoints`对象,这将用于对用户名和密码进行身份验证。 最后,你需要配置Spring Security来保护OAuth2端点。你可以使用以下代码: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private OAuth2AuthorizationServerConfig oauth2Config; @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/oauth/**").permitAll() .anyRequest().authenticated() .and() .csrf().disable(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.parentAuthenticationManager(authenticationManagerBean()); } @Bean public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("user") .password(passwordEncoder().encode("password")) .roles("USER"); } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean public SecurityEvaluationContextExtension securityEvaluationContextExtension() { return new SecurityEvaluationContextExtension(); } } ``` 在上面的代码中,我们使用`@EnableWebSecurity`注解启用Web安全性,并配置了`configure(HttpSecurity)`方法来保护所有OAuth2端点。我们允许对`/oauth/**`端点的所有请求进行访问,而其他所有请求都需要进行身份验证。我们还禁用了CSRF保护。 在`configure(AuthenticationManagerBuilder)`方法中,我们将`AuthenticationManager`的父级设置为`authenticationManagerBean()`,这将使Spring Security使用我们在OAuth2授权服务器配置中配置的`AuthenticationManager`。 在`configureGlobal(AuthenticationManagerBuilder)`方法中,我们配置了一个内存中的用户存储,其中包含一个名为`user`的用户和密码为`password`的密码,该用户拥有`USER`角色。 最后,我们定义了一个`PasswordEncoder` bean和一个`SecurityEvaluationContextExtension` bean。 现在你已经完成了OAuth2授权服务器的配置,可以使用你的客户端来请求授权并访问受保护的资源了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值