Skip to content

Commit

Permalink
Added authentication response bean for convenience.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jun 8, 2016
1 parent 2f5bb0d commit d360d34
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
@@ -0,0 +1,35 @@
package org.rapidoid.security;

/*
* #%L
* rapidoid-commons
* %%
* Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import org.rapidoid.RapidoidThing;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;

@Authors("Nikolche Mihajlovski")
@Since("5.1.7")
public class AuthResponse extends RapidoidThing {

public boolean success;

public String token;

}
1 change: 1 addition & 0 deletions rapidoid-commons/src/main/resources/rapidoid-classes.txt
Expand Up @@ -535,6 +535,7 @@ org.rapidoid.security.annotation.Manager
org.rapidoid.security.annotation.Moderator
org.rapidoid.security.annotation.Roles
org.rapidoid.security.Auth
org.rapidoid.security.AuthResponse
org.rapidoid.security.DataPermissions
org.rapidoid.security.Role
org.rapidoid.security.Secure
Expand Down
Expand Up @@ -7,9 +7,7 @@
import org.rapidoid.http.Req;
import org.rapidoid.http.ReqRespHandler;
import org.rapidoid.http.Resp;
import org.rapidoid.u.U;

import java.util.Map;
import org.rapidoid.security.AuthResponse;

/*
* #%L
Expand All @@ -36,15 +34,17 @@
public class LoginHandler extends RapidoidThing implements ReqRespHandler {

@Override
public Map<String, ?> execute(Req req, Resp resp) throws Exception {
public AuthResponse execute(Req req, Resp resp) throws Exception {
AuthResponse auth = new AuthResponse();

String username = req.data("username");
String password = req.data("password");

boolean ok = resp.login(username, password);
auth.success = resp.login(username, password);

String token = ok ? HttpUtils.token(req.cookiepack()) : "";
auth.token = auth.success ? HttpUtils.token(req.cookiepack()) : "";

return U.map("success", ok, "token", token);
return auth;
}

}

0 comments on commit d360d34

Please sign in to comment.