You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Dmitry Kesarev <at...@gmail.com> on 2019/09/11 14:31:09 UTC
Oak Spring web application integration
Hello,
please help me to configure embedded Oak repository with Spring. Tried to
find solution for a week, but it seems that mailing lis is the only chance,
How to configure security for web application? When i use repository in
standalone application i can login using "admin/admin" credentials and
everything works ok. But when i try to use the same code in web application
(Spring MVC, WildFly server, application packed in app.war), i get
PBOX00070: Password invalid/Password required. It looks like that Oak tries
to use WildFly Jaas configuration.
//Here is example code:
public static void main(String[] args) {//this works
Session session = null;
try {
SQLServerDataSource dataSource = new SQLServerDataSource();//i
use RDB as repository storage, it`s the only opton for me
SecurityProvider sp = new SecurityProviderImpl();
DocumentNodeStore ns = new
DocumentMK.Builder().setRDBConnection(dataSource).getNodeStore();
Oak oak = new Oak(ns).with("AppName").with(sp);
Repository repository = new Jcr(oak).createRepository();
session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));
Node root = session.getRootNode(); }
catch (RepositoryException e) {
e.printStackTrace();
}
finally {
session.logout();
}
}
I use the same code for bean creation in my web application. And get
PBOX00070: Password invalid/Password required
Here example:
//configuration
@Configuration
public class ReportConfiguration {
@Autowired
DataSource dataSource;
Repository repository = null;
@PostConstruct
private void init() {
DocumentNodeStore ns = new
DocumentMK.Builder().setRDBConnection(dataSource).getNodeStore();
SecurityProvider sp = new SecurityProviderImpl();
Oak oak = new Oak(ns).with("AppName").with(sp);
repository = new Jcr(oak).createRepository();
}
@Bean
public Repository getRepo() {
return repository;
}
}
//and controller
@Controller
@Component("ConfigController")
public class ConfigController {
@Autowired
Repository repository;
private Object RepositoryException;
//this causes PBOX00070: Password invalid/Password required
@PostMapping(value = "/upload", consumes = "multipart/form-data")
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
MultipartFile file) {
Session session = null;
try {
session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));
Node root = session.getRootNode();
} catch (javax.jcr.RepositoryException e) {
e.printStackTrace();
} finally {
session.logout();
}
return ResponseEntity.ok("ok");
}
}
The only difference that i see in debugger, that loginContext in
application on WildFly Oak has config = XMLLoginConfigImpl. And standalone
has config = ConfigurationUtils.
So the questions:
1. How to force Oak to use the same LoginContext as in standalone
application?
2. How to configure embeded Oak in web application with RDB storage. Where
to put repository.xml?