| | |
| | | { |
| | | String key = UUID.randomUUID().toString(); |
| | | UserSessionModel userSession = clientSession.getUserSession(); |
| | | OAuth2Code codeData = new OAuth2Code(key, clientSession.getClient().getId(), Time.currentTime() + userSession.getRealm().getAccessCodeLifespan(), null, null, null, redirectUriParam, null, null, null, userSession.getId()); |
| | | OAuth2Code codeData = new OAuth2Code(key, clientSession.getClient().getId(), Time.currentTime() + userSession.getRealm().getAccessCodeLifespan(), null, null, null, redirectUriParam, null, null, null, userSession.getId(), userSession.getUser().getId()); |
| | | session.singleUseObjects().put(prefix + key, clientSession.getUserSession().getRealm().getAccessCodeLifespan(), codeData.serializeCode()); |
| | | return prefix + key + "--" + hexEncode(clientSession.getUserSession().getId()) + "--" + clientSession.getClient().getId(); |
| | | } |
| | |
| | | } |
| | | |
| | | private String hexDecode(String hex) { |
| | | byte[] bytes = HexFormat.of().parseHex(hex); |
| | | return new String(bytes, StandardCharsets.US_ASCII); |
| | | try { |
| | | byte[] bytes = HexFormat.of().parseHex(hex); |
| | | return new String(bytes, StandardCharsets.US_ASCII); |
| | | } catch (IllegalArgumentException e) { |
| | | event.error(Errors.INVALID_CODE); |
| | | throw new CASValidationException(CASErrorCode.INVALID_TICKET_SPEC, "Invalid format of the code", Response.Status.BAD_REQUEST); |
| | | } |
| | | } |
| | | } |