Skip to content

Commit

Permalink
#231 Make PluginException correspond to PersoniumCoreAuthnException.
Browse files Browse the repository at this point in the history
  • Loading branch information
SawamiWataru committed Jul 9, 2018
1 parent d8dc961 commit 1d943a5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 45 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<dependency>
<groupId>io.personium</groupId>
<artifactId>personium-plugin-base</artifactId>
<version>1.0.5</version>
<version>1.0.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.personium</groupId>
<artifactId>personium-plugins</artifactId>
<version>1.0.4</version>
<version>1.0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.personium</groupId>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/personium/core/PersoniumCoreAuthnException.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.personium.core.auth.OAuth2Helper.Scheme;
import io.personium.core.utils.EscapeControlCode;
import io.personium.plugin.base.PluginMessageUtils.Severity;
import io.personium.plugin.base.auth.AuthPluginException;

/**
* ログメッセージ作成クラス.
Expand Down Expand Up @@ -247,6 +248,23 @@ public static PersoniumCoreAuthnException create(String code, String error) {
return new PersoniumCoreAuthnException(code, severity, message, statusCode, error, null);
}

/**
* Factory method.
* @param authPluginException AuthPluginException
* @return PersoniumCoreAuthnException
*/
public static PersoniumCoreAuthnException create(AuthPluginException authPluginException) {
int statusCode = authPluginException.getStatusCode();
Severity severity = decideSeverity(statusCode);
StringBuilder builder = new StringBuilder();
builder.append("PR").append(statusCode).append("-PA-0001");
String errorCode = builder.toString();
String message = PersoniumCoreMessageUtils.getMessage(errorCode);
message = MessageFormat.format(message, authPluginException.getMessage());
String oAuthError = authPluginException.getOAuthError();
return new PersoniumCoreAuthnException(errorCode, severity, message, statusCode, oAuthError, null);
}

/**
* メッセージをパラメタ置換したものを作成して返します. エラーメッセージ上の $1 $2 等の表現がパラメタ置換用キーワードです。
* @param params 付加メッセージ
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/io/personium/core/PersoniumCoreException.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import io.personium.core.exceptions.ODataErrorMessage;
import io.personium.core.utils.EscapeControlCode;
import io.personium.plugin.base.PluginException;
import io.personium.plugin.base.PluginMessageUtils.Severity;

/**
Expand Down Expand Up @@ -953,17 +952,6 @@ public static class Common {
* Pluginエラー.
*/
public static class Plugin {
// "PL-0001" is used only with create(PluginException).
// /**
// * プラグイン作者が定義したエラー.
// */
// public static final PersoniumCoreException PLUGIN_DEFINED_ERROR = create("PL-0001");

/**
* プラグイン認証失敗.
*/
public static final PersoniumCoreException PLUGIN_AUTHN_FAILED = create("PR400-PL-0001");

/**
* プラグイン内部でキャッチされず、外に出てきてしまった非チェック例外に対応.
*/
Expand Down Expand Up @@ -1114,19 +1102,6 @@ public static PersoniumCoreException create(String code) {
return new PersoniumCoreException(code, severity, message, statusCode);
}

/**
* Factory method.
* @param pluginException PluginException
* @return PersoniumCoreException
*/
public static PersoniumCoreException create(PluginException pluginException) {
int statusCode = pluginException.getStatusCode();
Severity severity = decideSeverity(statusCode);
String message = PersoniumCoreMessageUtils.getMessage("PL-0001");
message = MessageFormat.format(message, pluginException.getMessage());
return new PersoniumCoreException("PL-0001", severity, message, statusCode);
}

/**
* レスポンスコードからログレベルの判定.
* @param statusCode ステータスコード
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/personium/core/model/DavRsCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,14 @@ static final org.apache.wink.webdav.model.Response createDavResponse(final Strin
Element element = WebDAVModelHelper.createElement(qname);
element.setTextContent(dCmp.getCellStatus());
ret.setPropertyOk(element);
} else if (DavCmp.TYPE_NULL.equals(type)) {
// If TYPE_NULL, not display anything.
ret.getHref().remove(href);
} else {
// Collection Resource
Resourcetype colRt = of.createResourcetype();
colRt.setCollection(of.createCollection());
ret.setPropertyOk(colRt);

}

// Processing ACL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
import io.personium.core.rs.PersoniumCoreApplication;
import io.personium.core.utils.UriUtils;
import io.personium.plugin.base.Plugin;
import io.personium.plugin.base.PluginException;
import io.personium.plugin.base.auth.AuthPlugin;
import io.personium.plugin.base.auth.AuthPluginException;
import io.personium.plugin.base.auth.AuthenticatedIdentity;

/**
Expand Down Expand Up @@ -305,37 +305,37 @@ private Response callAuthPlugins(String grantType, MultivaluedMap<String, String
Object plugin = (Plugin) pi.getObj();
try {
ai = ((AuthPlugin) plugin).authenticate(body);
} catch (PluginException pe) {
throw PersoniumCoreException.create(pe);
} catch (AuthPluginException ape) {
throw PersoniumCoreAuthnException.create(ape);
} catch (Exception e) {
// Unexpected exception throwed from "Plugin", create default PersoniumCoreAuthException
// and set reason from catched Exception.
throw PersoniumCoreException.Plugin.UNEXPECTED_ERROR.reason(e);
}

if (ai == null) {
throw PersoniumCoreException.Plugin.PLUGIN_AUTHN_FAILED;
throw PersoniumCoreAuthnException.AUTHN_FAILED;
}
String accountName = ai.getAccountName();
String accountType = ai.getAccountType();
if (accountName == null || accountType == null) {
throw PersoniumCoreAuthnException.Plugin.PLUGIN_AUTHN_FAILED;
throw PersoniumCoreAuthnException.AUTHN_FAILED;
}

// If the Account shown in IdToken does not exist in cell.
OEntityWrapper idTokenUserOew = cell.getAccount(accountName);
if (idTokenUserOew == null) {
// アカウントの存在確認に悪用されないように、失敗の旨のみのエラー応答
PersoniumCoreLog.OIDC.NO_SUCH_ACCOUNT.params(accountName).writeLog();
throw PersoniumCoreAuthnException.Plugin.PLUGIN_AUTHN_FAILED;
throw PersoniumCoreAuthnException.AUTHN_FAILED;
}

// Confirm if OidC is included in Type when there is Account.
if (!AuthUtils.getAccountType(idTokenUserOew).contains(accountType)) {
// アカウントの存在確認に悪用されないように、失敗の旨のみのエラー応答
PersoniumCoreLog.OIDC.UNSUPPORTED_ACCOUNT_GRANT_TYPE.params(accountType,
accountName).writeLog();
throw PersoniumCoreAuthnException.Plugin.PLUGIN_AUTHN_FAILED;
throw PersoniumCoreAuthnException.AUTHN_FAILED;
}

// When processing is normally completed, issue a token.
Expand Down
15 changes: 5 additions & 10 deletions src/main/resources/personium-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,6 @@ io.personium.core.msg.PR500-NW-0001=HTTP {0} request to {1} failed. Response cod
io.personium.core.msg.PR500-NW-0002=Unexpected response from {0}, where {1} expected.
io.personium.core.msg.PR500-NW-0003=Unexpected value from key={0}, where "{1}" value expected.

## NetWork
io.personium.core.msg.PR500-NW-0000=Network error. {0}
io.personium.core.msg.PR500-NW-0001=HTTP {0} request to {1} failed. Response code : {2}.
io.personium.core.msg.PR500-NW-0002=Unexpected response from {0}, where {1} expected.
io.personium.core.msg.PR500-NW-0003=Unexpected value from key={0}, where "{1}" value expected.

## Misc
# PR405-MC
io.personium.core.msg.PR400-MC-0001=[{0}] does not exist in the snapshot file.
Expand All @@ -360,12 +354,13 @@ io.personium.core.msg.PR500-CM-0001=Failed to load the request body for some rea
io.personium.core.msg.PR500-CM-0002=Files I/O error caused [{0}] to fail.

## Plugin
# PluginException
io.personium.core.msg.PL-0001=Plugin error. [{0}].
# PR400-PL
io.personium.core.msg.PR400-PL-0001=Plugin authentication failed.
# PR500-PL
io.personium.core.msg.PR500-PL-0001=Unchecked exception not caught inside the plugin.
# AuthPluginException
io.personium.core.msg.PR400-PA-0001=AuthPlugin authentication failed. [{0}].
io.personium.core.msg.PR401-PA-0001=AuthPlugin authentication failed. [{0}].
io.personium.core.msg.PR500-PA-0001=AuthPlugin authentication error. [{0}].
io.personium.core.msg.PR503-PA-0001=AuthPlugin authentication error. [{0}].

### PL LogMessage
## ODATA
Expand Down

0 comments on commit 1d943a5

Please sign in to comment.