我相信我有基本的身份验证工作,但我不知道如何保护资源,以便只有在用户登录时才能访问它们.
public class SimpleAuthenticator implements Authenticator<BasicCredentials, User> {
UserDAO userDao;
public SimpleAuthenticator(UserDAO userDao) {this.userDao = userDao;}
@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException
{
User user = this.userDao.getUserByName(credentials.getUsername());
if (user!=null &&
user.getName().equalsIgnoreCase(credentials.getUsername()) &&
BCrypt.checkpw(credentials.getPassword(), user.getPwhash())) {
return Optional.of(new User(credentials.getUsername()));
}
return Optional.absent();
}
}
Run Code Online (Sandbox Code Playgroud)
我的Signin资源是这样的:
@Path("/myapp")
@Produces(MediaType.APPLICATION_JSON)
public class UserResource {
@GET
@Path("/signin")
public User signin(@Auth User user) {
return user;
}
}
Run Code Online (Sandbox Code Playgroud)
我签署了用户:
~/java/myservice $ curl -u "someuser" http://localhost:8080/myapp/signin
Enter host password for user 'someuser':
{"name":"someuser"}
Run Code Online (Sandbox Code Playgroud)
题
假设用户使用/myapp/signin …
private void insertIntoMyTable (Myclass m) {
String query = "INSERT INTO MYTABLE (NAME) VALUES (?)";
jdbcTemplate.update(query, m.getName());
}
Run Code Online (Sandbox Code Playgroud)
当上面的查询插入记录时,ID表中的列会自动增量.
有没有办法在插入时获得这个自动递增的ID.所以在这个例子中我的方法的返回值是int
如果我有一个像这样的字符串:
s = "This is a simple string 234 something else here as well 4334
Run Code Online (Sandbox Code Playgroud)
和一个正则表达式:
regex = ~"[0-9]{3}"
Run Code Online (Sandbox Code Playgroud)
如何使用该正则表达式从字符串中提取所有单词?在这种情况下,234和433?
我在Android工作室中使用gradle来安装android项目.我有一个我下载的jar叫TestFlightAppLib.jar.这个jar不存在于maven存储库中,所以我不能把它放在我的build.gradle.
如何将此JAR文件添加到我的项目中?我没有看到任何向项目添加外部jar的选项.

更新
这是我完整的build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.retrofit:retrofit:1.2.2'
compile 'com.github.rtyley:roboguice-sherlock:1.5'
compile 'org.roboguice:roboguice:2.0'
compile files('libs/TestFlightLib.jar')
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
Gradle: Execution failed for task ':MyProject:compileDebug'.
> Compilation failed; see the compiler error output for details.
/Users/droid/android/MyProjectProject/MyProject/src/main/java/com/mypkg/ui/activity/MainApplication.java
Gradle: error: package com.testflightapp.lib …Run Code Online (Sandbox Code Playgroud) android gradle testflight android-studio android-gradle-plugin
我需要帮助理解背后的理念@Autowired和@Service.我有一个DAO @Service和控制器定义,@Autowired一切似乎很好,但是,我@Autowired在不同的类使用相同,然后它不起作用.
例:
服务
@Service
public class MyService {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource (DataSource myDataSource) {
this.jdbcTemplate = new JdbcTemplate(myDataSource);
}
public void testUpdate(){
jdbcTemplate.update("some query");
}
}
Run Code Online (Sandbox Code Playgroud)
调节器
package com.springtest.mywork.controller;
@Controller
@RequestMapping(value = "/test.html")
public class MyController
{
@Autowired
MyService myService;
@RequestMapping(method = RequestMethod.GET)
public String test(Model model)
{
systemsService.testUpdate();
return "view/test";
}
}
Run Code Online (Sandbox Code Playgroud)
以上一切都很好.但是,如果我想MyService在POJO中使用那么它就不起作用了.例:
package com.springtest.mywork.pojos;
public class MyPojo {
@Autowired
MyService myService;
public …Run Code Online (Sandbox Code Playgroud) 我有一个我在hashmap中放置的Color类.我想调用containsKeyhashmap来确保该对象是否已存在于hashmap中
颜色类
public class Color {
public String name;
Color (String name) {this.name = name;}
//getters setters for name
}
Run Code Online (Sandbox Code Playgroud)
HashMap中
HashMap<Color, List<String>> m = new HashMap<Color, List<String>>();
Color c = new Color("red");
m.put(c, new ArrayList<String>());
Color c1 = new Color("red");
System.out.println(m.containsKey(c1)); //I'd like to return this as true
Run Code Online (Sandbox Code Playgroud)
既然c1有name红色.我希望System.out返回true,因为地图中已经存在的键c有name红色
怎么能实现这一目标?
我有一个列表视图,有多个textview像这样:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16dip"
android:textColor="#000000"
android:paddingLeft="10dip"
android:textStyle="bold"/>
<TextView
android:id="@+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16dip"
android:textColor="#000000"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:paddingLeft="10dip"
android:textStyle="bold"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我有一个POJO列表,它有一个name和address我希望列表视图中的每个项目都填充这些值.
我的POJO是这样的:
public class Person {
private String name;
private String address;
//getter setter
public String toString() {return name;}
}
Run Code Online (Sandbox Code Playgroud)
题
当我使用我的列表设置列表适配器时,如何设置名称和地址?
目前我这样做只设置名称:
setListAdapter(new ArrayAdapter<Person>(MyActivity.this, R.layout.list_text, R.id.name, personList));
Run Code Online (Sandbox Code Playgroud) 我正在使用allauth,在注册后,用户会收到一封电子邮件,要求他们点击链接以验证他们的电子邮件地址.我想改变这个链接的价值.
我想改变它
http://localhost:8001/account/confirm-email/hy72ozw8b1cexuw2dsx4wwrmgzbmnyxx4clswh67tcvgyovg/
Run Code Online (Sandbox Code Playgroud)
至
http://localhost:8001/index.html#/verifyEmail/hy72ozw8b1cexuw2dsx4wwrmgzbmnyxx4clswh67tcvgyovg/
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我看到该activate_url值正在email_confirmation_text.txt中使用
我在 django 应用程序中使用 allauth。创建用户后,它会发送一封包含如下链接的电子邮件http://localhost:8001/account/confirm-email/asdfafsd/
但是,我希望链接是这样的,http://localhost:8001/verifyEmail/asdfafsd因为我在前端使用角度。
我不知道在哪里更改此链接?
我有两个CQ实例,在它们之间我希望能够导入/导出任务.
例如:
在实例1中,我可以通过访问来查看所有任务 http://instance1/libs/cq/taskmanagement/content/taskmanager.html#/tasks/Delta
在实例2中,我可以通过访问来查看所有任务 http://instance2/libs/cq/taskmanagement/content/taskmanager.html#/tasks/Delta
在某些情况下,我希望从中获取所有任务instance2,并将它们作为附加任务添加到instance1中(在它可能已经拥有的任务之上).
这可能吗?
java ×4
android ×2
django ×2
spring-mvc ×2
aem ×1
angularjs ×1
autowired ×1
dropwizard ×1
gradle ×1
groovy ×1
hashmap ×1
jdbctemplate ×1
listactivity ×1
listview ×1
mysql ×1
osgi ×1
python ×1
regex ×1
rest ×1
sling ×1
spring-3 ×1
testflight ×1