Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JCR-612 : Restructure the Jackrabbit source tree
move jcr-server/server one level up git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@477625 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
81 changed files
with
16,774 additions
and
0 deletions.
There are no files selected for viewing
1,171 changes: 1,171 additions & 0 deletions
1,171
jcr-server/src/main/java/org/apache/jackrabbit/server/AbstractWebdavServlet.java
Large diffs are not rendered by default.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
jcr-server/src/main/java/org/apache/jackrabbit/server/BasicCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.jackrabbit.server; | ||
|
||
import org.apache.jackrabbit.util.Base64; | ||
import org.apache.jackrabbit.webdav.DavConstants; | ||
|
||
import javax.jcr.Credentials; | ||
import javax.jcr.LoginException; | ||
import javax.jcr.SimpleCredentials; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This Class implements a credentials provider that extracts the credentials | ||
* from the 'WWW-Authenticate' header and only supports 'Basic' authentication. | ||
*/ | ||
public class BasicCredentialsProvider implements CredentialsProvider { | ||
|
||
private final String defaultHeaderValue; | ||
|
||
/** | ||
* Constructs a new BasicCredentialsProvider with the given default | ||
* value {@see #getCredentials} for details. | ||
* | ||
* @param defaultHeaderValue | ||
*/ | ||
public BasicCredentialsProvider(String defaultHeaderValue) { | ||
this.defaultHeaderValue = defaultHeaderValue; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* Build a {@link Credentials} object for the given authorization header. | ||
* The creds may be used to login to the repository. If the specified header | ||
* string is <code>null</code> or not of the required format the behaviour | ||
* depends on the {@link #defaultHeaderValue} field:<br> | ||
* <ul> | ||
* <li> if this field is <code>null</code>, a LoginException is thrown. | ||
* This is suiteable for clients (eg. webdav clients) for with | ||
* sending a proper authorization header is not possible, if the | ||
* server never send a 401. | ||
* <li> if this an empty string, null-credentials are returned, thus | ||
* forcing an null login on the repository | ||
* <li> if this field has a 'user:password' value, the respective | ||
* simple credentials are generated. | ||
* </ul> | ||
* | ||
* @param request the servlet request | ||
* @return credentials or <code>null</code>. | ||
* @throws ServletException If an IOException occured while decoding the | ||
* Authorization header. | ||
* @throws LoginException if no suitable auth header and missing-auth-mapping | ||
* is not present | ||
*/ | ||
public Credentials getCredentials(HttpServletRequest request) | ||
throws LoginException, ServletException { | ||
try { | ||
String authHeader = request.getHeader(DavConstants.HEADER_AUTHORIZATION); | ||
if (authHeader != null) { | ||
String[] authStr = authHeader.split(" "); | ||
if (authStr.length >= 2 && authStr[0].equalsIgnoreCase(HttpServletRequest.BASIC_AUTH)) { | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
Base64.decode(authStr[1].toCharArray(), out); | ||
String decAuthStr = out.toString("ISO-8859-1"); | ||
int pos = decAuthStr.indexOf(':'); | ||
String userid = decAuthStr.substring(0, pos); | ||
String passwd = decAuthStr.substring(pos + 1); | ||
return new SimpleCredentials(userid, passwd.toCharArray()); | ||
} | ||
throw new ServletException("Unable to decode authorization."); | ||
} else { | ||
// check special handling | ||
if (defaultHeaderValue == null) { | ||
throw new LoginException(); | ||
} else if (defaultHeaderValue.equals("")) { | ||
return null; | ||
} else { | ||
int pos = defaultHeaderValue.indexOf(':'); | ||
if (pos<0) { | ||
return new SimpleCredentials(defaultHeaderValue, null); | ||
} else { | ||
return new SimpleCredentials( | ||
defaultHeaderValue.substring(0, pos), | ||
defaultHeaderValue.substring(pos+1).toCharArray() | ||
); | ||
} | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new ServletException("Unable to decode authorization: " + e.toString()); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
jcr-server/src/main/java/org/apache/jackrabbit/server/CredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.jackrabbit.server; | ||
|
||
import javax.jcr.Credentials; | ||
import javax.jcr.LoginException; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* This Interface defines a provider for the credentials. | ||
*/ | ||
public interface CredentialsProvider { | ||
|
||
/** | ||
* Extracts the credentials from the given servlet request. | ||
* | ||
* @param request | ||
* @return the credentials or null | ||
* @throws LoginException if the credentials are invalid | ||
* @throws ServletException if an error occurrs | ||
*/ | ||
public Credentials getCredentials(HttpServletRequest request) | ||
throws LoginException, ServletException; | ||
} |
51 changes: 51 additions & 0 deletions
51
jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.jackrabbit.server; | ||
|
||
import javax.jcr.LoginException; | ||
import javax.jcr.Repository; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* This Interface defines a provider for repository sessions | ||
*/ | ||
public interface SessionProvider { | ||
|
||
/** | ||
* Provides the repository session suitable for the given request. | ||
* | ||
* @param request | ||
* @param rep the repository to login | ||
* @param workspace the workspace name | ||
* @return the session or null | ||
* @throws LoginException if the credentials are invalid | ||
* @throws ServletException if an error occurrs | ||
*/ | ||
public Session getSession(HttpServletRequest request, Repository rep, String workspace) | ||
throws LoginException, ServletException, RepositoryException; | ||
|
||
/** | ||
* Informs this provider that the session aquired by a previous | ||
* {@link #getSession} call is no longer needed. | ||
* | ||
* @param session | ||
*/ | ||
public void releaseSession(Session session); | ||
} |
61 changes: 61 additions & 0 deletions
61
jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.jackrabbit.server; | ||
|
||
import javax.jcr.Credentials; | ||
import javax.jcr.LoginException; | ||
import javax.jcr.Repository; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* This Class implements a default session provider uses a credentials provider. | ||
*/ | ||
public class SessionProviderImpl implements SessionProvider { | ||
|
||
/** | ||
* the credentials provider | ||
*/ | ||
private CredentialsProvider cp; | ||
|
||
/** | ||
* Creates a new SessionProvider | ||
* @param cp | ||
*/ | ||
public SessionProviderImpl(CredentialsProvider cp) { | ||
this.cp = cp; | ||
} | ||
|
||
/** | ||
* {@inheritDoc } | ||
*/ | ||
public Session getSession(HttpServletRequest request, Repository repository, | ||
String workspace) | ||
throws LoginException, RepositoryException, ServletException { | ||
Credentials creds = cp.getCredentials(request); | ||
return repository.login(creds, workspace); | ||
} | ||
|
||
/** | ||
* {@inheritDoc } | ||
*/ | ||
public void releaseSession(Session session) { | ||
session.logout(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
jcr-server/src/main/java/org/apache/jackrabbit/server/io/AbstractExportContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.jackrabbit.server.io; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.jcr.Item; | ||
|
||
/** | ||
* <code>AbstractExportContext</code> covers methods common to most ExportContext | ||
* implementations. | ||
*/ | ||
public abstract class AbstractExportContext implements ExportContext { | ||
|
||
private static Logger log = LoggerFactory.getLogger(AbstractExportContext.class); | ||
|
||
private final IOListener ioListener; | ||
private final Item exportRoot; | ||
private final boolean hasStream; | ||
|
||
protected boolean completed; | ||
|
||
public AbstractExportContext(Item exportRoot, boolean hasStream, IOListener ioListener) { | ||
this.exportRoot = exportRoot; | ||
this.hasStream = hasStream; | ||
this.ioListener = (ioListener != null) ? ioListener : new DefaultIOListener(log); | ||
} | ||
|
||
public IOListener getIOListener() { | ||
return ioListener; | ||
} | ||
|
||
public Item getExportRoot() { | ||
return exportRoot; | ||
} | ||
|
||
public boolean hasStream() { | ||
return hasStream; | ||
} | ||
|
||
public void informCompleted(boolean success) { | ||
completed = true; | ||
} | ||
|
||
public boolean isCompleted() { | ||
return completed; | ||
} | ||
|
||
protected void checkCompleted() { | ||
if (completed) { | ||
throw new IllegalStateException("ExportContext has already been finalized."); | ||
} | ||
} | ||
} |
Oops, something went wrong.