-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds basic authentication handling while performing REST actions
Returns HTTP code 401 with the WWW-Authenticate header whenever the checkAccess method throw an ERXBasicAuthenticationException.
- Loading branch information
1 parent
9b90f9a
commit ef680a9
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
Frameworks/EOF/ERRest/Sources/er/rest/ERXBasicAuthenticationException.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,78 @@ | ||
package er.rest; | ||
|
||
|
||
/** | ||
* Basic Authentication Exception. | ||
* | ||
* <p> | ||
* This class responsible for exception when use Basic Authentication. | ||
* | ||
* This exception can be used with checkAcces method of ERXRouteController class. | ||
* </p> | ||
* | ||
* <b>Example</b> | ||
* | ||
* <pre> | ||
* protected void checkAccess() throws SecurityException { | ||
* throw new ERXBasicAuthenticationException("invalid credentials"); | ||
* } | ||
* </pre> | ||
*/ | ||
public class ERXBasicAuthenticationException extends SecurityException { | ||
|
||
private final String basicRealm; | ||
|
||
/** | ||
* Creates a <code>ERXBasicAuthenticationException</code> with the specified | ||
* detail message and cause. | ||
* | ||
* For @param basicRealm use default 'application'. | ||
* | ||
* @param message the detail message (which is saved for later retrieval | ||
* by the {@link #getMessage()} method). | ||
*/ | ||
public ERXBasicAuthenticationException(String message) { | ||
this(message, "application"); | ||
} | ||
|
||
/** | ||
* Creates a <code>ERXBasicAuthenticationException</code> with the specified | ||
* detail message and cause. | ||
* | ||
* @param message the detail message (which is saved for later retrieval | ||
* by the {@link #getMessage()} method). | ||
* @param basicRealm message about server authentication requested for user. | ||
*/ | ||
public ERXBasicAuthenticationException(String message, String basicRealm) { | ||
super(message); | ||
|
||
this.basicRealm = basicRealm; | ||
} | ||
|
||
/** | ||
* Creates a <code>ERXBasicAuthenticationException</code> with the specified | ||
* detail message and cause. | ||
* | ||
* @param message the detail message (which is saved for later retrieval | ||
* by the {@link #getMessage()} method). | ||
* @param cause the cause (which is saved for later retrieval by the | ||
* {@link #getCause()} method). (A <tt>null</tt> value is permitted, | ||
* and indicates that the cause is nonexistent or unknown.) | ||
* @param basicRealm message about server authentication requested for user. | ||
*/ | ||
public ERXBasicAuthenticationException(String message, Throwable cause, String basicRealm) { | ||
super(message, cause); | ||
|
||
this.basicRealm = basicRealm; | ||
} | ||
|
||
/** | ||
* Message about server authentication. | ||
* | ||
* @return basicRealm message | ||
*/ | ||
public String basicRealm() { | ||
return basicRealm; | ||
} | ||
|
||
} |
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