Skip to content

Commit

Permalink
WIP (it compiles!)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpurdy committed Nov 22, 2024
1 parent 6c0fb22 commit a53a0a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
25 changes: 17 additions & 8 deletions lib_xenia/src/main/x/xenia/ChainBundle.x
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import web.AcceptList;
import web.Body;
import web.BodyParam;
import web.ErrorHandler;
import web.Header;
import web.HttpMethod;
import web.HttpStatus;
import web.MediaType;
Expand Down Expand Up @@ -354,10 +355,10 @@ service ChainBundle {
// is it a principal or an entitlement?
val claim = attempt.claim;
if (claim.is(Principal)) {
principals = principals.addIfAbsent(claim);
principals := principals.addIfAbsent(claim);
} else {
assert claim.is(Entitlement);
entitlements = entitlements.addIfAbsent(claim);
entitlements := entitlements.addIfAbsent(claim);
}
break;
}
Expand Down Expand Up @@ -392,10 +393,10 @@ service ChainBundle {
SimpleResponse response = new SimpleResponse(status);
for (Attempt attempt : failures) {
if (String header := attempt.response.is(String)) {
response.header.add(WWWAuthenticate, header);
response.header.add(Header.WWWAuthenticate, header);
} else if (String[] headers := attempt.response.is(String[])) {
for (String header : headers) {
response.header.add(WWWAuthenticate, header);
response.header.add(Header.WWWAuthenticate, header);
}
}
}
Expand All @@ -407,8 +408,8 @@ service ChainBundle {
for (Entitlement entitlement : entitlements) {
Int pid = entitlement.principalId;
if (entitlement.conferIdentity && !principals.any(p -> p.principalId == pid)) {
if (Principal principal := realm.readPrincipal(pid)) {
principals = principals.addIfAbsent(principal);
if (Principal principal := authenticator.realm.readPrincipal(pid)) {
principals := principals.addIfAbsent(principal);
} else {
// TODO log failure?
}
Expand Down Expand Up @@ -442,21 +443,29 @@ service ChainBundle {
return True, new SimpleResponse(Forbidden);
};

/**
* Log a failed authentication.
*/
private void failedAuth(RequestIn request, Session? session, Attempt attempt) {
// TODO
}

/**
* Determine if the specified [Permission]/check is allowed using information from the
* session.
*/
private Boolean checkSessionApproval(Session session,
Permission permission, (function Boolean())? accessGranted) {
Permission? permission, (function Boolean())? accessGranted) {
return checkApproval(session.principal, session.entitlements, permission, accessGranted);
}

/**
* Determine if the specified [Permission]/check is allowed.
*/
private Boolean checkApproval(Principal? principal, Entitlement[] entitlements,
Permission permission, (function Boolean())? accessGranted) {
Permission? permission, (function Boolean())? accessGranted) {
if (permission != Null) {
Realm realm = authenticator.realm;
return principal?.permitted(realm, permission);
return entitlements.any(e -> e.permitted(realm, permission));
}
Expand Down
12 changes: 7 additions & 5 deletions lib_xenia/src/main/x/xenia/SessionImpl.x
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,18 @@ service SessionImpl

@Override
void deauthenticate() {
if (String oldUser ?= userId) {
userId = Null;
Principal? oldPrincipal = principal;
Entitlement[] oldEntitlements = entitlements;
if (oldPrincipal != Null || !oldEntitlements.empty) {
principal = Null;
entitlements = [];
exclusiveAgent = False;
trustLevel = None;
roles = [];
lastAuthenticated = Null;

issueEvent_(SessionDeauthenticated, Void, &sessionDeauthenticated(oldUser),
issueEvent_(SessionDeauthenticated, Void, &sessionDeauthenticated(oldPrincipal, oldEntitlements),
() -> $|An exception in session {this.internalId_} occurred during a\
| deauthentication event for user {oldUser.quoted()}
| deauthentication event
);
}
}
Expand Down

0 comments on commit a53a0a0

Please sign in to comment.