/** * Returns the secret provided by the user. * * @param request * The request to inspect. * @param response * The response to inspect. * @return The secret provided by the user. */ protected char[] getSecret(Request request, Response response) { return request.getChallengeResponse().getSecret(); }
@Override public void formatCredentials( StringBuilder sb, ChallengeResponse challenge, Request request, Series<Parameter> httpHeaders ) { try { final String credentials = challenge.getIdentifier() + ':' + new String( challenge.getSecret() ); sb.append( Base64.encode( credentials.getBytes( "US-ASCII" ), false ) ); } catch ( final UnsupportedEncodingException e ) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials" ); } }
@Override public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { try { final CharArrayWriter credentials = new CharArrayWriter(); credentials.write("^@"); credentials.write(challenge.getIdentifier()); credentials.write("^@"); credentials.write(challenge.getSecret()); cw.append(Base64.encode(credentials.toCharArray(), "US-ASCII", false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials"); } catch (IOException e) { throw new RuntimeException( "Unexpected exception, unable to encode credentials", e); } }
@Override public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { try { if (challenge == null) { throw new RuntimeException( "No challenge provided, unable to encode credentials"); } else { CharArrayWriter credentials = new CharArrayWriter(); credentials.write(challenge.getIdentifier()); credentials.write(":"); credentials.write(challenge.getSecret()); cw.append(Base64.encode(credentials.toCharArray(), "ISO-8859-1", false)); } } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials"); } catch (IOException e) { throw new RuntimeException( "Unexpected exception, unable to encode credentials", e); } }
sb.append(challenge.getSecret());
public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { cw.append("id=\""); cw.append(challenge.getIdentifier()); cw.append("\",ts=\""); cw.append((new Date()).getTime()); cw.append("\",nonce=\""); String nonce = CryptoUtils.makeNonce(String.valueOf(challenge .getSecret())); cw.append(nonce); cw.append("\",mac=\""); cw.append(String.valueOf(challenge.getSecret())); cw.append("\""); } }
@SubResource public void administration() { ChallengeResponse challenge = Request.getCurrent().getChallengeResponse(); if( challenge == null ) { Response.getCurrent() .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) ); throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() ); if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) ) { throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } current().select( user ); subResource( AdministrationResource.class ); }
@Override protected void afterHandle(Request request, Response response) { super.afterHandle(request, response); Cookie cookie = request.getCookies().getFirst("Credentials"); if (request.getClientInfo().isAuthenticated() && (cookie == null)) { String identifier = request.getChallengeResponse().getIdentifier(); String secret = new String(request.getChallengeResponse() .getSecret()); CookieSetting cookieSetting = new CookieSetting("Credentials", identifier + "=" + secret); cookieSetting.setAccessRestricted(true); cookieSetting.setPath("/"); cookieSetting.setComment("Unsecured cookie based authentication"); cookieSetting.setMaxAge(30); response.getCookieSettings().add(cookieSetting); } }
@Override protected void afterHandle(Request request, Response response) { super.afterHandle(request, response); Cookie cookie = request.getCookies().getFirst("Credentials"); if (request.getClientInfo().isAuthenticated() && (cookie == null)) { String identifier = request.getChallengeResponse().getIdentifier(); String secret = new String(request.getChallengeResponse() .getSecret()); CookieSetting cookieSetting = new CookieSetting("Credentials", identifier + "=" + secret); cookieSetting.setAccessRestricted(true); cookieSetting.setPath("/"); cookieSetting.setComment("Unsecured cookie based authentication"); cookieSetting.setMaxAge(30); response.getCookieSettings().add(cookieSetting); } }
clientSecret = cr.getSecret();
String identifier = request.getChallengeResponse() .getIdentifier(); char[] secret = request.getChallengeResponse().getSecret(); UserIdentifier userIdentifier = new UserIdentifier(identifier, secret);
String identifier = request.getChallengeResponse() .getIdentifier(); char[] secret = request.getChallengeResponse().getSecret(); UserIdentifier userIdentifier = new UserIdentifier(identifier, secret);
String identifier = request.getChallengeResponse() .getIdentifier(); char[] secret = request.getChallengeResponse().getSecret(); UserIdentifier userIdentifier = new UserIdentifier(identifier, secret);
String identifier = request.getChallengeResponse() .getIdentifier(); char[] secret = request.getChallengeResponse().getSecret(); UserIdentifier userIdentifier = new UserIdentifier(identifier, secret);